Skip to content

Commit

Permalink
#733 use new Monitor_Status if available
Browse files Browse the repository at this point in the history
  • Loading branch information
pliablepixels committed Oct 31, 2018
1 parent bd01cc9 commit 5a0f3c7
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
31 changes: 30 additions & 1 deletion www/js/DataModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,29 @@ angular.module('zmApp.controllers')
},*/

getMultiServersCached: function () {
return multiservers;
},

// use non cached for daemon status
getMultiServers: function () {
return $http.get (loginData.apiurl+'/servers.json');

},

getMultiServer: function (id) {

var ndx = -1;
for (var i=0; i < multiservers.length; i++) {
if (multiservers[i].Server.Id == id) {
ndx = i;
break;
}
}
return ndx == -1 ? {}:multiservers[ndx];

},

regenConnKeys: function () {

debug("DataModel: Regenerating connkeys...");
Expand Down Expand Up @@ -2144,7 +2167,7 @@ angular.module('zmApp.controllers')
data = data.data;
// We found a server list API, so lets make sure
// we get the hostname as it will be needed for playback
log("multi server list loaded" + JSON.stringify(data));
log("multi server list loaded:" + JSON.stringify(data));
multiservers = data.servers;

var multiserver_scheme = "http://";
Expand All @@ -2158,6 +2181,8 @@ angular.module('zmApp.controllers')
for (var i = 0; i < monitors.length; i++) {

// make them all show for now


monitors[i].Monitor.listDisplay = 'show';
monitors[i].Monitor.isAlarmed = false;
monitors[i].Monitor.connKey = (Math.floor((Math.random() * 999999) + 1)).toString();
Expand Down Expand Up @@ -2276,11 +2301,13 @@ angular.module('zmApp.controllers')

} else {
//monitors[i].Monitor.listDisplay = 'show';
debug ("No servers matched, filling defaults...");
monitors[i].Monitor.isAlarmed = false;
monitors[i].Monitor.connKey = (Math.floor((Math.random() * 999999) + 1)).toString();
monitors[i].Monitor.rndKey = (Math.floor((Math.random() * 999999) + 1)).toString();

var st2 = loginData.streamingurl;
controlURL = loginData.url;

if (zmsPort > 0 && !loginData.disableSimulStreaming) {
// we need to insert minport
Expand All @@ -2302,6 +2329,8 @@ angular.module('zmApp.controllers')
if (p3.path) controlURL += p3.path;
}

debug ("Storing streaming="+st2+" recording="+controlURL);

monitors[i].Monitor.streamingURL = st2;
monitors[i].Monitor.controlURL = controlURL;
//debug ("Streaming URL for Monitor " + monitors[i].Monitor.Id + " is " + monitors[i].Monitor.streamingURL );
Expand Down
2 changes: 1 addition & 1 deletion www/js/EventCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2815,7 +2815,7 @@ angular.module('zmApp.controllers')


function recomputeThumbSize() {
NVRDataModel.debug("EventCtrl: recompute thumbnails");
// NVRDataModel.debug("EventCtrl: recompute thumbnails");

for (var i = 0; i < $scope.events.length; i++) {
var tempMon = NVRDataModel.getMonitorObject($scope.events[i].Event.MonitorId);
Expand Down
54 changes: 53 additions & 1 deletion www/js/MonitorCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,60 @@ angular.module('zmApp.controllers')
//-----------------------------------------------------------------------

function monitorStateCheck() {

var ld = NVRDataModel.getLogin();
// force get for latest status of monitors if av.
NVRDataModel.getMonitors(1)
.then (function (data) {

$scope.monitors = data;
if (!$scope.monitors[0].Monitor_Status ) {
NVRDataModel.debug ("no Monitor_Status found reverting to daemonCheck...");
forceDaemonCheck();
}
else {
NVRDataModel.debug ("reporting status of monitors from multi-server API");
processMonitorStatus();
}

},
function (err) {
NVRDataModel.debug ("Monitor fetch error, reverting to daemonCheck...");
forceDaemonCheck();
})

}

function processMonitorStatus () {

//array('Unknown','NotRunning','Running','NoSignal','Signal'),


// console.log (JSON.stringify($scope.monitors));
for (var j=0; j < $scope.monitors.length; j++) {

if ($scope.monitors[j].Monitor_Status.Status == 'Connected') {
$scope.monitors[j].Monitor.isRunning = "true";
$scope.monitors[j].Monitor.color = zm.monitorRunningColor;
$scope.monitors[j].Monitor.char = "ion-checkmark-circled";
$scope.monitors[j].Monitor.isRunningText = $scope.monitors[j].Monitor_Status.Status;
}
else {
$scope.monitors[j].Monitor.isRunning = "false";
$scope.monitors[j].Monitor.color = zm.monitorNotRunningColor;
$scope.monitors[j].Monitor.char = "ion-close-circled";
$scope.monitors[j].Monitor.isRunningText = $scope.monitors[j].Monitor_Status.Status;
}

}

}

function forceDaemonCheck() {
var apiMonCheck;

$scope.loginData = NVRDataModel.getLogin();

// The status is provided by zmdc.pl
// "not running", "pending", "running since", "Unable to connect"
var i;
Expand All @@ -426,7 +478,7 @@ angular.module('zmApp.controllers')
$scope.monitors[j].Monitor.isRunning = "...";
$scope.monitors[j].Monitor.color = zm.monitorCheckingColor;
$scope.monitors[j].Monitor.char = "ion-checkmark-circled";
apiMonCheck = loginData.apiurl + "/monitors/daemonStatus/id:" + $scope.monitors[j].Monitor.Id + "/daemon:zmc.json";
apiMonCheck = $scope.loginData.apiurl + "/monitors/daemonStatus/id:" + $scope.monitors[j].Monitor.Id + "/daemon:zmc.json";


NVRDataModel.debug("MonitorCtrl:monitorStateCheck: " + apiMonCheck);
Expand Down

1 comment on commit 5a0f3c7

@pliablepixels
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.