Feat: Correctly iterates through players when the Player = "Auto" mode is selected. #4883
Feat: Correctly iterates through players when the Player = "Auto" mode is selected. #4883IgorA100 wants to merge 4 commits into
Conversation
|
@connortechnology |
There was a problem hiding this comment.
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/VideoStreamto register errors and restart playback. - Refactor
MonitorStream.start()to route through a newselectPlayer/selectNextPlayermechanism driven by aplayerPrioritylist and error counts. - Add RTSP2Web HLS.js error handling and a generic media-element
errorlistener 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.
| this.handlerEventListener['playStream'] = manageEventListener.addEventListener(stream, 'error', | ||
| (e) => { | ||
| this.writeTextInfoBlock("Error"); | ||
| manageEventListener.removeEventListener(this.handlerEventListener['volumechange']); | ||
| this.streamErrorRegistration(); | ||
| this.restart(this.currentChannelStream); |
| 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; | ||
| } |
| Janus.attachMediaStream(document.getElementById("liveStream" + id), ourstream); | ||
| } else { | ||
| Janus.debug("Janus stream is not active. Restart."); | ||
| this.streamErrorRegistration(); | ||
| monitorStream.restart(); | ||
| } |
| const playerPriority = { | ||
| 1: { // This setting should always be priority #1. | ||
| name: 'default', | ||
| countErrors: 0, | ||
| durationErrors: 0 | ||
| }, |
| 2: { | ||
| name: 'go2rtc_webrtc', | ||
| countErrors: 0, | ||
| durationErrors: 0 | ||
| }, | ||
| 3: { | ||
| name: 'go2rtc_mse', | ||
| countErrors: 0, | ||
| durationErrors: 0 |
Also added an error listener for HLS, RTSP2Web, and Go2RTC.
Closed #4868
Player = "Auto,"playback always starts with the monitor's default player."playerPriority"object."Auto,"we also begin iterating through the players in the priority order set in the "playerPriority" object."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."zms"(it is the last player in the priority list).Player = "Auto,"players will not be switched and the specified player will be attempted indefinitely (as before).