From e6677d6fa36e62ebec7544b5f8774bcb3eb8b9db Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Tue, 9 Jul 2019 12:16:46 -0400 Subject: don't regen montage connkeys immediatey. Implement a timer --- www/js/MenuController.js | 3 +- www/js/MontageCtrl.js | 85 +++++++++++--------------------------------- www/js/MontageHistoryCtrl.js | 2 -- www/js/NVR.js | 35 ++++++++++++++---- 4 files changed, 51 insertions(+), 74 deletions(-) diff --git a/www/js/MenuController.js b/www/js/MenuController.js index 7b117342..8496acff 100644 --- a/www/js/MenuController.js +++ b/www/js/MenuController.js @@ -38,7 +38,8 @@ angular.module('zmApp.controllers').controller('MenuController', ['$scope', '$io window.stop(); // after window stop executes, in next cycle // this _should_ ensure stop concludes before - // exit/entry lifecycles kick in? + // exit/entry lifecycles kick in?z + $timeout (function() {$state.go(view,args);}); });*/ diff --git a/www/js/MontageCtrl.js b/www/js/MontageCtrl.js index 60b49541..e5274b81 100644 --- a/www/js/MontageCtrl.js +++ b/www/js/MontageCtrl.js @@ -18,6 +18,7 @@ angular.module('zmApp.controllers') var intervalHandleReloadPage; var intervalHandleEventStatus; + var gridcontainer; var pckry, draggie; var draggies; @@ -58,59 +59,6 @@ angular.module('zmApp.controllers') NVR.debug ("Auth success, recomputing rand value..."); randEachTime(); - /* var tnow = new Date(); - var s = Math.round((tnow - timeInMontage) / 1000); - NVR.debug ("Montage re-auth: time since we are here: " + s + - " seconds"); - if (s >= 20) {// lets not regen connkey if we just got into montage - NVR.debug ("Montage-reauth: Regenerating connkeys"); - $timeout(function () { // after render - if (simulStreaming) { - NVR.debug("Re-creating all stream connkeys in montage ..."); - NVR.regenConnKeys(); - $scope.monitors = NVR.getMonitorsNow(); - $scope.MontageMonitors = angular.copy($scope.monitors); - $timeout(function () // after render - { - initPackery(); - }, zm.packeryTimer); - - - } - }); - } - else { - NVR.debug ("Montage re-auth: ignoring as time is only "+s+" seconds"); - }*/ - // do nothing, we are reloading here anyway? - /* - if ($scope.singleMonitorModalOpen) { - NVR.debug("Montage: Not creating streams, as modal is open"); - return; - } - - - NVR.debug("Montage Re-auth handler"); - - //streamState = true; - - $timeout(function () { // after render - if (simulStreaming) { - NVR.debug("Re-creating all stream connkeys in montage ..."); - NVR.regenConnKeys(); - $scope.monitors = NVR.getMonitorsNow(); - $scope.MontageMonitors = angular.copy($scope.monitors); - $timeout(function () // after render - { - initPackery(); - }, zm.packeryTimer); - - - } - }); - broadcastHandles.push(as); - //console.log (">>>>>>>>>>>>>>>>>>>>>>>>>>>AS="+as); - */ }); //-------------------------------------------------------------------------------------- @@ -860,10 +808,10 @@ angular.module('zmApp.controllers') } // before reorder array } // montage monitors - console.log ("AFTER REORDER="+JSON.stringify(beforeReorderPositions)); + // console.log ("AFTER REORDER="+JSON.stringify(beforeReorderPositions)); for (var n = 0; i < $scope.MontageMonitors.length; i++) { - $scope.MontageMonitors[n].Monitor.connKey = (Math.floor((Math.random() * 999999) + 1)).toString(); + $scope.MontageMonitors[n].Monitor.connKey = NVR.regenConnKeys($scope.MontageMonitors[i]); } var ld = NVR.getLogin(); @@ -1469,9 +1417,7 @@ angular.module('zmApp.controllers') for (var i = 0; i < $scope.MontageMonitors.length; i++) { if ($scope.MontageMonitors[i].Monitor.listDisplay == 'show') NVR.resumeLiveStream($scope.MontageMonitors[i].Monitor.connKey, $scope.MontageMonitors[i].Monitor.controlURL, $scope.MontageMonitors[i].Monitor.Name); } - /* NVR.regenConnKeys(); - $scope.monitors = NVR.getMonitorsNow(); - $scope.MontageMonitors = angular.copy($scope.monitors);*/ + } @@ -1916,16 +1862,26 @@ angular.module('zmApp.controllers') function getMode() { var mode = (simulStreaming && currentStreamState != streamState.SNAPSHOT && currentStreamState != streamState.STOPPED) ? 'jpeg' : 'single'; - //console.log ("mode="+mode); + //console.log ("mode="+mode); return mode; } $scope.processImageError = function(monitor) { - // NVR.debug ("Image load error for: "+monitor.Monitor.Id+" regenerated connKey is:"+monitor.Monitor.connKey); - //if (1) return; // REMOVE - monitor.Monitor.connKey = (Math.floor((Math.random() * 999999) + 1)).toString(); - NVR.debug ("Image load error for: "+monitor.Monitor.Id+" regenerated connKey is:"+monitor.Monitor.connKey); + + var mintimesec = 10; + var nowt = moment(); + var thent = monitor.Monitor.regenTime || moment(); + if (nowt.diff(thent, 'seconds') >=mintimesec) { + NVR.regenConnKeys(monitor); + NVR.debug ("Image load error for: "+monitor.Monitor.Id+" regenerated connKey is:"+monitor.Monitor.connKey); + } else { + dur = mintimesec - nowt.diff(thent, 'seconds'); + NVR.debug ("Image load error for Monitor: "+monitor.Monitor.Id+" scheduling for connkey regen in "+dur+"s"); + monitor.Monitor.regenHandle = $timeout ( function() {NVR.regenConnKeys(monitor);}, dur*1000 ); + } + + }; @@ -2148,8 +2104,7 @@ angular.module('zmApp.controllers') broadcastHandles = []; randToAvoidCacheMem = new Date().getTime(); currentStreamState = streamState.SNAPSHOT; - // NVR.regenConnKeys(); - $scope.monitors = NVR.getMonitorsNow(); + $scope.monitors = NVR.getMonitorsNow(); //console.log ("MONITORS:"+JSON.stringify($scope.monitors)); diff --git a/www/js/MontageHistoryCtrl.js b/www/js/MontageHistoryCtrl.js index 6b528ce8..ef3e07e3 100644 --- a/www/js/MontageHistoryCtrl.js +++ b/www/js/MontageHistoryCtrl.js @@ -237,8 +237,6 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc NVR.debug(">>Initializing monitor array with history specific stuff..."); for (i = 0; i < $scope.MontageMonitors.length; i++) { - //$scope.MontageMonitors[i].Monitor.connKey=''; - //$scope.MontageMonitors[i].Monitor.connKey = (Math.floor((Math.random() * 99999) + 1)).toString(); $scope.MontageMonitors[i].Monitor.eventUrl = 'img/noimage.png'; $scope.MontageMonitors[i].Monitor.eventType = ""; $scope.MontageMonitors[i].Monitor.eid = "-1"; diff --git a/www/js/NVR.js b/www/js/NVR.js index d9991b38..be2265ff 100644 --- a/www/js/NVR.js +++ b/www/js/NVR.js @@ -1465,6 +1465,33 @@ angular.module('zmApp.controllers') } + function regenConnKeys (mon) { + var nowt = moment(); + if (mon) { + debug ("NVR: Regnerating connkey for Monitor:"+mon.Monitor.Id + " at "+nowt); + mon.Monitor.connKey = (Math.floor((Math.random() * 999999) + 1)).toString(); + mon.Monitor.regenTime = nowt; + if (mon.Monitor.regenHandle) { + //debug ("cancelling regen timer for Monitor:"+mon.Monitor.Id); + $timeout.cancel(mon.Monitor.regenHandle); + mon.Monitor.regenHandle = null; + } + + } else { + debug("NVR: Regenerating connkeys for all monitors at "+nowt); + for (var i = 0; i < monitors.length; i++) { + monitors[i].Monitor.connKey = (Math.floor((Math.random() * 999999) + 1)).toString(); + monitors[i].Monitor.rndKey = (Math.floor((Math.random() * 999999) + 1)).toString(); + monitors[i].Monitor.regenTime = nowt; + if (monitors[i].Monitor.regenHandle) { + $timeout.cancel(monitors[i].Monitor.regenHandle); + monitors[i].Monitor.regenHandle = null; + } + } + + } + } + //-------------------------------------------------------------------------- // Banner display of messages //-------------------------------------------------------------------------- @@ -2540,13 +2567,9 @@ angular.module('zmApp.controllers') }, - regenConnKeys: function () { + regenConnKeys: function (mon) { - debug("NVR: Regenerating connkeys..."); - for (var i = 0; i < monitors.length; i++) { - monitors[i].Monitor.connKey = (Math.floor((Math.random() * 999999) + 1)).toString(); - monitors[i].Monitor.rndKey = (Math.floor((Math.random() * 999999) + 1)).toString(); - } + return regenConnKeys (mon); }, getMonitors: function (forceReload) { -- cgit v1.2.3