feat: use monitor names for go2rtc stream aliases#4864
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR introduces monitor-name-aware go2rtc stream naming across the UI and backend, while improving test reliability by avoiding hardcoded ports and making Catch2 availability more automatic for test builds.
Changes:
- Add a shared
ZMGo2RTCStreamNamesutility and use it to build go2rtcsrcvalues from monitor name (fallback to ID). - Extend live thumbnail overlays and
MonitorStreamto pass monitor name through to go2rtc stream selection. - Stabilize socket-based unit tests by using ephemeral ports / unique Unix socket paths; fetch Catch2 when not installed.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| web/skins/classic/js/skin.js | Passes monitor name into go2rtc thumbnail overlay and builds stream src via shared helper. |
| web/skins/classic/includes/functions.php | Loads the new go2rtc stream name helper in the classic skin. |
| web/js/go2rtc-stream-names.js | Adds a shared helper for deriving go2rtc stream names from monitor name/ID. |
| web/js/MonitorStream.js | Switches go2rtc stream src construction to use monitor name-aware helper. |
| web/ajax/console.php | Adds data-monitor-name / legacy go2rtc_name attributes for UI consumption. |
| tests/zm_comms.cpp | Replaces hardcoded ports and static Unix socket path with generated ones. |
| tests/js/go2rtc-stream-names.test.js | Adds basic unit tests for the new stream naming helper. |
| src/zm_monitor_go2rtc.cpp | Registers go2rtc streams under both monitor ID and (optionally) monitor name. |
| CMakeLists.txt | Falls back to fetching Catch2 via FetchContent when not found locally. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const streamName = ZMGo2RTCStreamNames.getGo2RTCStreamName(mid, monitorName, '_CameraDirectPrimary'); | ||
| url.search = new URLSearchParams({src: streamName}).toString(); |
| int reserveEphemeralPort(int socket_type) { | ||
| const int sd = ::socket(AF_INET, socket_type, 0); | ||
| REQUIRE(sd >= 0); | ||
|
|
||
| sockaddr_in addr = {}; | ||
| addr.sin_family = AF_INET; | ||
| addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | ||
| addr.sin_port = 0; | ||
|
|
||
| const int reuse_addr = 1; | ||
| REQUIRE(::setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(reuse_addr)) == 0); | ||
| REQUIRE(::bind(sd, reinterpret_cast<const sockaddr *>(&addr), sizeof(addr)) == 0); | ||
|
|
||
| socklen_t addr_len = sizeof(addr); | ||
| REQUIRE(::getsockname(sd, reinterpret_cast<sockaddr *>(&addr), &addr_len) == 0); | ||
|
|
||
| const int port = ntohs(addr.sin_port); | ||
| REQUIRE(port > 0); | ||
| REQUIRE(::close(sd) == 0); | ||
| return port; | ||
| } |
|
|
||
| #include "zm_comms.h" | ||
| #include <array> | ||
| #include <cstdio> |
|
Please address the copilot comments |
|
@connortechnology I have addressed copilot reviews |
|
FYI first thing I thought when I saw this was didn't we just merge a UTF-8 for monitor names PR? Not to take from the work, but I am not sure the benefits are there to enable this. @connortechnology? Core concern — using the monitor name as a stream identifier A stream identifier should be stable, unique, and URL-safe. A monitor name is none of those:
On the motivation: the win is friendlier handles for manually-written go2rtc/Home-Assistant config. For automated integrations (the common ZM↔HA path) the name adds nothing, they already pull {Id, Name} from /api/monitors. What I'd suggest
|
Summary
Use monitor names for go2rtc stream aliases to make downstream integrations friendlier, while preserving the existing monitor-ID aliases for backward compatibility.
This also fixes the local test/build path so the project configures with
BUILD_TEST_SUITE=ONeven when Catch2 is not preinstalled, and stabilizes the comms tests so they do not rely on fixed ports or fixed Unix socket paths.Changes
FetchContentfallback in CMake whenfind_package(Catch2)is not satisfied.Compatibility
Notes
ctestoutside the sandbox, because the sandbox blocks the socket operations those tests exercise.src/zms.cppaboutstrncpytruncation; this change does not modify that code.fixes #4622