Institute a status timer to be used when not streaming from zms.

pull/3506/head
Isaac Connor 2022-06-15 12:34:55 -04:00
parent 223a46393e
commit 5188346086
1 changed files with 65 additions and 9 deletions

View File

@ -12,10 +12,15 @@ function MonitorStream(monitorData) {
this.height = monitorData.height;
this.janusEnabled = monitorData.janusEnabled;
this.scale = 100;
this.status = null;
this.status = { capturefps: 0, analysisfps: 0}; // json object with alarmstatus, fps etc
this.lastAlarmState = STATE_IDLE;
this.statusCmdTimer = null;
this.streamCmdTimer = null;
this.statusCmdTimer = null; // timer for requests using ajax to get monitor status
this.statusCmdParms = {
view: 'request',
request: 'status',
connkey: this.connKey
};
this.streamCmdTimer = null; // timer for requests to zms for status
this.streamCmdParms = {
view: 'request',
request: 'stream',
@ -150,7 +155,6 @@ function MonitorStream(monitorData) {
const newSrc = oldSrc.replace(/scale=\d+/i, 'scale='+newscale);
if (newSrc != oldSrc) {
this.streamCmdTimer = clearTimeout(this.streamCmdTimer);
this.statusCmdTimer = clearTimeout(this.statusCmdTimer);
// We know that only the first zms will get the command because the
// second can't open the commandQueue until the first exits
// This is necessary because safari will never close the first image
@ -160,7 +164,7 @@ function MonitorStream(monitorData) {
console.log("Changing src from " + img.src + " to " + newSrc);
img.src = '';
img.src = newSrc;
this.statusCmdTimer = setTimeout(this.statusQuery.bind(this), statusRefreshTimeout);
this.streamCmdTimer = setTimeout(this.streamQuery.bind(this), statusRefreshTimeout);
}
}
}; // setscale
@ -183,6 +187,7 @@ function MonitorStream(monitorData) {
}});
}
attachVideo(parseInt(this.id));
this.statusCmdTimer = setTimeout(this.statusCmdQuery.bind(this), delay);
return;
}
@ -195,7 +200,7 @@ function MonitorStream(monitorData) {
console.log(stream);
return;
}
this.statusCmdTimer = clearTimeout(this.statusCmdTimer);
this.streamCmdTimer = clearTimeout(this.streamCmdTimer);
// Step 1 make sure we are streaming instead of a static image
if (stream.getAttribute('loading') == 'lazy') {
stream.setAttribute('loading', 'eager');
@ -209,7 +214,7 @@ function MonitorStream(monitorData) {
stream.src = '';
stream.src = src;
}
this.statusCmdTimer = setTimeout(this.statusQuery.bind(this), delay);
//this.streamCmdTimer = setTimeout(this.streamQuery.bind(this), delay);
stream.onerror = this.img_onerror.bind(this);
stream.onload = this.img_onload.bind(this);
}; // this.start
@ -528,6 +533,57 @@ function MonitorStream(monitorData) {
} // end if Ok or not
};
/* getStatusCmd is used when not streaming, since there is no persistent zms */
this.getStatusCmdResponse=function(respObj, respText) {
watchdogOk('status');
this.statusCmdTimer = clearTimeout(this.statusCmdTimer);
const alarmState = respObj.monitor.Status;
if (respObj.result == 'Ok') {
const captureFPSValue = $j('#captureFPSValue'+this.id);
const analysisFPSValue = $j('#analysisFPSValue'+this.id);
const fpses = respObj.monitor.FrameRate.split(",");
fpses.forEach(function(fps){
const name_values = fps.split(':');
const name = name_values[0].trim();
const value = name_values[1].trim().toLocaleString(undefined, {minimumFractionDigits: 1, maximumFractionDigits: 1});
if (name == 'analysis') {
this.status.analysisfps = value;
if (analysisFPSValue.length && (analysisFPSValue.text() != value)) {
analysisFPSValue.text(value);
}
} else if (name == 'capture') {
if (captureFPSValue.length && (captureFPSValue.text() != value)) {
captureFPSValue.text(value);
}
} else {
console.log("Unknown fps name " + name);
}
});
this.setAlarmState(alarmState);
} else {
checkStreamForErrors('getStatusCmdResponse', respObj);
}
let statusCmdTimeout = statusRefreshTimeout;
if (alarmState == STATE_ALARM || alarmState == STATE_ALERT) {
statusCmdTimeout = statusCmdTimeout/5;
}
this.statusCmdTimer = setTimeout(this.statusCmdQuery.bind(this), statusRefreshTimeout);
}
this.statusCmdQuery=function() {
$j.getJSON(this.url + '?view=request&request=status&entity=monitor&element[]=Status&element[]=FrameRate&id='+this.id+'&'+this.auth_relay)
.done(this.getStatusCmdResponse.bind(this))
.fail(logAjaxFail);
this.statusCmdTimer = null;
}
this.statusQuery = function() {
this.streamCommand(CMD_QUERY);
this.statusCmdTimer = setTimeout(this.statusQuery.bind(this), statusRefreshTimeout);
@ -535,9 +591,9 @@ function MonitorStream(monitorData) {
this.streamCmdQuery = function(resent) {
if (this.type != 'WebSite') {
this.streamCmdParms.command = CMD_QUERY;
this.streamCmdReq(this.streamCmdParms);
this.streamCommand(CMD_QUERY);
}
this.streamCmdTimer = setTimeout(this.streamCmdQuery.bind(this), statusRefreshTimeout);
};
this.streamCommand = function(command) {