replace mootools in MonitorStream
This commit is contained in:
parent
4a85ef2084
commit
29f3e9007a
|
@ -8,13 +8,16 @@ function MonitorStream(monitorData) {
|
|||
this.status = null;
|
||||
this.alarmState = 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 ) {
|
||||
this.streamCmdParms += '&auth='+auth_hash;
|
||||
this.streamCmdParms.auth = auth_hash;
|
||||
} else if ( auth_relay ) {
|
||||
this.streamCmdParms += '&'+auth_relay;
|
||||
this.streamCmdParms.auth_relay = '';
|
||||
}
|
||||
this.streamCmdTimer = null;
|
||||
this.type = monitorData.type;
|
||||
this.refresh = monitorData.refresh;
|
||||
this.start = function(delay) {
|
||||
|
@ -33,15 +36,7 @@ function MonitorStream(monitorData) {
|
|||
stream.src = '';
|
||||
stream.src = src;
|
||||
}
|
||||
|
||||
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.streamCmdQuery.delay(delay, this);
|
||||
};
|
||||
this.stop = function() {
|
||||
if ( 0 ) {
|
||||
|
@ -57,13 +52,16 @@ function MonitorStream(monitorData) {
|
|||
stream.src = src;
|
||||
}
|
||||
}
|
||||
this.streamCmdReq.send(this.streamCmdParms+"&command="+CMD_STOP);
|
||||
this.streamCmdParms.command = CMD_STOP;
|
||||
this.streamCmdReq(this.streamCmdParms);
|
||||
};
|
||||
this.pause = function() {
|
||||
this.streamCmdReq.send(this.streamCmdParms+"&command="+CMD_PAUSE);
|
||||
this.streamCmdParms.command = CMD_PAUSE;
|
||||
this.streamCmdReq(this.streamCmdParms);
|
||||
};
|
||||
this.play = function() {
|
||||
this.streamCmdReq.send(this.streamCmdParms+"&command="+CMD_PLAY);
|
||||
this.streamCmdParms.command = CMD_PLAY;
|
||||
this.streamCmdReq(this.streamCmdParms);
|
||||
};
|
||||
|
||||
this.eventHandler = function(event) {
|
||||
|
@ -86,55 +84,28 @@ function MonitorStream(monitorData) {
|
|||
document.getElementById('imageFeed'+this.id).removeEventListener('click', this.onclick );
|
||||
};
|
||||
|
||||
this.setStateClass = function(element, stateClass) {
|
||||
if ( !element ) {
|
||||
this.setStateClass = function(jobj, stateClass) {
|
||||
if ( !jobj ) {
|
||||
return;
|
||||
}
|
||||
if ( !element.hasClass( stateClass ) ) {
|
||||
if ( stateClass != 'alarm' ) {
|
||||
element.removeClass('alarm');
|
||||
}
|
||||
if ( stateClass != 'alert' ) {
|
||||
element.removeClass('alert');
|
||||
}
|
||||
if ( stateClass != 'idle' ) {
|
||||
element.removeClass('idle');
|
||||
}
|
||||
element.addClass(stateClass);
|
||||
if ( !jobj.hasClass( stateClass ) ) {
|
||||
if ( stateClass != 'alarm' ) jobj.removeClass('alarm');
|
||||
if ( stateClass != 'alert' ) jobj.removeClass('alert');
|
||||
if ( stateClass != 'idle' ) jobj.removeClass('idle');
|
||||
|
||||
jobj.addClass(stateClass);
|
||||
}
|
||||
};
|
||||
|
||||
this.onError = function(text, error) {
|
||||
console.log('onerror: ' + text + ' error:'+error);
|
||||
// Requeue, but want to wait a while.
|
||||
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.onFailure = function(jqxhr, textStatus, error) {
|
||||
this.streamCmdQuery.delay(1000*statusRefreshTimeout, this);
|
||||
logAjaxFail(jqxhr, textStatus, error);
|
||||
};
|
||||
|
||||
this.getStreamCmdResponse = function(respObj, respText) {
|
||||
if ( this.streamCmdTimer ) {
|
||||
this.streamCmdTimer = clearTimeout(this.streamCmdTimer);
|
||||
}
|
||||
|
||||
var stream = $j('#liveStream'+this.id)[0];
|
||||
|
||||
if ( ! stream ) {
|
||||
console.log('No live stream');
|
||||
return;
|
||||
|
@ -159,22 +130,16 @@ function MonitorStream(monitorData) {
|
|||
!COMPACT_MONTAGE) &&
|
||||
(this.type != 'WebSite')
|
||||
) {
|
||||
fpsValue = $('fpsValue'+this.id);
|
||||
if ( fpsValue ) {
|
||||
fpsValue.set('text', this.status.fps);
|
||||
}
|
||||
stateValue = $('stateValue'+this.id);
|
||||
if ( stateValue ) {
|
||||
stateValue.set('text', stateStrings[this.alarmState]);
|
||||
var fpsValue = $j('#fpsValue'+this.id);
|
||||
var stateValue = $j('#stateValue'+this.id);
|
||||
var monitorState = $j('#monitorState'+this.id);
|
||||
|
||||
if ( fpsValue.length ) fpsValue.text(this.status.fps);
|
||||
if ( stateValue.length ) stateValue.text(stateStrings[this.alarmState]);
|
||||
if ( monitorState.length ) this.setStateClass(monitorState, stateClass);
|
||||
}
|
||||
|
||||
monitorState = $('monitorState'+this.id);
|
||||
if ( monitorState ) {
|
||||
this.setStateClass(monitorState, stateClass);
|
||||
}
|
||||
}
|
||||
|
||||
this.setStateClass($('monitor'+this.id), stateClass);
|
||||
this.setStateClass($j('#monitor'+this.id), stateClass);
|
||||
|
||||
/*Stream could be an applet so can't use moo tools*/
|
||||
//stream.parentNode().className = stateClass;
|
||||
|
@ -188,7 +153,7 @@ function MonitorStream(monitorData) {
|
|||
if ( newAlarm ) {
|
||||
if ( false && SOUND_ON_ALARM ) {
|
||||
// Enable the alarm sound
|
||||
$('alarmSound').removeClass('hidden');
|
||||
$j('#alarmSound').removeClass('hidden');
|
||||
}
|
||||
if ( (typeof POPUP_ON_ALARM !== 'undefined') && POPUP_ON_ALARM ) {
|
||||
windowToFront();
|
||||
|
@ -197,7 +162,7 @@ function MonitorStream(monitorData) {
|
|||
if ( false && SOUND_ON_ALARM ) {
|
||||
if ( oldAlarm ) {
|
||||
// Disable alarm sound
|
||||
$('alarmSound').addClass('hidden');
|
||||
$j('#alarmSound').addClass('hidden');
|
||||
}
|
||||
}
|
||||
if ( this.status.auth ) {
|
||||
|
@ -230,38 +195,24 @@ function MonitorStream(monitorData) {
|
|||
}
|
||||
} // 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.streamCmdQuery.delay(statusRefreshTimeout, this);
|
||||
};
|
||||
|
||||
this.streamCmdQuery = function(resent) {
|
||||
if ( resent ) {
|
||||
console.log(this.connKey+': timeout: Resending');
|
||||
this.streamCmdReq.cancel();
|
||||
}
|
||||
//console.log("Starting CmdQuery for " + this.connKey );
|
||||
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' ) {
|
||||
this.streamCmdReq = new Request.JSON( {
|
||||
url: this.url,
|
||||
method: 'get',
|
||||
timeout: AJAX_TIMEOUT,
|
||||
onSuccess: this.getStreamCmdResponse.bind(this),
|
||||
onTimeout: this.streamCmdQuery.bind(this, true),
|
||||
onError: this.onError.bind(this),
|
||||
onFailure: this.onFailure.bind(this),
|
||||
link: 'cancel'
|
||||
} );
|
||||
this.streamCmdReq = function(streamCmdParms) {
|
||||
$j.ajaxSetup({timeout: AJAX_TIMEOUT});
|
||||
$j.getJSON(this.url, streamCmdParms)
|
||||
.done(this.getStreamCmdResponse.bind(this))
|
||||
.fail(this.onFailure.bind(this));
|
||||
};
|
||||
}
|
||||
} // end function MonitorStream
|
||||
|
|
|
@ -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
|
||||
* is rendered
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
var requestQueue = new Request.Queue({
|
||||
concurrent: monitorData.length,
|
||||
stopOnFailure: false
|
||||
});
|
||||
|
||||
var pauseBtn = $j('#pauseBtn');
|
||||
var playBtn = $j('#playBtn');
|
||||
var saveBtn = $j('#saveBtn');
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
|
||||
var requestQueue = new Request.Queue({
|
||||
concurrent: monitorData.length,
|
||||
stopOnFailure: false
|
||||
});
|
||||
function streamCmdQuit( ) {
|
||||
if ( action ) {
|
||||
streamCmdReq.send( streamCmdParms+"&command="+CMD_QUIT );
|
||||
|
|
Loading…
Reference in New Issue