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);
socketServer.on('connection', function(socket) {
if(socket.upgradeReq.url !== '/cryptpad_websocket') { return; }
let conn = socket.upgradeReq.connection;
let user = {
addr: conn.remoteAddress + '|' + conn.remotePort,

@ -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)

@ -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

@ -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);
});

Loading…
Cancel
Save