replace mootools in MonitorStream

This commit is contained in:
Andrew Bauer 2021-01-06 14:19:25 -06:00 committed by Isaac Connor
parent 4a85ef2084
commit 29f3e9007a
4 changed files with 46 additions and 109 deletions

View File

@ -8,13 +8,16 @@ function MonitorStream(monitorData) {
this.status = null; this.status = null;
this.alarmState = STATE_IDLE; this.alarmState = STATE_IDLE;
this.lastAlarmState = STATE_IDLE; this.lastAlarmState = STATE_IDLE;
this.streamCmdParms = 'view=request&request=stream&connkey='+this.connKey; this.streamCmdParms = {
view: 'request',
request: 'stream',
connkey: this.connKey
};
if ( auth_hash ) { if ( auth_hash ) {
this.streamCmdParms += '&auth='+auth_hash; this.streamCmdParms.auth = auth_hash;
} else if ( auth_relay ) { } else if ( auth_relay ) {
this.streamCmdParms += '&'+auth_relay; this.streamCmdParms.auth_relay = '';
} }
this.streamCmdTimer = null;
this.type = monitorData.type; this.type = monitorData.type;
this.refresh = monitorData.refresh; this.refresh = monitorData.refresh;
this.start = function(delay) { this.start = function(delay) {
@ -33,15 +36,7 @@ function MonitorStream(monitorData) {
stream.src = ''; stream.src = '';
stream.src = src; stream.src = src;
} }
this.streamCmdQuery.delay(delay, this);
if ( this.streamCmdQuery ) {
this.streamCmdTimer = this.streamCmdQuery.delay(delay, this);
} else {
console.log("No streamCmdQuery");
}
console.log("queueing for " + this.id + " " + this.connKey + " timeout is: " + AJAX_TIMEOUT);
requestQueue.addRequest("cmdReq"+this.id, this.streamCmdReq);
}; };
this.stop = function() { this.stop = function() {
if ( 0 ) { if ( 0 ) {
@ -57,13 +52,16 @@ function MonitorStream(monitorData) {
stream.src = src; stream.src = src;
} }
} }
this.streamCmdReq.send(this.streamCmdParms+"&command="+CMD_STOP); this.streamCmdParms.command = CMD_STOP;
this.streamCmdReq(this.streamCmdParms);
}; };
this.pause = function() { this.pause = function() {
this.streamCmdReq.send(this.streamCmdParms+"&command="+CMD_PAUSE); this.streamCmdParms.command = CMD_PAUSE;
this.streamCmdReq(this.streamCmdParms);
}; };
this.play = function() { this.play = function() {
this.streamCmdReq.send(this.streamCmdParms+"&command="+CMD_PLAY); this.streamCmdParms.command = CMD_PLAY;
this.streamCmdReq(this.streamCmdParms);
}; };
this.eventHandler = function(event) { this.eventHandler = function(event) {
@ -86,55 +84,28 @@ function MonitorStream(monitorData) {
document.getElementById('imageFeed'+this.id).removeEventListener('click', this.onclick ); document.getElementById('imageFeed'+this.id).removeEventListener('click', this.onclick );
}; };
this.setStateClass = function(element, stateClass) { this.setStateClass = function(jobj, stateClass) {
if ( !element ) { if ( !jobj ) {
return; return;
} }
if ( !element.hasClass( stateClass ) ) { if ( !jobj.hasClass( stateClass ) ) {
if ( stateClass != 'alarm' ) { if ( stateClass != 'alarm' ) jobj.removeClass('alarm');
element.removeClass('alarm'); if ( stateClass != 'alert' ) jobj.removeClass('alert');
} if ( stateClass != 'idle' ) jobj.removeClass('idle');
if ( stateClass != 'alert' ) {
element.removeClass('alert'); jobj.addClass(stateClass);
}
if ( stateClass != 'idle' ) {
element.removeClass('idle');
}
element.addClass(stateClass);
} }
}; };
this.onError = function(text, error) { this.onFailure = function(jqxhr, textStatus, error) {
console.log('onerror: ' + text + ' error:'+error); this.streamCmdQuery.delay(1000*statusRefreshTimeout, this);
// Requeue, but want to wait a while. logAjaxFail(jqxhr, textStatus, error);
var streamCmdTimeout = 10*statusRefreshTimeout;
this.streamCmdTimer = this.streamCmdQuery.delay(streamCmdTimeout, this);
};
this.onFailure = function(xhr) {
console.log('onFailure: ' + this.connKey);
console.log(xhr);
if ( ! requestQueue.hasNext('cmdReq'+this.id) ) {
console.log('Not requeuing because there is one already');
requestQueue.addRequest('cmdReq'+this.id, this.streamCmdReq);
}
if ( 0 ) {
// Requeue, but want to wait a while.
if ( this.streamCmdTimer ) {
this.streamCmdTimer = clearTimeout( this.streamCmdTimer );
}
var streamCmdTimeout = 1000*statusRefreshTimeout;
this.streamCmdTimer = this.streamCmdQuery.delay(streamCmdTimeout, this, true);
requestQueue.resume();
}
console.log('done failure');
}; };
this.getStreamCmdResponse = function(respObj, respText) { this.getStreamCmdResponse = function(respObj, respText) {
if ( this.streamCmdTimer ) {
this.streamCmdTimer = clearTimeout(this.streamCmdTimer);
}
var stream = $j('#liveStream'+this.id)[0]; var stream = $j('#liveStream'+this.id)[0];
if ( ! stream ) { if ( ! stream ) {
console.log('No live stream'); console.log('No live stream');
return; return;
@ -159,22 +130,16 @@ function MonitorStream(monitorData) {
!COMPACT_MONTAGE) && !COMPACT_MONTAGE) &&
(this.type != 'WebSite') (this.type != 'WebSite')
) { ) {
fpsValue = $('fpsValue'+this.id); var fpsValue = $j('#fpsValue'+this.id);
if ( fpsValue ) { var stateValue = $j('#stateValue'+this.id);
fpsValue.set('text', this.status.fps); var monitorState = $j('#monitorState'+this.id);
}
stateValue = $('stateValue'+this.id); if ( fpsValue.length ) fpsValue.text(this.status.fps);
if ( stateValue ) { if ( stateValue.length ) stateValue.text(stateStrings[this.alarmState]);
stateValue.set('text', stateStrings[this.alarmState]); if ( monitorState.length ) this.setStateClass(monitorState, stateClass);
} }
monitorState = $('monitorState'+this.id); this.setStateClass($j('#monitor'+this.id), stateClass);
if ( monitorState ) {
this.setStateClass(monitorState, stateClass);
}
}
this.setStateClass($('monitor'+this.id), stateClass);
/*Stream could be an applet so can't use moo tools*/ /*Stream could be an applet so can't use moo tools*/
//stream.parentNode().className = stateClass; //stream.parentNode().className = stateClass;
@ -188,7 +153,7 @@ function MonitorStream(monitorData) {
if ( newAlarm ) { if ( newAlarm ) {
if ( false && SOUND_ON_ALARM ) { if ( false && SOUND_ON_ALARM ) {
// Enable the alarm sound // Enable the alarm sound
$('alarmSound').removeClass('hidden'); $j('#alarmSound').removeClass('hidden');
} }
if ( (typeof POPUP_ON_ALARM !== 'undefined') && POPUP_ON_ALARM ) { if ( (typeof POPUP_ON_ALARM !== 'undefined') && POPUP_ON_ALARM ) {
windowToFront(); windowToFront();
@ -197,7 +162,7 @@ function MonitorStream(monitorData) {
if ( false && SOUND_ON_ALARM ) { if ( false && SOUND_ON_ALARM ) {
if ( oldAlarm ) { if ( oldAlarm ) {
// Disable alarm sound // Disable alarm sound
$('alarmSound').addClass('hidden'); $j('#alarmSound').addClass('hidden');
} }
} }
if ( this.status.auth ) { if ( this.status.auth ) {
@ -230,38 +195,24 @@ function MonitorStream(monitorData) {
} }
} // end if Ok or not } // end if Ok or not
var streamCmdTimeout = statusRefreshTimeout;
// The idea here is if we are alarmed, do updates faster.
// However, there is a timeout in the php side which isn't getting modified,
// so this may cause a problem. Also the server may only be able to update so fast.
//if ( this.alarmState == STATE_ALARM || this.alarmState == STATE_ALERT ) {
//streamCmdTimeout = streamCmdTimeout/5;
//}
this.streamCmdTimer = this.streamCmdQuery.delay(streamCmdTimeout, this);
this.lastAlarmState = this.alarmState; this.lastAlarmState = this.alarmState;
this.streamCmdQuery.delay(statusRefreshTimeout, this);
}; };
this.streamCmdQuery = function(resent) { this.streamCmdQuery = function(resent) {
if ( resent ) {
console.log(this.connKey+': timeout: Resending');
this.streamCmdReq.cancel();
}
//console.log("Starting CmdQuery for " + this.connKey ); //console.log("Starting CmdQuery for " + this.connKey );
if ( this.type != 'WebSite' ) { if ( this.type != 'WebSite' ) {
this.streamCmdReq.send(this.streamCmdParms+'&command='+CMD_QUERY); this.streamCmdParms.command = CMD_QUERY;
this.streamCmdReq(this.streamCmdParms);
} }
}; };
if ( this.type != 'WebSite' ) { if ( this.type != 'WebSite' ) {
this.streamCmdReq = new Request.JSON( { this.streamCmdReq = function(streamCmdParms) {
url: this.url, $j.ajaxSetup({timeout: AJAX_TIMEOUT});
method: 'get', $j.getJSON(this.url, streamCmdParms)
timeout: AJAX_TIMEOUT, .done(this.getStreamCmdResponse.bind(this))
onSuccess: this.getStreamCmdResponse.bind(this), .fail(this.onFailure.bind(this));
onTimeout: this.streamCmdQuery.bind(this, true), };
onError: this.onError.bind(this),
onFailure: this.onFailure.bind(this),
link: 'cancel'
} );
} }
} // end function MonitorStream } // end function MonitorStream

View File

@ -1,7 +1,3 @@
var requestQueue = new Request.Queue({
concurrent: monitorData.length,
stopOnFailure: false
});
/** /**
* called when the layoutControl select element is changed, or the page * called when the layoutControl select element is changed, or the page
* is rendered * is rendered

View File

@ -1,8 +1,3 @@
var requestQueue = new Request.Queue({
concurrent: monitorData.length,
stopOnFailure: false
});
var pauseBtn = $j('#pauseBtn'); var pauseBtn = $j('#pauseBtn');
var playBtn = $j('#playBtn'); var playBtn = $j('#playBtn');
var saveBtn = $j('#saveBtn'); var saveBtn = $j('#saveBtn');

View File

@ -1,8 +1,3 @@
var requestQueue = new Request.Queue({
concurrent: monitorData.length,
stopOnFailure: false
});
function streamCmdQuit( ) { function streamCmdQuit( ) {
if ( action ) { if ( action ) {
streamCmdReq.send( streamCmdParms+"&command="+CMD_QUIT ); streamCmdReq.send( streamCmdParms+"&command="+CMD_QUIT );