2009-05-08 18:04:12 +08:00
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function showEvents() {
|
2020-03-05 00:22:08 +08:00
|
|
|
$('ptzControls').addClass('hidden');
|
|
|
|
$('events').removeClass('hidden');
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( $('eventsControl') ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
$('eventsControl').addClass('hidden');
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
|
|
|
if ( $('controlControl') ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
$('controlControl').removeClass('hidden');
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-03-05 00:22:08 +08:00
|
|
|
showMode = 'events';
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function showPtzControls() {
|
2020-03-05 00:22:08 +08:00
|
|
|
$('events').addClass('hidden');
|
|
|
|
$('ptzControls').removeClass('hidden');
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( $('eventsControl') ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
$('eventsControl').removeClass('hidden');
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
|
|
|
if ( $('controlControl') ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
$('controlControl').addClass('hidden');
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-03-05 00:22:08 +08:00
|
|
|
showMode = 'control';
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function changeScale() {
|
|
|
|
var scale = $('scale').get('value');
|
2017-11-21 03:25:13 +08:00
|
|
|
var newWidth;
|
|
|
|
var newHeight;
|
2020-03-05 00:22:08 +08:00
|
|
|
if ( scale == '0' || scale == 'auto' ) {
|
2019-01-18 23:00:55 +08:00
|
|
|
var newSize = scaleToFit(monitorWidth, monitorHeight, $j('#liveStream'+monitorId), $j('#replayStatus'));
|
2017-11-21 03:25:13 +08:00
|
|
|
newWidth = newSize.width;
|
|
|
|
newHeight = newSize.height;
|
|
|
|
autoScale = newSize.autoScale;
|
|
|
|
} else {
|
|
|
|
$j(window).off('resize', endOfResize); //remove resize handler when Scale to Fit is not active
|
|
|
|
newWidth = monitorWidth * scale / SCALE_BASE;
|
|
|
|
newHeight = monitorHeight * scale / SCALE_BASE;
|
|
|
|
}
|
|
|
|
|
2020-01-06 06:33:53 +08:00
|
|
|
Cookie.write('zmWatchScale'+monitorId, scale, {duration: 10*365});
|
2016-09-27 23:51:55 +08:00
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
/*Stream could be an applet so can't use moo tools*/
|
2017-08-04 00:41:43 +08:00
|
|
|
var streamImg = $('liveStream'+monitorId);
|
2016-09-27 23:51:55 +08:00
|
|
|
if ( streamImg ) {
|
2020-01-06 06:33:53 +08:00
|
|
|
streamImg.style.width = newWidth + 'px';
|
|
|
|
streamImg.style.height = newHeight + 'px';
|
2016-09-27 23:51:55 +08:00
|
|
|
|
2017-11-21 03:25:13 +08:00
|
|
|
streamImg.src = streamImg.src.replace(/scale=\d+/i, 'scale='+(scale== 'auto' ? autoScale : scale));
|
2016-09-27 23:51:55 +08:00
|
|
|
} else {
|
2020-03-20 23:06:01 +08:00
|
|
|
console.error('No element found for liveStream'+monitorId);
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var alarmState = STATE_IDLE;
|
|
|
|
var lastAlarmState = STATE_IDLE;
|
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function setAlarmState( currentAlarmState ) {
|
|
|
|
alarmState = currentAlarmState;
|
|
|
|
|
2020-01-06 06:33:53 +08:00
|
|
|
var stateClass = '';
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( alarmState == STATE_ALARM ) {
|
2020-01-06 06:33:53 +08:00
|
|
|
stateClass = 'alarm';
|
2019-01-19 23:32:40 +08:00
|
|
|
} else if ( alarmState == STATE_ALERT ) {
|
2020-01-06 06:33:53 +08:00
|
|
|
stateClass = 'alert';
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-01-06 06:33:53 +08:00
|
|
|
$('stateValue').set('text', stateStrings[alarmState]);
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( stateClass ) {
|
2020-01-06 06:33:53 +08:00
|
|
|
$('stateValue').setProperty('class', stateClass);
|
2019-01-19 23:32:40 +08:00
|
|
|
} else {
|
2020-01-06 06:33:53 +08:00
|
|
|
$('stateValue').removeProperty('class');
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
|
|
|
|
var isAlarmed = ( alarmState == STATE_ALARM || alarmState == STATE_ALERT );
|
|
|
|
var wasAlarmed = ( lastAlarmState == STATE_ALARM || lastAlarmState == STATE_ALERT );
|
|
|
|
|
|
|
|
var newAlarm = ( isAlarmed && !wasAlarmed );
|
|
|
|
var oldAlarm = ( !isAlarmed && wasAlarmed );
|
|
|
|
|
|
|
|
if ( newAlarm ) {
|
|
|
|
if ( SOUND_ON_ALARM ) {
|
|
|
|
// Enable the alarm sound
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( !canPlayPauseAudio ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
$('alarmSound').removeClass('hidden');
|
2019-01-19 23:32:40 +08:00
|
|
|
} else {
|
2016-09-27 23:51:55 +08:00
|
|
|
$('MediaPlayer').Play();
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2008-07-16 23:47:33 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
if ( POPUP_ON_ALARM ) {
|
|
|
|
window.focus();
|
2008-07-16 23:47:33 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
2020-03-05 00:22:08 +08:00
|
|
|
if ( oldAlarm ) { // done with an event do a refresh
|
|
|
|
if ( SOUND_ON_ALARM ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
// Disable alarm sound
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( !canPlayPauseAudio ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
$('alarmSound').addClass('hidden');
|
2019-01-19 23:32:40 +08:00
|
|
|
} else {
|
2016-09-27 23:51:55 +08:00
|
|
|
$('MediaPlayer').Stop();
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
eventCmdQuery();
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2009-05-26 02:03:46 +08:00
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
lastAlarmState = alarmState;
|
2020-03-05 00:22:08 +08:00
|
|
|
} // end function setAlarmState( currentAlarmState )
|
2008-07-16 23:47:33 +08:00
|
|
|
|
2018-04-27 05:18:36 +08:00
|
|
|
if ( monitorType != 'WebSite' ) {
|
2020-01-06 06:33:53 +08:00
|
|
|
var streamCmdParms = 'view=request&request=stream&connkey='+connKey;
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( auth_hash ) {
|
2018-04-27 05:18:36 +08:00
|
|
|
streamCmdParms += '&auth='+auth_hash;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2018-04-27 05:18:36 +08:00
|
|
|
var streamCmdReq = new Request.JSON( {
|
2018-10-19 08:33:50 +08:00
|
|
|
url: monitorUrl,
|
2018-04-27 05:18:36 +08:00
|
|
|
method: 'get',
|
|
|
|
timeout: AJAX_TIMEOUT,
|
|
|
|
link: 'chain',
|
2018-08-31 22:34:54 +08:00
|
|
|
onError: getStreamCmdError,
|
2018-04-27 05:18:36 +08:00
|
|
|
onSuccess: getStreamCmdResponse,
|
|
|
|
onFailure: getStreamCmdFailure
|
|
|
|
} );
|
|
|
|
var streamCmdTimer = null;
|
|
|
|
}
|
2008-07-16 23:47:33 +08:00
|
|
|
|
|
|
|
var streamStatus;
|
|
|
|
|
2019-01-18 23:00:55 +08:00
|
|
|
function getStreamCmdError(text, error) {
|
2018-08-31 22:34:54 +08:00
|
|
|
console.log(error);
|
|
|
|
// Error are normally due to failed auth. reload the page.
|
|
|
|
window.location.reload();
|
|
|
|
}
|
2018-01-29 23:32:02 +08:00
|
|
|
function getStreamCmdFailure(xhr) {
|
2018-08-31 22:34:54 +08:00
|
|
|
console.log(xhr);
|
2018-01-29 23:32:02 +08:00
|
|
|
}
|
2018-08-31 22:34:54 +08:00
|
|
|
function getStreamCmdResponse(respObj, respText) {
|
2020-01-06 06:33:53 +08:00
|
|
|
watchdogOk('stream');
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( streamCmdTimer ) {
|
2018-08-31 22:34:54 +08:00
|
|
|
streamCmdTimer = clearTimeout(streamCmdTimer);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
if ( respObj.result == 'Ok' ) {
|
2018-01-30 00:25:46 +08:00
|
|
|
// The get status command can get backed up, in which case we won't be able to get the semaphore and will exit.
|
|
|
|
if ( respObj.status ) {
|
|
|
|
streamStatus = respObj.status;
|
2018-08-31 22:34:54 +08:00
|
|
|
$('fpsValue').set('text', streamStatus.fps);
|
2018-01-30 00:25:46 +08:00
|
|
|
|
2018-08-31 22:34:54 +08:00
|
|
|
setAlarmState(streamStatus.state);
|
2018-01-30 00:25:46 +08:00
|
|
|
|
2018-08-31 22:34:54 +08:00
|
|
|
$('levelValue').set('text', streamStatus.level);
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( streamStatus.level > 95 ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
$('levelValue').className = 'alarm';
|
2019-01-19 23:32:40 +08:00
|
|
|
} else if ( streamStatus.level > 80 ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
$('levelValue').className = 'alert';
|
2019-01-19 23:32:40 +08:00
|
|
|
} else {
|
2020-03-05 00:22:08 +08:00
|
|
|
$('levelValue').className = 'ok';
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2018-01-30 00:25:46 +08:00
|
|
|
|
2018-08-31 22:34:54 +08:00
|
|
|
var delayString = secsToTime(streamStatus.delay);
|
2018-01-30 00:25:46 +08:00
|
|
|
|
|
|
|
if ( streamStatus.paused == true ) {
|
2018-08-31 22:34:54 +08:00
|
|
|
$('modeValue').set('text', 'Paused');
|
|
|
|
$('rate').addClass('hidden');
|
|
|
|
$('delayValue').set('text', delayString);
|
|
|
|
$('delay').removeClass('hidden');
|
|
|
|
$('level').removeClass('hidden');
|
|
|
|
streamCmdPause(false);
|
2018-01-30 00:25:46 +08:00
|
|
|
} else if ( streamStatus.delayed == true ) {
|
2018-08-31 22:34:54 +08:00
|
|
|
$('modeValue').set('text', 'Replay');
|
|
|
|
$('rateValue').set('text', streamStatus.rate);
|
|
|
|
$('rate').removeClass('hidden');
|
|
|
|
$('delayValue').set('text', delayString);
|
|
|
|
$('delay').removeClass('hidden');
|
|
|
|
$('level').removeClass('hidden');
|
2018-01-30 00:25:46 +08:00
|
|
|
if ( streamStatus.rate == 1 ) {
|
2018-08-31 22:34:54 +08:00
|
|
|
streamCmdPlay(false);
|
2018-01-30 00:25:46 +08:00
|
|
|
} else if ( streamStatus.rate > 0 ) {
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( streamStatus.rate < 1 ) {
|
2018-08-31 22:34:54 +08:00
|
|
|
streamCmdSlowFwd(false);
|
2019-01-19 23:32:40 +08:00
|
|
|
} else {
|
2018-08-31 22:34:54 +08:00
|
|
|
streamCmdFastFwd(false);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2018-01-30 00:25:46 +08:00
|
|
|
} else {
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( streamStatus.rate > -1 ) {
|
2018-08-31 22:34:54 +08:00
|
|
|
streamCmdSlowRev(false);
|
2019-01-19 23:32:40 +08:00
|
|
|
} else {
|
2018-08-31 22:34:54 +08:00
|
|
|
streamCmdFastRev(false);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2018-01-30 00:25:46 +08:00
|
|
|
} // rate
|
2016-09-27 23:51:55 +08:00
|
|
|
} else {
|
2020-03-05 00:22:08 +08:00
|
|
|
$('modeValue').set( 'text', 'Live' );
|
2018-01-30 00:25:46 +08:00
|
|
|
$('rate').addClass( 'hidden' );
|
|
|
|
$('delay').addClass( 'hidden' );
|
|
|
|
$('level').addClass( 'hidden' );
|
2019-09-27 04:13:49 +08:00
|
|
|
streamCmdPlay(false);
|
2018-01-30 00:25:46 +08:00
|
|
|
} // end if paused or delayed
|
|
|
|
|
2019-09-27 04:13:49 +08:00
|
|
|
$('zoomValue').set('text', streamStatus.zoom);
|
|
|
|
if ( streamStatus.zoom == '1.0' ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('zoomOutBtn', 'unavail');
|
2019-01-19 23:32:40 +08:00
|
|
|
} else {
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('zoomOutBtn', 'inactive');
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2018-01-30 00:25:46 +08:00
|
|
|
|
|
|
|
if ( canEditMonitors ) {
|
|
|
|
if ( streamStatus.enabled ) {
|
2019-09-27 04:13:49 +08:00
|
|
|
$('enableAlarmsLink').addClass('hidden');
|
|
|
|
$('disableAlarmsLink').removeClass('hidden');
|
2018-01-30 00:25:46 +08:00
|
|
|
if ( streamStatus.forced ) {
|
2019-09-27 04:13:49 +08:00
|
|
|
$('forceAlarmLink').addClass('hidden');
|
|
|
|
$('cancelAlarmLink').removeClass('hidden');
|
2018-01-30 00:25:46 +08:00
|
|
|
} else {
|
2019-09-27 04:13:49 +08:00
|
|
|
$('forceAlarmLink').removeClass('hidden');
|
|
|
|
$('cancelAlarmLink').addClass('hidden');
|
2018-01-30 00:25:46 +08:00
|
|
|
}
|
2019-09-27 04:13:49 +08:00
|
|
|
$('forceCancelAlarm').removeClass('hidden');
|
2016-09-01 00:53:34 +08:00
|
|
|
} else {
|
2019-09-27 04:13:49 +08:00
|
|
|
$('enableAlarmsLink').removeClass('hidden');
|
|
|
|
$('disableAlarmsLink').addClass('hidden');
|
|
|
|
$('forceCancelAlarm').addClass('hidden');
|
2016-09-01 00:53:34 +08:00
|
|
|
}
|
2019-09-27 04:13:49 +08:00
|
|
|
$('enableDisableAlarms').removeClass('hidden');
|
2018-01-30 00:25:46 +08:00
|
|
|
} // end if canEditMonitors
|
|
|
|
|
|
|
|
if ( streamStatus.auth ) {
|
2020-01-08 06:08:57 +08:00
|
|
|
auth_hash = streamStatus.auth;
|
2018-01-30 00:25:46 +08:00
|
|
|
// Try to reload the image stream.
|
|
|
|
var streamImg = $('liveStream');
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( streamImg ) {
|
2018-08-31 22:34:54 +08:00
|
|
|
streamImg.src = streamImg.src.replace(/auth=\w+/i, 'auth='+streamStatus.auth);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-01-08 06:08:57 +08:00
|
|
|
streamCmdParms = streamCmdParms.replace(/auth=\w+/i, 'auth='+streamStatus.auth);
|
|
|
|
statusCmdParms = statusCmdParms.replace(/auth=\w+/i, 'auth='+streamStatus.auth);
|
|
|
|
eventCmdParms = eventCmdParms.replace(/auth=\w+/i, 'auth='+streamStatus.auth);
|
|
|
|
controlParms = controlParms.replace(/auth=\w+/i, 'auth='+streamStatus.auth);
|
2018-08-31 22:34:54 +08:00
|
|
|
} // end if have a new auth hash
|
2018-01-30 00:25:46 +08:00
|
|
|
} // end if respObj.status
|
2016-09-27 23:51:55 +08:00
|
|
|
} else {
|
2020-03-05 00:22:08 +08:00
|
|
|
checkStreamForErrors('getStreamCmdResponse', respObj);//log them
|
2016-09-27 23:51:55 +08:00
|
|
|
// Try to reload the image stream.
|
2018-08-31 22:34:54 +08:00
|
|
|
// If it's an auth error, we should reload the whole page.
|
|
|
|
window.location.reload();
|
|
|
|
if ( 0 ) {
|
2019-01-19 23:32:40 +08:00
|
|
|
var streamImg = $('liveStream'+monitorId);
|
|
|
|
if ( streamImg ) {
|
|
|
|
streamImg.src = streamImg.src.replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) ));
|
2020-03-05 00:22:08 +08:00
|
|
|
console.log('Changing livestream src to ' + streamImg.src);
|
2019-01-19 23:32:40 +08:00
|
|
|
} else {
|
2020-03-05 00:22:08 +08:00
|
|
|
console.log('Unable to find streamImg liveStream');
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2018-08-31 22:34:54 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
var streamCmdTimeout = statusRefreshTimeout;
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
streamCmdTimeout = streamCmdTimeout/5;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-03-05 00:22:08 +08:00
|
|
|
streamCmdTimer = streamCmdQuery.delay(streamCmdTimeout);
|
2017-05-19 01:50:56 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function streamCmdPause( action ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('pauseBtn', 'active');
|
|
|
|
setButtonState('playBtn', 'inactive');
|
|
|
|
setButtonState('stopBtn', 'inactive');
|
2020-03-03 01:43:07 +08:00
|
|
|
if ( monitorStreamReplayBuffer ) {
|
|
|
|
setButtonState('fastFwdBtn', 'inactive');
|
|
|
|
setButtonState('slowFwdBtn', 'inactive');
|
|
|
|
setButtonState('slowRevBtn', 'inactive');
|
|
|
|
setButtonState('fastRevBtn', 'inactive');
|
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( action ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
streamCmdReq.send(streamCmdParms+"&command="+CMD_PAUSE);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdPlay( action ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('pauseBtn', 'inactive');
|
|
|
|
setButtonState('playBtn', 'active');
|
2016-09-27 23:51:55 +08:00
|
|
|
if ( streamStatus.delayed == true ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('stopBtn', 'inactive');
|
2020-03-03 01:43:07 +08:00
|
|
|
if ( monitorStreamReplayBuffer ) {
|
|
|
|
setButtonState('fastFwdBtn', 'inactive');
|
|
|
|
setButtonState('slowFwdBtn', 'inactive');
|
|
|
|
setButtonState('slowRevBtn', 'inactive');
|
|
|
|
setButtonState('fastRevBtn', 'inactive');
|
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
} else {
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('stopBtn', 'unavail');
|
2020-03-03 01:43:07 +08:00
|
|
|
if ( monitorStreamReplayBuffer ) {
|
|
|
|
setButtonState('fastFwdBtn', 'unavail');
|
|
|
|
setButtonState('slowFwdBtn', 'unavail');
|
|
|
|
setButtonState('slowRevBtn', 'unavail');
|
|
|
|
setButtonState('fastRevBtn', 'unavail');
|
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( action ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
streamCmdReq.send(streamCmdParms+"&command="+CMD_PLAY);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdStop( action ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('pauseBtn', 'inactive');
|
|
|
|
setButtonState('playBtn', 'unavail');
|
|
|
|
setButtonState('stopBtn', 'active');
|
2020-03-03 01:43:07 +08:00
|
|
|
if ( monitorStreamReplayBuffer ) {
|
|
|
|
setButtonState('fastFwdBtn', 'unavail');
|
|
|
|
setButtonState('slowFwdBtn', 'unavail');
|
|
|
|
setButtonState('slowRevBtn', 'unavail');
|
|
|
|
setButtonState('fastRevBtn', 'unavail');
|
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( action ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
streamCmdReq.send(streamCmdParms+"&command="+CMD_STOP);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('stopBtn', 'unavail');
|
|
|
|
setButtonState('playBtn', 'active');
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdFastFwd( action ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('pauseBtn', 'inactive');
|
|
|
|
setButtonState('playBtn', 'inactive');
|
|
|
|
setButtonState('stopBtn', 'inactive');
|
2020-03-03 01:43:07 +08:00
|
|
|
if ( monitorStreamReplayBuffer ) {
|
|
|
|
setButtonState('fastFwdBtn', 'inactive');
|
|
|
|
setButtonState('slowFwdBtn', 'inactive');
|
|
|
|
setButtonState('slowRevBtn', 'inactive');
|
|
|
|
setButtonState('fastRevBtn', 'inactive');
|
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( action ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
streamCmdReq.send(streamCmdParms+"&command="+CMD_FASTFWD);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdSlowFwd( action ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('pauseBtn', 'inactive');
|
|
|
|
setButtonState('playBtn', 'inactive');
|
|
|
|
setButtonState('stopBtn', 'inactive');
|
2020-03-03 01:43:07 +08:00
|
|
|
if ( monitorStreamReplayBuffer ) {
|
|
|
|
setButtonState('fastFwdBtn', 'inactive');
|
|
|
|
setButtonState('slowFwdBtn', 'active');
|
|
|
|
setButtonState('slowRevBtn', 'inactive');
|
|
|
|
setButtonState('fastRevBtn', 'inactive');
|
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( action ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
streamCmdReq.send(streamCmdParms+"&command="+CMD_SLOWFWD);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('pauseBtn', 'active');
|
2020-03-03 01:43:07 +08:00
|
|
|
if ( monitorStreamReplayBuffer ) {
|
|
|
|
setButtonState('slowFwdBtn', 'inactive');
|
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdSlowRev( action ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('pauseBtn', 'inactive');
|
|
|
|
setButtonState('playBtn', 'inactive');
|
|
|
|
setButtonState('stopBtn', 'inactive');
|
2020-03-03 01:43:07 +08:00
|
|
|
if ( monitorStreamReplayBuffer ) {
|
|
|
|
setButtonState('fastFwdBtn', 'inactive');
|
|
|
|
setButtonState('slowFwdBtn', 'inactive');
|
|
|
|
setButtonState('slowRevBtn', 'active');
|
|
|
|
setButtonState('fastRevBtn', 'inactive');
|
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( action ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
streamCmdReq.send(streamCmdParms+"&command="+CMD_SLOWREV);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('pauseBtn', 'active');
|
2020-03-03 01:43:07 +08:00
|
|
|
if ( monitorStreamReplayBuffer ) {
|
|
|
|
setButtonState('slowRevBtn', 'inactive');
|
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdFastRev( action ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
setButtonState('pauseBtn', 'inactive');
|
|
|
|
setButtonState('playBtn', 'inactive');
|
|
|
|
setButtonState('stopBtn', 'inactive');
|
2020-03-03 01:43:07 +08:00
|
|
|
if ( monitorStreamReplayBuffer ) {
|
|
|
|
setButtonState('fastFwdBtn', 'inactive');
|
|
|
|
setButtonState('slowFwdBtn', 'inactive');
|
|
|
|
setButtonState('slowRevBtn', 'inactive');
|
|
|
|
setButtonState('fastRevBtn', 'inactive');
|
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( action ) {
|
2020-03-03 00:52:32 +08:00
|
|
|
streamCmdReq.send(streamCmdParms+"&command="+CMD_FASTREV);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdZoomIn( x, y ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
streamCmdReq.send(streamCmdParms+"&command="+CMD_ZOOMIN+"&x="+x+"&y="+y);
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdZoomOut() {
|
2020-03-05 00:22:08 +08:00
|
|
|
streamCmdReq.send(streamCmdParms+"&command="+CMD_ZOOMOUT);
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdScale( scale ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
streamCmdReq.send(streamCmdParms+"&command="+CMD_SCALE+"&scale="+scale);
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdPan( x, y ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
streamCmdReq.send(streamCmdParms+"&command="+CMD_PAN+"&x="+x+"&y="+y);
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdQuery() {
|
2020-03-05 00:22:08 +08:00
|
|
|
streamCmdReq.send(streamCmdParms+"&command="+CMD_QUERY);
|
2017-03-18 15:00:51 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2018-04-27 05:18:36 +08:00
|
|
|
if ( monitorType != 'WebSite' ) {
|
|
|
|
var statusCmdParms = "view=request&request=status&entity=monitor&id="+monitorId+"&element[]=Status&element[]=FrameRate";
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( auth_hash ) {
|
2018-04-27 05:18:36 +08:00
|
|
|
statusCmdParms += '&auth='+auth_hash;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-03-05 00:22:08 +08:00
|
|
|
var statusCmdReq = new Request.JSON( {
|
|
|
|
url: monitorUrl,
|
|
|
|
method: 'get',
|
|
|
|
timeout: AJAX_TIMEOUT,
|
|
|
|
link: 'cancel',
|
|
|
|
onSuccess: getStatusCmdResponse
|
|
|
|
} );
|
2018-04-27 05:18:36 +08:00
|
|
|
var statusCmdTimer = null;
|
|
|
|
}
|
2008-07-16 23:47:33 +08:00
|
|
|
|
2018-08-31 22:34:54 +08:00
|
|
|
function getStatusCmdResponse(respObj, respText) {
|
2020-03-05 00:22:08 +08:00
|
|
|
watchdogOk('status');
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( statusCmdTimer ) {
|
2018-08-31 22:34:54 +08:00
|
|
|
statusCmdTimer = clearTimeout(statusCmdTimer);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
|
|
|
|
if ( respObj.result == 'Ok' ) {
|
2018-08-31 22:34:54 +08:00
|
|
|
$('fpsValue').set('text', respObj.monitor.FrameRate);
|
|
|
|
setAlarmState(respObj.monitor.Status);
|
2019-01-19 23:32:40 +08:00
|
|
|
} else {
|
2020-03-05 00:22:08 +08:00
|
|
|
checkStreamForErrors('getStatusCmdResponse', respObj);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
|
|
|
|
var statusCmdTimeout = statusRefreshTimeout;
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
statusCmdTimeout = statusCmdTimeout/5;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-03-05 00:22:08 +08:00
|
|
|
statusCmdTimer = statusCmdQuery.delay(statusCmdTimeout);
|
2017-03-18 15:00:51 +08:00
|
|
|
}
|
2008-07-16 23:47:33 +08:00
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function statusCmdQuery() {
|
2020-03-05 00:22:08 +08:00
|
|
|
statusCmdReq.send(statusCmdParms);
|
2017-03-18 15:00:51 +08:00
|
|
|
}
|
2008-07-16 23:47:33 +08:00
|
|
|
|
2018-04-27 05:18:36 +08:00
|
|
|
if ( monitorType != 'WebSite' ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
var alarmCmdParms = 'view=request&request=alarm&id='+monitorId;
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( auth_hash ) {
|
2018-04-27 05:18:36 +08:00
|
|
|
alarmCmdParms += '&auth='+auth_hash;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2018-04-27 05:18:36 +08:00
|
|
|
var alarmCmdReq = new Request.JSON( {
|
2018-10-19 08:33:50 +08:00
|
|
|
url: monitorUrl,
|
|
|
|
method: 'get',
|
2018-04-27 05:18:36 +08:00
|
|
|
timeout: AJAX_TIMEOUT,
|
|
|
|
link: 'cancel',
|
|
|
|
onSuccess: getAlarmCmdResponse,
|
|
|
|
onTimeout: streamCmdQuery
|
|
|
|
} );
|
|
|
|
var alarmCmdFirst = true;
|
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2020-03-05 00:22:08 +08:00
|
|
|
function getAlarmCmdResponse(respObj, respText) {
|
|
|
|
checkStreamForErrors('getAlarmCmdResponse', respObj);
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function cmdDisableAlarms() {
|
2018-08-31 22:34:54 +08:00
|
|
|
alarmCmdReq.send(alarmCmdParms+"&command=disableAlarms");
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function cmdEnableAlarms() {
|
2018-08-31 22:34:54 +08:00
|
|
|
alarmCmdReq.send(alarmCmdParms+"&command=enableAlarms");
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function cmdForceAlarm() {
|
2018-08-31 22:34:54 +08:00
|
|
|
alarmCmdReq.send(alarmCmdParms+"&command=forceAlarm");
|
2020-03-05 00:22:08 +08:00
|
|
|
if ( window.event ) {
|
2019-03-11 11:52:28 +08:00
|
|
|
window.event.preventDefault();
|
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function cmdCancelForcedAlarm() {
|
2018-08-31 22:34:54 +08:00
|
|
|
alarmCmdReq.send(alarmCmdParms+"&command=cancelForcedAlarm");
|
2020-03-05 00:22:08 +08:00
|
|
|
if ( window.event ) {
|
2019-03-11 11:52:28 +08:00
|
|
|
window.event.preventDefault();
|
|
|
|
}
|
2017-08-04 00:41:43 +08:00
|
|
|
return false;
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function getActResponse( respObj, respText ) {
|
|
|
|
if ( respObj.result == 'Ok' ) {
|
2019-07-24 23:39:21 +08:00
|
|
|
if ( respObj.refreshParent && window.opener ) {
|
|
|
|
console.log('refreshing parent');
|
2016-09-27 23:51:55 +08:00
|
|
|
window.opener.location.reload();
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
eventCmdQuery();
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2020-03-05 00:22:08 +08:00
|
|
|
function deleteEvent(event, eventId) {
|
|
|
|
var actParms = 'view=request&request=event&action=delete&id='+eventId;
|
2020-01-08 06:08:57 +08:00
|
|
|
if ( auth_hash ) {
|
|
|
|
actParms += '&auth='+auth_hash;
|
|
|
|
}
|
2018-08-31 22:34:54 +08:00
|
|
|
var actReq = new Request.JSON( {
|
|
|
|
url: thisUrl,
|
|
|
|
method: 'post',
|
|
|
|
timeout: 3000,
|
|
|
|
onSuccess: getActResponse
|
|
|
|
} );
|
2020-03-05 00:22:08 +08:00
|
|
|
actReq.send(actParms);
|
2016-09-27 23:51:55 +08:00
|
|
|
event.stop();
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2018-04-27 05:18:36 +08:00
|
|
|
if ( monitorType != 'WebSite' ) {
|
|
|
|
var eventCmdParms = "view=request&request=status&entity=events&id="+monitorId+"&count="+maxDisplayEvents+"&sort=Id%20desc";
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( auth_hash ) {
|
2018-04-27 05:18:36 +08:00
|
|
|
eventCmdParms += '&auth='+auth_hash;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2018-10-19 08:33:50 +08:00
|
|
|
var eventCmdReq = new Request.JSON( {
|
|
|
|
url: monitorUrl,
|
|
|
|
method: 'get',
|
|
|
|
timeout: AJAX_TIMEOUT,
|
|
|
|
link: 'cancel',
|
|
|
|
onSuccess: getEventCmdResponse,
|
|
|
|
onTimeout: eventCmdQuery
|
|
|
|
} );
|
2018-04-27 05:18:36 +08:00
|
|
|
var eventCmdTimer = null;
|
|
|
|
var eventCmdFirst = true;
|
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function highlightRow( row ) {
|
2018-08-31 22:34:54 +08:00
|
|
|
$(row).toggleClass('highlight');
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function getEventCmdResponse( respObj, respText ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
watchdogOk('event');
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( eventCmdTimer ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
eventCmdTimer = clearTimeout(eventCmdTimer);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
|
|
|
|
if ( respObj.result == 'Ok' ) {
|
|
|
|
var dbEvents = respObj.events.reverse();
|
|
|
|
var eventList = $('eventList');
|
2020-03-05 00:22:08 +08:00
|
|
|
var eventListBody = $(eventList).getElement('tbody');
|
|
|
|
var eventListRows = $(eventListBody).getElements('tr');
|
2016-09-27 23:51:55 +08:00
|
|
|
|
2020-03-05 00:22:08 +08:00
|
|
|
eventListRows.each( function(row) {
|
|
|
|
row.removeClass('updated');
|
2019-01-19 23:32:40 +08:00
|
|
|
} );
|
2016-09-27 23:51:55 +08:00
|
|
|
|
|
|
|
for ( var i = 0; i < dbEvents.length; i++ ) {
|
2020-04-30 04:35:04 +08:00
|
|
|
var zm_event = dbEvents[i];
|
|
|
|
var row = $('event'+zm_event.Id);
|
2016-09-27 23:51:55 +08:00
|
|
|
var newEvent = (row == null ? true : false);
|
|
|
|
if ( newEvent ) {
|
2020-04-30 04:35:04 +08:00
|
|
|
row = new Element('tr', {'id': 'event'+zm_event.Id});
|
|
|
|
new Element('td', {'class': 'colId'}).inject(row);
|
|
|
|
new Element('td', {'class': 'colName'}).inject(row);
|
|
|
|
new Element('td', {'class': 'colTime'}).inject(row);
|
|
|
|
new Element('td', {'class': 'colSecs'}).inject(row);
|
|
|
|
new Element('td', {'class': 'colFrames'}).inject(row);
|
|
|
|
new Element('td', {'class': 'colScore'}).inject(row);
|
|
|
|
new Element('td', {'class': 'colDelete'}).inject(row);
|
|
|
|
|
|
|
|
var link = new Element('a', {
|
|
|
|
'href': '#',
|
|
|
|
'events': {
|
|
|
|
'click': createEventPopup.pass( [
|
|
|
|
zm_event.Id,
|
|
|
|
'&filter[Query][terms][0][attr]=MonitorId&filter[Query][terms][0][op]=%3d&filter[Query][terms][0][val]='+monitorId+'&page=1&popup=1',
|
|
|
|
zm_event.Width,
|
|
|
|
zm_event.Height
|
|
|
|
] )
|
|
|
|
}
|
|
|
|
});
|
|
|
|
link.set('text', zm_event.Id);
|
|
|
|
link.inject(row.getElement('td.colId'));
|
|
|
|
|
|
|
|
link = new Element('a', {
|
|
|
|
'href': '#',
|
|
|
|
'events': {
|
|
|
|
'click': createEventPopup.pass( [
|
|
|
|
zm_event.Id,
|
|
|
|
'&filter[Query][terms][0][attr]=MonitorId&filter[Query][terms][0][op]=%3d&filter[Query][terms][0][val]='+monitorId+'&page=1&popup=1',
|
|
|
|
zm_event.Width,
|
|
|
|
zm_event.Height
|
|
|
|
] )
|
|
|
|
}
|
|
|
|
});
|
|
|
|
link.set('text', zm_event.Name);
|
|
|
|
link.inject(row.getElement('td.colName'));
|
|
|
|
|
|
|
|
row.getElement('td.colTime').set('text', zm_event.StartTime);
|
|
|
|
row.getElement('td.colSecs').set('text', zm_event.Length);
|
|
|
|
|
|
|
|
link = new Element('a', {'href': '#', 'events': {'click': createFramesPopup.pass( [zm_event.Id, zm_event.Width, zm_event.Height] )}});
|
|
|
|
link.set('text', zm_event.Frames+'/'+zm_event.AlarmFrames);
|
|
|
|
link.inject(row.getElement('td.colFrames'));
|
|
|
|
|
|
|
|
link = new Element('a', {'href': '#', 'events': {'click': createFramePopup.pass( [zm_event.Id, '0', zm_event.Width, zm_event.Height] )}});
|
|
|
|
link.set('text', zm_event.AvgScore+'/'+zm_event.MaxScore);
|
|
|
|
link.inject(row.getElement('td.colScore'));
|
|
|
|
|
|
|
|
link = new Element('button', {
|
2019-07-24 23:39:21 +08:00
|
|
|
'type': 'button',
|
|
|
|
'title': deleteString,
|
2020-04-30 04:35:04 +08:00
|
|
|
'data-event-id': zm_event.Id,
|
2019-07-24 23:39:21 +08:00
|
|
|
'events': {
|
|
|
|
'click': function(e) {
|
|
|
|
var event_id = e.target.getAttribute('data-event-id');
|
|
|
|
if ( !event_id ) {
|
|
|
|
console.log('No event id in deleteEvent');
|
|
|
|
console.log(e);
|
|
|
|
} else {
|
|
|
|
deleteEvent(e, event_id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'mouseover': highlightRow.pass(row),
|
|
|
|
'mouseout': highlightRow.pass(row)
|
|
|
|
}
|
|
|
|
});
|
2020-03-05 00:22:08 +08:00
|
|
|
link.set('text', 'X');
|
|
|
|
link.inject(row.getElement('td.colDelete'));
|
2016-09-27 23:51:55 +08:00
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( i == 0 ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
row.inject($(eventListBody));
|
2019-01-19 23:32:40 +08:00
|
|
|
} else {
|
2020-03-05 00:22:08 +08:00
|
|
|
row.inject($(eventListBody), 'top');
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( !eventCmdFirst ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
row.addClass('recent');
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
} else {
|
2020-04-30 04:35:04 +08:00
|
|
|
row.getElement('td.colName a').set('text', zm_event.Name);
|
|
|
|
row.getElement('td.colSecs').set('text', zm_event.Length);
|
|
|
|
row.getElement('td.colFrames a').set('text', zm_event.Frames+'/'+zm_event.AlarmFrames);
|
|
|
|
row.getElement('td.colScore a').set('text', zm_event.AvgScore+'/'+zm_event.MaxScore);
|
2020-03-05 00:22:08 +08:00
|
|
|
row.removeClass('recent');
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
2020-03-05 00:22:08 +08:00
|
|
|
row.addClass('updated');
|
2020-05-30 01:28:33 +08:00
|
|
|
} // end foreach event
|
2008-12-06 07:58:58 +08:00
|
|
|
|
2020-03-05 00:22:08 +08:00
|
|
|
var rows = $(eventListBody).getElements('tr');
|
2016-09-27 23:51:55 +08:00
|
|
|
for ( var i = 0; i < rows.length; i++ ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
if ( !rows[i].hasClass('updated') ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
rows[i].destroy();
|
|
|
|
rows.splice( i, 1 );
|
|
|
|
i--;
|
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
while ( rows.length > maxDisplayEvents ) {
|
|
|
|
rows[rows.length-1].destroy();
|
|
|
|
rows.length--;
|
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
} else {
|
2020-03-05 00:22:08 +08:00
|
|
|
checkStreamForErrors('getEventCmdResponse', respObj);
|
2020-05-30 01:28:33 +08:00
|
|
|
} // end if objresult == ok
|
2008-12-06 07:58:58 +08:00
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
var eventCmdTimeout = eventsRefreshTimeout;
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
eventCmdTimeout = eventCmdTimeout/5;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-03-05 00:22:08 +08:00
|
|
|
eventCmdTimer = eventCmdQuery.delay(eventCmdTimeout);
|
2016-09-27 23:51:55 +08:00
|
|
|
eventCmdFirst = false;
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function eventCmdQuery() {
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( eventCmdTimer ) { // avoid firing another if we are firing one
|
2020-03-05 00:22:08 +08:00
|
|
|
eventCmdTimer = clearTimeout(eventCmdTimer);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-03-03 03:38:36 +08:00
|
|
|
eventCmdReq.send(eventCmdParms);
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2018-04-27 05:18:36 +08:00
|
|
|
if ( monitorType != 'WebSite' ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
var controlParms = 'view=request&request=control&id='+monitorId;
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( auth_hash ) {
|
2018-04-27 05:18:36 +08:00
|
|
|
controlParms += '&auth='+auth_hash;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-03-03 03:38:36 +08:00
|
|
|
var controlReq = new Request.JSON( {
|
|
|
|
url: monitorUrl,
|
|
|
|
method: 'post',
|
|
|
|
timeout: AJAX_TIMEOUT,
|
|
|
|
link: 'cancel',
|
|
|
|
onSuccess: getControlResponse
|
|
|
|
} );
|
2018-04-27 05:18:36 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2020-03-05 00:22:08 +08:00
|
|
|
function getControlResponse(respObj, respText) {
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( !respObj ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
return;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
//console.log( respText );
|
|
|
|
if ( respObj.result != 'Ok' ) {
|
2020-03-05 00:22:08 +08:00
|
|
|
alert("Control response was status = "+respObj.status+"\nmessage = "+respObj.message);
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-30 04:35:04 +08:00
|
|
|
function controlCmd(event) {
|
|
|
|
button = event.target;
|
2020-04-10 23:30:30 +08:00
|
|
|
control = button.getAttribute('value');
|
2020-05-13 20:01:04 +08:00
|
|
|
xtell = button.getAttribute('data-xtell');
|
|
|
|
ytell = button.getAttribute('data-ytell');
|
2020-04-10 23:30:30 +08:00
|
|
|
|
|
|
|
var locParms = '';
|
2016-09-27 23:51:55 +08:00
|
|
|
if ( event && (xtell || ytell) ) {
|
2018-01-12 02:14:11 +08:00
|
|
|
var target = event.target;
|
2016-09-27 23:51:55 +08:00
|
|
|
var coords = $(target).getCoordinates();
|
|
|
|
|
2018-01-12 02:14:11 +08:00
|
|
|
var x = event.pageX - coords.left;
|
|
|
|
var y = event.pageY - coords.top;
|
2016-09-27 23:51:55 +08:00
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
if ( xtell ) {
|
2020-04-30 04:35:04 +08:00
|
|
|
var xge = parseInt((x*100)/coords.width);
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( xtell == -1 ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
xge = 100 - xge;
|
2019-01-19 23:32:40 +08:00
|
|
|
} else if ( xtell == 2 ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
xge = 2*(50 - xge);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-04-10 23:30:30 +08:00
|
|
|
locParms += '&xge='+xge;
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
if ( ytell ) {
|
2020-04-30 04:35:04 +08:00
|
|
|
var yge = parseInt((y*100)/coords.height);
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( ytell == -1 ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
yge = 100 - yge;
|
2019-01-19 23:32:40 +08:00
|
|
|
} else if ( ytell == 2 ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
yge = 2*(50 - yge);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-04-10 23:30:30 +08:00
|
|
|
locParms += '&yge='+yge;
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
2020-03-05 00:22:08 +08:00
|
|
|
controlReq.send(controlParms+"&control="+control+locParms);
|
|
|
|
if ( streamMode == 'single' ) {
|
|
|
|
fetchImage.pass($('imageFeed').getElement('img')).delay(1000);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function controlCmdImage( x, y ) {
|
|
|
|
var imageControlParms = controlParms;
|
2020-03-05 00:22:08 +08:00
|
|
|
imageControlParms += '&scale='+scale;
|
|
|
|
imageControlParms += '&control='+imageControlMode;
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
controlReq.send( imageControlParms+"&x="+x+"&y="+y );
|
2020-03-05 00:22:08 +08:00
|
|
|
if ( streamMode == 'single' ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
fetchImage.pass( $('imageFeed').getElement('img') ).delay( 1000 );
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2018-10-19 08:33:50 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function fetchImage( streamImage ) {
|
2019-01-18 23:00:55 +08:00
|
|
|
streamImage.src = streamImage.src.replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) ));
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function handleClick( event ) {
|
|
|
|
var target = event.target;
|
|
|
|
var x = event.page.x - $(target).getLeft();
|
|
|
|
var y = event.page.y - $(target).getTop();
|
|
|
|
|
2020-03-05 00:22:08 +08:00
|
|
|
if ( showMode == 'events' || !imageControlMode ) {
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( event.shift ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
streamCmdPan( x, y );
|
2019-06-11 22:58:54 +08:00
|
|
|
} else if ( event.event.ctrlKey ) {
|
|
|
|
streamCmdZoomOut();
|
2019-01-19 23:32:40 +08:00
|
|
|
} else {
|
2019-09-27 04:13:49 +08:00
|
|
|
streamCmdZoomIn(x, y);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
} else {
|
2019-09-27 04:13:49 +08:00
|
|
|
controlCmdImage(x, y);
|
2016-09-27 23:51:55 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function appletRefresh() {
|
|
|
|
if ( streamStatus && (!streamStatus.paused && !streamStatus.delayed) ) {
|
2020-03-20 23:06:01 +08:00
|
|
|
var streamImg = $('liveStream'+monitorId);
|
|
|
|
if ( streamImg ) {
|
|
|
|
var parent = streamImg.getParent();
|
|
|
|
streamImg.dispose();
|
|
|
|
streamImg.inject( parent );
|
|
|
|
} else {
|
|
|
|
console.error("Nothing found for liveStream"+monitorId);
|
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( appletRefreshTime ) {
|
2016-09-27 23:51:55 +08:00
|
|
|
appletRefresh.delay( appletRefreshTime*1000 );
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
} else {
|
|
|
|
appletRefresh.delay( 15*1000 ); //if we are paused or delayed check every 15 seconds if we are live yet...
|
|
|
|
}
|
2009-05-26 02:03:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var watchdogInactive = {
|
2016-09-27 23:51:55 +08:00
|
|
|
'stream': false,
|
|
|
|
'status': false,
|
|
|
|
'event': false
|
2009-05-26 02:03:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var watchdogFunctions = {
|
2016-09-27 23:51:55 +08:00
|
|
|
'stream': streamCmdQuery,
|
|
|
|
'status': statusCmdQuery,
|
|
|
|
'event': eventCmdQuery
|
2009-05-26 02:03:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//Make sure the various refreshes are still taking effect
|
2016-09-27 23:51:55 +08:00
|
|
|
function watchdogCheck( type ) {
|
|
|
|
if ( watchdogInactive[type] ) {
|
2018-08-31 22:34:54 +08:00
|
|
|
console.log("Detected streamWatch of type: " + type + " stopped, restarting");
|
2016-09-27 23:51:55 +08:00
|
|
|
watchdogFunctions[type]();
|
2009-05-26 02:03:46 +08:00
|
|
|
watchdogInactive[type] = false;
|
2016-09-27 23:51:55 +08:00
|
|
|
} else {
|
|
|
|
watchdogInactive[type] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function watchdogOk( type ) {
|
|
|
|
watchdogInactive[type] = false;
|
|
|
|
}
|
|
|
|
|
2018-07-05 21:43:21 +08:00
|
|
|
function reloadWebSite() {
|
2018-08-31 22:34:54 +08:00
|
|
|
document.getElementById('imageFeed').innerHTML = document.getElementById('imageFeed').innerHTML;
|
2018-07-05 21:43:21 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 23:51:55 +08:00
|
|
|
function initPage() {
|
2018-04-27 05:18:36 +08:00
|
|
|
if ( monitorType != 'WebSite' ) {
|
2020-03-20 23:06:01 +08:00
|
|
|
if ( streamMode == 'single' ) {
|
2018-04-27 05:18:36 +08:00
|
|
|
statusCmdTimer = statusCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout );
|
|
|
|
watchdogCheck.pass('status').periodical(statusRefreshTimeout*2);
|
|
|
|
} else {
|
|
|
|
streamCmdTimer = streamCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout );
|
|
|
|
watchdogCheck.pass('stream').periodical(statusRefreshTimeout*2);
|
|
|
|
}
|
2016-09-27 23:51:55 +08:00
|
|
|
|
2018-04-27 05:18:36 +08:00
|
|
|
eventCmdTimer = eventCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout );
|
|
|
|
watchdogCheck.pass('event').periodical(eventsRefreshTimeout*2);
|
|
|
|
|
2020-03-20 23:06:01 +08:00
|
|
|
if ( canStreamNative || (streamMode == 'single') ) {
|
2018-04-27 05:18:36 +08:00
|
|
|
var streamImg = $('imageFeed').getElement('img');
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( !streamImg ) {
|
2018-04-27 05:18:36 +08:00
|
|
|
streamImg = $('imageFeed').getElement('object');
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-03-20 23:06:01 +08:00
|
|
|
if ( !streamImg ) {
|
|
|
|
console.error('No streamImg found for imageFeed');
|
2019-01-19 23:32:40 +08:00
|
|
|
} else {
|
2020-03-20 23:06:01 +08:00
|
|
|
if ( streamMode == 'single' ) {
|
|
|
|
streamImg.addEvent('click', fetchImage.pass(streamImg));
|
|
|
|
fetchImage.pass(streamImg).periodical(imageRefreshTimeout);
|
|
|
|
} else {
|
|
|
|
streamImg.addEvent('click', function(event) {
|
|
|
|
handleClick(event);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} // end if have streamImg
|
|
|
|
} // streamMode native or single
|
2018-04-27 05:18:36 +08:00
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( refreshApplet && appletRefreshTime ) {
|
2018-08-31 22:34:54 +08:00
|
|
|
appletRefresh.delay(appletRefreshTime*1000);
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-10-20 02:28:21 +08:00
|
|
|
if ( scale == 'auto' || scale == '0' ) changeScale();
|
2018-08-31 22:34:54 +08:00
|
|
|
if ( window.history.length == 1 ) {
|
2018-04-27 05:18:36 +08:00
|
|
|
$j('#closeControl').html('');
|
|
|
|
}
|
2019-09-20 22:44:38 +08:00
|
|
|
document.querySelectorAll('select[name="scale"]').forEach(function(el) {
|
2019-09-20 02:57:17 +08:00
|
|
|
el.onchange = window['changeScale'];
|
|
|
|
});
|
2018-04-27 05:18:36 +08:00
|
|
|
} else if ( monitorRefresh > 0 ) {
|
2019-01-19 23:32:40 +08:00
|
|
|
setInterval(reloadWebSite, monitorRefresh*1000);
|
2017-12-13 23:20:02 +08:00
|
|
|
}
|
2020-10-20 02:28:21 +08:00
|
|
|
} // initPage
|
2008-07-14 21:54:50 +08:00
|
|
|
|
|
|
|
// Kick everything off
|
2019-01-22 00:14:32 +08:00
|
|
|
window.addEventListener('DOMContentLoaded', initPage);
|