diff --git a/core/config.js b/core/config.js index 04729903..25e409f4 100644 --- a/core/config.js +++ b/core/config.js @@ -225,13 +225,12 @@ function getDefaultConfig() { firstMenuNewUser : 'sshConnectedNewUser', }, webSocket : { - port : 8810, - enabled : true, // :TODO: default to false - }, - secureWebSocket : { - port : 8811, + port : 8810, // ws:// enabled : false, - } + securePort : 8811, // wss:// - must provide certPem and keyPem + certPem : paths.join(__dirname, './../misc/https_cert.pem'), + keyPem : paths.join(__dirname, './../misc/https_cert_key.pem'), + }, }, contentServers : { diff --git a/core/servers/login/websocket.js b/core/servers/login/websocket.js index 4b73bcd3..3cad496e 100644 --- a/core/servers/login/websocket.js +++ b/core/servers/login/websocket.js @@ -28,6 +28,10 @@ function WebSocketClient(ws, req, serverType) { get : () => 'secure' === serverType ? true : false, }); + // + // This bridge makes accessible various calls that client sub classes + // want to access on I/O socket + // this.socketBridge = new class SocketBridge extends EventEmitter { constructor(ws) { super(); @@ -84,10 +88,12 @@ exports.getModule = class WebSocketLoginServer extends LoginServerModule { // * insecure websocket (ws://) // * secure (tls) websocket (wss://) // - const insecureConf = _.get(Config, 'loginServers.webSocket') || { enabled : false }; - const secureConf = _.get(Config, 'loginServers.secureWebSocket') || { enabled : false }; + const config = _.get(Config, 'loginServers.webSocket') || { enabled : false }; + if(!config || true !== config.enabled || !(config.port || config.securePort)) { + return; + } - if(insecureConf.enabled) { + if(config.port) { const httpServer = http.createServer( (req, resp) => { // dummy handler resp.writeHead(200); @@ -100,10 +106,10 @@ exports.getModule = class WebSocketLoginServer extends LoginServerModule { }; } - if(secureConf.enabled) { + if(config.securePort) { const httpServer = https.createServer({ - key : fs.readFileSync(Config.loginServers.secureWebSocket.keyPem), - cert : fs.readFileSync(Config.loginServers.secureWebSocket.certPem), + key : fs.readFileSync(Config.loginServers.webSocket.keyPem), + cert : fs.readFileSync(Config.loginServers.webSocket.certPem), }); this.secure = { @@ -113,10 +119,6 @@ exports.getModule = class WebSocketLoginServer extends LoginServerModule { } } - configName(serverType) { - return 'secure' === serverType ? 'secureWebSocket' : 'webSocket'; - } - listen() { WSS_SERVER_TYPES.forEach(serverType => { const server = this[serverType]; @@ -125,7 +127,7 @@ exports.getModule = class WebSocketLoginServer extends LoginServerModule { } const serverName = `${ModuleInfo.name} (${serverType})`; - const port = parseInt( _.get( Config, [ 'loginServers', this.configName(serverType), 'port' ] ) ); + const port = parseInt(_.get(Config, [ 'loginServers', 'webSocket', 'secure' === serverType ? 'securePort' : 'port' ] )); if(isNaN(port)) { Log.error( { server : serverName, port : port }, 'Cannot load server (invalid port)' );