From 542af9e7c3054fa6fddc18b69aa399035bbf7d53 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Mon, 28 Jan 2019 04:18:34 -0500 Subject: fix online/offline detection and wake up hack --- www/js/app.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'www/js/app.js') 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; -- cgit v1.2.3