A TV at another house, joined by a scan and reached over Tailscale
status: proposed #
A TV at another house, joined by a scan and reached over Tailscale
We want an Apple TV at Dad's house to be part of the station: his own profile, the same lineup, and changed from our Manager. Today that partly works already. Away from home a TV gets its settings from R2 (ADR 0001), sends edits and history through its outbox, and plays IPTV directly from the providers. What it can't do is set itself up without an invite link, which a TV can't open, or reach the server, so it gets no On Demand from the Mac mini, no relay feeds, and no status or commands.
Decisions #
- A TV joins by a scan. The TV shows a QR code ("Link this TV") with a
one-time secret and its address on the local network. A phone already in
the station scans it with the camera, which opens Rabbit Ears. You pick
the TV's profiles there: for Dad, his own profile and not a manager. The
phone gets the TV a device key from the server, and hands it over on the
local network on the remote's connection (
RemoteControl); the QR code's secret proves it's the right TV. It's the same flow for a new TV at home, and it does whatdocs/settings-sync.mdstage 3 planned ("a new Apple TV is set up from the phone"). - A TV away from home reaches the server over Tailscale, not Cloudflare
Access. Tailscale is the secure connection that carries video, so the TV
behaves like one at home: On Demand fetched by the Mac mini, the
provider VPN route and the IPTV relay (
docs/iptv-relay.md), the relay's feeds, the guide, status, errors and commands. Access stays for phones (ADR 0003 decision 9) and carries no video. - The TV is on our tailnet, tagged and fenced off.
- We install and log in at setup, by scanning Tailscale's own QR code. Dad needs no account.
- It's tagged
tag:tv, so its key doesn't expire. Untagged devices expire after 180 days by default. - The policy lets
tag:tvreach the server's port 8766 and nothing else. Only Tailscale addresses go through the tunnel, so Dad's other traffic doesn't.
- Video wants a direct connection. Tailscale's DERP fallback is fine
for settings but not for video. UDP 41641 is forwarded to the server on
our router, and
tailscale pingis part of setup. Our upload speed limits how many streams leave the house (roughly 5–8 Mbps for HD). - Tailscale is just another route. If the tunnel is down, the TV falls back to R2 for settings and to playing directly from the providers, as it does now. Its Settings says when it can't reach the station's server, so Dad can tell us.
- Commands go by the TV checking in. The server can't call into another house, so what the Manager sends a TV (reload the lineup, clear the cache, tune) waits for it. Over Tailscale the TV picks it up on its next check, every few seconds. Without Tailscale it comes from the updates Worker (decision 8).
- Updates come through TestFlight. We can't send dev builds to a TV
that isn't on the home network, so the tvOS upload goes into
app-release. - Updates for devices away from home come from a Cloudflare Worker
(agreed 2026-10-19). This applies to any device that can't reach the
server: Dad's TV without Tailscale, and phones.
- One Durable Object for the station holds the settings revision, each device's waiting commands, and the hashes of the device keys.
- The Mac mini pushes to it. On every change it sends
PUT /stationwith an admin secret: the revision, commands, and the devices (forgetting one removes its hash). These are requests going out from the house; nothing at home faces the internet. - Devices keep a WebSocket open to it while awake, with
Authorization: Bearer <device key>andsince=<rev>. The object uses the WebSocket Hibernation API, so it costs nothing while idle. APUTwakes it, and it sends the new revision and commands down every open socket. A device then fetches the sealed settings from R2, as now. - Check-ins and command acknowledgements go up the same socket, and
the Mac mini gets them in the reply to its next
PUT. That replaces most of its outbox reading. - When the house is down, the Worker still answers: devices see the server is away, and commands wait.
- A deliberate exception to Swift only (ADR 0002 decision 1): the
Worker is about 100 lines of TypeScript, deployed with
wrangler, and shares only a small JSON shape with the apps, not the Xtream code, the rules or the merge. Nothing else goes in it. - Cost: about 1,000 requests a day for three devices away from home, with check-ins counted at 20 messages to a request and messages to devices free. Duration is close to nothing. That's $0 on the free plan, or nothing beyond the $5 base on the paid plan.
- R2 polling becomes the safety net. A device that can't reach the server or the Worker reads the settings every 30 seconds for a few minutes after losing it or after queueing an edit, until the copy shows the edit taken. After that it reads every 5 minutes, then every 15 once an hour passes with nothing new. It also reads at once on coming to the front, waking from sleep or the screensaver, and opening the guide or channel list. The Mac mini reads only the outboxes of devices it hasn't heard from (directly or through the Worker) in the last minute.
Considered options #
- An Access service token for the TV: the phone gets one from the server and hands it over in the scan. It needs no VPN on the TV, but the tunnel carries no video, so the TV gets only feeds and status, and the server needs a Cloudflare API token to make the service tokens. We can add it later if a TV can't run Tailscale.
- R2 only, as today: nothing to install, but no On Demand from the Mac mini, no VPN route, and no status or commands.
- Tailscale Funnel: ruled out in ADR 0003. It puts the server on the internet with no login in front of it.
- The updates route on the home server, through the tunnel with a
bearer token (
GET /v1/updateson a listener of its own, one ingress path, no Access). It's sound, but something at home faces the internet, it needscloudflaredand path rules, and it goes quiet when the house is down. - Long-polling the Worker: a held request keeps the Durable Object awake. That's about 10,800 GB-s a day for three devices: inside the free plan's 13,000 a day, but about $28 a month on the paid plan (2.6M GB-s against 400k included, at $12.50 per million). Plain polling every 30 seconds likely keeps it awake as well.
- Workers KV for the revision: a change can take about 60 seconds to show everywhere, and the free plan allows 1,000 writes a day.
Consequences #
- IPTV connection limits: a login that allows one stream can't serve
both houses at once. A preferred login per channel (
set_preferred_login), a login for Dad's TV, or streams coming through the IPTV relay deal with it. - A provider that needs the VPN route works at Dad's only over the tunnel. Without it, the TV plays from his connection.
- It's one more device on the tailnet to keep alive. The Manager's device list shows when it was last seen, and the Tailscale admin page does too.
- Only one VPN at a time: another VPN app on that TV would fight Tailscale.
- To try first:
- that Tailscale on tvOS reconnects after sleep, a restart and a tvOS update;
- that we get a direct connection from Dad's network;
- a stream at our upload speed.
To build #
- The scan: "Link this TV" on tvOS (QR code, listening for the phone), and scanning and choosing profiles on iOS.
- The tvOS TestFlight upload in
app-release. - Tailscale as a route: the server's tailnet address in the settings, tried after the home network, and the "can't reach the server" note.
- Commands that wait for a TV to check in.
- The tailnet:
tag:tv, its policy, and UDP 41641 forwarded. - The updates Worker:
- the Durable Object, with hibernating WebSockets;
- the Mac mini's
PUTon each change; - the devices' socket (
URLSessionWebSocketTask), with check-ins and command acknowledgements going up it.
- The R2 polling schedule (decision 9), and the Mac mini skipping outboxes of devices it has heard from.
Phin Tech docs
Rabbit Ears Manager in the store →