Repository navigation
Description
Part of #602.
Scope
After this PR, every viewer of one device on its worker shares one capture, whether it asked by the device path or a lease path. A joiner gets the current picture's description, then the next key frame. A slow viewer skips frames instead of slowing the others. The capture closes once, when its last viewer leaves or the device stops or its lease ends.
If it goes wrong: every viewer of a device breaks at once, or a capture keeps running with no viewer.
Technical spec
Commit 5e639b4.
Rows
- Behaviours: B6, B7, B8, B9, B10
- Stored state: S1
- Interfaces: I1, I2
- Existing code: X1, X2, X3, X4, X12, X14 (the stream manual's gaps, the iOS manual's "Two viewers" line, the Android screen manual's "Two viewers of one lease" gap), X15, X19
Facts
| # | Fact | Source |
|---|---|---|
| F1 | createWorkerStream tests drive the worker's mount and relay target with a fake ScreenOpener and a fake clock. |
src/stream/create.test.ts:120-157 |
| F2 | readScreenMeta is private to framing.ts today; MetaFrameScanner uses it for a capture's first meta frame. |
src/stream/framing.ts:39-50 |
Modules touched
src/stream (captures.ts, worker-link.ts, framing.ts, new broadcast.ts, their tests, AGENTS.md), src/drivers/ios/AGENTS.md, src/drivers/android/screen/AGENTS.md, website/src/content/docs/docs/using-devices/watching-the-screen.mdx. Searches: beginOnDevice, stopOnDevice, readScreenFeed, MetaFrameScanner, Each viewer is, Two viewers.
Rules in play
- ADR 0079 §1, §4 and §6: one capture per device, the joiner's start, the slow viewer's drop.
- ADR 0045 §4: a shared capture still ends when its device stops running or its lease ends, and the lease end waits for its one close.
src/stream/AGENTS.md: the caller and the device are checked before any work, so a refused viewer joins nothing; a capture is registered before it starts.- Documentation rule 9: the website's stream page changes with the behaviour.
Retired words
Each viewer is its own capture: viewers of one device share one capture.Each viewer is a separate capture: the same, on the website.
Tests
The seam is createWorkerStream through create.test.ts, with a fake ScreenOpener, as its existing cases do; I1 and I2 also get unit tests beside framing.test.ts.
- B6: viewers of one device share one capture: two device-path viewers; a device-path and a lease-path viewer; a second viewer during a pending open; a joiner after a size change; before any parameter sets; a new meta and parameter sets before its first key frame; the lease ending while it waits; a later meta frame that fails the check; MJPEG; a refused viewer joins nothing.
- B7: a stalled viewer never delays the capture or another viewer: a stall while another reads 2,000 frames; reading again; a full queue at a lease end;
aliveframes dropped; MJPEG past the bound. - B8: the capture closes once, when its last viewer leaves: the first leaves, then the second; one viewer's
expiresAt; the last viewer'sexpiresAt; every viewer leaves during the open; one leaves during the open and another stays; a new viewer after every viewer left during the open gets a fresh capture (decided in delivery, pending the maintainer). - B9: a lease end or a device stop ends every viewer as it ends one today: a lease end with three viewers;
device.shutdownwith two;device.absence-detectedon a leased device; a viewer that asks after the stop. - B10: a failed capture fails every viewer it serves the same way: a start that fails; the start bound; a mid-stream read error; the silence bound; the device stopping during a shared start; a new open after a failure, also while an errored body is unread.
Done when
pnpm test:changedpasses, with the B6 to B10 cases insrc/stream/create.test.tsand I1/I2's unit tests besidesrc/stream/framing.test.ts.src/stream/AGENTS.mdhas neither Known gap of today, and its Captures rules say one capture per device is shared by its viewers.src/drivers/ios/AGENTS.mdno longer says "Two viewers ask for two streams (One capture per lease, shared by every viewer of its screen #602)";src/drivers/android/screen/AGENTS.mdno longer has the gap "Two viewers of one lease" and has a new gap: a phone that went dark mid-stream leaves a viewer that joins with no picture.- The website's "Watching the screen" page says viewers of a device share one capture, a joiner can wait up to 5 s for its picture, a slow viewer skips frames, and a phone that went dark off its charger shows no picture to a viewer that joins.
Out of scope
- The gateway's relay: its own task.
- The 5 s key frames: the iOS and Android tasks; until they land, a joiner waits for the capture's own next key frame.
Depends on
Written by an agent.
Activity
test: viewers of one device share one capture, a joiner waits for the…
test: a stalled viewer never delays the capture or another viewer (#1602
test: the capture closes once, when its last viewer leaves (#1602)
test: a lease end or a device stop ends every viewer of the device (#…
test: a capture that fails fails every viewer it serves the same way (#…
test: a capture that fails fails every viewer it serves the same way (#…
test: the frame splitter and the broadcast keep their own bounds and …
docs(stream): viewers of a device share one capture (#1602)
refactor(stream): split the longest stream tests into scenarios (#1602)
refactor(stream): read the capture's feed once per test scenario (#1602)
docs(stream): the stream manual fits the manuals' budget (#1602)
test(stream): the splitter's frame bound is straddled by one byte (#1602
test(stream): a viewer after a stop or after every viewer left gets a…
fix(stream): a viewer after the last one left gets a fresh capture, a…
test(stream): a broadcast that never stops fails on a named assertion…
test(stream): the lease-end and device-stop cases are one helper each…
feat(stream): viewers of one device on a worker share one capture (#1614