Add functionality for refetching latest data after computer wakes up (#5120)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
36b62333b1
Коммит
0d8bb03b57
@@ -67,9 +67,15 @@ export function close() {
|
|||||||
WebSocketClient.close();
|
WebSocketClient.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function reconnect() {
|
function reconnectWebSocket() {
|
||||||
close();
|
close();
|
||||||
initialize();
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function reconnect(includeWebSocket = true) {
|
||||||
|
if (includeWebSocket) {
|
||||||
|
reconnectWebSocket();
|
||||||
|
}
|
||||||
|
|
||||||
if (Client.teamId) {
|
if (Client.teamId) {
|
||||||
loadChannelsForCurrentUser();
|
loadChannelsForCurrentUser();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {browserHistory} from 'react-router/es6';
|
|||||||
import TeamStore from 'stores/team_store.jsx';
|
import TeamStore from 'stores/team_store.jsx';
|
||||||
import * as GlobalActions from 'actions/global_actions.jsx';
|
import * as GlobalActions from 'actions/global_actions.jsx';
|
||||||
import {loadStatusesForChannelAndSidebar} from 'actions/status_actions.jsx';
|
import {loadStatusesForChannelAndSidebar} from 'actions/status_actions.jsx';
|
||||||
|
import {reconnect} from 'actions/websocket_actions.jsx';
|
||||||
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
|
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
|
||||||
import Constants from 'utils/constants.jsx';
|
import Constants from 'utils/constants.jsx';
|
||||||
const ActionTypes = Constants.ActionTypes;
|
const ActionTypes = Constants.ActionTypes;
|
||||||
@@ -60,12 +61,28 @@ function doChannelChange(state, replace, callback) {
|
|||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let wakeUpInterval;
|
||||||
|
let lastTime = (new Date()).getTime();
|
||||||
|
const WAKEUP_CHECK_INTERVAL = 30000; // 30 seconds
|
||||||
|
const WAKEUP_THRESHOLD = 60000; // 60 seconds
|
||||||
|
|
||||||
function preNeedsTeam(nextState, replace, callback) {
|
function preNeedsTeam(nextState, replace, callback) {
|
||||||
if (RouteUtils.checkIfMFARequired(nextState)) {
|
if (RouteUtils.checkIfMFARequired(nextState)) {
|
||||||
browserHistory.push('/mfa/setup');
|
browserHistory.push('/mfa/setup');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearInterval(wakeUpInterval);
|
||||||
|
|
||||||
|
wakeUpInterval = setInterval(() => {
|
||||||
|
const currentTime = (new Date()).getTime();
|
||||||
|
if (currentTime > (lastTime + WAKEUP_THRESHOLD)) { // ignore small delays
|
||||||
|
console.log('computer woke up - fetching latest'); //eslint-disable-line no-console
|
||||||
|
reconnect(false);
|
||||||
|
}
|
||||||
|
lastTime = currentTime;
|
||||||
|
}, WAKEUP_CHECK_INTERVAL);
|
||||||
|
|
||||||
// First check to make sure you're in the current team
|
// First check to make sure you're in the current team
|
||||||
// for the current url.
|
// for the current url.
|
||||||
const teamName = nextState.params.team;
|
const teamName = nextState.params.team;
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user