Skip to content

feat: room events over live777 cable datachannel (dual with SSE) - #59

Merged
a-wing merged 6 commits into
mainfrom
feat/cable-events
Nov 24, 2026
Merged

a-wing merged 6 commits into
mainfrom
feat/cable-events

Conversation

@a-wing

@a-wing a-wing commented Nov 23, 2026

Copy link
Copy Markdown
Member

Summary

Adds an opt-in second transport for room events (snapshot/message/caption) over a Live777 cable (WebRTC datachannel), running dual with the existing SSE. Requires live777 ≥ 0.11.0 (cable messages API, binbat/live777#522 — merged to live777 main); with the pinned 0.10.2 image the toggle stays off and nothing changes.

  • EVENTS_CABLE env (unset/empty/0/false = off, default off) enables dual-push: every published room event is injected into a per-room {roomId}-events live777 stream via POST /api/streams/{stream}/cables/events/messages.
  • GET /room/{id} advertises eventsStream to active participants only; the WebApp WHEP-subscribes it with a pre-offer events datachannel (m=application) and receives the identical payloads/revisions as binary frames. SSE stays the fallback and is untouched when the toggle is off.
  • Backend inject: single ordered queue drained by one worker (enqueue happens under write_gate, so inject order == commit order); unknown stream → POST /api/streams/{stream} → retry once; failures warn-and-continue (event loss converges via revision + snapshots).
  • WHEP authorize branch for {roomId}-events: active participant of the room's current meeting; sessions reaped on meeting turnover via the existing media-session sweep.

Implementation

  • src/cable.rs — stream-id derive/parse, CableEvents worker (reqwest mirrors revoke_media_sessions; no json feature, body via serde_json::to_string).
  • src/store.rs — whep_events_authorization.
  • webapp/components/use/cableEvents.ts — datachannel events client (generation-guarded, 500ms reconnect, terminal on 401/403/404).
  • webapp/components/layout.vue — shared event dispatcher for both transports; transport re-evaluated on every room refetch; never both per generation.

Bugs found in live joint debugging (fixed in the third commit)

  • The vendored WHEPClient needs an absolute URL (location.origin), otherwise every view throws Invalid base URL and retries forever.
  • The cable has no retained initial snapshot like the SSE endpoint sends — resync on every channel open (first included); the presence PATCH yields a fresh snapshot over the open channel.
  • Snapshots healed missed chat messages without counting them unread — track seen message ids (re-based per snapshot) and count unseen, non-own, ts >= joinAt (second-granularity) messages as unread; live events dedupe by the same set.

Tests

  • Rust: npm run test:rust — 70 passed, incl. 7 new mock-upstream cable API tests (inject order/bodies, 404→create→retry, auth header, authorize matrix, advertise matrix, disabled-by-default).
  • WebApp: npm run lint, npm run build clean.
  • E2E live verification against live777 main (d1ef16a): tests/meeting.spec.ts + tests/chat.spec.ts + tests/media-lifecycle.spec.ts — 11/11 with EVENTS_CABLE=1 (cable) and 11/11 without (SSE). CI keeps the toggle off (playwright env passthrough) until the live777 image is bumped past 0.10.2.

Notes / follow-ups

  • compose.yml/CI live777 pin untouched (0.10.2); enabling requires ≥0.11.0 or live777 main.
  • Known boundary: live777 reaps publisher-less events streams as orphaned; the inject worker recreates on next event (404→create→retry) and clients reconnect — a WHEP subscribe in the gap gets a terminal 404. Presence heartbeat (15s) bounds it; eager stream creation at room/join time would close it if it ever surfaces.
  • Broadcast-only for now; per-user ended frames stay on SSE semantics (clients detect end/kick from the broadcast snapshot: meetingNo mismatch / own leaveAt). ?session= targeted injects are available upstream when we want stricter per-user termination.

@a-wing a-wing added this to the v0.1.0 milestone Nov 24, 2026
@a-wing a-wing added enhancement New feature or request mod::webapp In browser labels Nov 24, 2026
With EVENTS_CABLE enabled (default off), every published room event is
also injected into a per-room {roomId}-events live777 stream via the
cable messages API (POST /api/streams/{stream}/cables/events/messages),
so browsers can receive the identical payloads/revisions over a WHEP
datachannel instead of SSE. SSE is untouched and stays the fallback.

- src/cable.rs: CableEvents worker — one bounded (4096) global queue
  drained sequentially (enqueue happens under write_gate, so inject
  order == commit order); unknown stream -> create -> retry once;
  failures warn-and-continue; a full queue drops new events (loss
  converges via the full-state snapshots).
- src/proxy.rs: a WHEP subscribe to an -events stream ensures it exists
  before forwarding (live777 reaps publisher-less streams), authorized
  via the new store.whep_events_authorization (active participant of
  the room's current meeting; sessions reaped on turnover/kick with the
  existing media-session sweep).
- GET /room/{id} advertises eventsStream to active participants only.

Requires live777 with the cable messages API (binbat/live777#522).
Tests: mock-upstream coverage of inject order/payloads/auth,
create-on-404 retry, queue bound, the authorize matrix, the
advertise/omit matrix, and kick revoking the events session.
When GET /room/{id} advertises eventsStream, subscribe it over WHEP
with a pre-offer 'events' datachannel (m=application) and feed decoded
binary frames into the same dispatch as SSE (revision dedup,
message/caption/snapshot). The transport is re-evaluated on every room
refetch; both never run simultaneously for the same generation.

- The vendored WHEPClient needs an absolute URL (location.origin).
- Reconnect with exponential backoff (500ms doubling, 10s cap, reset on
  open): 401/403 are terminal, 404 is retryable (the events stream may
  be reaped or not created yet).
- Resync meeting state on every channel open, first one included: the
  cable has no retained initial snapshot like the SSE endpoint sends,
  so events fired while the channel was connecting are healed by the
  fresh snapshot the resync's presence PATCH triggers.
- Chat unread survives snapshot healing: track seen message ids
  (re-based on each snapshot) and count unseen, non-own,
  ts >= joinAt (second-granularity) messages as unread; live message
  events dedupe by the same set.
applySnapshot treats the first snapshot as the baseline (initializes
lastMuteAllAt without acting). On the cable transport the first snapshot
arrives after WHEP connect + resync — much later than the SSE endpoint's
connect-time initial snapshot — so a mute-all fired in that window was
silently absorbed as the baseline instead of muting me (caught by the
members mute-all e2e on the cable leg).

Seed lastMuteAllAt from GET /room/{id} at mount instead (the frontend
Room type gains the muteAllAt field the server already sends). Joining
an already-muted meeting still does not self-mute; only the first-join
baseline moves from first-snapshot to REST. restoreMeeting deliberately
does not re-seed, so a mute-all during a reconnect gap still applies.
The ticket-stub and EventSource-counting tests in recovery.spec.ts are
meaningless when room events ride the cable datachannel (the app never
touches those endpoints): a closed ticket connection, first-snapshot
meeting stubs, ticket 401/403/404, and the one-active-event-source
invariant. Skip them via a shared EVENTS_CABLE flag (tests/helper.ts)
that mirrors the server's unset/empty/0/false = off convention. The
transport-agnostic recovery tests keep running on both legs.
The cable messages API (binbat/live777#522) is merged but unreleased,
and no registry image tracks live777 main (image pushes happen on
version tags only):

- compose.yml builds the live777 service from the live777 git context
  pinned to commit d1ef16a (tagged liveion-main:local;
  `docker compose build live777` refreshes).
- The e2e job replaces the 0.10.2 service container with a buildx build
  of the same pin (LIVE777_REF at the top of test.yml, gha layer cache)
  started as a plain container.
- The e2e job runs twice via a transport matrix (sse, cable), so the
  datachannel events path is covered in CI; reports upload per
  transport.

Verified locally against the pinned image: full suite 54 passed + 7
skipped on the cable leg (SSE-transport specs), 61 passed on SSE.
"changes the processed camera image without restarting it" runs two
virtual-background swaps with 30s-bound enable/poll waits inside the
default 60s test timeout, so a loaded CI runner can time it out
mid-click (seen repeatedly on the e2e legs; locally green 21/21).
Matches the other heavy specs that raise their budget explicitly.
@a-wing
a-wing merged commit 5d32f97 into main Nov 24, 2026
14 checks passed
@a-wing
a-wing deleted the feat/cable-events branch November 24, 2026 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request mod::webapp In browser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant