diff --git a/js/e2ee/README.md b/js/e2ee/README.md index 78d3d39a2ac..e266b677810 100644 --- a/js/e2ee/README.md +++ b/js/e2ee/README.md @@ -45,9 +45,11 @@ video.finish(); video.close(); ``` -A subscriber resolves `credential.path(semantic)`, takes the epoch from the announced -route (or from the application's channel on a wire without route epochs), binds it with -`credential.consume(epoch)`, and wraps the broadcast in a `Broadcast.Consumer`. Its +A subscriber follows `credential.path(semantic)` with `origin.follow(path)`. It takes each +instance's epoch from the broadcast it resolved, `broadcast.epoch` (or from the application's +channel on a wire without route epochs), so the key always matches the instance it reads. It +binds the epoch with `credential.consume(epoch)` and wraps the broadcast in a +`Broadcast.Consumer`. Its `subscribe(semantic)` opens the track a decrypted catalog names, and `close()` releases the wrapped broadcast. A consuming generation cannot produce. Nothing survives a publisher instance: a restart mints a new epoch. diff --git a/js/e2ee/src/index.ts b/js/e2ee/src/index.ts index bd840c2411a..214530c4e64 100644 --- a/js/e2ee/src/index.ts +++ b/js/e2ee/src/index.ts @@ -7,9 +7,9 @@ * * A {@link Credential} is what the application distributes out of band. Each publisher instance * calls {@link Credential.produce} to mint a {@link Generation.Producer} and wraps its `@moq/net` - * broadcast in a {@link Broadcast.Producer}. Subscribers discover the epoch from the broadcast - * route, bind a {@link Generation.Consumer} with {@link Credential.consume}, and wrap the broadcast - * in a {@link Broadcast.Consumer}. Both sides name tracks by their semantic names; only the + * broadcast in a {@link Broadcast.Producer}. Subscribers follow the path, take each instance's + * epoch from the broadcast it resolved, bind a {@link Generation.Consumer} with + * {@link Credential.consume}, and wrap the broadcast in a {@link Broadcast.Consumer}. Both sides name tracks by their semantic names; only the * derived physical names reach `@moq/net`. * * ```ts diff --git a/js/wasm/README.md b/js/wasm/README.md index 0cb4a6c4686..8a4c8e46fdb 100644 --- a/js/wasm/README.md +++ b/js/wasm/README.md @@ -13,8 +13,8 @@ Moq.setup(); // install panic/tracing hooks for readable errors const session = await Moq.Session.connect("https://relay.example.com/anon"); const broadcast = await session.consume("room/alice"); -const track = await broadcast?.subscribe("video"); -for (let group = await track?.recvGroup(); group; group = await track?.recvGroup()) { +const track = await broadcast.subscribe("video"); +for (let group = await track.recvGroup(); group; group = await track.recvGroup()) { for (let frame = await group.readFrame(); frame; frame = await group.readFrame()) { // frame: Uint8Array } diff --git a/quest/m1/api-audit/resolve/README.md b/quest/m1/api-audit/resolve/README.md index c8abbf82d77..83b04f632fb 100644 --- a/quest/m1/api-audit/resolve/README.md +++ b/quest/m1/api-audit/resolve/README.md @@ -51,7 +51,7 @@ Wire: none. ## Required - [Bindings request and follow](/quest/m1/api-audit/resolve/bindings.md) - moq-ffi, the C ABI, and every wrapper mirror `request` and `follow` with an optional epoch -- [Callers resolve once](/quest/m1/api-audit/resolve/callers.md) - no caller hand-rolls synced resolution or decides table absence by wall clock +- [The carla demo pins its driver epoch](/quest/m1/api-audit/resolve/callers.md) - the demo's driver watcher requests each run pinned to its announced epoch ## Related diff --git a/quest/m1/api-audit/resolve/callers.md b/quest/m1/api-audit/resolve/callers.md index 3d686658a7f..617bd4bd4b2 100644 --- a/quest/m1/api-audit/resolve/callers.md +++ b/quest/m1/api-audit/resolve/callers.md @@ -1,27 +1,27 @@ -# [M] Callers resolve once +# [XS] The carla demo pins its driver epoch ## Goal -No caller hand-rolls synced resolution or relies on a wall clock to decide a -broadcast is absent. Each first-party caller resolves with `request` or -`follow`. +The carla demo's driver watcher resolves each driver run pinned to the epoch it +was announced under, so a lease never reads a newer run's commands. ## Plan Split from [Two broadcast resolutions](/quest/m1/api-audit/resolve/README.md) -on 2026-10-28 (maintainer). - -- Remove the hidden error in moq-wasm's resolve, which follows the path but - still discards why it failed. -- Replace moq-cli's resolve-and-drop waits before its stdout, RTMP, and WHIP - exports, which follow the path only to wait for its announcement and then - resolve it again. -- Review SRT, transcode, the benchmark connections, relay HTTP fetch - deadlines, the moq-hls server's `RESOLVE_TIMEOUT` handler-stall bound, the - e2ee epoch advice, and the demo's announce-derived epoch pin; fix each that - hand-rolls resolution or decides absence by time. - -List every caller in the PR with what it now uses. Run the affected packages' -tests and `just test interop --all`. - -Public API: none beyond the callers' own surfaces. Wire: none. +on 2026-10-28 (maintainer). Every other first-party caller now resolves once +with `request` or `follow`; see +[moq-dev/moq#7192](https://github.com/moq-dev/moq/pull/7192). + +`watch_drivers` in `demo/carla/sim/moq_carla_sim/publish.py` takes each +driver's epoch from its announcement, then `_pump_driver` requests the path +unpinned. A newer run that took over in between is read under the old run's +lease until its own announcement cancels the task. Pass the announced epoch +to the Python wrapper's `request(path, epoch)` once the bindings expose it. + +Run the demo's sim tests (`demo/carla/sim`). + +Public API: none. Wire: none. + +## Required + +- [Bindings request and follow](/quest/m1/api-audit/resolve/bindings.md) - the Python wrapper's `request` takes an epoch diff --git a/rs/moq-cli/src/main.rs b/rs/moq-cli/src/main.rs index 28e08262eca..5327c308134 100644 --- a/rs/moq-cli/src/main.rs +++ b/rs/moq-cli/src/main.rs @@ -920,16 +920,15 @@ async fn run_stdout( ) -> anyhow::Result<()> { let catalog = args.catalog_format(&name); - // Confirm the broadcast is reachable and wait for it to be announced; `Subscribe` then - // resolves it, and any sibling broadcast a rendition's `broadcast` field references - // (e.g. "./source") through the same origin. - consumer + // Wait for the broadcast to be announced; the export resolves any sibling broadcast a + // rendition's `broadcast` field references (e.g. "./source") through the same origin. + let broadcast = consumer .follow(name.as_str(), None)? .available() .await .with_context(|| format!("failed to resolve broadcast `{name}`"))?; - let subscribe = Subscribe::new(consumer, &name, catalog, args).await?; + let subscribe = Subscribe::new(moq_mux::Source::new(consumer, broadcast), catalog, args); let Some(echo) = echo else { return subscribe.run().await; }; diff --git a/rs/moq-cli/src/report/echo_test.rs b/rs/moq-cli/src/report/echo_test.rs index e1870ec1f6f..c6eb3a0a2c1 100644 --- a/rs/moq-cli/src/report/echo_test.rs +++ b/rs/moq-cli/src/report/echo_test.rs @@ -29,13 +29,8 @@ async fn export_echo_reports_where_the_import_solicits() { let mut import = ts::Import::new(broadcast, catalog.reserve()); import.decode(&CLIP[..HALF]).unwrap(); publication.announce(Default::default()).unwrap(); - origin - .consume() - .follow("demo", None) - .unwrap() - .available() - .await - .unwrap(); + let consumer = origin.consume(); + let resolved = consumer.follow("demo", None).unwrap().available().await.unwrap(); let args = SubscribeArgs { format: SubscribeFormat::Ts, @@ -48,9 +43,7 @@ async fn export_echo_reports_where_the_import_solicits() { catalog: None, select: SelectArgs::default(), }; - let subscribe = Subscribe::new(origin.consume(), "demo", CatalogFormat::Hang, args) - .await - .unwrap(); + let subscribe = Subscribe::new(moq_mux::Source::new(consumer, resolved), CatalogFormat::Hang, args); let target = EchoTarget { origin: origin.clone(), name: "alice".parse().unwrap(), diff --git a/rs/moq-cli/src/rtc.rs b/rs/moq-cli/src/rtc.rs index 80c275737a4..00812a9ae48 100644 --- a/rs/moq-cli/src/rtc.rs +++ b/rs/moq-cli/src/rtc.rs @@ -115,19 +115,20 @@ pub async fn connect_import(target: ImportTarget, url: Url, epoch: moq_net::Epoc /// WHIP client: push a broadcast from the Origin to a remote (export). pub async fn connect_export(origin: moq_net::origin::Consumer, url: Url, name: String) -> anyhow::Result<()> { - // Confirm the broadcast is reachable (and wait for it to be announced) before dialing; - // the egress re-resolves it (and any referenced sibling broadcast) through the origin. - origin + // Wait for the broadcast to be announced before dialing; the egress resolves any + // referenced sibling broadcast through the same origin. + let broadcast = origin .follow(name.as_str(), None)? .available() .await .with_context(|| format!("failed to resolve broadcast `{name}`"))?; + let source = moq_mux::Source::new(origin, broadcast); tracing::info!(url = %RedactedUrl::new(&url), %name, "WHIP client pushing"); notify_ready(); let client = moq_rtc::Client::new(moq_rtc::client::Config::default()); - client.publish(url, origin, &name).await?; + client.publish(url, source).await?; Ok(()) } diff --git a/rs/moq-cli/src/rtmp.rs b/rs/moq-cli/src/rtmp.rs index b4b0fe76d69..180d190f7b4 100644 --- a/rs/moq-cli/src/rtmp.rs +++ b/rs/moq-cli/src/rtmp.rs @@ -170,20 +170,21 @@ pub async fn connect_export( ) -> anyhow::Result<()> { let name = moq_net::Path::new(&name)?; let (addr, app, key) = parse_url(&url).await?; - // Confirm the broadcast is reachable (and wait for it to be announced) before dialing; - // the FLV export re-resolves it (and any referenced sibling broadcast) through the origin. - origin + // Wait for the broadcast to be announced before dialing; the FLV export resolves any + // referenced sibling broadcast through the same origin. + let broadcast = origin .follow(&name, None)? .available() .await .with_context(|| format!("failed to resolve broadcast `{name}`"))?; + let source = moq_mux::Source::new(origin, broadcast); // The stream key is the ingest credential, so log the dial target and app instead. tracing::info!(%addr, %app, %name, "RTMP client pushing"); notify_ready(); let client = Client::connect(addr, &app).await?.with_max_delay(max_delay); - Ok(client.publish(&key, origin, &name).await?) + Ok(client.publish(&key, source).await?) } /// Parse `rtmp://host[:1935]//` into a resolved address, app, and stream key. diff --git a/rs/moq-cli/src/subscribe.rs b/rs/moq-cli/src/subscribe.rs index 7ac908cecf8..39518500dee 100644 --- a/rs/moq-cli/src/subscribe.rs +++ b/rs/moq-cli/src/subscribe.rs @@ -1,8 +1,6 @@ use std::time::Duration; -use anyhow::Context; use hang::catalog::{AudioCodecKind, VideoCodecKind}; -use hang::moq_net; use moq_mux::catalog::{self, CatalogFormat, Stream}; use moq_mux::select; use tokio::io::AsyncWriteExt; @@ -268,26 +266,15 @@ fn log_release(release: &moq_mux::container::ts::stats::Release, message: &'stat } impl Subscribe { - /// Resolve the broadcast at `path` on `origin` to export it with the resolved settings; - /// [`run`](Self::run) drives it. - pub async fn new( - origin: moq_net::origin::Consumer, - path: &str, - catalog: CatalogFormat, - args: SubscribeArgs, - ) -> anyhow::Result { - let path = moq_net::Path::new(path)?; - let broadcast = origin - .request(&path, None) - .await - .with_context(|| format!("failed to resolve broadcast `{path}`"))?; - let source = moq_mux::Source::new(origin, broadcast); - Ok(Self { + /// Export the resolved broadcast `source` with the resolved settings; [`run`](Self::run) + /// drives it. + pub fn new(source: moq_mux::Source, catalog: CatalogFormat, args: SubscribeArgs) -> Self { + Self { source, catalog, args, sections: None, - }) + } } /// The resolved broadcast, whose [`stats`](moq_mux::Source::stats) count what the export reads. diff --git a/rs/moq-e2ee/README.md b/rs/moq-e2ee/README.md index 67274b35ea5..a127f42bb40 100644 --- a/rs/moq-e2ee/README.md +++ b/rs/moq-e2ee/README.md @@ -32,9 +32,10 @@ let video = protected.create_track("video", None)?; broadcast.announce(Route::default().with_epoch(generation.epoch().clone()))?; ``` -A subscriber discovers the broadcast at `credential.path(semantic)`, takes the epoch from the -announced `Route::epoch` (or from the application's channel on a wire older than lite-07), -binds it with `credential.consume(epoch)`, and wraps the broadcast in a +A subscriber follows `credential.path(semantic)` with `origin.follow(path, None)`. It takes +each instance's epoch from the broadcast it resolved, `broadcast.info().epoch` (or from the +application's channel on a wire older than lite-07), so the key always matches the instance +it reads. It binds the epoch with `credential.consume(epoch)` and wraps the broadcast in a `broadcast::Consumer`. Its `subscribe(semantic, subscription)` opens the track a decrypted catalog names. A consuming generation cannot produce. Nothing survives a publisher instance: a restart mints a new epoch. diff --git a/rs/moq-e2ee/src/lib.rs b/rs/moq-e2ee/src/lib.rs index d41b17f3053..0194986d3bd 100644 --- a/rs/moq-e2ee/src/lib.rs +++ b/rs/moq-e2ee/src/lib.rs @@ -7,9 +7,9 @@ //! //! A [`Credential`] is what the application distributes out of band. Each publisher //! instance calls [`Credential::produce`] to mint a [`generation::Producer`] and wraps its -//! `moq-net` broadcast in a [`broadcast::Producer`]. Subscribers discover the epoch from the -//! broadcast route, bind a [`generation::Consumer`] with [`Credential::consume`], and wrap the -//! broadcast in a [`broadcast::Consumer`]. Both sides name tracks by their semantic names; only +//! `moq-net` broadcast in a [`broadcast::Producer`]. Subscribers follow the path, take each +//! instance's epoch from the broadcast it resolved, bind a [`generation::Consumer`] with +//! [`Credential::consume`], and wrap the broadcast in a [`broadcast::Consumer`]. Both sides name tracks by their semantic names; only //! the derived physical names reach `moq-net`. //! //! A caller cannot reopen an explicit epoch for production: diff --git a/rs/moq-rtc/MIGRATE.md b/rs/moq-rtc/MIGRATE.md index 6abfe78fe47..7d719b8e64b 100644 --- a/rs/moq-rtc/MIGRATE.md +++ b/rs/moq-rtc/MIGRATE.md @@ -6,7 +6,7 @@ How to update your code for each breaking change, newest first. ### `moq_net::Path` has no lifetime -`Client::publish` and `client::whip::dial` take `impl TryInto>`, so `&str`, `String`, and `&Path` still work. `server::{whip, whep}::accept` take `impl Into`: pass a `Path`, from `moq_net::Path::new(s)?` or `moq_net::Path::from_static`. See moq-net's migration for the rest. +`server::{whip, whep}::accept` take `impl Into`: pass a `Path`, from `moq_net::Path::new(s)?` or `moq_net::Path::from_static`. See moq-net's migration for the rest. ### Client calls run the session diff --git a/rs/moq-rtc/src/client/mod.rs b/rs/moq-rtc/src/client/mod.rs index 6b8a1e735e8..52042b3691f 100644 --- a/rs/moq-rtc/src/client/mod.rs +++ b/rs/moq-rtc/src/client/mod.rs @@ -71,22 +71,14 @@ impl Client { whep::dial(self, url, broadcast).await } - /// `client publish`: pull the broadcast at `path` from `origin` and push it to a - /// remote WHIP endpoint, until the session ends. + /// `client publish`: push the broadcast `source` resolved to a remote WHIP endpoint, + /// until the session ends. /// - /// It stays on the publisher instance it resolved, and fails once that instance's - /// route dies. - /// - /// Taking the origin plus path (rather than a resolved [`moq_net::broadcast::Consumer`]) - /// lets the egress resolve a rendition whose catalog `broadcast` field references a - /// sibling broadcast, against the same origin. - pub async fn publish( - &self, - url: Url, - origin: moq_net::origin::Consumer, - path: impl TryInto>, - ) -> crate::Result<()> { - whip::dial(self, url, origin, path).await + /// It stays on that publisher instance, and fails once the instance's route dies. + /// The source's origin resolves a rendition whose catalog `broadcast` field references + /// a sibling broadcast. + pub async fn publish(&self, url: Url, source: moq_mux::Source) -> crate::Result<()> { + whip::dial(self, url, source).await } } diff --git a/rs/moq-rtc/src/client/whip.rs b/rs/moq-rtc/src/client/whip.rs index c7993fa29ad..92d61f6cd44 100644 --- a/rs/moq-rtc/src/client/whip.rs +++ b/rs/moq-rtc/src/client/whip.rs @@ -17,14 +17,8 @@ use url::Url; use crate::{Error, Result, client::Client, egress::EgressSource, session}; -pub(crate) async fn dial( - client: &Client, - url: Url, - origin: moq_net::origin::Consumer, - path: impl TryInto>, -) -> Result<()> { - let broadcast = origin.request(path, None).await?; - let source = EgressSource::new(moq_mux::Source::new(origin, broadcast)).await?; +pub(crate) async fn dial(client: &Client, url: Url, source: moq_mux::Source) -> Result<()> { + let source = EgressSource::new(source).await?; let codecs = source.catalog_codecs(); if codecs.is_empty() { return Err(Error::NoRenditions); diff --git a/rs/moq-rtc/src/lib.rs b/rs/moq-rtc/src/lib.rs index 38edebfc3ad..75d423b4a31 100644 --- a/rs/moq-rtc/src/lib.rs +++ b/rs/moq-rtc/src/lib.rs @@ -282,7 +282,9 @@ mod tests { let client = Client::new(client::Config::default()); let url = format!("http://{address}/whip/ingested").parse().expect("WHIP URL"); let source = origin.consume(); - let pushed = tokio::spawn(async move { client.publish(url, source, "source").await }); + let broadcast = source.request("source", None).await.unwrap(); + let source = moq_mux::Source::new(source, broadcast); + let pushed = tokio::spawn(async move { client.publish(url, source).await }); let ingested = ingest_origin.consume(); let ingested = ingested.follow("ingested", None).unwrap().available().await.unwrap(); let mut played = opus_output(&ingested).await; @@ -395,7 +397,12 @@ mod tests { // Each client call resolves once its session ends, so the test drives them aside. let whip_client = tokio::spawn({ let client = client.clone(); - async move { client.publish(whip, source_consumer, "source").await } + async move { + let broadcast = source_consumer.request("source", None).await?; + client + .publish(whip, moq_mux::Source::new(source_consumer, broadcast)) + .await + } }); let (whip_id, whip_task) = tokio::time::timeout(TIMEOUT, sources_rx.recv()) .await diff --git a/rs/moq-rtmp/src/dial.rs b/rs/moq-rtmp/src/dial.rs index 1ed62a77a0d..f40c94dd46f 100644 --- a/rs/moq-rtmp/src/dial.rs +++ b/rs/moq-rtmp/src/dial.rs @@ -231,17 +231,12 @@ impl Client { /// mux the broadcast to FLV, and send each tag as an RTMP audio/video message /// until the broadcast ends or the connection drops. /// - /// `path` names the broadcast to restream on `origin`; the FLV export resolves it - /// (and any sibling broadcast a rendition's catalog `broadcast` field references) - /// through the origin. This future resolves when the broadcast ends, so callers - /// usually run it on its own task. - pub async fn publish( - mut self, - stream_key: &str, - origin: origin::Consumer, - path: impl Into, - ) -> Result<()> { - let path: moq_net::Path = path.into(); + /// `source` is the resolved broadcast to restream; the FLV export resolves any sibling + /// broadcast a rendition's catalog `broadcast` field references through its origin. + /// This future resolves when the broadcast ends, so callers usually run it on its own + /// task. + pub async fn publish(mut self, stream_key: &str, source: moq_mux::Source) -> Result<()> { + let path = source.broadcast().info().path.clone(); let request = self .session .request_publishing(stream_key.to_string(), PublishRequestType::Live) @@ -257,8 +252,6 @@ impl Client { let queued = std::mem::take(&mut self.work); self.drain(queued).await?; - let broadcast = origin.request(path, None).await?; - let source = moq_mux::Source::new(origin, broadcast); let catalog = source .catalog::<()>(moq_mux::catalog::CatalogFormat::default()) .await @@ -772,6 +765,12 @@ mod tests { (broadcast, catalog, importer) } + /// Resolve `live/cam0` on `origin` to push it. + async fn exported(origin: origin::Consumer) -> moq_mux::Source { + let broadcast = origin.request("live/cam0", None).await.unwrap(); + moq_mux::Source::new(origin, broadcast) + } + /// A clean end crosses an RTMP hop in both directions: a finished export unpublishes, /// so the server it pushes to lingers, and a server whose play completes lets a pull /// linger. Each lingering side serves its finished copy for its linger. @@ -801,14 +800,11 @@ mod tests { .unwrap(), } }); - let exported = upstream.consume(); + let origin = upstream.consume(); let client = tokio::spawn(async move { let client = Client::with_stream(client_io, "live").await.unwrap(); match push { - true => client - .publish("cam0", exported, moq_net::Path::from_static("live/cam0")) - .await - .unwrap(), + true => client.publish("cam0", exported(origin).await).await.unwrap(), false => client .with_linger(linger) .pull("cam0", &pulled, moq_net::Path::from_static("live/cam0")) @@ -888,12 +884,10 @@ mod tests { }; let _ = publish.accept(&ingest, moq_net::Path::from_static("live/cam0")).await; }); - let exported = upstream.consume(); + let origin = upstream.consume(); let pushed = tokio::spawn(async move { let client = Client::with_stream(client_io, "live").await.unwrap(); - client - .publish("cam0", exported, moq_net::Path::from_static("live/cam0")) - .await + client.publish("cam0", exported(origin).await).await }); // Read what reaches the remote back out as FLV. diff --git a/rs/moq-wasm/src/lib.rs b/rs/moq-wasm/src/lib.rs index 37b5ad152ee..a80158db55e 100644 --- a/rs/moq-wasm/src/lib.rs +++ b/rs/moq-wasm/src/lib.rs @@ -154,23 +154,22 @@ impl Session { /// Subscribe to a broadcast by path, waiting until a route covers it. /// - /// Rejects with the close reason if the session closes first. - #[wasm_bindgen(unchecked_return_type = "Promise")] + /// Rejects with why it failed, such as an invalid path, or with the close reason if the + /// session closes first. + #[wasm_bindgen(unchecked_return_type = "Promise")] pub fn consume(&self, path: String) -> Promise { let session = self.inner.clone(); let consumer = self.consumer.clone(); future_to_promise(async move { - let request = pin!(async { consumer.follow(path.as_str(), None).ok()?.available().await.ok() }); + let request = pin!(async { consumer.follow(path.as_str(), None)?.available().await }); // The origin outlives the session, so its wait alone never ends on a close. let closed = pin!(session.closed()); match select(request, closed).await { - Either::Left((inner, _)) => Ok(inner.map_or(JsValue::UNDEFINED, |inner| { - Broadcast { - inner, - freed: Freed::new(), - } - .into() - })), + Either::Left((inner, _)) => Ok(Broadcast { + inner: inner.map_err(js_err)?, + freed: Freed::new(), + } + .into()), Either::Right((err, _)) => Err(js_err(err)), } }) diff --git a/test/wasm/baseline/consumer.ts b/test/wasm/baseline/consumer.ts index 4fc044df6aa..5082dc4ec1c 100644 --- a/test/wasm/baseline/consumer.ts +++ b/test/wasm/baseline/consumer.ts @@ -121,7 +121,6 @@ async function run(config: Sample) { await Promise.all( Array.from({ length: config.publishers }, async (_, publisher) => { const broadcast = await session.consume(`${config.id}/${publisher}`); - if (!broadcast) throw new Error("missing WASM broadcast"); disposers.push(() => broadcast.free()); const track = await broadcast.subscribe("data"); disposers.push(() => track.free()); diff --git a/test/wasm/src/main.ts b/test/wasm/src/main.ts index 701f01ec76c..d99e12f93a2 100644 --- a/test/wasm/src/main.ts +++ b/test/wasm/src/main.ts @@ -20,7 +20,6 @@ import * as Moq from "@moq/net"; /** The generated `@moq/wasm` module, typed from its published `.d.ts`. */ type Wasm = typeof import("@moq/wasm"); type Session = import("@moq/wasm").Session; -type Broadcast = import("@moq/wasm").Broadcast; type Track = import("@moq/wasm").Track; /** One relay the suite runs against, and the version it must negotiate. */ @@ -214,13 +213,6 @@ async function withSession(wasm: Wasm, relay: RelayFixture, body: (session: S } } -/** Wait for `path` to be announced and return the broadcast, or fail. */ -async function consume(session: Session, path: string): Promise { - const broadcast = await session.consume(path); - if (!broadcast) throw new Error(`consume(${path}) resolved without a broadcast`); - return broadcast; -} - /** * Read `count` consecutive groups off a track, asking the publisher for each next one * with `advance`, and check each against {@link FIXTURE}. @@ -307,7 +299,7 @@ const CASES: Case[] = [ const path = `wasm-test/${relay.name}`; await withPublisher(relay, path, async (advance) => { await withSession(wasm, relay, async (session) => { - const broadcast = await consume(session, path); + const broadcast = await session.consume(path); const track = await broadcast.subscribe(TRACK); try { await expectGroups(track, GROUPS_TO_READ, advance); @@ -330,7 +322,7 @@ const CASES: Case[] = [ const path = `wasm-test/${relay.name}-refuse`; await withPublisher(relay, path, async () => { await withSession(wasm, relay, async (session) => { - const broadcast = await consume(session, path); + const broadcast = await session.consume(path); let read: string; try { const track = await broadcast.subscribe("missing"); @@ -361,7 +353,7 @@ const CASES: Case[] = [ session.free(); const resolved = await pending.then( (broadcast) => { - broadcast?.free(); + broadcast.free(); return true; }, () => false, @@ -378,7 +370,7 @@ const CASES: Case[] = [ const path = `wasm-test/${relay.name}-free`; await withPublisher(relay, path, async () => { await withSession(wasm, relay, async (session) => { - const broadcast = await consume(session, path); + const broadcast = await session.consume(path); const track = await broadcast.subscribe(TRACK); const pendingTrack = broadcast.subscribe(TRACK); broadcast.free();