simple echo server for sake of testing connection-ability

This commit is contained in:
shockrah 2020-12-06 14:49:46 -08:00
parent 27c0af5b8d
commit 455f6ed6b3
2 changed files with 36 additions and 16 deletions

View File

@ -1 +1,3 @@
node_modules/
node_modules/
cert.pem
key.pem

View File

@ -1,22 +1,40 @@
const express = require('express')
const socketio = require('socket.io')({
serveClient: false
'use strict';
const https = require('https')
const WebSocket = require('ws')
const WebSocketServer = require('wss')
const fs = require('fs')
const serverConfig = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
}
const httpServer = https.createServer(serverConfig, (req, res) => {
res.writeHead(200)
res.end()
})
const app = express()
httpServer.listen(3535, '0.0.0.0')
var http = require('http').Server(app);
var io = require('socket.io')(http)
// Now for the websockets server
const port = process.env.PORT || 3000
const wss = new WebSocketServer({server: httpServer})
wss.on('connection', function(socket) {
socket.on('message', function(message) {
console.log('Socket received message: ', message)
wss.broadcast(message)
})
})
// Signals and shit yo
io.on('connection', function(socket) {
// do some kind of header auth checking here
console.log('New connection')
wss.broadcast = function(data) {
console.log('Cuurent clients list: ', this.clients)
this.clients.forEach(client => {
if(client.readyState == WebSocket.OPEN) {
client.send(data)
}
})
}
socket.on('create or join', function(room_id) {
let room = io.sockets.adapter.rooms
})
})
console.log('serving on https://localhost:3535')