diff --git a/src/libs/NetworkConnection.js b/src/libs/NetworkConnection.js index 71d7dadf416b..cb104b18d868 100644 --- a/src/libs/NetworkConnection.js +++ b/src/libs/NetworkConnection.js @@ -2,14 +2,12 @@ import _ from 'underscore'; import Onyx from 'react-native-onyx'; import NetInfo from './NetInfo'; import ONYXKEYS from '../ONYXKEYS'; -import SleepTimer from './SleepTimer'; import AppStateMonitor from './AppStateMonitor'; import promiseAllSettled from './promiseAllSettled'; // NetInfo.addEventListener() returns a function used to unsubscribe the // listener so we must create a reference to it and call it in stopListeningForReconnect() let unsubscribeFromNetInfo; -let unsubscribeFromSleepTimer; let unsubscribeFromAppState; let isOffline = false; let logInfo = () => {}; @@ -63,14 +61,6 @@ function listenForReconnect() { logInfo(`[NetworkConnection] NetInfo isConnected: ${state && state.isConnected}`); setOfflineStatus(!state.isConnected); }); - - // When a device is put to sleep, NetInfo is not always able to detect - // when connectivity has been lost. As a failsafe we will capture the time - // every two seconds and if the last time recorded goes past a threshold - // we know that the computer has been asleep. - unsubscribeFromSleepTimer = SleepTimer.addClockSkewListener(() => ( - triggerReconnectionCallbacks('timer clock skewed') - )); } /** @@ -82,10 +72,6 @@ function stopListeningForReconnect() { unsubscribeFromNetInfo(); unsubscribeFromNetInfo = undefined; } - if (unsubscribeFromSleepTimer) { - unsubscribeFromSleepTimer(); - unsubscribeFromSleepTimer = undefined; - } if (unsubscribeFromAppState) { unsubscribeFromAppState(); unsubscribeFromAppState = undefined; diff --git a/src/libs/SleepTimer/index.js b/src/libs/SleepTimer/index.js deleted file mode 100644 index 75c722304e2f..000000000000 --- a/src/libs/SleepTimer/index.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * The Timer module is used on web/desktop to detect when a computer has gone to sleep. We don't use this on native - * mobile since it does not work reliably and fires at inappropriate times. - */ -let sleepTimer; -let lastTime; - -/** - * Adds a listener for detecting when laptop screens have closed or desktop computers put to sleep. Not reliable on - * native platforms. - * - * @param {Function} onClockSkewCallback function to call when the - * @returns {Fuction} that when called clears the timer - */ -function addClockSkewListener(onClockSkewCallback) { - clearInterval(sleepTimer); - sleepTimer = setInterval(() => { - const currentTime = (new Date()).getTime(); - const isSkewed = currentTime > (lastTime + 8000); - lastTime = currentTime; - - if (!isSkewed) { - return; - } - - onClockSkewCallback(); - }, 2000); - - return () => { - clearInterval(sleepTimer); - sleepTimer = null; - }; -} - -export default { - addClockSkewListener, -}; diff --git a/src/libs/SleepTimer/index.native.js b/src/libs/SleepTimer/index.native.js deleted file mode 100644 index 96dcb1988f45..000000000000 --- a/src/libs/SleepTimer/index.native.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * We don't want the clock skew listener to run on native as it only helps us on desktop/web when a laptop is closed - * and reopened. This method of detecting timing variance to see if we are inactive doesn't work well on native mobile - * platforms. These platforms should use AppState instead to determine whether they must catch up on missing data. - */ -export default { - addClockSkewListener: () => () => {}, -};