From 6faabe34e8a56e247953be631a6af31a132b8b0b Mon Sep 17 00:00:00 2001 From: Andy Lo-A-Foe Date: Tue, 19 Jan 2016 19:41:39 +0100 Subject: Optionally specify ws:// and wss:// port in config --- web/react/stores/socket_store.jsx | 2 +- web/react/utils/utils.jsx | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'web') diff --git a/web/react/stores/socket_store.jsx b/web/react/stores/socket_store.jsx index 24fa79ca6..f1fade305 100644 --- a/web/react/stores/socket_store.jsx +++ b/web/react/stores/socket_store.jsx @@ -49,7 +49,7 @@ class SocketStoreClass extends EventEmitter { protocol = 'wss://'; } - var connUrl = protocol + location.host + '/api/v1/websocket?' + Utils.getSessionIndex(); + var connUrl = protocol + location.host + ((/:\d+/).test(location.host) ? '' : Utils.getWebsocketPort(protocol)) + '/api/v1/websocket?' + Utils.getSessionIndex(); if (this.failCount === 0) { console.log('websocket connecting to ' + connUrl); //eslint-disable-line no-console diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 24042321f..92ad82739 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -1101,6 +1101,17 @@ export function getFileName(path) { return split[split.length - 1]; } +// Gets the websocket port to use. Configurable on the server. +export function getWebsocketPort(protocol) { + if ((/^wss:/).test(protocol)) { // wss:// + return ':' + global.window.mm_config.WebsocketSecurePort; + } + if ((/^ws:/).test(protocol)) { + return ':' + global.window.mm_config.WebsocketPort; + } + return ''; +} + export function getSessionIndex() { if (global.window.mm_session_token_index >= 0) { return 'session_token_index=' + global.window.mm_session_token_index; -- cgit v1.2.3-1-g7c22