diff options
| author | Pliable Pixels <pliablepixels@gmail.com> | 2019-01-28 04:18:34 -0500 |
|---|---|---|
| committer | Pliable Pixels <pliablepixels@gmail.com> | 2019-01-28 04:18:34 -0500 |
| commit | 542af9e7c3054fa6fddc18b69aa399035bbf7d53 (patch) | |
| tree | c50ff2b530e8eb1fa271428e86822d1ad9c5b4b5 /www/js/app.js | |
| parent | d0d67a34e4751a05c0fd09dc59e7b835e0abebe3 (diff) | |
fix online/offline detection and wake up hack
Diffstat (limited to 'www/js/app.js')
| -rwxr-xr-x | www/js/app.js | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/www/js/app.js b/www/js/app.js index 58edd268..0b377420 100755 --- a/www/js/app.js +++ b/www/js/app.js @@ -1654,12 +1654,39 @@ angular.module('zmApp', [ $timeout (function() { NVR.log ("--------->Setting up network state handlers...."); - document.addEventListener("offline", onOffline, false); - document.addEventListener("online", onOnline, false); + window.addEventListener("offline", onOffline, false); + window.addEventListener("online", onOnline, false); + if ($rootScope.platformOS == 'desktop') { + NVR.log ("---> Hacked up waked detection..."); + detectWake(); + } },3000); + // credit: https://blog.alexmaccaw.com/javascript-wake-event + function detectWake() { + var TIMEOUT = 10000; + var iter = 1; + var lastTime = (new Date()).getTime(); + + setInterval(function() { + var currentTime = (new Date()).getTime(); + if (currentTime > (lastTime + TIMEOUT + 10000)) { + // Wake! + $rootScope.online = false; + NVR.log ("********* YOU WOKE UP!!!!!"); + onOnline(); + iter = 1; + } + else { + //NVR.debug ("alive..."+iter); + iter++; + } + lastTime = currentTime; + }, TIMEOUT); + } + function onOffline() { $timeout(function () { $rootScope.online = false; |
