Commit Graph
477 Commits
Author SHA1 Message Date
Jash Ambaliya dd883f8839 fix: RTSP2Web live view uses channel 0 for the Restream stream channel instead of a channel 2 that RTSP2Web never has refs #7291 (#7292) 2026-11-27 08:19:39 -05:00
IgorA100 caffcbf6ca Fix: Do not display a placeholder image when stream playback is stopped on the Zone page (#7662)
* Modify stop function to include default showImg option

* Modify liveStream to stop monitors with showImg option

Updated liveStream function to stop monitors without showing images.

* Add isLightboxOpen mock function to tests
2026-11-27 08:06:42 -05:00
Harsh Singh a316d68e49 fix: reset the go2rtc player error count when playback starts (#8128) 2026-11-25 20:35:15 -05:00
IgorA100 c368d30c65 Chore: Modified the logic for controlling the availability of #volumeControls. (#8234)
* Clean up volume control code in MonitorStream.js

We will not enable the availability of #volumeControls for the monitor within the `MonitorStream.createVolumeSlider()` execution, as this is handled by the global `getTracksFromStream()` function. Otherwise, it would remain enabled even in the absence of an audio track.

* Refactor controlMediaStream to remove volume controls

Remove volume control handling from media stream monitoring.
2026-11-25 18:04:35 -05:00
IgorA100 79394966a4 Re-register volumechange listener when resuming playback after pause
Re-register volumechange listener when resuming playback after pause

Call this.createVolumeSlider() in the 'playing' event handler when
streamStartedPlaying is already true, ensuring volumechange tracking is
restored after pause removes the previous listener.
2026-11-20 18:48:20 +03:00
IgorA100 e2f9d7629f Fix Loading overlay and add 8s startup stall detection with auto-restart
Fix Loading overlay and add 8s startup stall detection with auto-restart

- Wait for actual decoded frame or currentTime progression before clearing the Loading overlay
- Add an 8-second startup stall timeout to record an error and automatically restart stalled streams
- Restore the Loading overlay if mid-stream buffering stalls for more than 1.5 seconds
- Centralize timer cleanup in clearPlaybackTimers() and remove the waiting listener on stop()
2026-11-20 18:17:14 +03:00
Jash 0828401324 fix: keep the ZM_RTSP2WEB_PATH path prefix in browser stream URLs refs #6697 2026-11-18 18:39:25 +05:30
Jash d204919adb fix: MonitorStream stopMse resolves when there is no source buffer to clear refs #6545 2026-11-17 09:00:27 +05:30
Jash e2425bb42d fix: keep MonitorStream volume sync after pause, let Play retry after all players failed, send maxfps only to zms refs #6421 2026-11-16 15:23:28 +05:30
Isaac Connor 66c585b10a Merge pull request #5723 from AJ0070/nosocket-grace
fix: tolerate a brief no_socket so stream.php can stop waiting a second for zms
2026-11-14 19:45:28 -05:00
Isaac Connor 7d3a95182a Merge pull request #5789 from AJ0070/monitorstream-fixes
fix: MonitorStream reconnect timer on stop, RTSP2Web wss and buffer level
2026-11-14 18:53:27 -05:00
Jash 7f3f64be6e fix: show the zoom readout when zoomed and register the zoom-out button under its real key refs #5792 2026-11-14 18:27:23 +05:30
Jash 61e2e8c08e fix: keep the watch ResizeObserver on the current stream element refs #5792 2026-11-14 18:27:23 +05:30
Jash d06954cb5f fix: look up the per-monitor buffer level element refs #5788 2026-11-14 18:22:32 +05:30
Jash 8f583d307a fix: use wss for the RTSP2Web MSE websocket on https servers refs #5788 2026-11-14 18:22:31 +05:30
Jash 41a98654ad fix: cancel pending auth reconnect when a stream is stopped refs #5788 2026-11-14 18:22:31 +05:30
Jash ce1b37d174 fix: retry a stream command until no_socket persists before treating it as fatal refs #5722 2026-11-14 17:37:51 +05:30
Isaac ConnorandClaude Opus 5.5 f223b38e04 fix: ignore MonitorStream replies for a connkey that was already replaced
When a monitor's zms exits, the status poll gets reason=no_socket and the
stream is reloaded under a new connkey. A no_socket reply takes over a second
(stream.php waits for the socket file to appear) while the poll runs every
second, and every request on the page shares one ajaxQueue, so a second poll
for the dead connkey is usually already queued when the first reply arrives.
Its reply then reloaded the stream again: it sent CMD_QUIT to the zms the
first reload had just started and replaced the connkey a second time.

Each restart of an unreachable monitor therefore left an orphaned zms behind,
and a poll queued for that orphan between the two reloads could find it
shutting down. stream.php then waited the full MSG_TIMEOUT and logged
"Timed out waiting for msg ... after waiting 5000 milliseconds", while every
other monitor's poll on the page waited behind it in the shared queue.

Bind each reply to the connkey its request was sent with and drop replies
for a connkey we no longer hold, as EventStream already does. alarmCommand()
passes its connkey explicitly, since binding getStreamCmdResponse directly
would hand it jQuery's textStatus in that argument.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:12:27 -04:00
IgorA100 310a71e31e Refactor RTSP2WebType handling in MonitorStream
Removed conditional check for RTSP2WebType and added comments indicating its potential redundancy.
2026-10-23 10:44:47 +03:00
IgorA100 8d1a9054ec - On the Zone page, when changePlayer() is called, execute monitorStream.start() with a 200ms delay; otherwise, the preceding stop() call might not have enough time to complete properly.
- When calling `monitorStream.manageAvailablePlayers()`, now pass the candidate player as an argument instead of determining the player from stored cookies inside `manageAvailablePlayers()`. This is necessary because cookies could belong to either the Watch page or the Zone page.
- On the Zone page, load `hls.min.js` if Go2RTC or RTSP2Web is being used for the monitor.
- `monitorStream.setPlayer()` is now executed within `monitorStream.manageAvailablePlayers()`. Previously, `manageAvailablePlayers()` only handled the assignment of `monitorStream.player`.
- Added a new function, `this.setRTSP2WebType()`, to avoid code duplication. This ensures that `RTSP2WebType` is checked and set even if `setPlayer()` is not called on the page.
- Minor optimization regarding variable usage.
- If `hls.min.js` is not loaded, attempting to play via HLS will now trigger a "The HLS library is not loaded" warning in the browser console and initiate a stream restart. Previously, this would result in an error.
2026-10-17 20:54:57 +03:00
IgorA100 75fa7e2df0 Update Janus condition to include 'zone' view 2026-10-16 17:07:41 +03:00
IgorA100 9996e8967f Fix syntax error in MonitorStream.js 2026-10-16 13:09:18 +03:00
IgorA100 a266a82998 Refactor Janus handling in MonitorStream.js
- The `janus` variable is no longer global; it now belongs to `MonitorStream`.
- In the `Janus.init` callback, do not perform any actions if the monitor is in a stopping state or is already stopped.
- Check for the existence of the `destroy` method before calling `janus.destroy()`.
- Allow the Janus player to be selected in `this.selectPlayer` regardless of the `streamChannel` on the Montage page. This will not cause visual confusion, as the Montage page does not allow selecting a `streamChannel` (it uses the default one). 
However, if the default `streamChannel` is a secondary one and the default player is set to Janus, the Janus player would never be selected on the Montage page. I believe this is incorrect, as we should allow for more flexibility.
2026-10-16 13:05:33 +03:00
IgorA100 c398c6356e Avoiding errors when stopping a Janus stream (MonitorStream.js) 2026-10-15 23:22:24 +03:00
Isaac ConnorandClaude Opus 5.5 575e5484b3 fix: skip an unconfigured go2rtc under the Auto player
With its player left on Auto, a monitor with go2rtc enabled had
selectNextPlayer() pick go2rtc_webrtc first, and with ZM_GO2RTC_PATH
empty select_go2rtc() then alerted "ZM_GO2RTC_PATH is empty", on the
montage for every such monitor, although nobody had chosen go2rtc.

The fallback chain already skipped go2rtc for a monitor without it
enabled; skip it when ZM_GO2RTC_PATH is empty too. A monitor or browser
that chose go2rtc reaches select_go2rtc() directly and still gets the
alert.

A node test drives selectPlayer() through the restart chain for Auto
without a path, Auto with one, and go2rtc chosen explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 18:36:33 -04:00
Isaac ConnorandClaude Opus 5.5 c3ff83fa56 fix: do not use the RTSP restream when ZM_MIN_RTSP_PORT is not set
ZoneMinder's RTSP server only starts when ZM_MIN_RTSP_PORT is set, and it
defaults to empty. The go2rtc and Janus managers decided to use the
restream from the monitor's RTSP Server flag (Janus: its restream flag)
alone, so with the port unset they built rtsp://127.0.0.1:0/<name>.
go2rtc was given that as the monitor's primary stream and as
<id>_ZoneMinderPrimary, neither of which can play; Janus pointed its
mountpoint at it.

Use the restream only when the port is set as well, and warn when a
monitor asks for it without one, so the camera's own stream is used.
MonitorStream applies the same test before choosing the
_ZoneMinderPrimary stream, which is no longer registered in that case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 18:34:04 -04:00
Isaac ConnorandClaude Opus 5.5 0d6ebcd42c fix: accept ZM_GO2RTC_PATH with or without its /api suffix
go2rtc serves its API under /api, and its websocket at /api/ws. zmc
appends /streams to ZM_GO2RTC_PATH and the browser appends /ws, so the
setting only worked if it ended in /api. The natural value to enter is
the server address, http://host:1984, and with that zmc reached
/streams, which is go2rtc's RTSPtoWeb compatibility endpoint, so no
stream was ever registered, and the browser's /ws was a 404. Where
another player was available the failure went unnoticed.

Normalise the setting where URLs are built from it: a trailing slash is
dropped and /api is added unless the path already ends in it, which also
covers go2rtc behind a reverse proxy at a sub-path.

- Go2RTCApiEndpoint() in zm_utils, used by zmc's Go2RTCManager.
- go2rtcApiUrl() in skin.js, used by MonitorStream and the console
  thumbnail stream. It assigns the path once, since stripping the slash
  from a bare host's "/" and appending gave "//api", as the old
  pathname += '/ws' gave "//ws".
- The option's help says the suffix is optional.

Catch2 and node tests cover bare hosts, trailing slashes, an existing
/api, a proxy sub-path and credentials in the URL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 18:34:04 -04:00
IgorA100 7e4159da81 Merge branch 'master' into patch-756163 2026-09-13 23:38:02 +03:00
Isaac ConnorandClaude Opus 5 1361f93804 fix: send the initial mode=paused CMD_PLAY that streamCommand was dropping
select_zms() has three ways out, and two of them send a stream command before
the tail of the function sets started. streamCommand() drops anything sent while
that is false, so such a branch reports success having sent nothing and the
picture sits on its last keepalive frame.

The resume branch was fixed on this branch already. The branch below it, for a
page rendered with mode=paused, has the same shape and was missed. With auth on
it needed a still-valid hash to reach, so it was intermittent; with auth off,
where there is no hash that can go stale, the srcAuthCurrent change on this
branch makes it the path every initial load takes. Set started there too.

Add tests/js/monitorstream-resume.test.js, which asserts what reaches the wire
rather than which branch ran: the resume and initial-paused paths each send
exactly one CMD_PLAY on the connkey they are supposed to address, resuming
leaves src and connkey alone, and a stale auth hash still rebuilds and quits the
process the old connkey addressed. Removing the one-line fix fails the
initial-paused case and leaves the other three passing.

Full JS suite passes, ESLint clean on both files.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UkQwahn9pi1y4wJe9BTxjM
2026-09-12 15:51:14 -04:00
Isaac ConnorandClaude Opus 5 6514b1086a fix: resume a stopped zms instead of abandoning it and building another
select_zms() has a branch that resumes an existing zms with CMD_PLAY rather
than rebuilding the stream, but three things stopped it ever working. Every one
of them showed up only when the page was driven for real.

stop() ends by clearing activePlayer, which is the only thing that branch
tests, so after any stop it was unreachable and start() fell through to "new
src, new connkey" - a second zms, the first left running and no longer
addressable. That is the montage page's accumulating processes: hide the tab,
the handler stops each stream, and returning replaces rather than resumes. The
same happens when a monitor is scrolled out of view and back. stop() now
remembers what it shut down, and select_zms() resumes on that as well as on
activePlayer, provided we still hold the connkey to address it.

srcAuthCurrent required a non-empty zmAuth.hash, which is '' whenever auth is
off or the relay carries no hash. There is nothing that can go stale in that
case, so the src is as current as it will ever be; requiring a hash sent every
such install down the rebuild path for no reason.

streamCommand() drops anything sent while !started, and started is not set
until the end of select_zms(), so the resume issued its CMD_PLAY into nothing
and the stream stayed stopped. Resuming after a pause worked only because
pause() leaves started set. It is now set before the command goes out.

Finally, the rebuild path clears the "Loading..." info block from img_onload,
which cannot fire on a resume because src never changes. Without clearing it,
a stream that had in fact resumed sat behind that block and its still image and
looked frozen - the fault that made this look unfixable at first.

restart() is excluded from all of it: it is the error path, whatever failed may
be that very zms, and a broken img is not repaired by CMD_PLAY.

Verified on a live montage page with two monitors: across two hide/show cycles
the same two zms processes are kept - no orphans, no respawn - and both
pictures are live afterwards, with the zms status reporting stopped=0 and
~15 fps.

refs #4706

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 12:44:54 -04:00
Isaac ConnorandClaude Opus 5 a6515ae25b fix: quit the old zms before replacing the connkey that addresses it
select_zms() mints a fresh connkey whenever it has to rebuild the stream src,
without telling the process the old connkey belonged to that it is finished.
Once the key is replaced nothing can reach that process again: no CMD_QUIT can
be delivered, and a stopped one will not notice on its own.

getStreamCmdResponse() already learned this - its reload path calls
quitConnKey() first, with a comment saying why - but the path every ordinary
start() takes did not. quitConnKey had exactly two references in the file: its
own definition and that one use.

refs #4706

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 12:44:54 -04:00
IgorA100 b4ce46bcac - When executing monitorStream.img_onerror():
-- Check isActive first.
-- Run error registration
- When checking for errors in nextCycleView(), check monitorStream.player instead of (monitorStream.selectedPlayer || monitorStream.activePlayer)
2026-08-23 22:45:05 +03:00
IgorA100 814a10b1c6 Merge branch 'master' into patch-756163 2026-08-22 22:12:40 +03:00
IgorA100 7b4a22d657 Removed the unused MonitorStream.sessionActive() function.
Removed sessionActive method from MonitorStream class.
2026-08-22 13:44:45 +03:00
IgorA100 47c1e72037 Merge branch 'master' into patch-329060 2026-08-22 13:36:51 +03:00
IgorA100 abd00e1a71 - MonitorStream.sessionActive() will be replaced with streamSessionActive() for better compatibility. This way, we won't be tightly coupled to MonitorStream and won't need additional analysis when calling functions.
- onopen and onclose will be race-protected.
2026-08-22 13:33:46 +03:00
IgorA100 77c7292ca5 Fix: Eslint (MonitorStream.js) 2026-08-22 00:35:45 +03:00
IgorA100 94c2857ff2 Added MonitorStream.sessionActive() function (MonitorStream.js) 2026-08-22 00:25:46 +03:00
IgorA100 5c83800828 Continued fixing of race conditions when switching monitors (MonitorStream.js) 2026-08-21 20:18:13 +03:00
IgorA100 0444db55a4 Fix: If a codec for Rtsp2Web playback is missing, always log the error as a fatal error, not just when players are automatically selected.
This will ensure more correct code execution. This is especially true for switching to the next monitor in PR https://github.com/ZoneMinder/zoneminder/pull/4980
2026-08-21 16:13:39 +03:00
IgorA100 9272b54102 - In cyclic mode, switch to another monitor if a critical playback error threshold is reached for the specified player.
- When executing MonitorStream.restart(), do not clear the player's error count. This will allow us to analyze playback issues. We do this clearing elsewhere.
2026-08-21 14:04:52 +03:00
IgorA100 25fab2cd2a Added MonitorStream.fatalError handling 2026-08-21 13:35:42 +03:00
IgorA100 0eef643407 Merge branch 'master' into patch-756163 2026-08-21 12:03:25 +03:00
Isaac Connor 326181ea4f Merge pull request #5059 from IgorA100/patch-371115
The "rand" parameter change for SRC has been separated into a separate function, and a function for replacing SRC has been added.
2026-08-20 22:59:03 -04:00
IgorA100 b036b65b86 Reverted the missing src definition to stream.src. 2026-08-20 16:47:52 +03:00
IgorA100 32f0e37583 - Changing the "rand" parameter for SRC has been separated into a separate function, and a function for replacing SRC has been added.
- Instead of Math.random(), we'll use Date.now().
This will make the code cleaner and more understandable.
- We also now use refreshStreamSrc() when stopping stream playback.
2026-08-20 16:42:28 +03:00
IgorA100 a740e84def Update MonitorStream.js 2026-08-20 12:57:49 +03:00
IgorA100 4e8cf0f6d7 - We'll assign the listener for 'zm:tracksReceived' to stream instead of "document."
- When closing a socket, check the session before clearing the WebSocket, not after.
- Execute resetCountStreamErrors() when playback starts successfully.
- Recheck the session inside videoEl.onplay after the 500ms timeout.
2026-08-19 18:53:36 +03:00
IgorA100 2e5f23d2f0 Fix Eslint MonitorStream.js 2026-08-19 00:16:22 +03:00
IgorA100 b4778f1492 - Added isActive to MonitorStream.
- Exit this.img_onload if the monitor is already stopped.
- Assign the 'zm:tracksReceived' listener only after stream playback has started, not during start().
- Additional processing of MonitorStream.playbackSessionId
- Calling stream.load() inside stop() for the rtsp2web type MSE is redundant and can lead to unnecessary warnings. We do everything necessary in stopMse().
- When restarting a stream, call updatePlayerControls() instead of streamCmdStop() to avoid duplicating the stop() command (relevant for the Watch page).
- Now, to switch to the next player, we won't call MonitorStream.selectNextPlayer() in different places in the code. Instead of selectNextPlayer(), we will always call restart(), which will select the next player. This will allow us to more accurately clear all unnecessary objects. To achieve this, we have slightly modified restart(). - For go2rtc, execute playbackSessionId = generateUUID() when changing the SRC, not when selecting a player, since go2rtc itself can change src.
- Avoid looping when executing selectNextPlayer() during errors in the ZMS player.
- Added the "fatal" argument to streamErrorRegistration(), which prevents unnecessary relaunches of the same player that was previously playing in the event of a fatal playback error.
- Added a setter for src to the VideoStream class for go2rtc.
- Added support for monitorStream.isActive for the Watch page.
- Added the updatePlayerControls() function for the Watch page to manage the state of the player buttons. In the future, we need to create a single function for managing the state of the player buttons. It's a bit of a mess right now. We'll do this in the next PR to avoid breaking anything.
- To optimize performance, part of the code from getTracksFromStream() has been moved directly to the listener in MonitorStream.
2026-08-19 00:04:02 +03:00