diff --git a/NetFluxWebsocketServer.js b/NetFluxWebsocketServer.js index 113e8ded9..005cdcc6b 100644 --- a/NetFluxWebsocketServer.js +++ b/NetFluxWebsocketServer.js @@ -157,6 +157,7 @@ let run = module.exports.run = function (storage, socketServer) { }); }, 5000); socketServer.on('connection', function(socket) { + if(socket.upgradeReq.url !== '/cryptpad_websocket') { return; } let conn = socket.upgradeReq.connection; let user = { addr: conn.remoteAddress + '|' + conn.remotePort, diff --git a/WebRTCSrv.js b/WebRTCSrv.js index ffcde5c53..172d9f756 100644 --- a/WebRTCSrv.js +++ b/WebRTCSrv.js @@ -6,6 +6,7 @@ const CLOSE_UNSUPPORTED = 1003 var run = module.exports.run = function(server) { server.on('connection', (socket) => { + if(socket.upgradeReq.url !== '/cryptpad_webrtc') { return; } socket.on('message', (data) => { try { let msg = JSON.parse(data) diff --git a/config.js.dist b/config.js.dist index 56d7a1fc8..f61828e4c 100644 --- a/config.js.dist +++ b/config.js.dist @@ -11,8 +11,6 @@ module.exports = { httpPort: 3000, // the port used for websockets websocketPort: 3001, - // the port used for webrtc (uncomment to use the WebRTC server) - // webrtcPort: 3002, // You now have a choice of storage engines diff --git a/server.js b/server.js index a9100813e..f1eda1346 100644 --- a/server.js +++ b/server.js @@ -63,8 +63,8 @@ app.get('/api/config', function(req, res){ res.send('define(' + JSON.stringify({ websocketURL:'ws' + ((httpsOpts) ? 's' : '') + '://' + host + ':' + config.websocketPort + '/cryptpad_websocket', - webrtcURL: (config.webrtcPort) ? 'ws' + ((httpsOpts) ? 's' : '') + '://' + host + ':' + - config.webrtcPort : '' + webrtcURL:'ws' + ((httpsOpts) ? 's' : '') + '://' + host + ':' + + config.websocketPort + '/cryptpad_webrtc', }) + ');'); }); @@ -74,31 +74,14 @@ httpServer.listen(config.httpPort,config.httpAddress,function(){ console.log('listening on %s',config.httpPort); }); -if(config.websocketPort) { - var wsConfig = { server: httpServer }; - if (config.websocketPort !== config.httpPort) { - console.log("setting up a new websocket server"); - wsConfig = { port: config.websocketPort}; - } - var wsSrv = new WebSocketServer(wsConfig); - Storage.create(config, function (store) { - console.log('DB connected'); - // ChainPadSrv.create(wsSrv, store); - NetfluxSrv.run(store, wsSrv); - //WebRTCSrv.run(store, wsSrv); - }); -} -if(config.webrtcPort) { - var wrConfig = { server: httpServer }; - if (config.webrtcPort !== config.httpPort) { - console.log("setting up a new webrtc server"); - wrConfig = { port: config.webrtcPort}; - } - var wrSrv = new WebSocketServer(wrConfig); - WebRTCSrv.run(wrSrv); - // Storage.create(config, function (store) { - // console.log('DB connected for WebRTC'); - // ChainPadSrv.create(wsSrv, store); - //NetfluxSrv.run(store, wsSrv); - // }); +var wsConfig = { server: httpServer }; +if (config.websocketPort !== config.httpPort) { + console.log("setting up a new websocket server"); + wsConfig = { port: config.websocketPort}; } +var wsSrv = new WebSocketServer(wsConfig); +Storage.create(config, function (store) { + console.log('DB connected'); + NetfluxSrv.run(store, wsSrv); + WebRTCSrv.run(wsSrv); +});