Fix websocket on old versions of IE11 (#4501)

Этот коммит содержится в:
Joram Wilander
2016-11-10 09:22:06 -05:00
коммит произвёл Harrison Healey
родитель 39675afab4
Коммит 8c76560b48
4 изменённых файлов: 49 добавлений и 31 удалений

Просмотреть файл

@@ -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();
// 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';
WebSocketClient.setEventCallback(handleEvent);
WebSocketClient.setFirstConnectCallback(handleFirstConnect);
WebSocketClient.setReconnectCallback(handleReconnect);
WebSocketClient.setCloseCallback(handleClose);
WebSocketClient.initialize(connUrl);
if (!window.WebSocket) {
console.log('Browser does not support websocket'); //eslint-disable-line no-console
return;
}
let connUrl = Utils.getSiteURL();
// 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';
WebSocketClient.setEventCallback(handleEvent);
WebSocketClient.setFirstConnectCallback(handleFirstConnect);
WebSocketClient.setReconnectCallback(handleReconnect);
WebSocketClient.setCloseCallback(handleClose);
WebSocketClient.initialize(connUrl);
}
export function close() {

Просмотреть файл

@@ -8,6 +8,7 @@ const MAX_WEBSOCKET_RETRY_TIME = 300000; // 5 mins
export default class WebSocketClient {
constructor() {
this.conn = null;
this.connectionUrl = null;
this.sequence = 1;
this.connectFailCount = 0;
this.eventCallback = null;
@@ -18,16 +19,22 @@ export default class WebSocketClient {
this.closeCallback = null;
}
initialize(connectionUrl, token) {
initialize(connectionUrl = this.connectionUrl, token) {
if (this.conn) {
return;
}
if (connectionUrl == null) {
console.log('websocket must have connection url'); //eslint-disable-line no-console
return;
}
if (this.connectFailCount === 0) {
console.log('websocket connecting to ' + connectionUrl); //eslint-disable-line no-console
}
this.conn = new WebSocket(connectionUrl);
this.connectionUrl = connectionUrl;
this.conn.onopen = () => {
if (token) {
@@ -150,7 +157,7 @@ export default class WebSocketClient {
if (this.conn && this.conn.readyState === WebSocket.OPEN) {
this.conn.send(JSON.stringify(msg));
} else if (!this.conn || this.conn.readyState === WebSocket.Closed) {
} else if (!this.conn || this.conn.readyState === WebSocket.CLOSED) {
this.conn = null;
this.initialize();
}

Просмотреть файл

@@ -105,7 +105,7 @@ export default class LoggedIn extends React.Component {
}
componentDidMount() {
// Initalize websocket
// Initialize websocket
WebSocketActions.initialize();
// Listen for user

Просмотреть файл

@@ -1270,7 +1270,15 @@ export function isValidPassword(password) {
}
export function getSiteURL() {
return global.mm_config.SiteURL || window.location.origin;
if (global.mm_config.SiteURL) {
return global.mm_config.SiteURL;
}
if (window.location.origin) {
return window.location.origin;
}
return window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '');
}
export function handleFormattedTextClick(e) {