diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-01-19 09:58:38 -0500 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-01-19 09:58:38 -0500 |
commit | 0d8bb03b5773923cf52f4d8cb2711131caae105c (patch) | |
tree | e50a5cc27c9323a398032829a3b77a1fb3000503 /webapp | |
parent | 36b62333b1c5c1322a87a0d2bf3d430b9d88d3c9 (diff) | |
download | chat-0d8bb03b5773923cf52f4d8cb2711131caae105c.tar.gz chat-0d8bb03b5773923cf52f4d8cb2711131caae105c.tar.bz2 chat-0d8bb03b5773923cf52f4d8cb2711131caae105c.zip |
Add functionality for refetching latest data after computer wakes up (#5120)
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; |