Improve the server so that both protocol (WebSocket and WebRTC) can use the same port

pull/1/head
Yann Flory 9 years ago
parent 7ee75b9e7f
commit c7d190f1c0

@ -157,6 +157,7 @@ let run = module.exports.run = function (storage, socketServer) {
}); });
}, 5000); }, 5000);
socketServer.on('connection', function(socket) { socketServer.on('connection', function(socket) {
if(socket.upgradeReq.url !== '/cryptpad_websocket') { return; }
let conn = socket.upgradeReq.connection; let conn = socket.upgradeReq.connection;
let user = { let user = {
addr: conn.remoteAddress + '|' + conn.remotePort, addr: conn.remoteAddress + '|' + conn.remotePort,

@ -6,6 +6,7 @@ const CLOSE_UNSUPPORTED = 1003
var run = module.exports.run = function(server) { var run = module.exports.run = function(server) {
server.on('connection', (socket) => { server.on('connection', (socket) => {
if(socket.upgradeReq.url !== '/cryptpad_webrtc') { return; }
socket.on('message', (data) => { socket.on('message', (data) => {
try { try {
let msg = JSON.parse(data) let msg = JSON.parse(data)

@ -11,8 +11,6 @@ module.exports = {
httpPort: 3000, httpPort: 3000,
// the port used for websockets // the port used for websockets
websocketPort: 3001, websocketPort: 3001,
// the port used for webrtc (uncomment to use the WebRTC server)
// webrtcPort: 3002,
// You now have a choice of storage engines // You now have a choice of storage engines

@ -63,8 +63,8 @@ app.get('/api/config', function(req, res){
res.send('define(' + JSON.stringify({ res.send('define(' + JSON.stringify({
websocketURL:'ws' + ((httpsOpts) ? 's' : '') + '://' + host + ':' + websocketURL:'ws' + ((httpsOpts) ? 's' : '') + '://' + host + ':' +
config.websocketPort + '/cryptpad_websocket', config.websocketPort + '/cryptpad_websocket',
webrtcURL: (config.webrtcPort) ? 'ws' + ((httpsOpts) ? 's' : '') + '://' + host + ':' + webrtcURL:'ws' + ((httpsOpts) ? 's' : '') + '://' + host + ':' +
config.webrtcPort : '' config.websocketPort + '/cryptpad_webrtc',
}) + ');'); }) + ');');
}); });
@ -74,7 +74,6 @@ httpServer.listen(config.httpPort,config.httpAddress,function(){
console.log('listening on %s',config.httpPort); console.log('listening on %s',config.httpPort);
}); });
if(config.websocketPort) {
var wsConfig = { server: httpServer }; var wsConfig = { server: httpServer };
if (config.websocketPort !== config.httpPort) { if (config.websocketPort !== config.httpPort) {
console.log("setting up a new websocket server"); console.log("setting up a new websocket server");
@ -83,22 +82,6 @@ if(config.websocketPort) {
var wsSrv = new WebSocketServer(wsConfig); var wsSrv = new WebSocketServer(wsConfig);
Storage.create(config, function (store) { Storage.create(config, function (store) {
console.log('DB connected'); console.log('DB connected');
// ChainPadSrv.create(wsSrv, store);
NetfluxSrv.run(store, wsSrv); NetfluxSrv.run(store, wsSrv);
//WebRTCSrv.run(store, wsSrv); WebRTCSrv.run(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);
// });
}

Loading…
Cancel
Save