From 8c76560b4849f8d1fdc3c3f1c2f1877459a30fca Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Thu, 10 Nov 2016 09:22:06 -0500 Subject: Fix websocket on old versions of IE11 (#4501) --- webapp/actions/websocket_actions.jsx | 49 +++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'webapp/actions') 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() { -- cgit v1.2.3-1-g7c22