Skip to content

Feat: Correctly iterates through players when the Player = "Auto" mode is selected. #4883

Open
IgorA100 wants to merge 4 commits into
ZoneMinder:masterfrom
IgorA100:patch-10343
Open

Feat: Correctly iterates through players when the Player = "Auto" mode is selected. #4883
IgorA100 wants to merge 4 commits into
ZoneMinder:masterfrom
IgorA100:patch-10343

Conversation

@IgorA100
Copy link
Copy Markdown
Contributor

@IgorA100 IgorA100 commented Jun 4, 2026

Also added an error listener for HLS, RTSP2Web, and Go2RTC.

Closed #4868

  • When Player = "Auto," playback always starts with the monitor's default player.
  • If an error occurs while attempting playback with the default player, we begin iterating through the players in the priority order set in the "playerPriority" object.
  • If the monitor's default player is "Auto," we also begin iterating through the players in the priority order set in the "playerPriority" object.
  • The "playerPriority" object stores the number of errors and the duration over which these errors accumulated, but currently the duration is not saved or analyzed. Duration analysis may not be necessary in the future.
  • The next player is switched after the first playback error.
  • If none of the players are working, playback will be performed via "zms" (it is the last player in the priority list).
  • To change the player priority, simply change the digital key in "playerPriority." Keys may be out of order and have gaps in numbers. For example, 2, 5, 3, 1. Keys should not be repeated, as this will cause incorrect operation.
  • If a specific player is specified instead of Player = "Auto," players will not be switched and the specified player will be attempted indefinitely (as before).

@IgorA100 IgorA100 marked this pull request as ready for review June 4, 2026 14:41
@IgorA100
Copy link
Copy Markdown
Contributor Author

IgorA100 commented Jun 4, 2026

@connortechnology
I'd really like to finish this PR within 1-2 days, as it contains a large chunk of code split into several functions, and if someone makes changes to this chunk of code, it will be difficult to track correctly.
In fact, there aren't that many changes in this PR.
I really hope this PR gets reviewed quickly.
Isaac, I'm not rushing you; these are just my small wishes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the web live-view playback logic so that when the Watch page player is set to Auto, playback begins with the monitor’s configured default player and can fail over to other players on playback errors. It also adds error listeners for Go2RTC, RTSP2Web (including HLS.js), and video element playback errors to trigger restart/failover behavior.

Changes:

  • Add WebSocket error handling to Go2RTC’s VideoRTC/VideoStream to register errors and restart playback.
  • Refactor MonitorStream.start() to route through a new selectPlayer / selectNextPlayer mechanism driven by a playerPriority list and error counts.
  • Add RTSP2Web HLS.js error handling and a generic media-element error listener to trigger restart/failover.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
web/js/video-stream.js Adds a Go2RTC stream-level onerror hook that registers a playback error and triggers a restart.
web/js/video-rtc.js Wires WebSocket error events into a new onerror() handler for Go2RTC’s VideoRTC element.
web/js/MonitorStream.js Introduces player priority/error tracking and refactors startup/restart logic to enable Auto-mode player iteration and new error listeners.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread web/js/MonitorStream.js
Comment on lines +523 to +528
this.handlerEventListener['playStream'] = manageEventListener.addEventListener(stream, 'error',
(e) => {
this.writeTextInfoBlock("Error");
manageEventListener.removeEventListener(this.handlerEventListener['volumechange']);
this.streamErrorRegistration();
this.restart(this.currentChannelStream);
Comment thread web/js/MonitorStream.js
Comment on lines +1935 to +1955
let num = parseInt(key)+1;
let nextPlayer = (num < Object.keys(playerPriority).length) ? num : null;
if (nextPlayer !== null) {
while (nextPlayer !== null && !playerPriority[nextPlayer]) {
// It is required because priority numbers may not be consecutive and may have gaps in numbers.
num += 1;
nextPlayer = (num < Object.keys(playerPriority).length) ? num : null;
}

if (parseInt(playerPriority[nextPlayer]['countErrors']) === 0) {
this.player = playerPriority[nextPlayer]['name'];
this.restart(this.currentChannelStream);
foundNextPlayer = true;
return;
}
} else {
this.player = 'zms';
this.restart();
foundNextPlayer = true;
return;
}
Comment thread web/js/MonitorStream.js
Comment on lines 2034 to 2039
Janus.attachMediaStream(document.getElementById("liveStream" + id), ourstream);
} else {
Janus.debug("Janus stream is not active. Restart.");
this.streamErrorRegistration();
monitorStream.restart();
}
Comment thread web/js/MonitorStream.js
Comment on lines +4 to +9
const playerPriority = {
1: { // This setting should always be priority #1.
name: 'default',
countErrors: 0,
durationErrors: 0
},
Comment thread web/js/MonitorStream.js
Comment on lines +10 to +18
2: {
name: 'go2rtc_webrtc',
countErrors: 0,
durationErrors: 0
},
3: {
name: 'go2rtc_mse',
countErrors: 0,
durationErrors: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Player = Auto does not take into account the default player settings in the monitor on the Watch page

2 participants