Skip to content

Add a Cameras widget for go2rtc and HLS cameras - #22

Open
masonjmiller wants to merge 7 commits into
kemalandic:mainfrom
masonjmiller:cameras-widget
Open

masonjmiller wants to merge 7 commits into
kemalandic:mainfrom
masonjmiller:cameras-widget

Conversation

@masonjmiller

@masonjmiller masonjmiller commented Oct 6, 2026 •

Copy link
Copy Markdown

Hey team. I had this idea come to me, since I'm constantly watching my elderly dog sleep during the day while I work from home, so I turned to Claude for help on this one as i'm not a Swift developer.

A native Cameras widget (Media) for live cameras. It plays them from a go2rtc server, the streaming hub that Frigate and Home Assistant already ship, or from any HLS URL.

The Cameras widget in a grid on a XENEON EDGE, with Fill the Tile on and a square theme: two cameras across the top and the third spanning the bottom

What it does

  • Single: one camera, with name tabs over the picture to switch between them. It can cycle on a timer, and a tap pauses cycling for 30 s. The next camera starts 8 s before its turn and the switch waits until it's playing, so cycling never lands on a spinner. Cameras take a few seconds to start, and a Ring live view through go2rtc takes longer than most.
  • Grid: every camera at once. Cameras that don't fit go on further pages.
  • Full screen: tap any camera, in either layout, to open it across the whole dashboard, above every page. The controls fade four seconds after the last touch, and a tap anywhere brings them back or hides them:
    • close (Esc too);
    • pause and play, with a LIVE or PAUSED badge;
    • sound, when the stream has any;
    • arrows through the widget's other cameras.
  • Fill the Tile crops video to the card's edges, in the grid too. Off, every picture stays whole and the grid keeps 16:9 cells.
  • Follows the theme:
    • Corner radius for the video. Tabs, labels and buttons stay pill-shaped whatever the radius.
    • Widget gap between grid cells.
    • The accent for tabs and buttons, until a color is picked for Cameras on the Theme page.
  • Sound: a speaker button appears, in Single and full screen, when a stream carries audio. One camera plays at a time.
  • Streams only while someone can see it:
    • cameras on the neighbouring pages that stay rendered for swiping don't stream;
    • the tiles under a full-screen camera rest;
    • nothing streams while the displays sleep;
    • a camera shown on two widgets streams once.

A camera opened full screen, with its controls showing: the name and "2 of 3", close, arrows to the other cameras, pause, the LIVE badge and sound:

A camera open full screen across the XENEON EDGE, with the camera's name and 2 of 3 at the top left, a close button at the top right, arrows at either side, and pause, a LIVE badge and a speaker button along the bottom

The widget's settings:

The Cameras widget's settings: the go2rtc server, three picked cameras with reorder and remove buttons, the HLS URL field, Show, Switch Every, Fill the Tile and Show Camera Names

How

  • Camera lists. CameraService (ServiceKey.cameras) reads GET /api/streams through CITransport, so its tests use StubTransport. It re-reads each watched server every minute.

  • Playback. LiveStreamPlayer wraps AVPlayer on go2rtc's /api/stream.m3u8?src=:

    • starts as soon as the stream is ready;
    • jumps back to the live edge when it falls 2.5 s behind;
    • rebuilds a stalled or failed stream with backoff.

    Against go2rtc's half-second segments it runs about 2 s behind the camera, measured against the camera's own clock overlay. There are no web views and no third-party code.

    Pausing holds the picture and stops the download, and playing again jumps back to live.

  • Shared players. CameraService keeps one LiveStreamPlayer per stream, shared by every view showing that camera. Each view says whether it wants the stream playing, and it plays while any of them does. That makes full screen instant: it shows the player the tile was already using. The service claims that stream before the tiles underneath let go of it, and keeps it a second after closing while they take it back.

  • Full screen is drawn by CameraFullScreenLayer, one line in DashboardShell's root ZStack above the focus layer.

  • Settings. A new ConfigFieldType.cameraList, next to notePicker/noteStack, rendered by CameraListEditor. It lists the server's cameras to pick from (or "All Cameras"), lets you reorder and remove them, and can add an HLS stream by URL. An empty list means every camera on the server.

  • DashboardWidget.defaultsToAccentColor (default false) lets a widget default to the theme accent rather than a fixed color. ThemeSettingsView shows the accent as that widget's default swatch, so the two always agree.

  • NSLocalNetworkUsageDescription, because macOS asks before the app reaches cameras on the LAN.

  • No "Opens on Tap": Cameras joins WidgetLaunch.excluded, since its taps switch cameras and open them full screen.

Choices worth a look

  • HLS rather than WebRTC. go2rtc's WebRTC is sub-second, but it would need a web view per camera, and the AAC audio most cameras send can't travel over WebRTC. AVPlayer on HLS is native and hardware-decoded, and keeps the sound, at a cost of about 2 s.
  • RTSP cameras live in go2rtc. go2rtc's HLS endpoint only serves streams it already knows. Keeping RTSP URLs there also keeps camera passwords out of layout.json.
  • Touch layers (a small change outside the widget). EdgeControl's hardware touch matched a tap to the smallest zone under the finger, with no idea of anything drawn over the dashboard. A widget button under the full-screen camera could take a tap meant for its close button, and a hardware swipe paged the dashboard behind it.
    • TouchZone now has a layer (default 0), and touchTappable takes one. While any zone on a higher layer is registered, the ones beneath can't be hit.
    • The hardware swipe leaves the pages alone while anything is on a higher layer.
    • Nothing else changes for existing widgets.
  • Touch zone ids carry a per-instance id, so two Cameras widgets don't collide.

Testing

  • xcodebuild test passes in full: 432 Swift Testing tests in 46 suites and 111 XCTest tests. 45 of the tests are new, in nine suites:
    • camera sources;
    • the go2rtc API;
    • the service;
    • grid layout;
    • the live-edge policy;
    • full screen and shared players;
    • touch zone layers;
    • when timed switching starts the next camera and moves to it;
    • whether a widget is on screen, wherever it sits on the dashboard. An earlier version compared rectangles in two coordinate spaces, and a widget on the right half stopped streaming.
  • go2rtc-streams.json is synthetic, shaped like go2rtc 1.9.14's response. It includes a stream named after its source URL, password and all, to prove those are left out of the list.
  • On a XENEON EDGE (macOS 27.2), against go2rtc 1.9.14 on Home Assistant with three Wyze cameras:
    • single and grid, with Fill on;
    • tabs, and full screen with its controls, by touch;
    • a theme with corner radius 0 and widget gap 0;
    • the accent as the default color.
  • Starting the next camera early is unit-tested. Against the same go2rtc, a player with nothing on screen reaches playing in about 4.6 s, which is the spinner this hides. I haven't yet watched it switch on the Edge.

Not in this PR

MJPEG and snapshot cameras, go2rtc API logins, and an optional low-latency WebRTC mode. I'm happy to follow up if any of those are wanted.

🤖 Generated with Claude Code

masonjmiller and others added 2 commits October 6, 2026 16:51
A touchscreen beside the desk is a natural place to keep an eye on the house,
and most camera setups that would want one already run go2rtc: Frigate and
Home Assistant ship it, and it turns RTSP, ONVIF, HomeKit and the rest into
streams anything can play. The widget asks go2rtc for its camera list and plays
each camera through go2rtc's HLS endpoint with AVPlayer, so there is nothing
else to install and no third-party code.

Two layouts: one camera at a time with tabs over the picture, or all of them
in a grid where a tap enlarges one. Fill the Tile crops to the card's edges,
in the grid too; off, every picture stays whole. Tabs, names and the speaker
take the theme's corner radius, the grid takes its widget gap, and the color
follows the accent until one is picked for the widget on the Theme page. That
last part needed a small addition, defaultsToAccentColor, so the Theme page's
swatch shows what the widget actually draws.

AVPlayer is built for video on demand: left alone it buffers seconds and
drifts further behind with every hiccup. LiveStreamPlayer starts as soon as the
stream is ready, jumps back to the live edge when it lags, and rebuilds a
stalled stream with backoff. Against go2rtc's half-second segments it runs
about two seconds behind the camera, measured against the camera's own clock
overlay.

Cameras stream only while somebody can see them: not on the neighbouring
pages that stay rendered for swiping, and not while the displays sleep.

RTSP cameras are not entries of their own. go2rtc's HLS endpoint serves only
streams it already has, and keeping RTSP URLs in go2rtc keeps their passwords
out of the layout file. HLS URLs can be added directly.

Tested on a XENEON EDGE against go2rtc 1.9.14 with three Wyze cameras.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With no cameras picked, the list already says it is showing every camera on
the server, and the help under it said the same thing again in other words.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A tile is a glance; sometimes the dog needs a proper look. A tap on any
camera, in either layout, now opens it across the whole dashboard, above
every page, with controls that fade four seconds after the last touch:
close, pause and play, sound when the stream has any, a LIVE or PAUSED
badge, and arrows through the widget's other cameras. A tap anywhere else
shows or hides the controls; Esc closes. This replaces the grid's
enlarge-in-place, which full screen does better.

Opening is instant because the picture doesn't reconnect: CameraService now
keeps one LiveStreamPlayer per stream, shared by every view showing that
camera, which also means one camera on two widgets streams once. The
service claims the full-screen camera's stream before the tiles underneath
let go of it, and keeps it a second after closing while they take it back;
meanwhile the other tiles rest. Pausing holds the picture and stops the
download; playing again jumps back to live, and closing leaves the stream
live and muted as its tile had it.

EdgeControl's own touch handling had no idea of something drawn over the
dashboard: the smallest zone under a finger won, so a widget button beneath
the camera could take a tap meant for it, and a swipe paged the dashboard
behind it. Touch zones now have a layer. While any zone on a higher layer is
registered, the ones beneath can't be hit, and the hardware swipe leaves the
pages alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
masonjmiller and others added 3 commits October 9, 2026 14:08
Tabs, camera names, the speaker, and the full-screen buttons and badge are
controls floating on the picture, not boxes on the dashboard, so they're
capsules (circles, for the square buttons) even in a square theme. The
video itself still takes the card's corners.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… picture

With Switch Every set, the next camera's stream starts 8 seconds before
its turn, and the switch waits until it plays (up to 12 seconds more, then
moves on to show what's wrong). Cameras take seconds to start, a Ring live
view more than most, so before this every switch showed a spinner first.
The early stream goes through the service's shared players, so the tile
takes it over as it is. Nothing starts early while the widget is off
screen, the displays sleep, a camera is open full screen, or switching is
paused after a touch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Cameras widget decides it's off screen, and stops its cameras, when less
than half of it is on the dashboard. It compared its frame in the
dashboard's coordinates with the dashboard's bounds from
GeometryProxy.bounds(of:), which are in the widget's own coordinates, so a
widget whose left edge was right of about the middle counted as off screen
and stopped three seconds after appearing. Moving or resizing a widget
there left it blank for good.

Both rectangles are now in the widget's coordinates. Checked against
go2rtc: a widget at column 12 of a 2560-point dashboard stopped streaming
before and plays on now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant