Skip to content

Viewers of one device on a worker share one capture #1602

Closed

Description

@V3RON

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; alive frames 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's expiresAt; 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.shutdown with two; device.absence-detected on 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:changed passes, with the B6 to B10 cases in src/stream/create.test.ts and I1/I2's unit tests beside src/stream/framing.test.ts.
  • src/stream/AGENTS.md has neither Known gap of today, and its Captures rules say one capture per device is shared by its viewers.
  • src/drivers/ios/AGENTS.md no 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.md no 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

  1. added
    task:draft
    on Nov 16, 2026
  2. added
    task:ready
    and removed
    task:draft
    on Nov 16, 2026
  3. self-assigned this
    on Nov 16, 2026
  4. added a commit that references this issue on Nov 16, 2026
    41c0cb9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

task:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions