diff options
Diffstat (limited to 'www/js/MonitorModalCtrl.js')
| -rw-r--r-- | www/js/MonitorModalCtrl.js | 219 |
1 files changed, 140 insertions, 79 deletions
diff --git a/www/js/MonitorModalCtrl.js b/www/js/MonitorModalCtrl.js index ff0368cd..51f08fd5 100644 --- a/www/js/MonitorModalCtrl.js +++ b/www/js/MonitorModalCtrl.js @@ -10,7 +10,6 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ $scope.isModalActive = true; var intervalModalHandle; var cycleHandle; - var nphTimer; var ld = NVRDataModel.getLogin(); $scope.svgReady = false; $scope.zoneArray = []; @@ -20,6 +19,8 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ var targetID = ""; $scope.imageZoomable = true; $scope.ptzButtonsShown = true; + + @@ -31,16 +32,16 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ }, false); - $rootScope.authSession = "undefined"; + //$rootScope.authSession = "undefined"; - $ionicLoading.show({ + /* $ionicLoading.show({ template: $translate.instant('kNegotiatingStreamAuth') + '...', animation: 'fade-in', showBackdrop: true, duration: zm.loadingTimeout, maxWidth: 300, showDelay: 0 - }); + });*/ $scope.currentStreamMode = 'single'; NVRDataModel.log("Using stream mode " + $scope.currentStreamMode); @@ -48,7 +49,8 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ NVRDataModel.debug("MonitorModalCtrl called from " + $ionicHistory.currentStateName()); - $rootScope.validMonitorId = $scope.monitors[0].Monitor.Id; + //no need to recompute auth in modal + /*$rootScope.validMonitorId = $scope.monitors[0].Monitor.Id; NVRDataModel.getAuthKey($rootScope.validMonitorId, $scope.monitors[0].Monitor.connKey) .then(function (success) { $ionicLoading.hide(); @@ -63,7 +65,7 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ //$rootScope.authSession=""; NVRDataModel.log("Modal: Error returned Stream authentication construction. Retaining old value of: " + $rootScope.authSession); }); - +*/ $interval.cancel(intervalModalHandle); $interval.cancel(cycleHandle); @@ -71,13 +73,9 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ intervalModalHandle = $interval(function () { loadModalNotifications(); // console.log ("Refreshing Image..."); - }.bind(this), 5000); + }.bind(this), zm.alarmStatusTime); - $timeout.cancel(nphTimer); - nphTimer = $timeout(function () { - $scope.currentStreamMode = 'jpeg'; - NVRDataModel.log("Switching playback via nphzms"); - }, zm.nphSwitchTimer); + // This is the PTZ menu @@ -195,12 +193,28 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ // On re-auth, we need a new zms //------------------------------------------------------------- - $rootScope.$on("auth-success", function () { + var as = $scope.$on("auth-success", function () { NVRDataModel.debug("MonitorModalCtrl: Re-login detected, resetting everything & re-generating connkey"); //NVRDataModel.stopNetwork("MonitorModal-auth success"); - NVRDataModel.killStream($scope.connKey); + $scope.isModalStreamPaused = false; + + $timeout (function() { + + if (0 && $rootScope.platformOS == 'ios') { + NVRDataModel.debug ("Webkit hack, hammering window.stop();"); + NVRDataModel.stopNetwork(); + } + else { + NVRDataModel.killLiveStream($scope.connKey, $scope.controlURL); + } + + + $scope.connKey = (Math.floor((Math.random() * 999999) + 1)).toString(); + }); + + }); @@ -266,7 +280,13 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ $interval.cancel(cycleHandle); NVRDataModel.debug("Killing single stream..."); - NVRDataModel.killStream($scope.connKey); + + if (0 && $rootScope.platformOS == 'ios') { + NVRDataModel.debug ("Webkit hack, hammering window.stop();"); + NVRDataModel.stopNetwork(); + } else { + NVRDataModel.killLiveStream($scope.connKey, $scope.controlURL); + } // $interval.cancel(modalIntervalHandle); // FIXME: Do I need to setAwake(false) here? @@ -285,7 +305,7 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ intervalModalHandle = $interval(function () { loadModalNotifications(); - }.bind(this), 5000); + }.bind(this), zm.alarmStatusTime); if (ld.cycleMonitors) { NVRDataModel.debug("Cycling enabled at " + ld.cycleMonitorsInterval); @@ -577,46 +597,38 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ // this is a good time to calculate scaled zone points function imageLoaded() { + if ($scope.animationInProgress) return; + /* var img = document.getElementById("singlemonitor"); - - //$scope.cw = img.naturalWidth; - //$scope.ch = img.naturalHeight; - $scope.cw = img.naturalWidth; $scope.ch = img.naturalHeight; - //console.log ("REPORTED DIM:" + $scope.cw+ "x"+$scope.ch ); - //console.log ("ORIGINAL DIM:" + img.naturalWidth+ "x"+img.naturalHeight); - //https://server/zm/api/zones/forMonitor/7.json - // + $scope.zoneArray = []; $scope.circlePoints = []; var ow = $scope.monitor.Monitor.Width; - var oh = $scope.monitor.Monitor.Height; + var oh = $scope.monitor.Monitor.Height;*/ // console.log ("MONITOR IS: "+JSON.stringify($scope.monitor)); // console.log ("ORIGINAL WH="+ow+"x"+oh); - for (var i = 0; i < originalZones.length; i++) { + /*for (var i = 0; i < originalZones.length; i++) { var sx = $scope.cw / ow; var sy = $scope.ch / oh; - //$scope.zoneArray.push({ - // coords:scaleCoords(originalZones[i].coords,sx,sy), - // type:originalZones[i].type}); $scope.zoneArray.push({ coords: originalZones[i].coords, type: originalZones[i].type }); - } + }*/ // now create a points array for circle handles - for (i = 0; i < $scope.zoneArray.length; i++) { - /*jshint loopfunc: true */ - // console.log ("ZONE ARRAY="+$scope.zoneArray[i].coords); + + /* for (i = 0; i < $scope.zoneArray.length; i++) { + //jshint loopfunc: true $scope.zoneArray[i].coords.split(' ') .forEach(function (itm) { var o = itm.split(','); @@ -629,8 +641,10 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ // console.log ("CIRCLE X="+o[0]+"Y="+o[1]); }); - } + }*/ + $scope.isModalStreamPaused = false; + NVRDataModel.debug ("Modal image loaded, switching to streaming"); @@ -638,18 +652,7 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ } - //------------------------------------------------------------- - // this is checked to make sure we are not pulling images - // when app is in background. This is a problem with Android, - // for example - //------------------------------------------------------------- - - $scope.isBackground = function () { - // console.log ("Is background called from ModalCtrl and returned " + - // NVRDataModel.isBackground()); - return NVRDataModel.isBackground(); - }; - + //------------------------------------------------------------- // Send PTZ command to ZM // Note: PTZ fails on desktop, don't bother about it @@ -799,6 +802,7 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ function moveToMonitor(m, d) { + $scope.animationInProgress = true; if ($scope.isZoneEdit) { NVRDataModel.log("Not cycling, as you are editing zones"); } @@ -838,38 +842,57 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ } while (found != 1); + // now kill stream and set up next + NVRDataModel.debug("Killing stream before we move on to next monitor..."); + + $scope.isModalStreamPaused = true; + var element = angular.element(document.getElementById("monitorimage")); var slidein; var slideout; - var dirn = d; - if (dirn == 1) { - slideout = "animated slideOutLeft"; - slidein = "animated slideInRight"; - } else { - slideout = "animated slideOutRight"; - slidein = "animated slideInLeft"; - } + $timeout (function() { + NVRDataModel.killLiveStream($scope.connKey, $scope.controlURL); + + // we should now have a paused stream, time to animate out + + + + var dirn = d; + if (dirn == 1) { + slideout = "animated slideOutLeft"; + slidein = "animated slideInRight"; + } else { + slideout = "animated slideOutRight"; + slidein = "animated slideInLeft"; + } + + + element.addClass(slideout) + .one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', outWithOld); + }); + + - var element = angular.element(document.getElementById("monitorimage")); - element.addClass(slideout) - .one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', outWithOld); function outWithOld() { - NVRDataModel.log("ModalCtrl:Stopping network pull..."); - NVRDataModel.stopNetwork("MonitorModal-outwithOld"); + NVRDataModel.log(">>>Old image out"); + // NVRDataModel.log("ModalCtrl:Stopping network pull..."); + //NVRDataModel.stopNetwork("MonitorModal-outwithOld"); $scope.rand = Math.floor((Math.random() * 100000) + 1); - $scope.animationInProgress = true; + $timeout(function () { element.removeClass(slideout); element.addClass(slidein) .one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', inWithNew); + $scope.monitorId = mid; $scope.monitorName = NVRDataModel.getMonitorName(mid); $scope.monitor = NVRDataModel.getMonitorObject(mid); + $scope.controlURL = $scope.monitor.Monitor.controlURL; $scope.zoneArray = []; $scope.circlePoints = []; - getZones(); + // getZones(); configurePTZ($scope.monitorId); }, 200); } @@ -877,24 +900,15 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ function inWithNew() { element.removeClass(slidein); - $scope.animationInProgress = false; + + $scope.isModalStreamPaused = false; - NVRDataModel.log("New image loaded in"); + var ld = NVRDataModel.getLogin(); carouselUtils.setStop(false); - if (ld.useNphZms == true) { - $scope.currentStreamMode = 'single'; - NVRDataModel.log("Setting timer to play nph-zms mode"); - // first 5 seconds, load a snapshot, then switch to real FPS display - // this is to avoid initial image load delay - // FIXME: 5 seconds fair? - $timeout.cancel(nphTimer); - nphTimer = $timeout(function () { - $scope.currentStreamMode = 'jpeg'; - NVRDataModel.log("Switching playback via nphzms"); - }, zm.nphSwitchTimer); - } - + $scope.connKey = (Math.floor((Math.random() * 999999) + 1)).toString(); // get new key for new id + $scope.animationInProgress = false; // has to be AFTER new connkey + NVRDataModel.log("<<<New image loaded in with ck:"+$scope.connKey); } $ionicLoading.hide(); @@ -1114,6 +1128,36 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ } } + + $scope.constructSingleStream = function() { + + + var stream; + stream = $scope.monitor.Monitor.streamingURL + + "/nph-zms?mode="+getSingleStreamMode() + + "&monitor="+$scope.monitorId + + "&scale="+$scope.quality + + $rootScope.authSession + + "&rand="+$rootScope.modalRand + + appendSingleStreamConnKey(); + + //console.log ("STREAM="+stream); + + return stream; + + + }; + + + function getSingleStreamMode() { + return $scope.isModalStreamPaused ? 'single': 'jpeg'; + } + +function appendSingleStreamConnKey() { + return $scope.isModalStreamPaused ? "": "&connkey="+$scope.connKey; + + } + //------------------------------------------------------------- //reloaads mon - do we need it? //------------------------------------------------------------- @@ -1170,11 +1214,21 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ $scope.$on('modal.removed', function () { + as(); // dregister auth success $scope.isModalActive = false; - NVRDataModel.debug("Single monitor exited, killing stream"); - NVRDataModel.killStream($scope.connKey); + if (1 || $rootScope.platformOS != 'ios') { + + // ios calls window stop... + NVRDataModel.debug("Single monitor exited killing stream"); + NVRDataModel.killLiveStream($scope.connKey, $scope.controlURL); + } + else { + + NVRDataModel.debug("Webkit hack, hammering window.stop();"); + NVRDataModel.stopNetwork(); + } //console.log("**MODAL REMOVED: Stopping modal timer"); $interval.cancel(intervalModalHandle); @@ -1572,6 +1626,13 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ } $scope.$on('modal.shown', function () { + + + if (0 && $rootScope.platformOS == 'ios') { + NVRDataModel.debug("Webkit hack, hammering window.stop();"); + NVRDataModel.stopNetwork(); + } + $scope.connKey = (Math.floor((Math.random() * 999999) + 1)).toString(); $scope.monStatus = ""; $scope.isToggleListMenu = true; @@ -1590,7 +1651,7 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$ $scope.showZones = false; - getZones(); + //getZones(); var ld = NVRDataModel.getLogin(); //currentEvent = $scope.currentEvent; |
