feat(media): live channels across relay instances; viewers hear when a channel goes live
With several relays sharing pins, a viewer and the publisher could land on
different instances and never meet. LiveRelayOptions.mesh: each relay
claims the channels whose publisher it holds (LivePublisherLocator,
Postgres table shade_live_publishers, heartbeat 10 s). A relay whose
viewers want a channel published elsewhere subscribes to that relay once,
with a viewer's own read token, and fans out locally, verifying every
frame against the pin (a peer or a poisoned locator row cannot forge
one). Re-following replays a backlog; frames are passed on once (seq).
Viewers follow a publisher that moves. A token that fails the in-memory
pin is checked against the shared pin before refusal, so a publisher
back with a new read token is honoured on every instance.
SHADE_MEDIA_RELAY_URL / `media serve --advertise`.
Relays now send {"type":"state","live"} when a channel goes live or quiet
after a viewer joined; handled by the TS client (browser) and Android's
LiveWatcher.
Fixed on the way:
- The relay never saw its publisher leave: Hono gives each event its own
WSContext and the close handler compared identity. Channels stayed
"live" with nobody publishing; a replaced publisher was never closed.
- FileMediaStore on an unusable directory raised an unhandled rejection
at start; now each call fails with the reason.
Verified: 5 mesh tests (follow, late join, publisher moving A→B with
dedupe, forging peer refused, new read token) + state test, each fix
mutation-checked; Postgres locator + two media services over Postgres;
CLI relays with --advertise behind a round-robin HTTP+WS balancer:
publisher on A, Chromium viewer on B, "live", 208 lines. Suites: media
93, storage-postgres 20, server 55; Kotlin 92 (1 skipped), 0 failures.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
14
CHANGELOG.md
14
CHANGELOG.md
@@ -5,7 +5,7 @@ All notable changes to Shade are documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [4.15.0] — 2026-10-19 — Media: films, video, images, audio and live streams, end to end
|
||||
## [4.15.0] — 2026-10-18 — Media: films, video, images, audio and live streams, end to end
|
||||
|
||||
New package **`@shade/media`** — see `docs/media.md`.
|
||||
|
||||
@@ -66,6 +66,12 @@ New package **`@shade/media`** — see `docs/media.md`.
|
||||
`PostgresLivePinStore`, `createSharedMediaBackend` in
|
||||
`@shade/storage-postgres`. A live pin can no longer change key, even between
|
||||
instances (`LivePinTakenError`).
|
||||
- **Live channels across relay instances.** `LiveRelayOptions.mesh` with a
|
||||
`LivePublisherLocator` (`PostgresLivePublisherLocator`;
|
||||
`SHADE_MEDIA_RELAY_URL` / `media serve --advertise`): a relay with viewers
|
||||
of a channel published elsewhere follows the relay that has the publisher,
|
||||
verifying every frame against the pin, and viewers follow a publisher that
|
||||
moves. Viewers get a `state` message when a channel goes live or quiet.
|
||||
- **Library.** `media put` records each upload and its grant in
|
||||
`$XDG_CONFIG_HOME/shade/media-library.jsonl` (0600, append-only); `media
|
||||
ls` shows names, `media link <name|id>` prints a link again. Grants now
|
||||
@@ -88,6 +94,12 @@ New package **`@shade/media`** — see `docs/media.md`.
|
||||
- A relay test raced: `flush()` means sent, not received, so a viewer could
|
||||
join mid-burst and (correctly) get an older backlog. The relay now counts
|
||||
`framesIn` in `stats()`, and the test waits on it.
|
||||
- The live relay never noticed its publisher leave: Hono hands each event its
|
||||
own `WSContext`, and the close handler compared them by identity. A channel
|
||||
stayed "live" with nobody publishing, and a replaced publisher's socket was
|
||||
never closed. They are compared by the socket underneath now.
|
||||
- `FileMediaStore` on a directory it could not use rejected at start with no
|
||||
handler (an unhandled rejection). Now every call fails with the reason.
|
||||
|
||||
- The container refused every request body over 128 MiB (Bun's default),
|
||||
which would have made every film a 413. The cap is raised only when media
|
||||
|
||||
Reference in New Issue
Block a user