Merge pull request #4643 from IgorA100/patch-412820

Fix: More correct processing of the stream after hiding and then displaying the Watch page
pull/4683/head
Isaac Connor 2026-03-05 08:32:23 -05:00 committed by GitHub
commit a13d618946
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 7 deletions

View File

@ -6,6 +6,7 @@ function MonitorStream(monitorData) {
this.id = monitorData.id;
this.name = monitorData.name;
this.started = false;
this.zmsState = null;
this.muted = (currentView == 'watch') ? !!getCookie('zmWatchMuted') : true;
this.connKey = monitorData.connKey;
this.genConnKey = function() {
@ -1558,6 +1559,13 @@ function MonitorStream(monitorData) {
params.command = command;
}
this.streamCmdReq(params);
if (params.command == CMD_PAUSE) {
this.zmsState = 'paused';
} else if (params.command == CMD_PLAY) {
this.zmsState = 'played';
} else if (params.command == CMD_STOP || params.command == CMD_QUIT) {
this.zmsState = 'stopped';
}
};
this.alarmCommand = function(command) {

View File

@ -42,6 +42,7 @@ class VideoStream extends VideoRTC {
*/
oninit() {
console.debug('stream.oninit');
this.visibilityCheck = false;
super.oninit();
}
@ -68,6 +69,11 @@ class VideoStream extends VideoRTC {
super.ondisconnect();
}
connectedCallback() {
console.debug('stream.connectedCallback');
super.connectedCallback();
}
onopen() {
console.debug('stream.onopen');
const result = super.onopen();

View File

@ -1382,7 +1382,7 @@ function changePlayer() {
// Kick everything off
$j( window ).on("load", initPage);
var prevStateStarted = false;
var prevStateStarted = null;
document.onvisibilitychange = () => {
// Always clear it because the return to visibility might happen before timeout
TimerHideShow = clearTimeout(TimerHideShow);
@ -1391,22 +1391,29 @@ document.onvisibilitychange = () => {
//Stop monitor when closing or hiding page
if (monitorStream) {
if (monitorStream.started) {
prevStateStarted = 'played';
//Stop only if playing or paused.
// We might want to continue status updates so that alarm sounds etc still happen
monitorStream.stop();
if ((monitorStream.zmsState == 'paused') || (monitorStream.element.video && monitorStream.element.video.paused) || monitorStream.element.paused) {
prevStateStarted = 'paused';
} else {
prevStateStarted = 'played';
//Stop only if playing (not paused).
// We might want to continue status updates so that alarm sounds etc still happen
monitorStream.stop();
}
} else {
prevStateStarted = false;
prevStateStarted = 'stopped';
}
}
}, 15*1000);
} else {
//Start monitor when show page
if (monitorStream && prevStateStarted == 'played' && !idleTimeoutTriggered) {
prevStateStarted = false;
prevStateStarted = null;
onPlay(); //Set the correct state of the player buttons.
monitorStream.start(monitorStream.currentChannelStream);
monitorsSetScale(monitorId);
//} else if (prevStateStarted != 'paused') {
} else if (monitorStream && monitorStream.element && ((monitorStream.zmsState == 'paused') || (monitorStream.element.video && monitorStream.element.video.paused) || monitorStream.element.paused)) {
prevStateStarted = null;
}
}
};