diff options
Diffstat (limited to 'webapp')
-rw-r--r-- | webapp/actions/websocket_actions.jsx | 8 | ||||
-rw-r--r-- | webapp/routes/route_team.jsx | 17 |
2 files changed, 24 insertions, 1 deletions
diff --git a/webapp/actions/websocket_actions.jsx b/webapp/actions/websocket_actions.jsx index 9a52eb05c..1a0ddda63 100644 --- a/webapp/actions/websocket_actions.jsx +++ b/webapp/actions/websocket_actions.jsx @@ -67,9 +67,15 @@ export function close() { WebSocketClient.close(); } -export function reconnect() { +function reconnectWebSocket() { close(); initialize(); +} + +export function reconnect(includeWebSocket = true) { + if (includeWebSocket) { + reconnectWebSocket(); + } if (Client.teamId) { loadChannelsForCurrentUser(); diff --git a/webapp/routes/route_team.jsx b/webapp/routes/route_team.jsx index 4cc85c81b..fe68324c4 100644 --- a/webapp/routes/route_team.jsx +++ b/webapp/routes/route_team.jsx @@ -8,6 +8,7 @@ import {browserHistory} from 'react-router/es6'; import TeamStore from 'stores/team_store.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import {loadStatusesForChannelAndSidebar} from 'actions/status_actions.jsx'; +import {reconnect} from 'actions/websocket_actions.jsx'; import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import Constants from 'utils/constants.jsx'; const ActionTypes = Constants.ActionTypes; @@ -60,12 +61,28 @@ function doChannelChange(state, replace, 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) { if (RouteUtils.checkIfMFARequired(nextState)) { browserHistory.push('/mfa/setup'); 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 // for the current url. const teamName = nextState.params.team; |