PLT-4233 When internet reconnects, reconnect websocket and grab latest posts, etc. (#4500)
* When internet reconnects, reconnect websocket and grab latest posts, etc. * Rename internet connection variable
Этот коммит содержится в:
коммит произвёл
enahum
родитель
58215e573f
Коммит
557aa68636
@@ -156,6 +156,10 @@ export default class Client {
|
||||
// NO-OP for inherited classes to override
|
||||
}
|
||||
|
||||
handleSuccess(res) { // eslint-disable-line no-unused-vars
|
||||
// NO-OP for inherited classes to override
|
||||
}
|
||||
|
||||
handleResponse(methodName, successCallback, errorCallback, err, res) {
|
||||
if (res && res.header) {
|
||||
this.serverVersion = res.header[HEADER_X_VERSION_ID];
|
||||
@@ -212,6 +216,7 @@ export default class Client {
|
||||
console.error('Missing response body for ' + methodName); // eslint-disable-line no-console
|
||||
successCallback('', res);
|
||||
}
|
||||
this.handleSuccess(res);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
// See License.txt for license information.
|
||||
|
||||
import Client from './client.jsx';
|
||||
import TeamStore from '../stores/team_store.jsx';
|
||||
import BrowserStore from '../stores/browser_store.jsx';
|
||||
|
||||
import TeamStore from 'stores/team_store.jsx';
|
||||
import BrowserStore from 'stores/browser_store.jsx';
|
||||
|
||||
import * as GlobalActions from 'actions/global_actions.jsx';
|
||||
import {reconnect} from 'actions/websocket_actions.jsx';
|
||||
|
||||
import request from 'superagent';
|
||||
|
||||
@@ -14,6 +17,7 @@ class WebClientClass extends Client {
|
||||
constructor() {
|
||||
super();
|
||||
this.enableLogErrorsToConsole(true);
|
||||
this.hasInternetConnection = true;
|
||||
TeamStore.addChangeListener(this.onTeamStoreChanged.bind(this));
|
||||
}
|
||||
|
||||
@@ -37,6 +41,17 @@ class WebClientClass extends Client {
|
||||
if (err.status === HTTP_UNAUTHORIZED && res.req.url !== '/api/v3/users/login') {
|
||||
GlobalActions.emitUserLoggedOutEvent('/login');
|
||||
}
|
||||
|
||||
if (err.status == null) {
|
||||
this.hasInternetConnection = false;
|
||||
}
|
||||
}
|
||||
|
||||
handleSuccess = (res) => { // eslint-disable-line no-unused-vars
|
||||
if (res && !this.hasInternetConnection) {
|
||||
reconnect();
|
||||
this.hasInternetConnection = true;
|
||||
}
|
||||
}
|
||||
|
||||
// not sure why but super.login doesn't work if using an () => arrow functions.
|
||||
|
||||
Ссылка в новой задаче
Block a user