MM-9857 Disconnect WS for Android when sent to the background (#1511)
This commit is contained in:
parent
cc64cc5dc6
commit
df1df76eae
1 changed files with 28 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import React, {PureComponent} from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
import {injectIntl, intlShape} from 'react-intl';
|
||||
import {
|
||||
AppState,
|
||||
Platform,
|
||||
View,
|
||||
} from 'react-native';
|
||||
|
|
@ -66,6 +67,10 @@ class Channel extends PureComponent {
|
|||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (Platform.OS === 'android') {
|
||||
AppState.addEventListener('change', this.handleAppStateChange);
|
||||
}
|
||||
|
||||
if (tracker.initialLoad) {
|
||||
this.props.actions.recordLoadTime('Start time', 'initialLoad');
|
||||
}
|
||||
|
|
@ -95,6 +100,10 @@ class Channel extends PureComponent {
|
|||
EventEmitter.off('leave_team', this.handleLeaveTeam);
|
||||
this.networkListener.removeEventListener();
|
||||
|
||||
if (Platform.OS === 'android') {
|
||||
AppState.removeEventListener('change', this.handleAppStateChange);
|
||||
}
|
||||
|
||||
closeWebSocket();
|
||||
stopPeriodicStatusUpdates();
|
||||
}
|
||||
|
|
@ -141,6 +150,25 @@ class Channel extends PureComponent {
|
|||
}
|
||||
});
|
||||
|
||||
handleAppStateChange = async (appState) => {
|
||||
const {actions} = this.props;
|
||||
const {
|
||||
closeWebSocket,
|
||||
initWebSocket,
|
||||
startPeriodicStatusUpdates,
|
||||
stopPeriodicStatusUpdates,
|
||||
} = actions;
|
||||
const isActive = appState === 'active';
|
||||
|
||||
if (isActive) {
|
||||
initWebSocket(Platform.OS);
|
||||
startPeriodicStatusUpdates();
|
||||
} else {
|
||||
closeWebSocket(true);
|
||||
stopPeriodicStatusUpdates();
|
||||
}
|
||||
};
|
||||
|
||||
handleConnectionChange = (isConnected) => {
|
||||
const {actions} = this.props;
|
||||
const {
|
||||
|
|
|
|||
Loading…
Reference in a new issue