diff --git a/js/net/src/origin.ts b/js/net/src/origin.ts index 772b34f40a4..8af6989d3a0 100644 --- a/js/net/src/origin.ts +++ b/js/net/src/origin.ts @@ -1105,7 +1105,8 @@ class OriginState { * * What a shared connection lends out. {@link Producer} implements it, so code that is * handed an origin rather than owning one should accept this type: closing the origin - * stays the owner's alone, and a borrower cannot express it. + * stays the owner's alone, and a borrower cannot express it. A borrower that only reads + * should accept just the {@link Consumer} members it needs, so `producer.consume()` fits too. * * @public */ diff --git a/js/watch/api/element.api.md b/js/watch/api/element.api.md index e3ea8a99964..3c3ed50a4ec 100644 --- a/js/watch/api/element.api.md +++ b/js/watch/api/element.api.md @@ -16,7 +16,7 @@ import { Video } from "@moq/watch"; export default class extends HTMLElement { constructor(); - attributeChangedCallback(name: "delay" | "buffer" | "url" | "name" | "follow" | "volume" | "muted" | "paused" | "visible" | "backend" | "versions" | "announced" | "catalog-format" | "captions", oldValue: string | null, newValue: string | null): void; + attributeChangedCallback(name: "delay" | "buffer" | "follow" | "announced" | "url" | "name" | "volume" | "muted" | "paused" | "visible" | "backend" | "versions" | "catalog-format" | "captions", oldValue: string | null, newValue: string | null): void; readonly audio: Audio.Decoder; get backend(): Video.Backend; set backend(value: Video.Backend); diff --git a/js/watch/api/index.api.md b/js/watch/api/index.api.md index 4e444f96155..16172b792d3 100644 --- a/js/watch/api/index.api.md +++ b/js/watch/api/index.api.md @@ -107,7 +107,7 @@ export type BroadcastInput = { enabled: Signals.Getter; follow: Signals.Getter; name: Signals.Getter; - origin: Signals.Getter; + origin: Signals.Getter | undefined>; }; export type BroadcastOutput = { @@ -161,7 +161,7 @@ export type PlayerInput = { enabled: Signals.Getter; follow: Signals.Getter; name: Signals.Getter; - origin: Signals.Getter; + origin: BroadcastInput["origin"]; paused: Signals.Getter; probe: Signals.Getter; text: { diff --git a/js/watch/src/broadcast.test.ts b/js/watch/src/broadcast.test.ts index d2792e8d3d4..6401527af72 100644 --- a/js/watch/src/broadcast.test.ts +++ b/js/watch/src/broadcast.test.ts @@ -27,7 +27,7 @@ function origin(paths: string[]): Origin.Producer { function broadcast(name: string, paths: string[] = [name]): { source: Broadcast; owner: Origin.Producer } { const owner = origin(paths); const source = new Broadcast({ - origin: owner, + origin: owner.consume(), name: Path.from(name), enabled: true, follow: false, diff --git a/js/watch/src/broadcast.ts b/js/watch/src/broadcast.ts index af29ac561be..eba038b74d0 100644 --- a/js/watch/src/broadcast.ts +++ b/js/watch/src/broadcast.ts @@ -46,7 +46,7 @@ function provesOther(active: Moq.Broadcast.Consumer | undefined, epoch: Moq.Epoc // Whether an announced route covers `path`, until closed. Hidden routes count: a service claim // under a `.`-named prefix is kept out of listings, but it still covers the renditions it would // produce, and this is never shown to anyone. -function watchCovered(origin: Moq.Origin.Table, path: Moq.Path.Valid): { covered: Getter; close: () => void } { +function watchCovered(origin: Origin, path: Moq.Path.Valid): { covered: Getter; close: () => void } { const announced = origin.announced(Path.Pattern.literal(path), { hidden: true, covering: true }); const covered = new Signal(false); const active = new Set(); @@ -101,9 +101,9 @@ export type CatalogFormat = (typeof CATALOG_FORMATS)[number]; * another component whose output is wired in) does the writing. */ export type BroadcastInput = { - // The origin to consume from. Independent of any connection: whichever sessions feed + // The read-side origin to borrow. Independent of any connection: whichever sessions feed // the origin resolve the broadcast, and the handle spans their reconnects. - origin: Getter; + origin: Getter | undefined>; // Whether to start downloading the broadcast. Defaults to true. enabled: Getter; @@ -127,6 +127,8 @@ export type BroadcastInput = { catalog: Getter; }; +type Origin = NonNullable>; + /** Signals the component derives. */ export type BroadcastOutput = { // "error" means the origin refused the broadcast; `error` says why. @@ -164,13 +166,13 @@ export class Broadcast { // its relay about the broadcasts a catalog actually references. readonly #watches = new Map< Moq.Path.Valid, - { origin: Moq.Origin.Table; covered: Getter; close: () => void; users: number } + { origin: Origin; covered: Getter; close: () => void; users: number } >(); // Requests are shared by callers; each owns its restart watch in the origin. readonly #references = new Map< Moq.Path.Valid, - { origin: Moq.Origin.Table; follow: boolean; request: Moq.Origin.Requesting; users: number } + { origin: Origin; follow: boolean; request: Moq.Origin.Requesting; users: number } >(); // The catalog as published, before renditions this consumer cannot use are dropped. Kept @@ -226,7 +228,7 @@ export class Broadcast { // gets selected: its service claims a covering prefix, and nothing announces the exact path // until this subscribes. Watches exactly `path`, shared by every caller asking about it. // The blind cases (announcement gate off, no discovery) never reach here; see `#relativeTarget`. - #isPathAnnounced(effect: Effect, origin: Moq.Origin.Table, path: Moq.Path.Valid): boolean { + #isPathAnnounced(effect: Effect, origin: Origin, path: Moq.Path.Valid): boolean { let entry = this.#watches.get(path); if (!entry || entry.origin !== origin) { entry?.close(); @@ -249,11 +251,7 @@ export class Broadcast { } // Share one origin request across callers reading the same referenced broadcast. - #requestBroadcast( - effect: Effect, - origin: Moq.Origin.Table, - path: Moq.Path.Valid, - ): Moq.Broadcast.Consumer | undefined { + #requestBroadcast(effect: Effect, origin: Origin, path: Moq.Path.Valid): Moq.Broadcast.Consumer | undefined { const follow = effect.get(this.in.follow); let entry = this.#references.get(path); if (!entry || entry.origin !== origin || entry.follow !== follow) { diff --git a/js/watch/src/player.test.ts b/js/watch/src/player.test.ts index 4e593d23a01..d4f131d6a78 100644 --- a/js/watch/src/player.test.ts +++ b/js/watch/src/player.test.ts @@ -1,4 +1,5 @@ import { expect, mock, test } from "bun:test"; +import { Origin, Path } from "@moq/net"; import { Signal } from "@moq/signals"; // Bun does not run Vite's worklet loader; these tests never create an AudioContext. @@ -15,6 +16,41 @@ test("Player refuses the renamed reload and announced inputs", () => { expect(() => new Player({ announced: true } as never)).toThrow("`announced` was renamed to `follow`"); }); +test.each(["table", "consumer", "structural"] as const)("Player borrows a %s origin", async (role) => { + const producer = new Origin.Producer(); + const consumer = producer.consume(); + const table: Origin.Table = producer; + const origins = { + table, + consumer, + structural: { + closed: consumer.closed, + discovery: consumer.discovery, + request: consumer.request.bind(consumer), + follow: consumer.follow.bind(consumer), + announced: consumer.announced.bind(consumer), + }, + }; + const name = Path.from("live.hang"); + const player = new Player({ origin: origins[role], name, catalogFormat: "manual", catalog: {} }); + try { + const active = player.broadcast.out.active.changed(); + const publication = producer.createBroadcast(name); + publication.announce(); + expect((await active)?.path).toBe(name); + expect(player.in.origin.peek()).toBe(origins[role]); + expect(player.broadcast.in.origin.peek()).toBe(origins[role]); + + player.close(); + await flush(); + expect(producer.closed.peek()).toBeUndefined(); + expect(publication.broadcast.closed.peek()).toBeUndefined(); + } finally { + player.close(); + producer.close(); + } +}); + test("Player owns the shared pipeline and feeds output policy into decoders", async () => { const enabled = new Signal(true); const paused = new Signal(false); diff --git a/js/watch/src/player.ts b/js/watch/src/player.ts index b31ac65fb28..245837bba15 100644 --- a/js/watch/src/player.ts +++ b/js/watch/src/player.ts @@ -4,15 +4,15 @@ import type * as Moq from "@moq/net"; import { Path } from "@moq/net"; import { Effect, type Getter, getter, type Inputs, type Readonlys, Signal } from "@moq/signals"; import * as Audio from "./audio"; -import { Broadcast, type CatalogFormat } from "./broadcast"; +import { Broadcast, type BroadcastInput, type CatalogFormat } from "./broadcast"; import { type Delay, Sync } from "./sync"; import * as Text from "./text"; import * as Video from "./video"; /** Inputs for a complete broadcast playback pipeline. */ export type PlayerInput = { - /** Origin that supplies the broadcast. */ - origin: Getter; + /** Read-side origin that supplies the broadcast, borrowed without its lifecycle. */ + origin: BroadcastInput["origin"]; /** Broadcast path relative to the origin. */ name: Getter; /** Whether the pipeline may subscribe. */ diff --git a/quest/m1/api-audit/resolve/README.md b/quest/m1/api-audit/resolve/README.md index 87d53d5d5e1..a4f8fcf08ce 100644 --- a/quest/m1/api-audit/resolve/README.md +++ b/quest/m1/api-audit/resolve/README.md @@ -56,7 +56,6 @@ Wire: none. ## Required -- [The player takes any read-side origin](/quest/m1/api-audit/resolve/watch-origin.md) - `@moq/watch`'s `Player` and `Broadcast` accept a read-only `Origin.Consumer` as well as a `Table` - [JS follow returns a Following](/quest/m1/api-audit/resolve/js-following.md) - `follow` and `request` get their own JS types, matching Rust and the bindings - [JS follow takes FollowOptions](/quest/m1/api-audit/resolve/follow-options.md) - `follow` and `request` get their own JS options types diff --git a/quest/m1/api-audit/resolve/watch-origin.md b/quest/m1/api-audit/resolve/watch-origin.md deleted file mode 100644 index 553aaa0e2f9..00000000000 --- a/quest/m1/api-audit/resolve/watch-origin.md +++ /dev/null @@ -1,22 +0,0 @@ -# [S] The player takes any read-side origin - -## Goal - -`@moq/watch`'s `Player` and `Broadcast` accept a read-only `Origin.Consumer` -as well as an `Origin.Table`, so `new Player({ origin: producer.consume() })` -type-checks. - -## Plan - -Decided 2026-10-27 (maintainer): both take a structural read-side origin type -(`closed`, `discovery`, `request`, `follow`, `announced`), not -`Origin.Table`. Today the call above fails to type-check because `Table` also -requires `createBroadcast` and `requests`. Retype every `Moq.Origin.Table` -input in `js/watch/src/player.ts` and `broadcast.ts`. Do not add an adapter -or a parallel player class. - -The `request(path, { announced })` calls already map onto `follow` and -`request` ([moq-dev/moq#7173](https://github.com/moq-dev/moq/pull/7173)). - -Public API: widens `@moq/watch`'s accepted input; not breaking. -Wire: none. diff --git a/quest/m1/api-audit/route/handle.md b/quest/m1/api-audit/route/handle.md index c29ab9ad2cb..b43378746ba 100644 --- a/quest/m1/api-audit/route/handle.md +++ b/quest/m1/api-audit/route/handle.md @@ -113,5 +113,4 @@ wrappers. Wire: none. ## Related -- [The player takes any read-side origin](/quest/m1/api-audit/resolve/watch-origin.md) - also retypes JS `Table` - No constructible internal handles - the same JS hygiene rule