zoneminder/web/skins/classic/views/js/watch.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

947 lines
27 KiB
JavaScript
Raw Normal View History

2020-12-10 07:58:46 +08:00
var streamCmdTimer = null;
2020-11-27 07:00:05 +08:00
var streamStatus;
var alarmState = STATE_IDLE;
var lastAlarmState = STATE_IDLE;
2020-10-16 21:08:23 +08:00
var backBtn = $j('#backBtn');
var settingsBtn = $j('#settingsBtn');
var enableAlmBtn = $j('#enableAlmBtn');
var forceAlmBtn = $j('#forceAlmBtn');
2020-11-27 07:00:05 +08:00
var table = $j('#eventList');
var filterQuery = '&filter[Query][terms][0][attr]=MonitorId&filter[Query][terms][0][op]=%3d&filter[Query][terms][0][val]='+monitorId;
2020-11-27 07:00:05 +08:00
/*
This is the format of the json object sent by bootstrap-table
var params =
{
"type":"get",
"data":
{
"search":"some search text",
"sort":"StartDateTime",
"order":"asc",
"offset":0,
"limit":25
"filter":
{
"Name":"some advanced search text"
"StartDateTime":"some more advanced search text"
}
},
"cache":true,
"contentType":"application/json",
"dataType":"json"
};
*/
// Called by bootstrap-table to retrieve zm event data
function ajaxRequest(params) {
// Maintain legacy behavior by statically setting these parameters
var data = params.data;
data.order = 'desc';
data.limit = maxDisplayEvents;
data.sort = 'Id';
data.view = 'request';
data.request = 'watch';
data.mid = monitorId;
if ( auth_hash ) data.auth = auth_hash;
$j.getJSON(thisUrl, data)
2020-11-27 07:00:05 +08:00
.done(function(data) {
var rows = processRows(data.rows);
params.success(rows);
2020-11-27 07:00:05 +08:00
})
.fail(logAjaxFail);
}
function processRows(rows) {
$j.each(rows, function(ndx, row) {
var eid = row.Id;
row.Delete = '<i class="fa fa-trash text-danger"></i>';
2020-11-27 07:00:05 +08:00
row.Id = '<a href="?view=event&amp;eid=' + eid + filterQuery + '">' + eid + '</a>';
row.Name = '<a href="?view=event&amp;eid=' + eid + filterQuery + '">' + row.Name + '</a>';
row.Frames = '<a href="?view=frames&amp;eid=' + eid + '">' + row.Frames + '</a>';
row.AlarmFrames = '<a href="?view=frames&amp;eid=' + eid + '">' + row.AlarmFrames + '</a>';
row.MaxScore = '<a href="?view=frame&amp;eid=' + eid + '&amp;fid=0">' + row.MaxScore + '</a>';
if ( LIST_THUMBS ) row.Thumbnail = '<a href="?view=event&amp;eid=' + eid + filterQuery + '&amp;page=1">' + row.imgHtml + '</a>';
2020-11-27 07:00:05 +08:00
});
return rows;
}
function showEvents() {
2020-12-04 03:12:01 +08:00
$j('#ptzControls').addClass('hidden');
$j('#events').removeClass('hidden');
if ( $j('#eventsControl') ) {
$j('#eventsControl').addClass('hidden');
}
2020-12-04 03:12:01 +08:00
if ( $j('#controlControl') ) {
$j('#controlControl').removeClass('hidden');
}
showMode = 'events';
}
function showPtzControls() {
2020-12-04 03:12:01 +08:00
$j('#events').addClass('hidden');
$j('#ptzControls').removeClass('hidden');
if ( $j('#eventsControl') ) {
$j('#eventsControl').removeClass('hidden');
}
2020-12-04 03:12:01 +08:00
if ( $j('#controlControl') ) {
$j('#controlControl').addClass('hidden');
}
showMode = 'control';
}
function changeScale() {
2020-12-04 03:12:01 +08:00
var scale = $j('#scale').val();
2017-11-21 03:25:13 +08:00
var newWidth;
var newHeight;
2021-01-27 06:44:23 +08:00
// Always turn it off, we will re-add it below. I don't know if you can add a callback multiple
// times and what the consequences would be
$j(window).off('resize', endOfResize); //remove resize handler when Scale to Fit is not active
2021-08-19 06:40:25 +08:00
if (scale == '0' || scale == 'auto') {
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;
$j(window).on('resize', endOfResize); //remove resize handler when Scale to Fit is not active
2017-11-21 03:25:13 +08:00
} else {
newWidth = monitorWidth * scale / SCALE_BASE;
newHeight = monitorHeight * scale / SCALE_BASE;
}
setCookie('zmWatchScale'+monitorId, scale, 3600);
var streamImg = $j('#liveStream'+monitorId);
2021-05-10 23:08:16 +08:00
if (streamImg) {
var oldSrc = streamImg.attr('src');
2021-05-10 23:08:16 +08:00
var newSrc = oldSrc.replace(/scale=\d+/i, 'scale='+((scale == 'auto' || scale == '0') ? autoScale : scale));
streamImg.width(newWidth);
streamImg.height(newHeight);
streamImg.attr('src', newSrc);
} else {
console.error('No element found for liveStream'+monitorId);
}
2021-01-27 06:44:23 +08:00
} // end function changeScale
2021-01-30 03:05:04 +08:00
function setAlarmState(currentAlarmState) {
alarmState = currentAlarmState;
2020-01-06 06:33:53 +08:00
var stateClass = '';
if ( alarmState == STATE_ALARM ) {
2020-01-06 06:33:53 +08:00
stateClass = 'alarm';
} else if ( alarmState == STATE_ALERT ) {
2020-01-06 06:33:53 +08:00
stateClass = 'alert';
}
2020-12-04 03:12:01 +08:00
$j('#stateValue').text(stateStrings[alarmState]);
if ( stateClass ) {
2020-12-04 03:12:01 +08:00
$j('#stateValue').addClass(stateClass);
} else {
2020-12-04 03:12:01 +08:00
$j('#stateValue').removeClass();
}
var isAlarmed = ( alarmState == STATE_ALARM || alarmState == STATE_ALERT );
var wasAlarmed = ( lastAlarmState == STATE_ALARM || lastAlarmState == STATE_ALERT );
var newAlarm = ( isAlarmed && !wasAlarmed );
var oldAlarm = ( !isAlarmed && wasAlarmed );
2021-08-19 06:40:25 +08:00
if (newAlarm) {
2020-12-03 22:31:52 +08:00
table.bootstrapTable('refresh');
2021-08-19 06:40:25 +08:00
if (SOUND_ON_ALARM) {
// Enable the alarm sound
2021-08-19 06:40:25 +08:00
if (!msieVer) {
$j('#alarmSound').removeClass('hidden');
} else {
$j('#MediaPlayer').trigger('play');
}
}
2021-08-19 06:40:25 +08:00
if (POPUP_ON_ALARM) {
window.focus();
}
}
2021-08-19 06:40:25 +08:00
if (oldAlarm) { // done with an event do a refresh
2020-12-03 22:31:52 +08:00
table.bootstrapTable('refresh');
2021-08-19 06:40:25 +08:00
if (SOUND_ON_ALARM) {
// Disable alarm sound
2021-08-19 06:40:25 +08:00
if (!msieVer) {
$j('#alarmSound').addClass('hidden');
} else {
$j('#MediaPlayer').trigger('pause');
}
}
}
lastAlarmState = alarmState;
} // end function setAlarmState( currentAlarmState )
function getStreamCmdError(text, error) {
console.log(error);
// Error are normally due to failed auth. reload the page.
//window.location.reload();
}
2020-11-27 07:00:05 +08:00
function getStreamCmdResponse(respObj, respText) {
2020-01-06 06:33:53 +08:00
watchdogOk('stream');
2021-08-19 06:40:25 +08:00
if (streamCmdTimer) {
streamCmdTimer = clearTimeout(streamCmdTimer);
}
2021-08-19 06:40:25 +08:00
if (respObj.result == 'Ok') {
// The get status command can get backed up, in which case we won't be able to get the semaphore and will exit.
2021-08-19 06:40:25 +08:00
if (respObj.status) {
streamStatus = respObj.status;
2020-12-04 03:12:01 +08:00
$j('#fpsValue').text(streamStatus.fps);
$j('#capturefpsValue').text(streamStatus.capturefps);
$j('#analysisfpsValue').text(streamStatus.analysisfps);
setAlarmState(streamStatus.state);
2020-12-04 03:12:01 +08:00
$j('#levelValue').text(streamStatus.level);
var newClass = 'ok';
2021-08-19 06:40:25 +08:00
if (streamStatus.level > 95) {
newClass = 'alarm';
2021-08-19 06:40:25 +08:00
} else if (streamStatus.level > 80) {
newClass = 'alert';
}
$j('#levelValue').removeClass();
$j('#levelValue').addClass(newClass);
var delayString = secsToTime(streamStatus.delay);
2021-08-19 06:40:25 +08:00
if (streamStatus.paused == true) {
2020-12-04 03:12:01 +08:00
$j('#modeValue').text('Paused');
$j('#rate').addClass('hidden');
$j('#delayValue').text(delayString);
$j('#delay').removeClass('hidden');
$j('#level').removeClass('hidden');
streamCmdPause(false);
2021-08-19 06:40:25 +08:00
} else if (streamStatus.delayed == true) {
2020-12-04 03:12:01 +08:00
$j('#modeValue').text('Replay');
$j('#rateValue').text(streamStatus.rate);
$j('#rate').removeClass('hidden');
$j('#delayValue').text(delayString);
$j('#delay').removeClass('hidden');
$j('#level').removeClass('hidden');
2021-08-19 06:40:25 +08:00
if (streamStatus.rate == 1) {
streamCmdPlay(false);
2021-08-19 06:40:25 +08:00
} else if (streamStatus.rate > 0) {
if (streamStatus.rate < 1) {
streamCmdSlowFwd(false);
} else {
streamCmdFastFwd(false);
}
} else {
2021-08-19 06:40:25 +08:00
if (streamStatus.rate > -1) {
streamCmdSlowRev(false);
} else {
streamCmdFastRev(false);
}
} // rate
} else {
2020-12-16 04:56:41 +08:00
$j('#modeValue').text('Live');
$j('#rate').addClass('hidden');
$j('#delay').addClass('hidden');
$j('#level').addClass('hidden');
2019-09-27 04:13:49 +08:00
streamCmdPlay(false);
} // end if paused or delayed
2020-12-16 04:56:41 +08:00
$j('#zoomValue').text(streamStatus.zoom);
2021-08-19 06:40:25 +08:00
if (streamStatus.zoom == '1.0') {
setButtonState('zoomOutBtn', 'unavail');
} else {
setButtonState('zoomOutBtn', 'inactive');
}
2021-08-19 06:40:25 +08:00
if (canEdit.Monitors) {
if (streamStatus.enabled) {
enableAlmBtn.addClass('disabled');
enableAlmBtn.prop('title', disableAlarmsStr);
2021-08-19 06:40:25 +08:00
if (streamStatus.forced) {
forceAlmBtn.addClass('disabled');
forceAlmBtn.prop('title', cancelForcedAlarmStr);
} else {
forceAlmBtn.removeClass('disabled');
forceAlmBtn.prop('title', forceAlarmStr);
}
forceAlmBtn.prop('disabled', false);
} else {
enableAlmBtn.removeClass('disabled');
enableAlmBtn.prop('title', enableAlarmsStr);
forceAlmBtn.prop('disabled', true);
}
enableAlmBtn.prop('disabled', false);
2020-12-09 04:25:48 +08:00
} // end if canEdit.Monitors
2021-08-19 06:40:25 +08:00
if (streamStatus.auth) {
auth_hash = streamStatus.auth;
// Try to reload the image stream.
var streamImg = $j('#liveStream'+monitorId);
2021-08-19 06:40:25 +08:00
if (streamImg) {
var oldSrc = streamImg.attr('src');
var newSrc = oldSrc.replace(/auth=\w+/i, 'auth='+streamStatus.auth);
2021-08-19 06:40:25 +08:00
if (oldSrc != newSrc) {
streamImg.attr('src', newSrc);
table.bootstrapTable('refresh');
}
}
} // end if have a new auth hash
} // end if respObj.status
} else {
checkStreamForErrors('getStreamCmdResponse', respObj);//log them
// Try to reload the image stream.
// If it's an auth error, we should reload the whole page.
console.log("have error");
//window.location.reload();
2021-08-19 06:40:25 +08:00
var streamImg = $j('#liveStream'+monitorId);
if (streamImg) {
var oldSrc = streamImg.attr('src');
var newSrc = oldSrc.replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) ));
streamImg.attr('src', newSrc);
console.log('Changing livestream src to ' + newSrc);
} else {
console.log('Unable to find streamImg liveStream');
}
}
var streamCmdTimeout = statusRefreshTimeout;
2021-08-19 06:40:25 +08:00
if (alarmState == STATE_ALARM || alarmState == STATE_ALERT) {
streamCmdTimeout = streamCmdTimeout/5;
}
2021-01-09 02:25:17 +08:00
streamCmdTimer = setTimeout(streamCmdQuery, streamCmdTimeout);
2017-05-19 01:50:56 +08:00
}
2021-01-30 03:05:04 +08:00
function streamCmdPause(action) {
setButtonState('pauseBtn', 'active');
setButtonState('playBtn', 'inactive');
setButtonState('stopBtn', 'inactive');
2021-08-19 06:40:25 +08:00
if (monitorStreamReplayBuffer) {
setButtonState('fastFwdBtn', 'inactive');
setButtonState('slowFwdBtn', 'inactive');
setButtonState('slowRevBtn', 'inactive');
setButtonState('fastRevBtn', 'inactive');
}
2021-08-19 06:40:25 +08:00
if (action) {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = CMD_PAUSE;
streamCmdReq(data);
}
}
2021-01-30 03:05:04 +08:00
function streamCmdPlay(action) {
setButtonState('pauseBtn', 'inactive');
setButtonState('playBtn', 'active');
2021-08-19 06:40:25 +08:00
if (streamStatus.delayed == true) {
setButtonState('stopBtn', 'inactive');
2021-08-19 06:40:25 +08:00
if (monitorStreamReplayBuffer) {
setButtonState('fastFwdBtn', 'inactive');
setButtonState('slowFwdBtn', 'inactive');
setButtonState('slowRevBtn', 'inactive');
setButtonState('fastRevBtn', 'inactive');
}
} else {
setButtonState('stopBtn', 'unavail');
2021-08-19 06:40:25 +08:00
if (monitorStreamReplayBuffer) {
setButtonState('fastFwdBtn', 'unavail');
setButtonState('slowFwdBtn', 'unavail');
setButtonState('slowRevBtn', 'unavail');
setButtonState('fastRevBtn', 'unavail');
}
}
2021-08-19 06:40:25 +08:00
if (action) {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = CMD_PLAY;
streamCmdReq(data);
}
}
function streamCmdReq(data) {
$j.getJSON(monitorUrl + '?view=request&request=stream&connkey='+connKey, data)
.done(getStreamCmdResponse)
.fail(getStreamCmdError);
2020-12-10 10:06:38 +08:00
streamCmdTimer = null;
}
2021-01-30 03:05:04 +08:00
function streamCmdStop(action) {
setButtonState('pauseBtn', 'inactive');
setButtonState('playBtn', 'unavail');
setButtonState('stopBtn', 'active');
2021-08-19 06:40:25 +08:00
if (monitorStreamReplayBuffer) {
setButtonState('fastFwdBtn', 'unavail');
setButtonState('slowFwdBtn', 'unavail');
setButtonState('slowRevBtn', 'unavail');
setButtonState('fastRevBtn', 'unavail');
}
2021-08-19 06:40:25 +08:00
if (action) {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = CMD_STOP;
streamCmdReq(data);
}
setButtonState('stopBtn', 'unavail');
setButtonState('playBtn', 'active');
}
2021-01-30 03:05:04 +08:00
function streamCmdFastFwd(action) {
setButtonState('pauseBtn', 'inactive');
setButtonState('playBtn', 'inactive');
setButtonState('stopBtn', 'inactive');
2021-08-19 06:40:25 +08:00
if (monitorStreamReplayBuffer) {
setButtonState('fastFwdBtn', 'inactive');
setButtonState('slowFwdBtn', 'inactive');
setButtonState('slowRevBtn', 'inactive');
setButtonState('fastRevBtn', 'inactive');
}
2021-08-19 06:40:25 +08:00
if (action) {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = CMD_FASTFWD;
streamCmdReq(data);
}
}
2021-01-30 03:05:04 +08:00
function streamCmdSlowFwd(action) {
setButtonState('pauseBtn', 'inactive');
setButtonState('playBtn', 'inactive');
setButtonState('stopBtn', 'inactive');
2021-08-19 06:40:25 +08:00
if (monitorStreamReplayBuffer) {
setButtonState('fastFwdBtn', 'inactive');
setButtonState('slowFwdBtn', 'active');
setButtonState('slowRevBtn', 'inactive');
setButtonState('fastRevBtn', 'inactive');
}
2021-08-19 06:40:25 +08:00
if (action) {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = CMD_SLOWFWD;
streamCmdReq(data);
}
setButtonState('pauseBtn', 'active');
2021-08-19 06:40:25 +08:00
if (monitorStreamReplayBuffer) {
setButtonState('slowFwdBtn', 'inactive');
}
}
2021-01-30 03:05:04 +08:00
function streamCmdSlowRev(action) {
setButtonState('pauseBtn', 'inactive');
setButtonState('playBtn', 'inactive');
setButtonState('stopBtn', 'inactive');
2021-08-19 06:40:25 +08:00
if (monitorStreamReplayBuffer) {
setButtonState('fastFwdBtn', 'inactive');
setButtonState('slowFwdBtn', 'inactive');
setButtonState('slowRevBtn', 'active');
setButtonState('fastRevBtn', 'inactive');
}
2021-08-19 06:40:25 +08:00
if (action) {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = CMD_SLOWREV;
streamCmdReq(data);
}
setButtonState('pauseBtn', 'active');
2021-08-19 06:40:25 +08:00
if (monitorStreamReplayBuffer) {
setButtonState('slowRevBtn', 'inactive');
}
}
2021-01-30 03:05:04 +08:00
function streamCmdFastRev(action) {
setButtonState('pauseBtn', 'inactive');
setButtonState('playBtn', 'inactive');
setButtonState('stopBtn', 'inactive');
2021-08-19 06:40:25 +08:00
if (monitorStreamReplayBuffer) {
setButtonState('fastFwdBtn', 'inactive');
setButtonState('slowFwdBtn', 'inactive');
setButtonState('slowRevBtn', 'inactive');
setButtonState('fastRevBtn', 'inactive');
}
2021-08-19 06:40:25 +08:00
if (action) {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = CMD_FASTREV;
streamCmdReq(data);
}
}
2021-08-19 06:40:25 +08:00
function streamCmdZoomIn(x, y) {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.x = x;
data.y = y;
data.command = CMD_ZOOMIN;
streamCmdReq(data);
}
function streamCmdZoomOut() {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = CMD_ZOOMOUT;
streamCmdReq(data);
}
2021-08-19 06:40:25 +08:00
function streamCmdScale(scale) {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = CMD_SCALE;
data.scale = scale;
2020-12-10 07:58:46 +08:00
streamCmdReq(data);
}
2021-08-19 06:40:25 +08:00
function streamCmdPan(x, y) {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.x = x;
data.y = y;
data.command = CMD_PAN;
streamCmdReq(data);
}
function streamCmdQuery() {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = CMD_QUERY;
streamCmdReq(data);
}
function getStatusCmdResponse(respObj, respText) {
watchdogOk('status');
2021-08-19 06:40:25 +08:00
if (statusCmdTimer) {
statusCmdTimer = clearTimeout(statusCmdTimer);
}
2021-08-19 06:40:25 +08:00
if (respObj.result == 'Ok') {
2020-12-04 03:12:01 +08:00
$j('#fpsValue').text(respObj.monitor.FrameRate);
setAlarmState(respObj.monitor.Status);
} else {
checkStreamForErrors('getStatusCmdResponse', respObj);
}
var statusCmdTimeout = statusRefreshTimeout;
if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) {
statusCmdTimeout = statusCmdTimeout/5;
}
2021-01-09 02:25:17 +08:00
statusCmdTimer = setTimeout(statusCmdQuery, statusCmdTimeout);
}
function statusCmdQuery() {
$j.getJSON(monitorUrl + '?view=request&request=status&entity=monitor&element[]=Status&element[]=FrameRate&id='+monitorId)
.done(getStatusCmdResponse)
.fail(logAjaxFail);
2020-12-10 10:06:38 +08:00
streamCmdTimer = null;
}
function alarmCmdReq(data) {
$j.getJSON(monitorUrl + '?view=request&request=alarm&id='+monitorId, data)
.done(getAlarmCmdResponse)
.fail(function(jqxhr, textStatus, error) {
2021-01-31 23:09:22 +08:00
if ( textStatus === "timeout" ) {
streamCmdQuery();
} else {
logAjaxFail(jqxhr, textStatus, error);
}
});
}
function getAlarmCmdResponse(respObj, respText) {
checkStreamForErrors('getAlarmCmdResponse', respObj);
}
function cmdDisableAlarms() {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = 'disableAlarms';
alarmCmdReq(data);
}
function cmdEnableAlarms() {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = 'enableAlarms';
alarmCmdReq(data);
}
function cmdAlarm() {
2021-08-19 06:40:25 +08:00
if (enableAlmBtn.hasClass('disabled')) {
cmdEnableAlarms();
} else {
cmdDisableAlarms();
}
}
function cmdForceAlarm() {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = 'forceAlarm';
alarmCmdReq(data);
2021-08-19 06:40:25 +08:00
if (window.event) window.event.preventDefault();
}
function cmdCancelForcedAlarm() {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.command = 'cancelForcedAlarm';
alarmCmdReq(data);
2021-08-19 06:40:25 +08:00
if (window.event) window.event.preventDefault();
2017-08-04 00:41:43 +08:00
return false;
}
function cmdForce() {
2021-08-19 06:40:25 +08:00
if (forceAlmBtn.hasClass('disabled')) {
cmdCancelForcedAlarm();
} else {
cmdForceAlarm();
}
}
function controlReq(data) {
$j.getJSON(monitorUrl + '?view=request&request=control&id='+monitorId, data)
.done(getControlResponse)
.fail(logAjaxFail);
}
function getControlResponse(respObj, respText) {
2021-08-19 06:40:25 +08:00
if (!respObj) {
return;
}
//console.log( respText );
2021-08-19 06:40:25 +08:00
if (respObj.result != 'Ok') {
alert("Control response was status = "+respObj.status+"\nmessage = "+respObj.message);
}
}
function controlCmd(event) {
button = event.target;
2021-04-24 07:40:52 +08:00
console.log(event);
if (event.type !='mouseup') {
control = button.getAttribute('value');
} else {
console.log('stop');
console.log(event);
control = 'moveStop';
}
xtell = button.getAttribute('data-xtell');
ytell = button.getAttribute('data-ytell');
2020-04-10 23:30:30 +08:00
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (event && (xtell || ytell)) {
var target = event.target;
var offset = $j(target).offset();
var width = $j(target).width();
var height = $j(target).height();
var x = event.pageX - offset.left;
var y = event.pageY - offset.top;
2021-08-19 06:40:25 +08:00
if (xtell) {
var xge = parseInt((x*100)/width);
2021-08-19 06:40:25 +08:00
if (xtell == -1) {
xge = 100 - xge;
2021-08-19 06:40:25 +08:00
} else if (xtell == 2) {
xge = 2*(50 - xge);
}
data.xge = xge;
}
2021-08-19 06:40:25 +08:00
if (ytell) {
var yge = parseInt((y*100)/height);
2021-08-19 06:40:25 +08:00
if (ytell == -1) {
yge = 100 - yge;
2021-08-19 06:40:25 +08:00
} else if (ytell == 2) {
yge = 2*(50 - yge);
}
data.yge = yge;
}
}
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
2020-12-10 07:58:46 +08:00
data.control = control;
controlReq(data);
2021-08-19 06:40:25 +08:00
if (streamMode == 'single') {
2020-12-13 02:45:36 +08:00
setTimeout(fetchImage, 1000, $j('#imageFeed img'));
}
}
2021-08-19 06:40:25 +08:00
function controlCmdImage(x, y) {
2020-12-10 07:58:46 +08:00
var data = {};
2021-08-19 06:40:25 +08:00
if (auth_hash) data.auth = auth_hash;
data.scale = scale;
data.control = imageControlMode;
data.x = x;
data.y = y;
controlReq(data);
2020-12-10 07:58:46 +08:00
2021-08-19 06:40:25 +08:00
if (streamMode == 'single') {
2020-12-13 02:45:36 +08:00
setTimeout(fetchImage, 1000, $j('#imageFeed img'));
}
}
function fetchImage(streamImage) {
2020-12-13 02:45:36 +08:00
streamImage.attr('src', streamImage.attr('src').replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) )));
}
function handleClick(event) {
// target should be the img tag
var target = $j(event.target);
var width = target.width();
var height = target.height();
2020-12-08 04:44:45 +08:00
var scaleX = parseInt(monitorWidth / width);
var scaleY = parseInt(monitorHeight / height);
var pos = target.offset();
var x = parseInt((event.pageX - pos.left) * scaleX);
var y = parseInt((event.pageY - pos.top) * scaleY);
2021-08-19 06:40:25 +08:00
if (showMode == 'events' || !imageControlMode) {
if ( event.shift ) {
streamCmdPan(x, y);
2021-08-19 06:40:25 +08:00
} else if (event.ctrlKey) {
streamCmdZoomOut();
} else {
2019-09-27 04:13:49 +08:00
streamCmdZoomIn(x, y);
}
} else {
2019-09-27 04:13:49 +08:00
controlCmdImage(x, y);
}
}
function appletRefresh() {
2021-08-19 06:40:25 +08:00
if (streamStatus && (!streamStatus.paused && !streamStatus.delayed)) {
var streamImg = $j('#liveStream'+monitorId);
2021-08-19 06:40:25 +08:00
if (streamImg) {
var parent = streamImg.parent();
streamImg.remove();
2021-01-30 03:05:04 +08:00
streamImg.append(parent);
} else {
console.error("Nothing found for liveStream"+monitorId);
}
2021-08-19 06:40:25 +08:00
if (appletRefreshTime) {
2021-01-09 02:25:17 +08:00
setTimeout(appletRefresh, appletRefreshTime*1000);
}
} else {
2021-01-30 03:05:04 +08:00
setTimeout(appletRefresh, 15*1000); // if we are paused or delayed check every 15 seconds if we are live yet...
}
}
var watchdogInactive = {
'stream': false,
2020-11-27 07:00:05 +08:00
'status': false
};
var watchdogFunctions = {
'stream': streamCmdQuery,
'status': statusCmdQuery,
};
//Make sure the various refreshes are still taking effect
2021-08-19 06:40:25 +08:00
function watchdogCheck(type) {
if (watchdogInactive[type]) {
console.log("Detected streamWatch of type: " + type + " stopped, restarting");
watchdogFunctions[type]();
watchdogInactive[type] = false;
} else {
watchdogInactive[type] = true;
}
}
2021-08-19 06:40:25 +08:00
function watchdogOk(type) {
watchdogInactive[type] = false;
}
function reloadWebSite() {
document.getElementById('imageFeed').innerHTML = document.getElementById('imageFeed').innerHTML;
}
2020-10-03 04:46:28 +08:00
function updatePresetLabels() {
2021-01-30 03:05:04 +08:00
var lblNdx = $j('#ctrlPresetForm option:selected').val();
2020-10-03 04:46:28 +08:00
2020-12-08 02:32:07 +08:00
$j('#newLabel').val(labels[lblNdx]);
2020-10-03 04:46:28 +08:00
}
function getCtrlPresetModal() {
$j.getJSON(monitorUrl + '?request=modal&modal=controlpreset&mid=' + monitorId)
2020-10-03 04:46:28 +08:00
.done(function(data) {
2020-10-15 04:58:39 +08:00
insertModalHtml('ctrlPresetModal', data.html);
2020-10-03 04:46:28 +08:00
updatePresetLabels();
2020-10-04 10:14:24 +08:00
// Manage the Preset Select box
$j('#preset').change(updatePresetLabels);
2020-10-03 05:10:32 +08:00
// Manage the Save button
$j('#cPresetSubmitModal').click(function(evt) {
evt.preventDefault();
$j('#ctrlPresetForm').submit();
2020-10-03 10:11:54 +08:00
});
2020-10-03 04:46:28 +08:00
})
.fail(logAjaxFail);
}
2020-10-04 05:51:25 +08:00
function getSettingsModal() {
$j.getJSON(monitorUrl + '?request=modal&modal=settings&mid=' + monitorId)
2020-10-04 05:51:25 +08:00
.done(function(data) {
2020-10-15 04:58:39 +08:00
insertModalHtml('settingsModal', data.html);
2020-10-04 05:51:25 +08:00
// Manage the Save button
$j('#settingsSubmitModal').click(function(evt) {
evt.preventDefault();
$j('#settingsForm').submit();
});
})
.fail(logAjaxFail);
}
2020-11-27 07:00:05 +08:00
function processClicks(event, field, value, row, $element) {
2021-08-19 06:40:25 +08:00
if (field == 'Delete') {
$j.getJSON(monitorUrl + '?request=modal&modal=delconfirm')
2020-11-27 09:28:25 +08:00
.done(function(data) {
insertModalHtml('deleteConfirm', data.html);
manageDelConfirmModalBtns();
$j('#deleteConfirm').data('eid', row.Id.replace(/(<([^>]+)>)/gi, ''));
$j('#deleteConfirm').modal('show');
})
.fail(logAjaxFail);
2020-11-27 07:00:05 +08:00
}
}
// Manage the DELETE CONFIRMATION modal button
function manageDelConfirmModalBtns() {
document.getElementById("delConfirmBtn").addEventListener("click", function onDelConfirmClick(evt) {
2021-08-19 06:40:25 +08:00
if (!canEdit.Events) {
2020-11-27 07:00:05 +08:00
enoperm();
return;
}
var eid = $j('#deleteConfirm').data('eid');
evt.preventDefault();
$j.getJSON(thisUrl + '?request=events&task=delete&eids[]='+eid)
2021-08-19 06:40:25 +08:00
.done(function(data) {
2020-11-27 07:00:05 +08:00
table.bootstrapTable('refresh');
$j('#deleteConfirm').modal('hide');
})
.fail(logAjaxFail);
});
// Manage the CANCEL modal button
document.getElementById("delCancelBtn").addEventListener("click", function onDelCancelClick(evt) {
$j('#deleteConfirm').modal('hide');
});
}
function msieVer() {
2021-01-08 22:50:57 +08:00
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
2021-08-19 06:40:25 +08:00
if (msie >= 0) { // If Internet Explorer, return version number
2021-01-08 22:50:57 +08:00
return msie;
} else { // If another browser, return 0
return 0;
}
}
function initPage() {
2021-08-19 06:40:25 +08:00
if (canView.Control) {
2020-10-04 05:51:25 +08:00
// Load the PTZ Preset modal into the DOM
2021-08-19 06:40:25 +08:00
if (monitorControllable) getCtrlPresetModal();
2020-10-04 05:51:25 +08:00
// Load the settings modal into the DOM
2021-08-19 06:40:25 +08:00
if (monitorType == "Local") getSettingsModal();
2020-10-04 05:51:25 +08:00
}
2020-10-03 04:46:28 +08:00
2021-08-19 06:40:25 +08:00
if (monitorType != 'WebSite') {
if (streamMode == 'single') {
2021-01-09 02:25:17 +08:00
statusCmdTimer = setTimeout(statusCmdQuery, (Math.random()+0.1)*statusRefreshTimeout );
2020-12-13 02:45:36 +08:00
setInterval(watchdogCheck, statusRefreshTimeout*2, 'status');
} else {
2021-01-09 02:25:17 +08:00
streamCmdTimer = setTimeout(streamCmdQuery, (Math.random()+0.1)*statusRefreshTimeout );
2020-12-13 02:45:36 +08:00
setInterval(watchdogCheck, statusRefreshTimeout*2, 'stream');
}
2021-08-19 06:40:25 +08:00
if (canStreamNative || (streamMode == 'single')) {
2020-12-13 02:45:36 +08:00
var streamImg = $j('#imageFeed img');
2021-08-19 06:40:25 +08:00
if (!streamImg) {
2020-12-13 02:45:36 +08:00
streamImg = $j('#imageFeed object');
}
2021-08-19 06:40:25 +08:00
if (!streamImg) {
console.error('No streamImg found for imageFeed');
} else {
2021-08-19 06:40:25 +08:00
if (streamMode == 'single') {
2020-12-13 02:45:36 +08:00
streamImg.click(streamImg, fetchImage);
setInterval(fetchImage, imageRefreshTimeout, $j('#imageFeed img'));
} else {
2020-12-13 02:45:36 +08:00
streamImg.click(function(event) {
handleClick(event);
});
}
} // end if have streamImg
} // streamMode native or single
2021-08-19 06:40:25 +08:00
if (refreshApplet && appletRefreshTime) {
2021-01-09 02:25:17 +08:00
setTimeout(appletRefresh, appletRefreshTime*1000);
}
2021-08-19 06:40:25 +08:00
if (window.history.length == 1) {
$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'];
});
changeScale();
2021-08-19 06:40:25 +08:00
} else if (monitorRefresh > 0) {
setInterval(reloadWebSite, monitorRefresh*1000);
}
2020-11-27 07:00:05 +08:00
2020-10-16 21:08:23 +08:00
// Manage the BACK button
bindButton('#backBtn', 'click', null, function onBackClick(evt) {
2020-10-16 21:08:23 +08:00
evt.preventDefault();
window.history.back();
});
// Don't enable the back button if there is no previous zm page to go back to
backBtn.prop('disabled', !document.referrer.length);
// Manage the REFRESH Button
bindButton('#refreshBtn', 'click', null, function onRefreshClick(evt) {
2020-10-16 21:08:23 +08:00
evt.preventDefault();
window.location.reload(true);
});
// Manage the SETTINGS button
bindButton('#settingsBtn', 'click', null, function onSettingsClick(evt) {
2020-10-16 21:08:23 +08:00
evt.preventDefault();
$j('#settingsModal').modal('show');
});
// Only enable the settings button for local cameras
settingsBtn.prop('disabled', !(canView.Control && monitorType == 'Local'));
2020-11-27 07:00:05 +08:00
// Init the bootstrap-table
2021-08-19 06:40:25 +08:00
if (monitorType != 'WebSite') table.bootstrapTable({icons: icons});
2020-11-27 07:00:05 +08:00
// Update table rows each time after new data is loaded
table.on('post-body.bs.table', function(data) {
$j('#eventList tr:contains("New Event")').addClass('recent');
});
// Take appropriate action when the user clicks on a cell
table.on('click-cell.bs.table', processClicks);
// Some toolbar events break the thumbnail animation, so re-init eventlistener
table.on('all.bs.table', initThumbAnimation);
// Update table links each time after new data is loaded
table.on('post-body.bs.table', function(data) {
var thumb_ndx = $j('#eventList tr th').filter(function() {
return $j(this).text().trim() == 'Thumbnail';
}).index();
table.find("tr td:nth-child(" + (thumb_ndx+1) + ")").addClass('colThumbnail');
});
2020-10-23 21:34:35 +08:00
} // initPage
// Kick everything off
2020-10-03 04:46:28 +08:00
$j(document).ready(initPage);