diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-11-14 07:09:41 -0500 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-11-14 07:09:41 -0500 |
commit | 323ce8b203c570ed6a1dd57b44d6637ad8207616 (patch) | |
tree | efc3c61b905244bdb0e1ace0ce9f5ae4876644ad /webapp/actions/websocket_actions.jsx | |
parent | d1207d34c1d99eba9ebf85c98d267ee7e955ea7d (diff) | |
parent | b55ec6148caa93d54b660afe55408c643d217108 (diff) | |
download | chat-323ce8b203c570ed6a1dd57b44d6637ad8207616.tar.gz chat-323ce8b203c570ed6a1dd57b44d6637ad8207616.tar.bz2 chat-323ce8b203c570ed6a1dd57b44d6637ad8207616.zip |
Merge branch 'release-3.5'
Diffstat (limited to 'webapp/actions/websocket_actions.jsx')
-rw-r--r-- | webapp/actions/websocket_actions.jsx | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/webapp/actions/websocket_actions.jsx b/webapp/actions/websocket_actions.jsx index 431922b0d..36c6cbdc9 100644 --- a/webapp/actions/websocket_actions.jsx +++ b/webapp/actions/websocket_actions.jsx @@ -30,34 +30,37 @@ import {browserHistory} from 'react-router/es6'; const MAX_WEBSOCKET_FAILS = 7; export function initialize() { - if (window.WebSocket) { - let connUrl = Utils.getSiteURL(); + if (!window.WebSocket) { + console.log('Browser does not support websocket'); //eslint-disable-line no-console + return; + } - // replace the protocol with a websocket one - if (connUrl.startsWith('https:')) { - connUrl = connUrl.replace(/^https:/, 'wss:'); - } else { - connUrl = connUrl.replace(/^http:/, 'ws:'); - } + let connUrl = Utils.getSiteURL(); - // append a port number if one isn't already specified - if (!(/:\d+$/).test(connUrl)) { - if (connUrl.startsWith('wss:')) { - connUrl += ':' + global.window.mm_config.WebsocketSecurePort; - } else { - connUrl += ':' + global.window.mm_config.WebsocketPort; - } + // replace the protocol with a websocket one + if (connUrl.startsWith('https:')) { + connUrl = connUrl.replace(/^https:/, 'wss:'); + } else { + connUrl = connUrl.replace(/^http:/, 'ws:'); + } + + // append a port number if one isn't already specified + if (!(/:\d+$/).test(connUrl)) { + if (connUrl.startsWith('wss:')) { + connUrl += ':' + global.window.mm_config.WebsocketSecurePort; + } else { + connUrl += ':' + global.window.mm_config.WebsocketPort; } + } - // append the websocket api path - connUrl += Client.getUsersRoute() + '/websocket'; + // append the websocket api path + connUrl += Client.getUsersRoute() + '/websocket'; - WebSocketClient.setEventCallback(handleEvent); - WebSocketClient.setFirstConnectCallback(handleFirstConnect); - WebSocketClient.setReconnectCallback(handleReconnect); - WebSocketClient.setCloseCallback(handleClose); - WebSocketClient.initialize(connUrl); - } + WebSocketClient.setEventCallback(handleEvent); + WebSocketClient.setFirstConnectCallback(handleFirstConnect); + WebSocketClient.setReconnectCallback(handleReconnect); + WebSocketClient.setCloseCallback(handleClose); + WebSocketClient.initialize(connUrl); } export function close() { |