Fix android web socket error (#321)
* Fix android web socket error * Modify init args
This commit is contained in:
parent
433a95ed69
commit
bb1446da91
4 changed files with 27 additions and 5 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
import React from 'react';
|
||||
import {
|
||||
Platform,
|
||||
StatusBar,
|
||||
Text
|
||||
} from 'react-native';
|
||||
|
|
@ -59,7 +60,7 @@ export default class Channel extends React.PureComponent {
|
|||
this.props.subscribeToHeaderEvent('show_channel_info', this.props.actions.goToChannelInfo);
|
||||
EventEmitter.on('leave_team', this.handleLeaveTeam);
|
||||
const teamId = this.props.currentTeam.id;
|
||||
this.props.actions.initWebSocket();
|
||||
this.props.actions.initWebSocket(Platform.OS);
|
||||
this.loadChannels(teamId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ import {getUserIdFromChannelName} from 'service/utils/channel_utils';
|
|||
import {isSystemMessage, shouldIgnorePost} from 'service/utils/post_utils';
|
||||
import EventEmitter from 'service/utils/event_emitter';
|
||||
|
||||
export function init(siteUrl, token, optionalWebSocket) {
|
||||
export function init(platform, siteUrl, token, optionalWebSocket) {
|
||||
return async (dispatch, getState) => {
|
||||
const config = getState().entities.general.config;
|
||||
let connUrl = siteUrl || Client.getUrl();
|
||||
|
|
@ -62,7 +62,17 @@ export function init(siteUrl, token, optionalWebSocket) {
|
|||
websocketClient.setReconnectCallback(handleReconnect);
|
||||
websocketClient.setCloseCallback(handleClose);
|
||||
websocketClient.setConnectingCallback(handleConnecting);
|
||||
return websocketClient.initialize(true, connUrl, authToken, dispatch, getState, optionalWebSocket);
|
||||
|
||||
const websocketOpts = {
|
||||
connectionUrl: connUrl,
|
||||
platform
|
||||
};
|
||||
|
||||
if (optionalWebSocket) {
|
||||
websocketOpts.webSocketConnector = optionalWebSocket;
|
||||
}
|
||||
|
||||
return websocketClient.initialize(authToken, dispatch, getState, websocketOpts);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,15 @@ class WebSocketClient {
|
|||
this.stop = false;
|
||||
}
|
||||
|
||||
initialize(forceConnection = true, connectionUrl = this.connectionUrl, token, dispatch, getState, webSocketConnector = WebSocket) {
|
||||
initialize(token, dispatch, getState, opts) {
|
||||
const defaults = {
|
||||
forceConnection: true,
|
||||
connectionUrl: this.connectionUrl,
|
||||
webSocketConnector: WebSocket
|
||||
};
|
||||
|
||||
const {connectionUrl, forceConnection, webSocketConnector, platform} = Object.assign({}, defaults, opts);
|
||||
|
||||
if (forceConnection) {
|
||||
this.stop = false;
|
||||
}
|
||||
|
|
@ -57,8 +65,10 @@ class WebSocketClient {
|
|||
this.connectingCallback(dispatch, getState);
|
||||
}
|
||||
|
||||
const captured = (/^(?:https?|wss?):\/\/[^/]*/).exec(connectionUrl);
|
||||
const regex = platform === 'android' ? /^(?:https?|wss?):\/\/[^/][^*:]*/ : /^(?:https?|wss?):\/\/[^/]*/;
|
||||
const captured = (regex).exec(connectionUrl);
|
||||
const origin = captured ? captured[0] : null;
|
||||
|
||||
this.conn = new Socket(connectionUrl, null, {origin});
|
||||
this.connectionUrl = connectionUrl;
|
||||
this.token = token;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ describe('Actions.Websocket', () => {
|
|||
await TestHelper.initBasic(Client);
|
||||
const webSocketConnector = require('ws');
|
||||
return await Actions.init(
|
||||
'ios',
|
||||
null,
|
||||
null,
|
||||
webSocketConnector
|
||||
|
|
|
|||
Loading…
Reference in a new issue