@moq/net 0.4.2 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"publisher.js","sourceRoot":"","sources":["../../src/lite/publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEvE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/E,OAAO,EAAE,IAAI,EAAwB,WAAW,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG/D,OAAO,EAA4B,MAAM,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAwC,MAAM,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,UAAU,EAAwB,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxG,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EACN,uBAAuB,EACvB,iBAAiB,EAEjB,YAAY,EACZ,WAAW,EACX,cAAc,EACd,eAAe,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAA8B,MAAM,YAAY,CAAC;AACvF,OAAO,EACN,aAAa,EACb,aAAa,EACb,YAAY,EACZ,W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ED,KAAK;QACJ,iFAAiF;QACjF,4EAA4E;QAE5E,qEAAqE;QACrE,IAAI,CAAC,eAAe,EAAE,WAAW,EAAE,CAAC;QACpC,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;IAClC,CAAC;CACD","sourcesContent":["import { type Dispose, type Getter, race, Signal } from \"@moq/signals\";\nimport type * as broadcast from \"../broadcast.ts\";\nimport { error, NotFound, reason, StreamCode, StreamError } from \"../error.ts\";\nimport type * as group from \"../group.ts\";\nimport { Cost, type Hop, type Route, routesEqual } from \"../hop.ts\";\nimport { hiddenBelow, hooks, presented } from \"../internal.ts\";\nimport type { Consumer as OriginConsumer } from \"../origin.ts\";\nimport type * as Path from \"../path.ts\";\nimport { type Reader, type Stream, Writer } from \"../stream.ts\";\nimport { Milli, Timescale } from \"../time.ts\";\nimport type * as track from \"../track.ts\";\nimport { type Advertised, type Advertisements, wireOf } from \"../wire.ts\";\nimport { AnnounceInit, AnnounceOk, type AnnounceRequest, encodeAnnounceBroadcast } from \"./announce.ts\";\nimport { Datagram as DatagramMessage } from \"./datagram.ts\";\nimport * as DatagramStream from \"./datagram_stream.ts\";\nimport type { Fetch } from \"./fetch.ts\";\nimport { Group as GroupMessage } from \"./group.ts\";\nimport { Priority, sendOrder } from \"./priority.ts\";\nimport { Probe } from \"./probe.ts\";\nimport {\n\tencodeSubscribeResponse,\n\texclusiveGroupEnd,\n\ttype Subscribe,\n\tSubscribeEnd,\n\tSubscribeOk,\n\tSubscribeStart,\n\tSubscribeUpdate,\n} from \"./subscribe.ts\";\nimport { TrackInfo as TrackInfoMessage, type Track as TrackMessage } from \"./track.ts\";\nimport {\n\thasAnnounceId,\n\thasAnnounceOk,\n\thasDatagrams,\n\thasProbeRtt,\n\thasRouteCost,\n\thasStreamCount,\n\tresolvesStart,\n\tVersion,\n} from \"./version.ts\";\n\nconst PROBE_INTERVAL = 100; // ms\nconst PROBE_MAX_AGE = 10_000; // ms\nconst PROBE_MAX_DELTA = 0.25;\nconst PROBE_RTT_DELTA = 0.25;\n\n/** Map a signed delta to an unsigned zigzag varint value (mirrors Rust `VarInt::from_zigzag`). */\nfunction zigzag(delta: bigint): bigint {\n\treturn delta >= 0n ? delta << 1n : (-delta << 1n) - 1n;\n}\n\n/** What {@link Publisher.openGroup} and {@link Publisher.serveGroup} need to serve one group. */\ninterface RunGroup {\n\t/** The subscription ID. */\n\tsub: bigint;\n\n\t/** The group to serve. */\n\tgroup: group.Consumer;\n\n\t/** The track's advertised timescale, applied to every frame timestamp. */\n\ttimescale: Timescale;\n\n\t/** The subscription's ranking, which this stream joins for as long as it runs. */\n\tpriority: Priority;\n\n\t/** Settles when the subscriber leaves, dropping a group still queued for a stream slot. */\n\tunsubscribed: Promise<void>;\n\n\t/** First frame to send; anything below it was excluded by the subscription. */\n\tstart: number;\n\n\t/** Last frame to send (inclusive), or undefined for the rest of the group. */\n\tend?: number;\n}\n\n// The TRACK stream, implicit SUBSCRIBE acceptance, and SUBSCRIBE_START/END are\n// all lite-05+.\nfunction supportsTrackStream(version: Version): boolean {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/**\n * The frame bounds a subscription placed on its start and end group, as they stand\n * after any SUBSCRIBE_UPDATE.\n *\n * Only the two named groups are qualified; the group range itself lives on the\n * subscriber's read cursor (see {@link frameRange}).\n */\ntype FrameBounds = {\n\t/** The group {@link startFrame} qualifies, if the subscription named one. */\n\tstartGroup?: number;\n\t/** First frame to send within {@link startGroup}; every other group starts at 0. */\n\tstartFrame: number;\n\t/** The group {@link endFrame} qualifies, if the subscription named one. */\n\tendGroup?: number;\n\t/** Last frame (inclusive) to send within {@link endGroup}; every other group runs to its end. */\n\tendFrame?: number;\n};\n\n/**\n * The frames of `sequence` a subscription asked for, as a start index and an inclusive end.\n *\n * The frame bounds qualify the start and end group only; every other group is served whole.\n * Which groups are served at all is the subscriber's read cursor (`replaceGroups`),\n * applied when a group is popped rather than re-checked here.\n *\n * The serving loop calls this synchronously after the pop, before any SUBSCRIBE_UPDATE can\n * change `bounds`. Nothing downstream trims the frame range: it is a wire request,\n * deliberately decoupled from the receiver's local read cursor.\n */\nfunction frameRange(bounds: FrameBounds, sequence: number): { start: number; end?: number } {\n\treturn {\n\t\tstart: bounds.startGroup === sequence ? bounds.startFrame : 0,\n\t\tend: bounds.endGroup === sequence ? bounds.endFrame : undefined,\n\t};\n}\n\n/** What serving one group needs beyond the group itself. */\ntype ServeGroup = {\n\t/** The Subscribe ID the GROUP message references. */\n\tsub: bigint;\n\t/** The track's advertised timescale, which every frame timestamp is converted to. */\n\ttimescale: Timescale;\n\t/** First frame to send; anything below it was excluded by the subscription. */\n\tstart: number;\n\t/** Last frame to send (inclusive), or undefined for the rest of the group. */\n\tend?: number;\n};\n\n/** What serving fetched frames needs beyond the group and destination stream. */\ntype ServeFetch = Omit<ServeGroup, \"sub\">;\n\n/** What the serving loop takes from the subscribe stream instead of serving a group. */\ntype Control =\n\t/** The peer re-stated the subscription: priority, ordering, latency, and both ranges. */\n\t| { kind: \"update\"; update: SubscribeUpdate }\n\t/** The peer FIN'd, or our own half went away. Either way there is nobody left to serve. */\n\t| { kind: \"done\" }\n\t/** The stream failed; the subscription goes down with it. */\n\t| { kind: \"error\"; error: Error };\n\ntype SubscriptionControlOptions = {\n\treader: Reader;\n\twriter: Writer;\n\tversion: Version;\n\tapply: (update: SubscribeUpdate) => void;\n};\n\n/**\n * The subscribe stream's control half, decoded ahead of the serving loop.\n *\n * Decoding runs on its own and publishes each full subscription update immediately, so a\n * blocked response write cannot delay re-ranking streams already in flight. It separately\n * stores only the latest range state for the serving loop, which owns the local track cursor\n * and frame bounds. That keeps a group pop and its frame-range snapshot one indivisible step.\n *\n * Reading ahead makes control-first ordering hold for a burst. Coalescing bounds memory while\n * preserving the newest state decoded before the next group pop. The Rust publisher gets the\n * same ordering from `poll_decode_maybe`, which decodes straight out of the reader's buffer;\n * nothing here can decode synchronously, so it reads ahead instead.\n */\nclass SubscriptionControls {\n\t#writer: Writer;\n\t#update?: SubscribeUpdate;\n\t// Sticky, first one wins: null once the stream is over, an Error once it failed.\n\t#end?: Error | null;\n\t#ended: Promise<Error | null>;\n\t#resolveEnd!: (end: Error | null) => void;\n\t#changed = new Signal(0);\n\n\t/** Settles once decoding stops, so teardown can wait for it rather than leaving it running. */\n\treadonly decoding: Promise<void>;\n\n\tconstructor({ reader, writer, version, apply }: SubscriptionControlOptions) {\n\t\tthis.#writer = writer;\n\t\tthis.#ended = new Promise((resolve) => {\n\t\t\tthis.#resolveEnd = resolve;\n\t\t});\n\t\tthis.decoding = this.#decode(reader, version, apply);\n\t\t// Our own half going away ends the loop too, and has to reach it the same way: the\n\t\t// loop looks at nothing else.\n\t\tvoid writer.closed.then(\n\t\t\t() => this.#finish(null),\n\t\t\t(err: unknown) => this.#finish(error(err)),\n\t\t);\n\t}\n\n\t/** The next control to apply, or undefined while the peer is quiet. */\n\ttake(): Control | undefined {\n\t\tconst update = this.#update;\n\t\tthis.#update = undefined;\n\t\t// An update decoded before the stream ended still applies before the sticky end.\n\t\tif (update) return { kind: \"update\", update };\n\t\tif (this.#end === undefined) return undefined;\n\t\treturn this.#end === null ? { kind: \"done\" } : { kind: \"error\", error: this.#end };\n\t}\n\n\t/** Calls `fn` once {@link take} may answer differently. */\n\tchanged(fn: () => void): Dispose {\n\t\treturn this.#changed.changed(fn);\n\t}\n\n\t/** Returns false when peer departure supersedes a blocked response write. */\n\tasync response(pending: Promise<void>): Promise<boolean> {\n\t\t// `#ended` lives as long as the stream, so it is raced as-is rather than mapped per call.\n\t\tconst result = await race([\n\t\t\tpending.then(\n\t\t\t\t() => ({ kind: \"sent\" }) as const,\n\t\t\t\t(err: unknown) => ({ kind: \"error\", error: error(err) }) as const,\n\t\t\t),\n\t\t\tthis.#ended,\n\t\t]);\n\n\t\tif (result !== null && !(result instanceof Error)) {\n\t\t\tif (result.kind === \"sent\") return true;\n\t\t\tthrow result.error;\n\t\t}\n\n\t\t// The race leaves the blocked encode running, so reset the writable half too.\n\t\tthis.#writer.reset(result ?? new StreamError(StreamCode.Cancel, { message: \"cancel\" }));\n\t\tif (result) throw result;\n\t\treturn false;\n\t}\n\n\t/** Settles once the stream is over: `null` when it ended cleanly, or the failure. */\n\tget ended(): Promise<Error | null> {\n\t\treturn this.#ended;\n\t}\n\n\t#finish(end: Error | null) {\n\t\tif (this.#end !== undefined) return;\n\t\tthis.#end = end;\n\t\tthis.#resolveEnd(end);\n\t\tthis.#changed.update((value) => value + 1);\n\t}\n\n\tasync #decode(reader: Reader, version: Version, apply: (update: SubscribeUpdate) => void) {\n\t\ttry {\n\t\t\twhile (this.#end === undefined) {\n\t\t\t\tconst update = await SubscribeUpdate.decodeMaybe(reader, version);\n\t\t\t\tif (!update) break;\n\t\t\t\tapply(update);\n\t\t\t\tthis.#update = update;\n\t\t\t\tthis.#changed.update((value) => value + 1);\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tthis.#finish(error(err));\n\t\t\treturn;\n\t\t}\n\t\tthis.#finish(null);\n\t}\n}\n\n// A microtask is too short: decoding one framed update crosses several awaits, each of which\n// can requeue behind the serving continuation. A task boundary lets the decoder finish whatever\n// the transport already delivered before the next group pop. Updates are rare, so groups do not\n// pay this scheduling cost on the normal path.\nconst yieldToControls = () => new Promise<void>((resolve) => setTimeout(resolve, 0));\n\n// Register both readiness sources in the same turn after the caller observed neither ready.\n// The winner disposes both registrations, so an idle subscription accumulates nothing no\n// matter how many times it wakes.\nfunction waitForSubscription(controls: SubscriptionControls, subscriber: track.Subscriber): Promise<void> {\n\treturn new Promise((resolve) => {\n\t\tlet settled = false;\n\t\tconst dispose: Dispose[] = [];\n\t\tconst wake = () => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tfor (const close of dispose) close();\n\t\t\tresolve();\n\t\t};\n\t\tdispose.push(controls.changed(wake), hooks.groupChanged(subscriber, wake));\n\t});\n}\n\n/**\n * The budget to serve a peer with, given what its wire could tell us.\n *\n * A version without the field decodes as `0`, which is indistinguishable from a peer\n * genuinely asking for the live edge. Serving that as real time would discard backlog\n * a legacy subscriber never declined, so fall back to a window wide enough not to drop\n * and leave enforcement to the receiver, as the IETF path does for the same reason.\n */\nfunction servingMaxAge(version: Version, requested: number | undefined): number {\n\treturn carriesMaxAge(version) ? (requested ?? 0) : Number.MAX_SAFE_INTEGER;\n}\n\n/** Whether this version's SUBSCRIBE carries Subscriber Max Age at all. */\nfunction carriesMaxAge(version: Version): boolean {\n\treturn version !== Version.DRAFT_01 && version !== Version.DRAFT_02;\n}\n\n/**\n * Position a subscription's read cursor for the wire serving it.\n *\n * On lite-06 there is nothing to do: the cursor is floored at the group the subscription\n * named (or 0), and its Max Age decides what above the floor is worth delivering.\n *\n * Pre-06 wires are the exception: their drafts define an absent `Group Start` as the\n * latest group, so say so explicitly rather than letting the budget reach back. Lite-03/04/05\n * carry a Max Age, but there it is a staleness tolerance only; lite-01/02 additionally get\n * an unbounded budget so nothing is dropped under them (see {@link servingMaxAge}), which\n * must not read as a request to replay the whole cache on join.\n */\nfunction positionCursor(track: track.Subscriber, version: Version, startGroup: number | undefined) {\n\tif (resolvesStart(version) || startGroup !== undefined) return;\n\n\tconst latest = track.latest();\n\tif (latest !== undefined) hooks.replaceGroups(track, { start: { included: latest } });\n}\n\n/**\n * Handles publishing broadcasts and managing their lifecycle.\n *\n * @internal\n */\nexport class Publisher {\n\t// The version of the connection.\n\treadonly version: Version;\n\n\t// Per-connection origin appended to outbound Announce hops, so the peer\n\t// can detect loops and prefer shorter paths. Created by Connection and\n\t// shared with Subscriber, which can optionally use it to filter out its\n\t// own announcements.\n\treadonly hop: Hop;\n\n\t#quic: WebTransport;\n\n\t// The one writer for the outbound datagram stream (getWriter locks it), acquired once at\n\t// construction when this version + transport carry datagrams, released in close(). Its\n\t// presence is the gate: undefined means datagrams aren't served on this connection. All\n\t// subscriptions share it, since a second getWriter on the same stream would throw.\n\t#datagramWriter?: WritableStreamDefaultWriter<Uint8Array>;\n\n\t// Originated advertisements this session forwards.\n\t#advertised: Getter<Advertisements | undefined>;\n\n\t#publish?: OriginConsumer;\n\n\t// TRACK_INFO is immutable per track, so resolve it from the application once\n\t// (via a throwaway subscribe whose info() resolves when the app calls accept)\n\t// and reuse it for every later TRACK request of the same track. Keyed by the\n\t// routing front rather than the path: immutability holds for one broadcast, and a\n\t// republish puts a different one on the path, so its entries must not be reused.\n\t// A rejected lookup is evicted so a retry can re-probe.\n\t#trackInfo = new WeakMap<broadcast.Consumer, Map<string, Promise<TrackInfoMessage>>>();\n\n\t/**\n\t * Creates a new Publisher instance.\n\t * @param quic - The WebTransport session to use\n\t * @param version - Negotiated protocol version\n\t * @param origin - Hop id shared with the Subscriber\n\t * @param publish - The origin whose broadcasts this session serves; omit to publish nothing\n\t *\n\t * @internal\n\t */\n\tconstructor(quic: WebTransport, version: Version, hop: Hop, publish?: OriginConsumer) {\n\t\tthis.#quic = quic;\n\t\tthis.version = version;\n\t\tthis.hop = hop;\n\t\tconst origin = publish && wireOf(publish);\n\t\tthis.#advertised = origin?.advertised ?? new Signal(new Map());\n\t\tthis.#publish = publish;\n\n\t\t// Grab the datagram writer up front when the transport carries datagrams (no group\n\t\t// fallback, so it stays undefined otherwise). One writer for all subscriptions.\n\t\tif (hasDatagrams(version)) {\n\t\t\tthis.#datagramWriter = DatagramStream.datagramWriter(quic);\n\t\t}\n\t}\n\n\t/**\n\t * Handles an announce interest message.\n\t * @param msg - The announce interest message\n\t * @param stream - The stream to write announcements to\n\t *\n\t * @internal\n\t */\n\tasync runAnnounce(msg: AnnounceRequest, stream: Stream) {\n\t\tconsole.debug(`announce: prefix=${msg.prefix}`);\n\n\t\t// Keyed by suffix, valued by identity plus route, so a republish diffs as\n\t\t// ended-then-active and a re-price as a restart.\n\t\tlet active = new Map<Path.Valid, Advertised>();\n\n\t\t// Lite06+: announce ids. Every active we send implicitly assigns the next\n\t\t// per-stream ordinal; ended/restart reference the id instead of repeating the path.\n\t\tlet nextAnnounceId = 0n;\n\t\tconst announceIds = new Map<Path.Valid, bigint>();\n\n\t\tconst wireHops = (route: Route): Hop[] => {\n\t\t\tif (hasAnnounceOk(this.version)) return route.hops;\n\t\t\treturn [...route.hops, this.hop];\n\t\t};\n\n\t\t// What the peer decodes for a route: pre-lite-06 wires carry no cost, so a re-price\n\t\t// there must not restart.\n\t\tconst onWire = (route: Route): Route => (hasRouteCost(this.version) ? route : { ...route, cost: Cost.zero });\n\n\t\tconst announce = async (suffix: Path.Valid, route: Route) => {\n\t\t\tconsole.debug(`announce: broadcast=${suffix} active=true`);\n\t\t\tif (hasAnnounceId(this.version)) announceIds.set(suffix, nextAnnounceId++);\n\t\t\tawait encodeAnnounceBroadcast(\n\t\t\t\tstream.writer,\n\t\t\t\t{ status: \"active\", suffix, hops: wireHops(route), cost: route.cost },\n\t\t\t\tthis.version,\n\t\t\t);\n\t\t};\n\n\t\tconst restart = async (suffix: Path.Valid, route: Route) => {\n\t\t\tif (!hasAnnounceId(this.version)) {\n\t\t\t\tawait retract(suffix);\n\t\t\t\tawait announce(suffix, route);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst id = announceIds.get(suffix);\n\t\t\tif (id === undefined) {\n\t\t\t\tawait announce(suffix, route);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconsole.debug(`announce: broadcast=${suffix} restart=true`);\n\t\t\tawait encodeAnnounceBroadcast(\n\t\t\t\tstream.writer,\n\t\t\t\t{ status: \"restart\", id, hops: wireHops(route), cost: route.cost },\n\t\t\t\tthis.version,\n\t\t\t);\n\t\t};\n\n\t\t// Lite06+ retracts by announce id; older versions repeat the path (ended announces\n\t\t// don't need hops).\n\t\tconst retract = async (suffix: Path.Valid) => {\n\t\t\tconsole.debug(`announce: broadcast=${suffix} active=false`);\n\t\t\tif (!hasAnnounceId(this.version)) {\n\t\t\t\tawait encodeAnnounceBroadcast(stream.writer, { status: \"ended\", suffix }, this.version);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst id = announceIds.get(suffix);\n\t\t\tannounceIds.delete(suffix);\n\t\t\tif (id === undefined) return; // never announced\n\t\t\tawait encodeAnnounceBroadcast(stream.writer, { status: \"endedId\", id }, this.version);\n\t\t};\n\n\t\t// Subscribe BEFORE writing anything: every encode below awaits the wire, and a publish\n\t\t// landing in that window only notifies the listeners already registered. One created\n\t\t// afterwards would sleep through it, leaving the change unannounced until something\n\t\t// unrelated moved.\n\t\t// TODO Make a better helper within Signals.\n\t\tlet dispose!: Dispose;\n\t\tlet changed = new Promise<Advertisements | undefined>((resolve) => {\n\t\t\tdispose = this.#advertised.changed(resolve);\n\t\t});\n\n\t\t// A hidden route stays off the wire unless the request opted in.\n\t\tconst carries = (covered: Path.Valid) => msg.hidden || !hiddenBelow(msg.prefix, covered);\n\n\t\ttry {\n\t\t\tconst initial = this.#advertised.peek();\n\t\t\tif (!initial) return; // closed\n\n\t\t\tfor (const [name, snap] of presented(msg.prefix, initial, carries)) {\n\t\t\t\tactive.set(name, snap);\n\t\t\t}\n\n\t\t\tswitch (this.version) {\n\t\t\t\tcase Version.DRAFT_01:\n\t\t\t\tcase Version.DRAFT_02: {\n\t\t\t\t\tfor (const suffix of active.keys()) {\n\t\t\t\t\t\tconsole.debug(`announce: broadcast=${suffix} active=true`);\n\t\t\t\t\t}\n\t\t\t\t\tconst init = new AnnounceInit([...active.keys()]);\n\t\t\t\t\tawait init.encode(stream.writer, this.version);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tif (!hasAnnounceOk(this.version)) {\n\t\t\t\t\t\tfor (const [suffix, snap] of active) {\n\t\t\t\t\t\t\tawait announce(suffix, snap.route);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst ok = new AnnounceOk(this.hop, active.size);\n\t\t\t\t\tawait ok.encode(stream.writer, this.version);\n\t\t\t\t\tfor (const [suffix, snap] of active) {\n\t\t\t\t\t\tawait announce(suffix, snap.route);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (;;) {\n\t\t\t\tconst advertised = await race([changed, stream.reader.closed]);\n\t\t\t\tdispose();\n\t\t\t\tif (!advertised) break;\n\n\t\t\t\t// Re-arm before reading, so an advertise that lands while we write is not lost.\n\t\t\t\tchanged = new Promise<Advertisements | undefined>((resolve) => {\n\t\t\t\t\tdispose = this.#advertised.changed(resolve);\n\t\t\t\t});\n\n\t\t\t\tconst latest = this.#advertised.peek();\n\t\t\t\tif (!latest) break;\n\n\t\t\t\tconst updated = new Map<Path.Valid, Advertised>();\n\t\t\t\tfor (const [name, snap] of presented(msg.prefix, latest, carries)) {\n\t\t\t\t\tupdated.set(name, snap);\n\t\t\t\t}\n\n\t\t\t\tfor (const [suffix, snap] of active) {\n\t\t\t\t\tconst cur = updated.get(suffix);\n\t\t\t\t\tif (!cur || cur.identity !== snap.identity) await retract(suffix);\n\t\t\t\t}\n\t\t\t\tfor (const [suffix, snap] of updated) {\n\t\t\t\t\tconst prev = active.get(suffix);\n\t\t\t\t\tif (!prev || prev.identity !== snap.identity) {\n\t\t\t\t\t\tawait announce(suffix, snap.route);\n\t\t\t\t\t} else if (!routesEqual(onWire(prev.route), onWire(snap.route))) {\n\t\t\t\t\t\tawait restart(suffix, snap.route);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tactive = updated;\n\t\t\t}\n\t\t} finally {\n\t\t\tdispose();\n\t\t}\n\t}\n\n\t/**\n\t * Handles a subscribe message.\n\t * @param msg - The subscribe message\n\t * @param stream - The stream to write track data to\n\t *\n\t * @internal\n\t */\n\tasync runSubscribe(msg: Subscribe, stream: Stream) {\n\t\tlet front: broadcast.Consumer | undefined;\n\t\ttry {\n\t\t\tfront =\n\t\t\t\tthis.#publish &&\n\t\t\t\t(wireOf(this.#publish).local(msg.broadcast) ?? (await wireOf(this.#publish).demand(msg.broadcast)));\n\t\t} catch (err: unknown) {\n\t\t\tstream.writer.reset(error(err));\n\t\t\treturn;\n\t\t}\n\t\tif (!front) {\n\t\t\tconsole.debug(`publish unknown: broadcast=${msg.broadcast}`);\n\t\t\tstream.writer.reset(new NotFound(`broadcast ${msg.broadcast}`));\n\t\t\treturn;\n\t\t}\n\n\t\tconst endGroup = exclusiveGroupEnd(msg.endGroup);\n\t\tconst track = wireOf(front).subscribe(msg.track, {\n\t\t\tpriority: msg.priority,\n\t\t\tmaxAge: Milli(servingMaxAge(this.version, msg.maxAge)),\n\t\t\tgroups: {\n\t\t\t\tstart: msg.startGroup === undefined ? undefined : { included: msg.startGroup },\n\t\t\t\tend: endGroup === undefined ? undefined : { excluded: endGroup },\n\t\t\t},\n\t\t});\n\t\tpositionCursor(track, this.version, msg.startGroup);\n\t\thooks.replaceGroups(track, { end: endGroup === undefined ? undefined : { excluded: endGroup } });\n\n\t\t// The best-effort datagram loop, started once serving begins. It parks when the\n\t\t// track finishes (recvDatagram returns undefined), so #runTrack alone ends the\n\t\t// subscription; awaited during teardown so it doesn't outlive the subscription.\n\t\tlet datagrams = Promise.resolve();\n\t\tlet controls: SubscriptionControls | undefined;\n\n\t\ttry {\n\t\t\tlet timescale: Timescale = Timescale.MILLI;\n\n\t\t\tif (supportsTrackStream(this.version)) {\n\t\t\t\t// Lite-05+ accepts implicitly: no SUBSCRIBE_OK (the immutable\n\t\t\t\t// properties live in TRACK_INFO), and the resolved range arrives as\n\t\t\t\t// SUBSCRIBE_START / SUBSCRIBE_END emitted from #runTrack.\n\t\t\t\t//\n\t\t\t\t// The timescale is an immutable property, so serving MUST use exactly\n\t\t\t\t// what TRACK_INFO advertised. It comes from the producer's accept(), so\n\t\t\t\t// they always agree. Awaiting info() also surfaces a rejected track\n\t\t\t\t// (accept never called, track closed) as an error here, which resets the\n\t\t\t\t// stream.\n\t\t\t\tconst info = await track.info();\n\t\t\t\ttimescale = info.timescale;\n\t\t\t} else {\n\t\t\t\t// Older drafts acknowledge with SUBSCRIBE_OK and stream frames verbatim.\n\t\t\t\tconst ok = new SubscribeOk({\n\t\t\t\t\tpriority: msg.priority,\n\t\t\t\t\tmaxAge: msg.maxAge,\n\t\t\t\t\tstartGroup: msg.startGroup,\n\t\t\t\t\tendGroup: msg.endGroup,\n\t\t\t\t});\n\t\t\t\tawait encodeSubscribeResponse(stream.writer, { ok }, this.version);\n\t\t\t}\n\n\t\t\tconsole.debug(`publish ok: broadcast=${msg.broadcast} track=${track.name}`);\n\n\t\t\t// Serve datagrams concurrently with groups whenever the transport carries them\n\t\t\t// (the writer exists iff so). No group fallback: otherwise they simply aren't sent.\n\t\t\tif (this.#datagramWriter) {\n\t\t\t\tdatagrams = this.#runDatagrams(msg.id, track, timescale);\n\t\t\t}\n\n\t\t\tcontrols = new SubscriptionControls({\n\t\t\t\treader: stream.reader,\n\t\t\t\twriter: stream.writer,\n\t\t\t\tversion: this.version,\n\t\t\t\tapply: (update) => {\n\t\t\t\t\tconst end = exclusiveGroupEnd(update.endGroup);\n\t\t\t\t\ttrack.update({\n\t\t\t\t\t\tpriority: update.priority,\n\t\t\t\t\t\tmaxAge: Milli(servingMaxAge(this.version, update.maxAge)),\n\t\t\t\t\t\tgroups: {\n\t\t\t\t\t\t\tstart: update.startGroup === undefined ? undefined : { included: update.startGroup },\n\t\t\t\t\t\t\tend: end === undefined ? undefined : { excluded: end },\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t});\n\t\t\tawait this.#runTrack(track, stream.writer, controls, {\n\t\t\t\tsub: msg.id,\n\t\t\t\tbroadcast: msg.broadcast,\n\t\t\t\ttimescale,\n\t\t\t\tbounds: {\n\t\t\t\t\tstartGroup: msg.startGroup,\n\t\t\t\t\tstartFrame: msg.startFrame,\n\t\t\t\t\tendGroup: msg.endGroup,\n\t\t\t\t\tendFrame: msg.endFrame,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconsole.debug(`publish done: broadcast=${msg.broadcast} track=${track.name}`);\n\t\t\tstream.close();\n\t\t\ttrack.close();\n\t\t\t// Closing the stream ends the decoder and track.close ends the datagram loop.\n\t\t\tawait Promise.all([datagrams, controls.decoding]);\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(`publish error: broadcast=${msg.broadcast} track=${track.name} error=${reason(e)}`);\n\t\t\ttrack.close(e);\n\t\t\tstream.abort(e);\n\t\t\tawait Promise.all([datagrams, controls?.decoding]);\n\t\t}\n\t}\n\n\t/**\n\t * Handles a FETCH stream by serving one group as bare frame records (lite-05+).\n\t *\n\t * @internal\n\t */\n\tasync runFetch(msg: Fetch, stream: Stream) {\n\t\tif (!supportsTrackStream(this.version)) {\n\t\t\tstream.writer.reset(new Error(\"fetch requires moq-lite-05 or newer\"));\n\t\t\treturn;\n\t\t}\n\n\t\tlet front: broadcast.Consumer | undefined;\n\t\ttry {\n\t\t\tfront =\n\t\t\t\tthis.#publish &&\n\t\t\t\t(wireOf(this.#publish).local(msg.broadcast) ?? (await wireOf(this.#publish).demand(msg.broadcast)));\n\t\t} catch (err: unknown) {\n\t\t\tstream.writer.reset(error(err));\n\t\t\treturn;\n\t\t}\n\t\tif (!front) {\n\t\t\tconsole.debug(`fetch unknown: broadcast=${msg.broadcast}`);\n\t\t\tstream.writer.reset(new NotFound(`broadcast ${msg.broadcast}`));\n\t\t\treturn;\n\t\t}\n\n\t\t// The subscriber opened this stream, so its send order only ranked the request. Rank the\n\t\t// response here, on the same scale as the group streams it competes with.\n\t\tstream.writer.setPriority(sendOrder({ priority: msg.priority }));\n\n\t\tlet group: group.Consumer | undefined;\n\t\ttry {\n\t\t\t// The timescale is immutable, so serve exactly what TRACK_INFO advertised. Both\n\t\t\t// come off the same front, so the metadata and the frames are one generation.\n\t\t\tconst info = await this.#resolveTrackInfo(front, msg.track);\n\t\t\tgroup = await wireOf(front).fetchGroup(msg.track, msg.group, { priority: msg.priority });\n\t\t\tawait this.#runFetchGroup(group, stream.writer, {\n\t\t\t\ttimescale: Timescale(info.timescale),\n\t\t\t\tstart: msg.startFrame,\n\t\t\t\tend: msg.endFrame,\n\t\t\t});\n\t\t\tconsole.debug(`fetch done: broadcast=${msg.broadcast} track=${msg.track} group=${msg.group}`);\n\t\t\tstream.close();\n\t\t\tgroup.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(\n\t\t\t\t`fetch error: broadcast=${msg.broadcast} track=${msg.track} group=${msg.group} error=${reason(e)}`,\n\t\t\t);\n\t\t\tgroup?.close(e);\n\t\t\tstream.abort(e);\n\t\t}\n\t}\n\n\t/**\n\t * Runs a track and sends its data to the stream.\n\t * @param sub - The subscription ID\n\t * @param broadcast - The broadcast name\n\t * @param track - The track to run\n\t * @param stream - The stream to write to\n\t *\n\t * @internal\n\t */\n\tasync #runTrack(\n\t\ttrack: track.Subscriber,\n\t\tstream: Writer,\n\t\tcontrols: SubscriptionControls,\n\t\tserving: { sub: bigint; broadcast: Path.Valid; timescale: Timescale; bounds: FrameBounds },\n\t) {\n\t\tconst { sub, broadcast, timescale, bounds } = serving;\n\t\t// Lite-05+ resolves the range on the subscribe stream: SUBSCRIBE_START once the\n\t\t// first group is known, SUBSCRIBE_END when the track finishes.\n\t\tconst emitRange = supportsTrackStream(this.version);\n\t\tlet startSent = false;\n\t\tlet endSent = false;\n\n\t\t// Lite-07+ counts the group streams in SUBSCRIBE_END, so it goes out only once every\n\t\t// served group has opened its stream or given up, and a cap holding groups back\n\t\t// delays it until they are released.\n\t\tconst countStreams = hasStreamCount(this.version);\n\t\tlet streams = 0;\n\t\tconst opening = new Set<Promise<unknown>>();\n\n\t\t// The track's exclusive final boundary. A Rust subscriber feeds SUBSCRIBE_END\n\t\t// straight into finish_at, so it must name the track's boundary (which counts\n\t\t// datagram sequences too), not the delivered range: a subscription cap can hold\n\t\t// produced groups back. The latest() fallback covers a subscription torn down\n\t\t// before the producer declared it.\n\t\tconst boundary = () => track.final() ?? (track.latest() ?? -1) + 1;\n\n\t\t// Before lite-07, SUBSCRIBE_END names that boundary, which a cap can hold groups back\n\t\t// from, so it goes out as soon as the producer finishes and the subscription keeps\n\t\t// serving whatever a later cap raise releases (see the Rust publisher's Recv::Boundary).\n\t\tconst sendEnd = async (): Promise<boolean> => {\n\t\t\tendSent = true;\n\t\t\tif (!emitRange) return true;\n\t\t\treturn controls.response(\n\t\t\t\t(async () => {\n\t\t\t\t\t// A group that gives up before its stream opens is never counted.\n\t\t\t\t\tif (countStreams) while (opening.size > 0) await Promise.all(opening);\n\t\t\t\t\tconst end = new SubscribeEnd(boundary(), streams);\n\t\t\t\t\tawait encodeSubscribeResponse(stream, { end }, this.version);\n\t\t\t\t})(),\n\t\t\t);\n\t\t};\n\n\t\t// One ranking for the whole subscription, shared by every group it serves.\n\t\tconst priority = new Priority(track);\n\n\t\t// Every group this subscription started serving, until its stream finishes or resets.\n\t\tconst groups = new Set<Promise<void>>();\n\n\t\t// Cancels groups still queued for a stream slot. Only the subscriber leaving counts:\n\t\t// a track that ran out of groups still has to flush the ones already queued, and the\n\t\t// caller FINs the subscribe stream to say so.\n\t\tlet finished = false;\n\t\tlet unsubscribe!: () => void;\n\t\tconst unsubscribed = new Promise<void>((resolve) => {\n\t\t\tunsubscribe = resolve;\n\t\t});\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\t// Control before data, matching the Rust publisher: every control decoded while\n\t\t\t\t// the loop was parked applies to the next pop, never to one already made. This\n\t\t\t\t// drain is synchronous, so nothing the decoder holds can land between the pop\n\t\t\t\t// below and its frame range.\n\t\t\t\tconst control = controls.take();\n\t\t\t\tif (control) {\n\t\t\t\t\tswitch (control.kind) {\n\t\t\t\t\t\tcase \"done\":\n\t\t\t\t\t\t\t// The subscriber left. Its queued groups are pointless now, which\n\t\t\t\t\t\t\t// the finally below acts on since `finished` stays false.\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\tcase \"error\":\n\t\t\t\t\t\t\tthrow control.error;\n\t\t\t\t\t\tcase \"update\": {\n\t\t\t\t\t\t\tconst update = control.update;\n\t\t\t\t\t\t\tconsole.debug(`subscribe update: broadcast=${broadcast} track=${track.name}`);\n\t\t\t\t\t\t\thooks.replaceGroups(track, {\n\t\t\t\t\t\t\t\tstart: update.startGroup === undefined ? undefined : { included: update.startGroup },\n\t\t\t\t\t\t\t\tend: update.endGroup === undefined ? undefined : { included: update.endGroup },\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tbounds.startGroup = update.startGroup;\n\t\t\t\t\t\t\tbounds.startFrame = update.startFrame;\n\t\t\t\t\t\t\tbounds.endGroup = update.endGroup;\n\t\t\t\t\t\t\tbounds.endFrame = update.endFrame;\n\t\t\t\t\t\t\tawait yieldToControls();\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Exactly-once arrival-order serving. This synchronous package-internal pop\n\t\t\t\t// and frameRange call are the operation's linearization point.\n\t\t\t\tconst recv = hooks.tryRecvGroup(track);\n\t\t\t\tswitch (recv.kind) {\n\t\t\t\t\tcase \"error\":\n\t\t\t\t\t\tthrow recv.error;\n\t\t\t\t\tcase \"idle\":\n\t\t\t\t\t\t// Before lite-07, an end declared ahead of the live edge goes out as\n\t\t\t\t\t\t// soon as it is known, while the remaining groups are still being\n\t\t\t\t\t\t// produced. The lite-07 count is not final until those groups open.\n\t\t\t\t\t\tif (!endSent && !countStreams && track.final() !== undefined) {\n\t\t\t\t\t\t\tif (!(await sendEnd())) return;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait waitForSubscription(controls, track);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tcase \"boundary\":\n\t\t\t\t\t\t// The producer finished but is still holding groups above the cap.\n\t\t\t\t\t\t// Declare the boundary, then wait for an update to release them.\n\t\t\t\t\t\tif (!endSent && !countStreams) {\n\t\t\t\t\t\t\tif (!(await sendEnd())) return;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait waitForSubscription(controls, track);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tcase \"done\": {\n\t\t\t\t\t\tif (!endSent) {\n\t\t\t\t\t\t\tif (!(await sendEnd())) return;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// The FIN tells the subscriber every group is accounted for, so it waits\n\t\t\t\t\t\t// until each group stream finished or reset. The subscriber leaving\n\t\t\t\t\t\t// instead cancels whatever is still queued.\n\t\t\t\t\t\tconst drained = Symbol(\"drained\");\n\t\t\t\t\t\tconst end = await Promise.race([Promise.all(groups).then(() => drained), controls.ended]);\n\t\t\t\t\t\tif (end instanceof Error) throw end;\n\t\t\t\t\t\tif (end !== drained) return;\n\t\t\t\t\t\tfinished = true;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst group = recv.group;\n\t\t\t\tconst range = frameRange(bounds, group.sequence);\n\n\t\t\t\tif (emitRange && !startSent) {\n\t\t\t\t\tstartSent = true;\n\t\t\t\t\t// SUBSCRIBE_START promises nothing below this sequence will be delivered.\n\t\t\t\t\t// Arrival-order serving could later surface a straggler below the first\n\t\t\t\t\t// group, so pin the floor to what was announced.\n\t\t\t\t\thooks.replaceGroups(track, {\n\t\t\t\t\t\tstart: { included: group.sequence },\n\t\t\t\t\t\tend: bounds.endGroup === undefined ? undefined : { included: bounds.endGroup },\n\t\t\t\t\t});\n\t\t\t\t\tif (\n\t\t\t\t\t\t!(await controls.response(\n\t\t\t\t\t\t\tencodeSubscribeResponse(\n\t\t\t\t\t\t\t\tstream,\n\t\t\t\t\t\t\t\t{ start: new SubscribeStart(group.sequence) },\n\t\t\t\t\t\t\t\tthis.version,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t))\n\t\t\t\t\t)\n\t\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst options: RunGroup = {\n\t\t\t\t\tsub,\n\t\t\t\t\tgroup,\n\t\t\t\t\ttimescale,\n\t\t\t\t\tpriority,\n\t\t\t\t\tunsubscribed,\n\t\t\t\t\tstart: range.start,\n\t\t\t\t\tend: range.end,\n\t\t\t\t};\n\t\t\t\t// `opening` settles when the stream opens so the lite-07 count can be sent.\n\t\t\t\t// `groups` covers the serve too, so the FIN still waits for every stream to\n\t\t\t\t// finish or reset, including one that has not opened yet.\n\t\t\t\tconst opened = this.#openGroup(options);\n\t\t\t\tconst task = opened.then(async (writer) => {\n\t\t\t\t\tif (!writer) return;\n\t\t\t\t\tstreams += 1;\n\t\t\t\t\tawait this.#serveGroup(writer, options);\n\t\t\t\t});\n\t\t\t\tgroups.add(task);\n\t\t\t\tvoid task.finally(() => groups.delete(task));\n\t\t\t\topening.add(opened);\n\t\t\t\tvoid opened.finally(() => opening.delete(opened));\n\t\t\t}\n\t\t} finally {\n\t\t\tif (!finished) unsubscribe();\n\t\t\tpriority.close();\n\t\t}\n\t}\n\n\t/**\n\t * Answers a TRACK stream (0x6) with a single TRACK_INFO, then FINs.\n\t *\n\t * @internal\n\t */\n\tasync runTrackInfo(msg: TrackMessage, stream: Stream) {\n\t\ttry {\n\t\t\tconst front =\n\t\t\t\tthis.#publish &&\n\t\t\t\t(wireOf(this.#publish).local(msg.broadcast) ?? (await wireOf(this.#publish).demand(msg.broadcast)));\n\t\t\tif (!front) throw new NotFound(`broadcast ${msg.broadcast}`);\n\n\t\t\tconst info = await this.#resolveTrackInfo(front, msg.track);\n\t\t\tawait info.encode(stream.writer, this.version);\n\t\t\tconsole.debug(`track info: broadcast=${msg.broadcast} track=${msg.track}`);\n\t\t\tstream.close();\n\t\t} catch (err) {\n\t\t\tconsole.debug(`track unknown: broadcast=${msg.broadcast} track=${msg.track}`);\n\t\t\tstream.writer.reset(error(err));\n\t\t}\n\t}\n\n\t// Resolve (and cache) a track's immutable TRACK_INFO by asking the application.\n\t// `resolveTrackInfo` triggers a TrackRequest the app answers with accept(TrackInfo);\n\t// only the immutable properties are needed (not the groups). Cached because they're\n\t// fixed for the track's lifetime. Rejects if the track is unavailable.\n\t#resolveTrackInfo(front: broadcast.Consumer, track: string): Promise<TrackInfoMessage> {\n\t\tlet tracks = this.#trackInfo.get(front);\n\t\tif (!tracks) {\n\t\t\ttracks = new Map();\n\t\t\tthis.#trackInfo.set(front, tracks);\n\t\t}\n\n\t\tconst cached = tracks.get(track);\n\t\tif (cached !== undefined) return cached;\n\n\t\tconst pending = (async () => {\n\t\t\tconst info = await wireOf(front).resolveTrackInfo(track);\n\t\t\treturn new TrackInfoMessage({\n\t\t\t\tpriority: info.priority,\n\t\t\t\t// Publisher Max Age: the publisher's retention bound, advertised so\n\t\t\t\t// relays re-serve with the same window.\n\t\t\t\tmaxAge: info.maxAge,\n\t\t\t\t// Lite05 mandates per-frame timestamps. Advertise the track's timescale;\n\t\t\t\t// `#serveGroup` emits each frame converted to it.\n\t\t\t\ttimescale: info.timescale,\n\t\t\t});\n\t\t})();\n\n\t\t// Don't poison the cache on failure: a later request may succeed.\n\t\tpending.catch(() => tracks.delete(track));\n\t\ttracks.set(track, pending);\n\t\treturn pending;\n\t}\n\n\t/**\n\t * Forwards a track's datagrams best-effort over QUIC datagrams (lite-05 §6.4), parallel to\n\t * its groups. Each datagram is dropped (there is no group fallback) if the encoded body\n\t * doesn't fit the transport's datagram limit or the send fails. Returns once the track\n\t * finishes; a failure never tears down the subscription.\n\t *\n\t * @internal\n\t */\n\tasync #runDatagrams(sub: bigint, track: track.Subscriber, timescale: Timescale) {\n\t\tconst writer = this.#datagramWriter;\n\t\tif (!writer) return; // Only reached with a writer (see the #datagramWriter gate).\n\t\tconst maxSize = DatagramStream.maxDatagramSize(this.#quic);\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst datagram = await track.recvDatagram();\n\t\t\t\tif (!datagram) return; // Track finished; #runTrack tears the subscription down.\n\n\t\t\t\t// Convert the timestamp to the track's advertised timescale, matching #serveGroup.\n\t\t\t\tconst ts = Math.round(datagram.timestamp.as(timescale));\n\t\t\t\tconst body = new DatagramMessage(sub, datagram.sequence, ts, datagram.payload).encode(this.version);\n\n\t\t\t\t// No group fallback: drop anything that doesn't fit a single datagram.\n\t\t\t\tif (body.byteLength > maxSize) {\n\t\t\t\t\tconsole.debug(`dropping oversize datagram: sub=${sub} size=${body.byteLength} max=${maxSize}`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tawait writer.ready;\n\t\t\t\tawait writer.write(body);\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\t// Best-effort: a datagram send failure stops sending but never fails the subscription.\n\t\t\tconsole.debug(`datagram send stopped: sub=${sub} error=${reason(err)}`);\n\t\t}\n\t}\n\n\t// Serialize a fetched group's frames onto the FETCH stream as bare records: each a\n\t// zigzag-delta timestamp (at the track's advertised timescale) followed by size + bytes.\n\tasync #runFetchGroup(\n\t\tgroup: group.Consumer,\n\t\tstream: Writer,\n\t\t{ timescale, start: startFrame, end: endFrame }: ServeFetch,\n\t) {\n\t\t// The response carries no header, so the receiver numbers the first frame it gets\n\t\t// as `startFrame`. Skipping the head here is the only thing keeping those numbers\n\t\t// honest; a group that ends before we reach it can't be served at all.\n\t\tfor (let i = 0; i < startFrame; i++) {\n\t\t\tif (!(await race([group.readFrame(), stream.closed]))) {\n\t\t\t\tthrow new Error(`fetch group ended at frame ${i}, before the requested start ${startFrame}`);\n\t\t\t}\n\t\t}\n\n\t\tlet prevTs = 0n;\n\t\tfor (let index = startFrame; endFrame === undefined || index <= endFrame; index++) {\n\t\t\tconst frame = await race([group.readFrame(), stream.closed]);\n\t\t\tif (!frame) break;\n\n\t\t\tconst ts = BigInt(Math.round(frame.timestamp.as(timescale)));\n\t\t\tawait stream.u62(zigzag(ts - prevTs));\n\t\t\tprevTs = ts;\n\n\t\t\tawait stream.u53(frame.payload.byteLength);\n\t\t\tawait stream.write(frame.payload);\n\t\t}\n\t}\n\n\t/**\n\t * Opens the unidirectional stream for one group, or closes the group and resolves\n\t * `undefined` when it cannot get one.\n\t *\n\t * @internal\n\t */\n\tasync #openGroup(options: RunGroup): Promise<Writer | undefined> {\n\t\tconst { group, priority, unsubscribed } = options;\n\t\ttry {\n\t\t\t// The transport drains streams by send order, so this is what makes a high-priority\n\t\t\t// track (and a newer group within it) win the link when there isn't room for both.\n\t\t\t//\n\t\t\t// One stream per group is faster than a peer at its limit can retire them, so this\n\t\t\t// is the one path that doesn't wait for a slot: the transport would serve the opens\n\t\t\t// in the order we asked, which is oldest-first, exactly backwards for live media.\n\t\t\t// Failing here drops the group and lets the next one compete for the next slot.\n\t\t\tconst stream = await Writer.tryOpen(this.#quic, {\n\t\t\t\tversion: this.version,\n\t\t\t\tsendOrder: priority.rank(group.sequence),\n\t\t\t\tcancel: unsubscribed,\n\t\t\t\twaitUntilAvailable: false,\n\t\t\t});\n\t\t\tif (!stream) group.close(new Error(\"no stream slot\"));\n\t\t\treturn stream;\n\t\t} catch (err: unknown) {\n\t\t\tgroup.close(error(err));\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Serves one group on the stream {@link #openGroup} opened for it.\n\t *\n\t * @internal\n\t */\n\tasync #serveGroup(stream: Writer, options: RunGroup) {\n\t\tconst { sub, group, timescale, priority, start: startFrame, end: endFrame } = options;\n\t\t// This model holds whole groups, so frame `startFrame` is always reachable unless\n\t\t// the group ends first. Declaring it up front keeps the stream self-describing.\n\t\tconst msg = new GroupMessage({ subscribe: sub, sequence: group.sequence, frameStart: startFrame });\n\t\t// Everything past this point runs inside the cleanup scope, so a failure never leaves\n\t\t// a finished group's stream being ranked.\n\t\ttry {\n\t\t\t// A SUBSCRIBE_UPDATE re-ranks the subscription, so a group already on the wire\n\t\t\t// follows it too rather than keeping a stale rank until it finishes.\n\t\t\tpriority.add(stream, group.sequence);\n\n\t\t\tawait hooks.guardGroup(group, async () => {\n\t\t\t\tawait stream.u53(0); // stream type\n\t\t\t\tawait msg.encode(stream, this.version);\n\t\t\t});\n\n\t\t\t// Lite05+ prefixes every frame with a zigzag-delta timestamp at the track's\n\t\t\t// advertised timescale; older drafts omit it.\n\t\t\tconst timestamps = supportsTrackStream(this.version);\n\t\t\tlet prevTs = 0n;\n\t\t\t// Whether the cursor ever reached the requested start, which decides how the\n\t\t\t// end of the group is read below.\n\t\t\tlet reached = startFrame === 0;\n\n\t\t\tfor (;;) {\n\t\t\t\tconst read = await race([hooks.readGroupFrame(group), stream.closed]);\n\t\t\t\tif (!read) {\n\t\t\t\t\t// The group ended before the frame the subscriber asked to start\n\t\t\t\t\t// at, so this publisher can't serve the range at all. FINning here\n\t\t\t\t\t// would claim an empty group under that index; reset so it reads\n\t\t\t\t\t// as the gap it is.\n\t\t\t\t\tif (!reached) throw new Error(`group ended before frame ${startFrame}`);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\t// A group that ends exactly at the start is a valid, empty range.\n\t\t\t\t\tif (read.sequence + 1 >= startFrame) reached = true;\n\t\t\t\t\t// Frames below the requested start were excluded, and the receiver\n\t\t\t\t\t// numbers what it gets from `startFrame`.\n\t\t\t\t\tif (read.sequence < startFrame) continue;\n\t\t\t\t\tif (endFrame !== undefined && read.sequence > endFrame) break;\n\n\t\t\t\t\tif (timestamps) {\n\t\t\t\t\t\t// Convert each frame to the track's advertised timescale.\n\t\t\t\t\t\tconst ts = BigInt(Math.round(read.frame.timestamp.as(timescale)));\n\t\t\t\t\t\tawait hooks.guardGroup(group, () => stream.u62(zigzag(ts - prevTs)));\n\t\t\t\t\t\tprevTs = ts;\n\t\t\t\t\t}\n\n\t\t\t\t\tawait hooks.guardGroup(group, () => stream.u53(read.frame.payload.byteLength));\n\t\t\t\t\tawait hooks.guardGroup(group, () => stream.write(read.frame.payload));\n\t\t\t\t} finally {\n\t\t\t\t\tread.complete();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstream.close();\n\t\t\tgroup.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tstream.reset(e);\n\t\t\tgroup.close(e);\n\t\t} finally {\n\t\t\tpriority.remove(stream);\n\t\t}\n\t}\n\n\t/**\n\t * Handles a probe stream by periodically reporting estimated bitrate.\n\t * @param stream - The probe bidi stream\n\t *\n\t * @internal\n\t */\n\tasync runProbe(stream: Stream) {\n\t\t// getStats is not yet in the TypeScript WebTransport type definitions.\n\t\tconst quic = this.#quic as unknown as {\n\t\t\tgetStats?: () => Promise<{ estimatedSendRate: number | null; smoothedRtt?: number | null }>;\n\t\t};\n\t\tif (!quic.getStats) {\n\t\t\t// Best-effort: we can't supply bandwidth estimates, so close the\n\t\t\t// whole bidi (FIN + STOP_SENDING) to let the peer release its end.\n\t\t\tstream.close();\n\t\t\treturn;\n\t\t}\n\n\t\tlet lastSent: Probe | undefined;\n\t\tlet lastSentTime: number | undefined;\n\n\t\t// Whether a metric moved enough to be worth another report. Gaining or\n\t\t// losing a value always counts; both unknown never does.\n\t\tconst moved = (prev?: number, next?: number, threshold = 0): boolean => {\n\t\t\tif (prev === undefined && next === undefined) return false;\n\t\t\tif (prev === undefined || next === undefined) return true;\n\t\t\tif (prev === 0) return next !== 0;\n\t\t\treturn Math.abs(next - prev) / prev >= threshold;\n\t\t};\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst timeout = new Promise<\"timeout\">((resolve) =>\n\t\t\t\t\tsetTimeout(() => resolve(\"timeout\"), PROBE_INTERVAL),\n\t\t\t\t);\n\t\t\t\tconst result = await race([timeout, stream.reader.closed]);\n\t\t\t\tif (result !== \"timeout\") break;\n\n\t\t\t\t// The two fields are independent on the wire, each using 0 for\n\t\t\t\t// unknown, so a transport exposing only one still has something to\n\t\t\t\t// report. Anything this version can't carry is dropped here rather\n\t\t\t\t// than by the encoder, so it reads as unknown to every check below.\n\t\t\t\tconst stats = await quic.getStats();\n\t\t\t\t// `smoothedRtt` is a DOMHighResTimeStamp, i.e. a double, but the wire\n\t\t\t\t// carries whole milliseconds and the varint encoder throws on a\n\t\t\t\t// fractional value. Round before it ever reaches `Probe`.\n\t\t\t\tconst rtt = stats.smoothedRtt != null ? Math.round(stats.smoothedRtt) : undefined;\n\t\t\t\tconst report = new Probe({\n\t\t\t\t\tbitrate: stats.estimatedSendRate ?? undefined,\n\t\t\t\t\trtt: hasProbeRtt(this.version) ? rtt : undefined,\n\t\t\t\t});\n\n\t\t\t\t// Nothing left to report. Say so once if it retracts a value the peer\n\t\t\t\t// is still holding, then stay quiet rather than repeating \"unknown\"\n\t\t\t\t// every time the max age comes around.\n\t\t\t\tif (report.bitrate === undefined && report.rtt === undefined) {\n\t\t\t\t\tconst retracts =\n\t\t\t\t\t\tlastSent !== undefined && (lastSent.bitrate !== undefined || lastSent.rtt !== undefined);\n\t\t\t\t\tif (!retracts) continue;\n\t\t\t\t}\n\n\t\t\t\tlet shouldSend: boolean;\n\t\t\t\tif (lastSent === undefined || lastSentTime === undefined) {\n\t\t\t\t\tshouldSend = true;\n\t\t\t\t} else {\n\t\t\t\t\tconst elapsed = performance.now() - lastSentTime;\n\t\t\t\t\t// The bitrate threshold decays to zero as the last report ages: a\n\t\t\t\t\t// stale estimate is worth refreshing for a smaller move.\n\t\t\t\t\tconst t = Math.max(PROBE_INTERVAL, Math.min(PROBE_MAX_AGE, elapsed));\n\t\t\t\t\tconst range = PROBE_MAX_AGE - PROBE_INTERVAL;\n\t\t\t\t\tconst threshold = (PROBE_MAX_DELTA * (PROBE_MAX_AGE - t)) / range;\n\t\t\t\t\tshouldSend =\n\t\t\t\t\t\telapsed >= PROBE_MAX_AGE ||\n\t\t\t\t\t\tmoved(lastSent.bitrate, report.bitrate, threshold) ||\n\t\t\t\t\t\tmoved(lastSent.rtt, report.rtt, PROBE_RTT_DELTA);\n\t\t\t\t}\n\n\t\t\t\tif (shouldSend) {\n\t\t\t\t\tawait report.encode(stream.writer, this.version);\n\t\t\t\t\tlastSent = report;\n\t\t\t\t\tlastSentTime = performance.now();\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tconsole.warn(\"probe stream error\", err);\n\t\t\tstream.close();\n\t\t}\n\t}\n\n\tclose() {\n\t\t// The broadcasts belong to the origin, which outlives this session; closing here\n\t\t// only drops the borrow. The peer sees the unannounce when the streams die.\n\n\t\t// Release the datagram writer's lock so the stream can be torn down.\n\t\tthis.#datagramWriter?.releaseLock();\n\t\tthis.#datagramWriter = undefined;\n\t}\n}\n"]}
1
+ {"version":3,"file":"publisher.js","sourceRoot":"","sources":["../../src/lite/publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEvE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/E,OAAO,EAAE,IAAI,EAAwB,WAAW,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG/D,OAAO,EAA4B,MAAM,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAwC,MAAM,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,UAAU,EAAwB,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxG,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EACN,uBAAuB,EACvB,iBAAiB,EAEjB,YA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E,UAAU;wBACT,OAAO,IAAI,aAAa;4BACxB,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC;4BAClD,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;gBACnD,CAAC;gBAED,IAAI,UAAU,EAAE,CAAC;oBAChB,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;oBACjD,QAAQ,GAAG,MAAM,CAAC;oBAClB,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;gBAClC,CAAC;YACF,CAAC;QACF,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACvB,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;YACxC,MAAM,CAAC,KAAK,EAAE,CAAC;QAChB,CAAC;IACF,CAAC;IAED,KAAK;QACJ,iFAAiF;QACjF,4EAA4E;QAE5E,qEAAqE;QACrE,IAAI,CAAC,eAAe,EAAE,WAAW,EAAE,CAAC;QACpC,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;IAClC,CAAC;CACD","sourcesContent":["import { type Dispose, type Getter, race, Signal } from \"@moq/signals\";\nimport type * as broadcast from \"../broadcast.ts\";\nimport { error, NotFound, reason, StreamCode, StreamError } from \"../error.ts\";\nimport type * as group from \"../group.ts\";\nimport { Cost, type Hop, type Route, routesEqual } from \"../hop.ts\";\nimport { hiddenBelow, hooks, presented } from \"../internal.ts\";\nimport type { Consumer as OriginConsumer } from \"../origin.ts\";\nimport type * as Path from \"../path.ts\";\nimport { type Reader, type Stream, Writer } from \"../stream.ts\";\nimport { Milli, Timescale } from \"../time.ts\";\nimport type * as track from \"../track.ts\";\nimport { type Advertised, type Advertisements, wireOf } from \"../wire.ts\";\nimport { AnnounceInit, AnnounceOk, type AnnounceRequest, encodeAnnounceBroadcast } from \"./announce.ts\";\nimport { Datagram as DatagramMessage } from \"./datagram.ts\";\nimport * as DatagramStream from \"./datagram_stream.ts\";\nimport type { Fetch } from \"./fetch.ts\";\nimport { Group as GroupMessage } from \"./group.ts\";\nimport { Priority, sendOrder } from \"./priority.ts\";\nimport { Probe } from \"./probe.ts\";\nimport {\n\tencodeSubscribeResponse,\n\texclusiveGroupEnd,\n\ttype Subscribe,\n\tSubscribeEnd,\n\tSubscribeOk,\n\tSubscribeStart,\n\tSubscribeUpdate,\n} from \"./subscribe.ts\";\nimport { TrackInfo as TrackInfoMessage, type Track as TrackMessage } from \"./track.ts\";\nimport {\n\thasAnnounceId,\n\thasAnnounceOk,\n\thasDatagrams,\n\thasProbeRtt,\n\thasRouteCost,\n\thasStreamCount,\n\tresolvesStart,\n\tVersion,\n} from \"./version.ts\";\n\nconst PROBE_INTERVAL = 100; // ms\nconst PROBE_MAX_AGE = 10_000; // ms\nconst PROBE_MAX_DELTA = 0.25;\nconst PROBE_RTT_DELTA = 0.25;\n\n/** Map a signed delta to an unsigned zigzag varint value (mirrors Rust `VarInt::from_zigzag`). */\nfunction zigzag(delta: bigint): bigint {\n\treturn delta >= 0n ? delta << 1n : (-delta << 1n) - 1n;\n}\n\n/** What {@link Publisher.openGroup} and {@link Publisher.serveGroup} need to serve one group. */\ninterface RunGroup {\n\t/** The subscription ID. */\n\tsub: bigint;\n\n\t/** The group to serve. */\n\tgroup: group.Consumer;\n\n\t/** The track's advertised timescale, applied to every frame timestamp. */\n\ttimescale: Timescale;\n\n\t/** The subscription's ranking, which this stream joins for as long as it runs. */\n\tpriority: Priority;\n\n\t/** Settles when the subscriber leaves, dropping a group still queued for a stream slot. */\n\tunsubscribed: Promise<void>;\n\n\t/** First frame to send; anything below it was excluded by the subscription. */\n\tstart: number;\n\n\t/** Last frame to send (inclusive), or undefined for the rest of the group. */\n\tend?: number;\n}\n\n// The TRACK stream, implicit SUBSCRIBE acceptance, and SUBSCRIBE_START/END are\n// all lite-05+.\nfunction supportsTrackStream(version: Version): boolean {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/**\n * The frame bounds a subscription placed on its start and end group, as they stand\n * after any SUBSCRIBE_UPDATE.\n *\n * Only the two named groups are qualified; the group range itself lives on the\n * subscriber's read cursor (see {@link frameRange}).\n */\ntype FrameBounds = {\n\t/** The group {@link startFrame} qualifies, if the subscription named one. */\n\tstartGroup?: number;\n\t/** First frame to send within {@link startGroup}; every other group starts at 0. */\n\tstartFrame: number;\n\t/** The group {@link endFrame} qualifies, if the subscription named one. */\n\tendGroup?: number;\n\t/** Last frame (inclusive) to send within {@link endGroup}; every other group runs to its end. */\n\tendFrame?: number;\n};\n\n/**\n * The frames of `sequence` a subscription asked for, as a start index and an inclusive end.\n *\n * The frame bounds qualify the start and end group only; every other group is served whole.\n * Which groups are served at all is the subscriber's read cursor (`replaceGroups`),\n * applied when a group is popped rather than re-checked here.\n *\n * The serving loop calls this synchronously after the pop, before any SUBSCRIBE_UPDATE can\n * change `bounds`. Nothing downstream trims the frame range: it is a wire request,\n * deliberately decoupled from the receiver's local read cursor.\n */\nfunction frameRange(bounds: FrameBounds, sequence: number): { start: number; end?: number } {\n\treturn {\n\t\tstart: bounds.startGroup === sequence ? bounds.startFrame : 0,\n\t\tend: bounds.endGroup === sequence ? bounds.endFrame : undefined,\n\t};\n}\n\n/** What serving one group needs beyond the group itself. */\ntype ServeGroup = {\n\t/** The Subscribe ID the GROUP message references. */\n\tsub: bigint;\n\t/** The track's advertised timescale, which every frame timestamp is converted to. */\n\ttimescale: Timescale;\n\t/** First frame to send; anything below it was excluded by the subscription. */\n\tstart: number;\n\t/** Last frame to send (inclusive), or undefined for the rest of the group. */\n\tend?: number;\n};\n\n/** What serving fetched frames needs beyond the group and destination stream. */\ntype ServeFetch = Omit<ServeGroup, \"sub\">;\n\n/** What the serving loop takes from the subscribe stream instead of serving a group. */\ntype Control =\n\t/** The peer re-stated the subscription: priority, ordering, latency, and both ranges. */\n\t| { kind: \"update\"; update: SubscribeUpdate }\n\t/** The peer FIN'd, or our own half went away. Either way there is nobody left to serve. */\n\t| { kind: \"done\" }\n\t/** The stream failed; the subscription goes down with it. */\n\t| { kind: \"error\"; error: Error };\n\ntype SubscriptionControlOptions = {\n\treader: Reader;\n\twriter: Writer;\n\tversion: Version;\n\tapply: (update: SubscribeUpdate) => void;\n};\n\n/**\n * The subscribe stream's control half, decoded ahead of the serving loop.\n *\n * Decoding runs on its own and publishes each full subscription update immediately, so a\n * blocked response write cannot delay re-ranking streams already in flight. It separately\n * stores only the latest range state for the serving loop, which owns the local track cursor\n * and frame bounds. That keeps a group pop and its frame-range snapshot one indivisible step.\n *\n * Reading ahead makes control-first ordering hold for a burst. Coalescing bounds memory while\n * preserving the newest state decoded before the next group pop. The Rust publisher gets the\n * same ordering from `poll_decode_maybe`, which decodes straight out of the reader's buffer;\n * nothing here can decode synchronously, so it reads ahead instead.\n */\nclass SubscriptionControls {\n\t#writer: Writer;\n\t#update?: SubscribeUpdate;\n\t// Sticky, first one wins: null once the stream is over, an Error once it failed.\n\t#end?: Error | null;\n\t#ended: Promise<Error | null>;\n\t#resolveEnd!: (end: Error | null) => void;\n\t#changed = new Signal(0);\n\n\t/** Settles once decoding stops, so teardown can wait for it rather than leaving it running. */\n\treadonly decoding: Promise<void>;\n\n\tconstructor({ reader, writer, version, apply }: SubscriptionControlOptions) {\n\t\tthis.#writer = writer;\n\t\tthis.#ended = new Promise((resolve) => {\n\t\t\tthis.#resolveEnd = resolve;\n\t\t});\n\t\tthis.decoding = this.#decode(reader, version, apply);\n\t\t// Our own half going away ends the loop too, and has to reach it the same way: the\n\t\t// loop looks at nothing else.\n\t\tvoid writer.closed.then(\n\t\t\t() => this.#finish(null),\n\t\t\t(err: unknown) => this.#finish(error(err)),\n\t\t);\n\t}\n\n\t/** The next control to apply, or undefined while the peer is quiet. */\n\ttake(): Control | undefined {\n\t\tconst update = this.#update;\n\t\tthis.#update = undefined;\n\t\t// An update decoded before the stream ended still applies before the sticky end.\n\t\tif (update) return { kind: \"update\", update };\n\t\tif (this.#end === undefined) return undefined;\n\t\treturn this.#end === null ? { kind: \"done\" } : { kind: \"error\", error: this.#end };\n\t}\n\n\t/** Calls `fn` once {@link take} may answer differently. */\n\tchanged(fn: () => void): Dispose {\n\t\treturn this.#changed.changed(fn);\n\t}\n\n\t/** Returns false when peer departure supersedes a blocked response write. */\n\tasync response(pending: Promise<void>): Promise<boolean> {\n\t\t// `#ended` lives as long as the stream, so it is raced as-is rather than mapped per call.\n\t\tconst result = await race([\n\t\t\tpending.then(\n\t\t\t\t() => ({ kind: \"sent\" }) as const,\n\t\t\t\t(err: unknown) => ({ kind: \"error\", error: error(err) }) as const,\n\t\t\t),\n\t\t\tthis.#ended,\n\t\t]);\n\n\t\tif (result !== null && !(result instanceof Error)) {\n\t\t\tif (result.kind === \"sent\") return true;\n\t\t\tthrow result.error;\n\t\t}\n\n\t\t// The race leaves the blocked encode running, so reset the writable half too.\n\t\tthis.#writer.reset(result ?? new StreamError(StreamCode.Cancel, { message: \"cancel\" }));\n\t\tif (result) throw result;\n\t\treturn false;\n\t}\n\n\t/** Settles once the stream is over: `null` when it ended cleanly, or the failure. */\n\tget ended(): Promise<Error | null> {\n\t\treturn this.#ended;\n\t}\n\n\t#finish(end: Error | null) {\n\t\tif (this.#end !== undefined) return;\n\t\tthis.#end = end;\n\t\tthis.#resolveEnd(end);\n\t\tthis.#changed.update((value) => value + 1);\n\t}\n\n\tasync #decode(reader: Reader, version: Version, apply: (update: SubscribeUpdate) => void) {\n\t\ttry {\n\t\t\twhile (this.#end === undefined) {\n\t\t\t\tconst update = await SubscribeUpdate.decodeMaybe(reader, version);\n\t\t\t\tif (!update) break;\n\t\t\t\tapply(update);\n\t\t\t\tthis.#update = update;\n\t\t\t\tthis.#changed.update((value) => value + 1);\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tthis.#finish(error(err));\n\t\t\treturn;\n\t\t}\n\t\tthis.#finish(null);\n\t}\n}\n\n// A microtask is too short: decoding one framed update crosses several awaits, each of which\n// can requeue behind the serving continuation. A task boundary lets the decoder finish whatever\n// the transport already delivered before the next group pop. Updates are rare, so groups do not\n// pay this scheduling cost on the normal path.\nconst yieldToControls = () => new Promise<void>((resolve) => setTimeout(resolve, 0));\n\n// Register both readiness sources in the same turn after the caller observed neither ready.\n// The winner disposes both registrations, so an idle subscription accumulates nothing no\n// matter how many times it wakes.\nfunction waitForSubscription(controls: SubscriptionControls, subscriber: track.Subscriber): Promise<void> {\n\treturn new Promise((resolve) => {\n\t\tlet settled = false;\n\t\tconst dispose: Dispose[] = [];\n\t\tconst wake = () => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tfor (const close of dispose) close();\n\t\t\tresolve();\n\t\t};\n\t\tdispose.push(controls.changed(wake), hooks.groupChanged(subscriber, wake));\n\t});\n}\n\n/**\n * The budget to serve a peer with, given what its wire could tell us.\n *\n * A version without the field decodes as `0`, which is indistinguishable from a peer\n * genuinely asking for the live edge. Serving that as real time would discard backlog\n * a legacy subscriber never declined, so fall back to a window wide enough not to drop\n * and leave enforcement to the receiver, as the IETF path does for the same reason.\n */\nfunction servingMaxAge(version: Version, requested: number | undefined): number {\n\treturn carriesMaxAge(version) ? (requested ?? 0) : Number.MAX_SAFE_INTEGER;\n}\n\n/** Whether this version's SUBSCRIBE carries Subscriber Max Age at all. */\nfunction carriesMaxAge(version: Version): boolean {\n\treturn version !== Version.DRAFT_01 && version !== Version.DRAFT_02;\n}\n\n/**\n * Position a subscription's read cursor for the wire serving it.\n *\n * On lite-06 there is nothing to do: the cursor is floored at the group the subscription\n * named (or 0), and its Max Age decides what above the floor is worth delivering.\n *\n * Pre-06 wires are the exception: their drafts define an absent `Group Start` as the\n * latest group, so say so explicitly rather than letting the budget reach back. Lite-03/04/05\n * carry a Max Age, but there it is a staleness tolerance only; lite-01/02 additionally get\n * an unbounded budget so nothing is dropped under them (see {@link servingMaxAge}), which\n * must not read as a request to replay the whole cache on join.\n */\nfunction positionCursor(track: track.Subscriber, version: Version, startGroup: number | undefined) {\n\tif (resolvesStart(version) || startGroup !== undefined) return;\n\n\tconst latest = track.latest();\n\tif (latest !== undefined) hooks.replaceGroups(track, { start: { included: latest } });\n}\n\n/**\n * Handles publishing broadcasts and managing their lifecycle.\n *\n * @internal\n */\nexport class Publisher {\n\t// The version of the connection.\n\treadonly version: Version;\n\n\t// Per-connection origin appended to outbound Announce hops, so the peer\n\t// can detect loops and prefer shorter paths. Created by Connection and\n\t// shared with Subscriber, which can optionally use it to filter out its\n\t// own announcements.\n\treadonly hop: Hop;\n\n\t#quic: WebTransport;\n\n\t// The one writer for the outbound datagram stream (getWriter locks it), acquired once at\n\t// construction when this version + transport carry datagrams, released in close(). Its\n\t// presence is the gate: undefined means datagrams aren't served on this connection. All\n\t// subscriptions share it, since a second getWriter on the same stream would throw.\n\t#datagramWriter?: WritableStreamDefaultWriter<Uint8Array>;\n\n\t// Originated advertisements this session forwards.\n\t#advertised: Getter<Advertisements | undefined>;\n\n\t#publish?: OriginConsumer;\n\n\t// TRACK_INFO is immutable per track, so resolve it from the application once\n\t// (via a throwaway subscribe whose info() resolves when the app calls accept)\n\t// and reuse it for every later TRACK request of the same track. Keyed by the\n\t// routing front rather than the path: immutability holds for one broadcast, and a\n\t// republish puts a different one on the path, so its entries must not be reused.\n\t// A rejected lookup is evicted so a retry can re-probe.\n\t#trackInfo = new WeakMap<broadcast.Consumer, Map<string, Promise<TrackInfoMessage>>>();\n\n\t/**\n\t * Creates a new Publisher instance.\n\t * @param quic - The WebTransport session to use\n\t * @param version - Negotiated protocol version\n\t * @param origin - Hop id shared with the Subscriber\n\t * @param publish - The origin whose broadcasts this session serves; omit to publish nothing\n\t *\n\t * @internal\n\t */\n\tconstructor(quic: WebTransport, version: Version, hop: Hop, publish?: OriginConsumer) {\n\t\tthis.#quic = quic;\n\t\tthis.version = version;\n\t\tthis.hop = hop;\n\t\tconst origin = publish && wireOf(publish);\n\t\tthis.#advertised = origin?.advertised ?? new Signal(new Map());\n\t\tthis.#publish = publish;\n\n\t\t// Grab the datagram writer up front when the transport carries datagrams (no group\n\t\t// fallback, so it stays undefined otherwise). One writer for all subscriptions.\n\t\tif (hasDatagrams(version)) {\n\t\t\tthis.#datagramWriter = DatagramStream.datagramWriter(quic);\n\t\t}\n\t}\n\n\t/**\n\t * Handles an announce interest message.\n\t * @param msg - The announce interest message\n\t * @param stream - The stream to write announcements to\n\t *\n\t * @internal\n\t */\n\tasync runAnnounce(msg: AnnounceRequest, stream: Stream) {\n\t\tconsole.debug(`announce: prefix=${msg.prefix}`);\n\n\t\t// Keyed by suffix, valued by identity plus route, so a republish diffs as\n\t\t// ended-then-active and a re-price as a restart.\n\t\tlet active = new Map<Path.Valid, Advertised>();\n\n\t\t// Lite06+: announce ids. Every active we send implicitly assigns the next\n\t\t// per-stream ordinal; ended/restart reference the id instead of repeating the path.\n\t\tlet nextAnnounceId = 0n;\n\t\tconst announceIds = new Map<Path.Valid, bigint>();\n\n\t\tconst wireHops = (route: Route): Hop[] => {\n\t\t\tif (hasAnnounceOk(this.version)) return route.hops;\n\t\t\treturn [...route.hops, this.hop];\n\t\t};\n\n\t\t// What the peer decodes for a route: pre-lite-06 wires carry no cost, so a re-price\n\t\t// there must not restart.\n\t\tconst onWire = (route: Route): Route => (hasRouteCost(this.version) ? route : { ...route, cost: Cost.zero });\n\n\t\tconst announce = async (suffix: Path.Valid, route: Route) => {\n\t\t\tconsole.debug(`announce: broadcast=${suffix} active=true`);\n\t\t\tif (hasAnnounceId(this.version)) announceIds.set(suffix, nextAnnounceId++);\n\t\t\tawait encodeAnnounceBroadcast(\n\t\t\t\tstream.writer,\n\t\t\t\t{ status: \"active\", suffix, hops: wireHops(route), cost: route.cost },\n\t\t\t\tthis.version,\n\t\t\t);\n\t\t};\n\n\t\tconst restart = async (suffix: Path.Valid, route: Route) => {\n\t\t\tif (!hasAnnounceId(this.version)) {\n\t\t\t\tawait retract(suffix);\n\t\t\t\tawait announce(suffix, route);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst id = announceIds.get(suffix);\n\t\t\tif (id === undefined) {\n\t\t\t\tawait announce(suffix, route);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconsole.debug(`announce: broadcast=${suffix} restart=true`);\n\t\t\tawait encodeAnnounceBroadcast(\n\t\t\t\tstream.writer,\n\t\t\t\t{ status: \"restart\", id, hops: wireHops(route), cost: route.cost },\n\t\t\t\tthis.version,\n\t\t\t);\n\t\t};\n\n\t\t// Lite06+ retracts by announce id; older versions repeat the path (ended announces\n\t\t// don't need hops).\n\t\tconst retract = async (suffix: Path.Valid) => {\n\t\t\tconsole.debug(`announce: broadcast=${suffix} active=false`);\n\t\t\tif (!hasAnnounceId(this.version)) {\n\t\t\t\tawait encodeAnnounceBroadcast(stream.writer, { status: \"ended\", suffix }, this.version);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst id = announceIds.get(suffix);\n\t\t\tannounceIds.delete(suffix);\n\t\t\tif (id === undefined) return; // never announced\n\t\t\tawait encodeAnnounceBroadcast(stream.writer, { status: \"endedId\", id }, this.version);\n\t\t};\n\n\t\t// Subscribe BEFORE writing anything: every encode below awaits the wire, and a publish\n\t\t// landing in that window only notifies the listeners already registered. One created\n\t\t// afterwards would sleep through it, leaving the change unannounced until something\n\t\t// unrelated moved.\n\t\t// TODO Make a better helper within Signals.\n\t\tlet dispose!: Dispose;\n\t\tlet changed = new Promise<Advertisements | undefined>((resolve) => {\n\t\t\tdispose = this.#advertised.changed(resolve);\n\t\t});\n\n\t\t// A hidden route stays off the wire unless the request opted in.\n\t\tconst carries = (covered: Path.Valid) => msg.hidden || !hiddenBelow(msg.prefix, covered);\n\n\t\ttry {\n\t\t\tconst initial = this.#advertised.peek();\n\t\t\tif (!initial) return; // closed\n\n\t\t\tfor (const [name, snap] of presented(msg.prefix, initial, carries)) {\n\t\t\t\tactive.set(name, snap);\n\t\t\t}\n\n\t\t\tswitch (this.version) {\n\t\t\t\tcase Version.DRAFT_01:\n\t\t\t\tcase Version.DRAFT_02: {\n\t\t\t\t\tfor (const suffix of active.keys()) {\n\t\t\t\t\t\tconsole.debug(`announce: broadcast=${suffix} active=true`);\n\t\t\t\t\t}\n\t\t\t\t\tconst init = new AnnounceInit([...active.keys()]);\n\t\t\t\t\tawait init.encode(stream.writer, this.version);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tif (!hasAnnounceOk(this.version)) {\n\t\t\t\t\t\tfor (const [suffix, snap] of active) {\n\t\t\t\t\t\t\tawait announce(suffix, snap.route);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst ok = new AnnounceOk(this.hop, active.size);\n\t\t\t\t\tawait ok.encode(stream.writer, this.version);\n\t\t\t\t\tfor (const [suffix, snap] of active) {\n\t\t\t\t\t\tawait announce(suffix, snap.route);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (;;) {\n\t\t\t\tconst advertised = await race([changed, stream.reader.closed]);\n\t\t\t\tdispose();\n\t\t\t\tif (!advertised) break;\n\n\t\t\t\t// Re-arm before reading, so an advertise that lands while we write is not lost.\n\t\t\t\tchanged = new Promise<Advertisements | undefined>((resolve) => {\n\t\t\t\t\tdispose = this.#advertised.changed(resolve);\n\t\t\t\t});\n\n\t\t\t\tconst latest = this.#advertised.peek();\n\t\t\t\tif (!latest) break;\n\n\t\t\t\tconst updated = new Map<Path.Valid, Advertised>();\n\t\t\t\tfor (const [name, snap] of presented(msg.prefix, latest, carries)) {\n\t\t\t\t\tupdated.set(name, snap);\n\t\t\t\t}\n\n\t\t\t\tfor (const [suffix, snap] of active) {\n\t\t\t\t\tconst cur = updated.get(suffix);\n\t\t\t\t\tif (!cur || cur.identity !== snap.identity) await retract(suffix);\n\t\t\t\t}\n\t\t\t\tfor (const [suffix, snap] of updated) {\n\t\t\t\t\tconst prev = active.get(suffix);\n\t\t\t\t\tif (!prev || prev.identity !== snap.identity) {\n\t\t\t\t\t\tawait announce(suffix, snap.route);\n\t\t\t\t\t} else if (!routesEqual(onWire(prev.route), onWire(snap.route))) {\n\t\t\t\t\t\tawait restart(suffix, snap.route);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tactive = updated;\n\t\t\t}\n\t\t} finally {\n\t\t\tdispose();\n\t\t}\n\t}\n\n\t/**\n\t * Handles a subscribe message.\n\t * @param msg - The subscribe message\n\t * @param stream - The stream to write track data to\n\t *\n\t * @internal\n\t */\n\tasync runSubscribe(msg: Subscribe, stream: Stream) {\n\t\tlet front: broadcast.Consumer | undefined;\n\t\ttry {\n\t\t\tfront =\n\t\t\t\tthis.#publish &&\n\t\t\t\t(wireOf(this.#publish).local(msg.broadcast) ?? (await wireOf(this.#publish).demand(msg.broadcast)));\n\t\t} catch (err: unknown) {\n\t\t\tstream.writer.reset(error(err));\n\t\t\treturn;\n\t\t}\n\t\tif (!front) {\n\t\t\tconsole.debug(`publish unknown: broadcast=${msg.broadcast}`);\n\t\t\tstream.writer.reset(new NotFound(`broadcast ${msg.broadcast}`));\n\t\t\treturn;\n\t\t}\n\n\t\tconst endGroup = exclusiveGroupEnd(msg.endGroup);\n\t\tconst track = wireOf(front).subscribe(msg.track, {\n\t\t\tpriority: msg.priority,\n\t\t\tmaxAge: Milli(servingMaxAge(this.version, msg.maxAge)),\n\t\t\tgroups: {\n\t\t\t\tstart: msg.startGroup === undefined ? undefined : { included: msg.startGroup },\n\t\t\t\tend: endGroup === undefined ? undefined : { excluded: endGroup },\n\t\t\t},\n\t\t});\n\t\tpositionCursor(track, this.version, msg.startGroup);\n\t\thooks.replaceGroups(track, { end: endGroup === undefined ? undefined : { excluded: endGroup } });\n\n\t\t// The best-effort datagram loop, started once serving begins. It parks when the\n\t\t// track finishes (recvDatagram returns undefined), so #runTrack alone ends the\n\t\t// subscription; awaited during teardown so it doesn't outlive the subscription.\n\t\tlet datagrams = Promise.resolve();\n\t\tlet controls: SubscriptionControls | undefined;\n\n\t\ttry {\n\t\t\tlet timescale: Timescale = Timescale.MILLI;\n\n\t\t\tif (supportsTrackStream(this.version)) {\n\t\t\t\t// Lite-05+ accepts implicitly: no SUBSCRIBE_OK (the immutable\n\t\t\t\t// properties live in TRACK_INFO), and the resolved range arrives as\n\t\t\t\t// SUBSCRIBE_START / SUBSCRIBE_END emitted from #runTrack.\n\t\t\t\t//\n\t\t\t\t// The timescale is an immutable property, so serving MUST use exactly\n\t\t\t\t// what TRACK_INFO advertised. It comes from the producer's accept(), so\n\t\t\t\t// they always agree. Awaiting info() also surfaces a rejected track\n\t\t\t\t// (accept never called, track closed) as an error here, which resets the\n\t\t\t\t// stream.\n\t\t\t\tconst info = await track.info();\n\t\t\t\ttimescale = info.timescale;\n\t\t\t} else {\n\t\t\t\t// Older drafts acknowledge with SUBSCRIBE_OK and stream frames verbatim.\n\t\t\t\tconst ok = new SubscribeOk({\n\t\t\t\t\tpriority: msg.priority,\n\t\t\t\t\tmaxAge: msg.maxAge,\n\t\t\t\t\tstartGroup: msg.startGroup,\n\t\t\t\t\tendGroup: msg.endGroup,\n\t\t\t\t});\n\t\t\t\tawait encodeSubscribeResponse(stream.writer, { ok }, this.version);\n\t\t\t}\n\n\t\t\tconsole.debug(`publish ok: broadcast=${msg.broadcast} track=${track.name}`);\n\n\t\t\t// Serve datagrams concurrently with groups whenever the transport carries them\n\t\t\t// (the writer exists iff so). No group fallback: otherwise they simply aren't sent.\n\t\t\tif (this.#datagramWriter) {\n\t\t\t\tdatagrams = this.#runDatagrams(msg.id, track, timescale);\n\t\t\t}\n\n\t\t\tcontrols = new SubscriptionControls({\n\t\t\t\treader: stream.reader,\n\t\t\t\twriter: stream.writer,\n\t\t\t\tversion: this.version,\n\t\t\t\tapply: (update) => {\n\t\t\t\t\tconst end = exclusiveGroupEnd(update.endGroup);\n\t\t\t\t\ttrack.update({\n\t\t\t\t\t\tpriority: update.priority,\n\t\t\t\t\t\tmaxAge: Milli(servingMaxAge(this.version, update.maxAge)),\n\t\t\t\t\t\tgroups: {\n\t\t\t\t\t\t\tstart: update.startGroup === undefined ? undefined : { included: update.startGroup },\n\t\t\t\t\t\t\tend: end === undefined ? undefined : { excluded: end },\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t});\n\t\t\tawait this.#runTrack(track, stream.writer, controls, {\n\t\t\t\tsub: msg.id,\n\t\t\t\tbroadcast: msg.broadcast,\n\t\t\t\ttimescale,\n\t\t\t\tbounds: {\n\t\t\t\t\tstartGroup: msg.startGroup,\n\t\t\t\t\tstartFrame: msg.startFrame,\n\t\t\t\t\tendGroup: msg.endGroup,\n\t\t\t\t\tendFrame: msg.endFrame,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconsole.debug(`publish done: broadcast=${msg.broadcast} track=${track.name}`);\n\t\t\tstream.close();\n\t\t\ttrack.close();\n\t\t\t// Closing the stream ends the decoder and track.close ends the datagram loop.\n\t\t\tawait Promise.all([datagrams, controls.decoding]);\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(`publish error: broadcast=${msg.broadcast} track=${track.name} error=${reason(e)}`);\n\t\t\ttrack.close(e);\n\t\t\tstream.abort(e);\n\t\t\tawait Promise.all([datagrams, controls?.decoding]);\n\t\t}\n\t}\n\n\t/**\n\t * Handles a FETCH stream by serving one group as bare frame records (lite-05+).\n\t *\n\t * @internal\n\t */\n\tasync runFetch(msg: Fetch, stream: Stream) {\n\t\tif (!supportsTrackStream(this.version)) {\n\t\t\tstream.writer.reset(new Error(\"fetch requires moq-lite-05 or newer\"));\n\t\t\treturn;\n\t\t}\n\n\t\tlet front: broadcast.Consumer | undefined;\n\t\ttry {\n\t\t\tfront =\n\t\t\t\tthis.#publish &&\n\t\t\t\t(wireOf(this.#publish).local(msg.broadcast) ?? (await wireOf(this.#publish).demand(msg.broadcast)));\n\t\t} catch (err: unknown) {\n\t\t\tstream.writer.reset(error(err));\n\t\t\treturn;\n\t\t}\n\t\tif (!front) {\n\t\t\tconsole.debug(`fetch unknown: broadcast=${msg.broadcast}`);\n\t\t\tstream.writer.reset(new NotFound(`broadcast ${msg.broadcast}`));\n\t\t\treturn;\n\t\t}\n\n\t\t// The subscriber opened this stream, so its send order only ranked the request. Rank the\n\t\t// response here, on the same scale as the group streams it competes with.\n\t\tstream.writer.setPriority(sendOrder({ priority: msg.priority }));\n\n\t\tlet group: group.Consumer | undefined;\n\t\ttry {\n\t\t\t// The timescale is immutable, so serve exactly what TRACK_INFO advertised. Both\n\t\t\t// come off the same front, so the metadata and the frames are one generation.\n\t\t\tconst info = await this.#resolveTrackInfo(front, msg.track);\n\t\t\tgroup = await wireOf(front).fetchGroup(msg.track, msg.group, { priority: msg.priority });\n\t\t\tawait this.#runFetchGroup(group, stream.writer, {\n\t\t\t\ttimescale: Timescale(info.timescale),\n\t\t\t\tstart: msg.startFrame,\n\t\t\t\tend: msg.endFrame,\n\t\t\t});\n\t\t\tconsole.debug(`fetch done: broadcast=${msg.broadcast} track=${msg.track} group=${msg.group}`);\n\t\t\tstream.close();\n\t\t\tgroup.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(\n\t\t\t\t`fetch error: broadcast=${msg.broadcast} track=${msg.track} group=${msg.group} error=${reason(e)}`,\n\t\t\t);\n\t\t\tgroup?.close(e);\n\t\t\tstream.abort(e);\n\t\t}\n\t}\n\n\t/**\n\t * Runs a track and sends its data to the stream.\n\t * @param sub - The subscription ID\n\t * @param broadcast - The broadcast name\n\t * @param track - The track to run\n\t * @param stream - The stream to write to\n\t *\n\t * @internal\n\t */\n\tasync #runTrack(\n\t\ttrack: track.Subscriber,\n\t\tstream: Writer,\n\t\tcontrols: SubscriptionControls,\n\t\tserving: { sub: bigint; broadcast: Path.Valid; timescale: Timescale; bounds: FrameBounds },\n\t) {\n\t\tconst { sub, broadcast, timescale, bounds } = serving;\n\t\t// Lite-05+ resolves the range on the subscribe stream: SUBSCRIBE_START once the\n\t\t// first group is known, SUBSCRIBE_END when the track finishes.\n\t\tconst emitRange = supportsTrackStream(this.version);\n\t\tlet startSent = false;\n\t\tlet endSent = false;\n\n\t\t// Lite-07+ counts the group streams in SUBSCRIBE_END, so it goes out only once every\n\t\t// served group has opened its stream or given up, and a cap holding groups back\n\t\t// delays it until they are released.\n\t\tconst countStreams = hasStreamCount(this.version);\n\t\tlet streams = 0;\n\t\tconst opening = new Set<Promise<unknown>>();\n\n\t\t// The track's exclusive final boundary. A Rust subscriber feeds SUBSCRIBE_END\n\t\t// straight into finish_at, so it must name the track's boundary (which counts\n\t\t// datagram sequences too), not the delivered range: a subscription cap can hold\n\t\t// produced groups back. The latest() fallback covers a subscription torn down\n\t\t// before the producer declared it.\n\t\tconst boundary = () => track.final() ?? (track.latest() ?? -1) + 1;\n\n\t\t// Before lite-07, SUBSCRIBE_END names that boundary, which a cap can hold groups back\n\t\t// from, so it goes out as soon as the producer finishes and the subscription keeps\n\t\t// serving whatever a later cap raise releases (see the Rust publisher's Recv::Boundary).\n\t\tconst sendEnd = async (): Promise<boolean> => {\n\t\t\tendSent = true;\n\t\t\tif (!emitRange) return true;\n\t\t\treturn controls.response(\n\t\t\t\t(async () => {\n\t\t\t\t\t// A group that gives up before its stream opens is never counted.\n\t\t\t\t\tif (countStreams) while (opening.size > 0) await Promise.all(opening);\n\t\t\t\t\tconst end = new SubscribeEnd(boundary(), streams);\n\t\t\t\t\tawait encodeSubscribeResponse(stream, { end }, this.version);\n\t\t\t\t})(),\n\t\t\t);\n\t\t};\n\n\t\t// One ranking for the whole subscription, shared by every group it serves.\n\t\tconst priority = new Priority(track);\n\n\t\t// Every group this subscription started serving, until its stream finishes or resets.\n\t\tconst groups = new Set<Promise<void>>();\n\n\t\t// Cancels groups still queued for a stream slot. Only the subscriber leaving counts:\n\t\t// a track that ran out of groups still has to flush the ones already queued, and the\n\t\t// caller FINs the subscribe stream to say so.\n\t\tlet finished = false;\n\t\tlet unsubscribe!: () => void;\n\t\tconst unsubscribed = new Promise<void>((resolve) => {\n\t\t\tunsubscribe = resolve;\n\t\t});\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\t// Control before data, matching the Rust publisher: every control decoded while\n\t\t\t\t// the loop was parked applies to the next pop, never to one already made. This\n\t\t\t\t// drain is synchronous, so nothing the decoder holds can land between the pop\n\t\t\t\t// below and its frame range.\n\t\t\t\tconst control = controls.take();\n\t\t\t\tif (control) {\n\t\t\t\t\tswitch (control.kind) {\n\t\t\t\t\t\tcase \"done\":\n\t\t\t\t\t\t\t// The subscriber left. Its queued groups are pointless now, which\n\t\t\t\t\t\t\t// the finally below acts on since `finished` stays false.\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\tcase \"error\":\n\t\t\t\t\t\t\tthrow control.error;\n\t\t\t\t\t\tcase \"update\": {\n\t\t\t\t\t\t\tconst update = control.update;\n\t\t\t\t\t\t\tconsole.debug(`subscribe update: broadcast=${broadcast} track=${track.name}`);\n\t\t\t\t\t\t\t// `positionCursor` pins an unfloored pre-06 SUBSCRIBE to the latest\n\t\t\t\t\t\t\t// group, so an update that drops a named floor re-pins there too. On\n\t\t\t\t\t\t\t// an empty track the next group is the latest, whatever its sequence.\n\t\t\t\t\t\t\tconst start =\n\t\t\t\t\t\t\t\tupdate.startGroup === undefined &&\n\t\t\t\t\t\t\t\tbounds.startGroup !== undefined &&\n\t\t\t\t\t\t\t\t!resolvesStart(this.version)\n\t\t\t\t\t\t\t\t\t? (track.latest() ?? 0)\n\t\t\t\t\t\t\t\t\t: update.startGroup;\n\t\t\t\t\t\t\thooks.replaceGroups(track, {\n\t\t\t\t\t\t\t\tstart: start === undefined ? undefined : { included: start },\n\t\t\t\t\t\t\t\tend: update.endGroup === undefined ? undefined : { included: update.endGroup },\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tbounds.startGroup = update.startGroup;\n\t\t\t\t\t\t\tbounds.startFrame = update.startFrame;\n\t\t\t\t\t\t\tbounds.endGroup = update.endGroup;\n\t\t\t\t\t\t\tbounds.endFrame = update.endFrame;\n\t\t\t\t\t\t\tawait yieldToControls();\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Exactly-once arrival-order serving. This synchronous package-internal pop\n\t\t\t\t// and frameRange call are the operation's linearization point.\n\t\t\t\tconst recv = hooks.tryRecvGroup(track);\n\t\t\t\tswitch (recv.kind) {\n\t\t\t\t\tcase \"error\":\n\t\t\t\t\t\tthrow recv.error;\n\t\t\t\t\tcase \"idle\":\n\t\t\t\t\t\t// Before lite-07, an end declared ahead of the live edge goes out as\n\t\t\t\t\t\t// soon as it is known, while the remaining groups are still being\n\t\t\t\t\t\t// produced. The lite-07 count is not final until those groups open.\n\t\t\t\t\t\tif (!endSent && !countStreams && track.final() !== undefined) {\n\t\t\t\t\t\t\tif (!(await sendEnd())) return;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait waitForSubscription(controls, track);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tcase \"boundary\":\n\t\t\t\t\t\t// The producer finished but is still holding groups above the cap.\n\t\t\t\t\t\t// Declare the boundary, then wait for an update to release them.\n\t\t\t\t\t\tif (!endSent && !countStreams) {\n\t\t\t\t\t\t\tif (!(await sendEnd())) return;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait waitForSubscription(controls, track);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tcase \"done\": {\n\t\t\t\t\t\tif (!endSent) {\n\t\t\t\t\t\t\tif (!(await sendEnd())) return;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// The FIN tells the subscriber every group is accounted for, so it waits\n\t\t\t\t\t\t// until each group stream finished or reset. The subscriber leaving\n\t\t\t\t\t\t// instead cancels whatever is still queued.\n\t\t\t\t\t\tconst drained = Symbol(\"drained\");\n\t\t\t\t\t\tconst end = await Promise.race([Promise.all(groups).then(() => drained), controls.ended]);\n\t\t\t\t\t\tif (end instanceof Error) throw end;\n\t\t\t\t\t\tif (end !== drained) return;\n\t\t\t\t\t\tfinished = true;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst group = recv.group;\n\t\t\t\tconst range = frameRange(bounds, group.sequence);\n\n\t\t\t\tif (emitRange && !startSent) {\n\t\t\t\t\tstartSent = true;\n\t\t\t\t\t// SUBSCRIBE_START names the first group served now. A later group at or\n\t\t\t\t\t// above an explicit floor is still delivered, so the cursor stays put.\n\t\t\t\t\t// A pre-06 subscribe that named no group is the exception: an absent\n\t\t\t\t\t// Group Start is the latest group, and this sequence becomes the floor.\n\t\t\t\t\t// Lite-06 encodes a floor of group 0 as 0, so an omitted start is not pinned.\n\t\t\t\t\tif (bounds.startGroup === undefined && !resolvesStart(this.version)) {\n\t\t\t\t\t\thooks.replaceGroups(track, {\n\t\t\t\t\t\t\tstart: { included: group.sequence },\n\t\t\t\t\t\t\tend: bounds.endGroup === undefined ? undefined : { included: bounds.endGroup },\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\t!(await controls.response(\n\t\t\t\t\t\t\tencodeSubscribeResponse(\n\t\t\t\t\t\t\t\tstream,\n\t\t\t\t\t\t\t\t{ start: new SubscribeStart(group.sequence) },\n\t\t\t\t\t\t\t\tthis.version,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t))\n\t\t\t\t\t)\n\t\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst options: RunGroup = {\n\t\t\t\t\tsub,\n\t\t\t\t\tgroup,\n\t\t\t\t\ttimescale,\n\t\t\t\t\tpriority,\n\t\t\t\t\tunsubscribed,\n\t\t\t\t\tstart: range.start,\n\t\t\t\t\tend: range.end,\n\t\t\t\t};\n\t\t\t\t// `opening` settles when the stream opens so the lite-07 count can be sent.\n\t\t\t\t// `groups` covers the serve too, so the FIN still waits for every stream to\n\t\t\t\t// finish or reset, including one that has not opened yet.\n\t\t\t\tconst opened = this.#openGroup(options);\n\t\t\t\tconst task = opened.then(async (writer) => {\n\t\t\t\t\tif (!writer) return;\n\t\t\t\t\tstreams += 1;\n\t\t\t\t\tawait this.#serveGroup(writer, options);\n\t\t\t\t});\n\t\t\t\tgroups.add(task);\n\t\t\t\tvoid task.finally(() => groups.delete(task));\n\t\t\t\topening.add(opened);\n\t\t\t\tvoid opened.finally(() => opening.delete(opened));\n\t\t\t}\n\t\t} finally {\n\t\t\tif (!finished) unsubscribe();\n\t\t\tpriority.close();\n\t\t}\n\t}\n\n\t/**\n\t * Answers a TRACK stream (0x6) with a single TRACK_INFO, then FINs.\n\t *\n\t * @internal\n\t */\n\tasync runTrackInfo(msg: TrackMessage, stream: Stream) {\n\t\ttry {\n\t\t\tconst front =\n\t\t\t\tthis.#publish &&\n\t\t\t\t(wireOf(this.#publish).local(msg.broadcast) ?? (await wireOf(this.#publish).demand(msg.broadcast)));\n\t\t\tif (!front) throw new NotFound(`broadcast ${msg.broadcast}`);\n\n\t\t\tconst info = await this.#resolveTrackInfo(front, msg.track);\n\t\t\tawait info.encode(stream.writer, this.version);\n\t\t\tconsole.debug(`track info: broadcast=${msg.broadcast} track=${msg.track}`);\n\t\t\tstream.close();\n\t\t} catch (err) {\n\t\t\tconsole.debug(`track unknown: broadcast=${msg.broadcast} track=${msg.track}`);\n\t\t\tstream.writer.reset(error(err));\n\t\t}\n\t}\n\n\t// Resolve (and cache) a track's immutable TRACK_INFO by asking the application.\n\t// `resolveTrackInfo` triggers a TrackRequest the app answers with accept(TrackInfo);\n\t// only the immutable properties are needed (not the groups). Cached because they're\n\t// fixed for the track's lifetime. Rejects if the track is unavailable.\n\t#resolveTrackInfo(front: broadcast.Consumer, track: string): Promise<TrackInfoMessage> {\n\t\tlet tracks = this.#trackInfo.get(front);\n\t\tif (!tracks) {\n\t\t\ttracks = new Map();\n\t\t\tthis.#trackInfo.set(front, tracks);\n\t\t}\n\n\t\tconst cached = tracks.get(track);\n\t\tif (cached !== undefined) return cached;\n\n\t\tconst pending = (async () => {\n\t\t\tconst info = await wireOf(front).resolveTrackInfo(track);\n\t\t\treturn new TrackInfoMessage({\n\t\t\t\tpriority: info.priority,\n\t\t\t\t// Publisher Max Age: the publisher's retention bound, advertised so\n\t\t\t\t// relays re-serve with the same window.\n\t\t\t\tmaxAge: info.maxAge,\n\t\t\t\t// Lite05 mandates per-frame timestamps. Advertise the track's timescale;\n\t\t\t\t// `#serveGroup` emits each frame converted to it.\n\t\t\t\ttimescale: info.timescale,\n\t\t\t});\n\t\t})();\n\n\t\t// Don't poison the cache on failure: a later request may succeed.\n\t\tpending.catch(() => tracks.delete(track));\n\t\ttracks.set(track, pending);\n\t\treturn pending;\n\t}\n\n\t/**\n\t * Forwards a track's datagrams best-effort over QUIC datagrams (lite-05 §6.4), parallel to\n\t * its groups. Each datagram is dropped (there is no group fallback) if the encoded body\n\t * doesn't fit the transport's datagram limit or the send fails. Returns once the track\n\t * finishes; a failure never tears down the subscription.\n\t *\n\t * @internal\n\t */\n\tasync #runDatagrams(sub: bigint, track: track.Subscriber, timescale: Timescale) {\n\t\tconst writer = this.#datagramWriter;\n\t\tif (!writer) return; // Only reached with a writer (see the #datagramWriter gate).\n\t\tconst maxSize = DatagramStream.maxDatagramSize(this.#quic);\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst datagram = await track.recvDatagram();\n\t\t\t\tif (!datagram) return; // Track finished; #runTrack tears the subscription down.\n\n\t\t\t\t// Convert the timestamp to the track's advertised timescale, matching #serveGroup.\n\t\t\t\tconst ts = Math.round(datagram.timestamp.as(timescale));\n\t\t\t\tconst body = new DatagramMessage(sub, datagram.sequence, ts, datagram.payload).encode(this.version);\n\n\t\t\t\t// No group fallback: drop anything that doesn't fit a single datagram.\n\t\t\t\tif (body.byteLength > maxSize) {\n\t\t\t\t\tconsole.debug(`dropping oversize datagram: sub=${sub} size=${body.byteLength} max=${maxSize}`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tawait writer.ready;\n\t\t\t\tawait writer.write(body);\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\t// Best-effort: a datagram send failure stops sending but never fails the subscription.\n\t\t\tconsole.debug(`datagram send stopped: sub=${sub} error=${reason(err)}`);\n\t\t}\n\t}\n\n\t// Serialize a fetched group's frames onto the FETCH stream as bare records: each a\n\t// zigzag-delta timestamp (at the track's advertised timescale) followed by size + bytes.\n\tasync #runFetchGroup(\n\t\tgroup: group.Consumer,\n\t\tstream: Writer,\n\t\t{ timescale, start: startFrame, end: endFrame }: ServeFetch,\n\t) {\n\t\t// The response carries no header, so the receiver numbers the first frame it gets\n\t\t// as `startFrame`. Skipping the head here is the only thing keeping those numbers\n\t\t// honest; a group that ends before we reach it can't be served at all.\n\t\tfor (let i = 0; i < startFrame; i++) {\n\t\t\tif (!(await race([group.readFrame(), stream.closed]))) {\n\t\t\t\tthrow new Error(`fetch group ended at frame ${i}, before the requested start ${startFrame}`);\n\t\t\t}\n\t\t}\n\n\t\tlet prevTs = 0n;\n\t\tfor (let index = startFrame; endFrame === undefined || index <= endFrame; index++) {\n\t\t\tconst frame = await race([group.readFrame(), stream.closed]);\n\t\t\tif (!frame) break;\n\n\t\t\tconst ts = BigInt(Math.round(frame.timestamp.as(timescale)));\n\t\t\tawait stream.u62(zigzag(ts - prevTs));\n\t\t\tprevTs = ts;\n\n\t\t\tawait stream.u53(frame.payload.byteLength);\n\t\t\tawait stream.write(frame.payload);\n\t\t}\n\t}\n\n\t/**\n\t * Opens the unidirectional stream for one group, or closes the group and resolves\n\t * `undefined` when it cannot get one.\n\t *\n\t * @internal\n\t */\n\tasync #openGroup(options: RunGroup): Promise<Writer | undefined> {\n\t\tconst { group, priority, unsubscribed } = options;\n\t\ttry {\n\t\t\t// The transport drains streams by send order, so this is what makes a high-priority\n\t\t\t// track (and a newer group within it) win the link when there isn't room for both.\n\t\t\t//\n\t\t\t// One stream per group is faster than a peer at its limit can retire them, so this\n\t\t\t// is the one path that doesn't wait for a slot: the transport would serve the opens\n\t\t\t// in the order we asked, which is oldest-first, exactly backwards for live media.\n\t\t\t// Failing here drops the group and lets the next one compete for the next slot.\n\t\t\tconst stream = await Writer.tryOpen(this.#quic, {\n\t\t\t\tversion: this.version,\n\t\t\t\tsendOrder: priority.rank(group.sequence),\n\t\t\t\tcancel: unsubscribed,\n\t\t\t\twaitUntilAvailable: false,\n\t\t\t});\n\t\t\tif (!stream) group.close(new Error(\"no stream slot\"));\n\t\t\treturn stream;\n\t\t} catch (err: unknown) {\n\t\t\tgroup.close(error(err));\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Serves one group on the stream {@link #openGroup} opened for it.\n\t *\n\t * @internal\n\t */\n\tasync #serveGroup(stream: Writer, options: RunGroup) {\n\t\tconst { sub, group, timescale, priority, start: startFrame, end: endFrame } = options;\n\t\t// This model holds whole groups, so frame `startFrame` is always reachable unless\n\t\t// the group ends first. Declaring it up front keeps the stream self-describing.\n\t\tconst msg = new GroupMessage({ subscribe: sub, sequence: group.sequence, frameStart: startFrame });\n\t\t// Everything past this point runs inside the cleanup scope, so a failure never leaves\n\t\t// a finished group's stream being ranked.\n\t\ttry {\n\t\t\t// A SUBSCRIBE_UPDATE re-ranks the subscription, so a group already on the wire\n\t\t\t// follows it too rather than keeping a stale rank until it finishes.\n\t\t\tpriority.add(stream, group.sequence);\n\n\t\t\tawait hooks.guardGroup(group, async () => {\n\t\t\t\tawait stream.u53(0); // stream type\n\t\t\t\tawait msg.encode(stream, this.version);\n\t\t\t});\n\n\t\t\t// Lite05+ prefixes every frame with a zigzag-delta timestamp at the track's\n\t\t\t// advertised timescale; older drafts omit it.\n\t\t\tconst timestamps = supportsTrackStream(this.version);\n\t\t\tlet prevTs = 0n;\n\t\t\t// Whether the cursor ever reached the requested start, which decides how the\n\t\t\t// end of the group is read below.\n\t\t\tlet reached = startFrame === 0;\n\n\t\t\tfor (;;) {\n\t\t\t\tconst read = await race([hooks.readGroupFrame(group), stream.closed]);\n\t\t\t\tif (!read) {\n\t\t\t\t\t// The group ended before the frame the subscriber asked to start\n\t\t\t\t\t// at, so this publisher can't serve the range at all. FINning here\n\t\t\t\t\t// would claim an empty group under that index; reset so it reads\n\t\t\t\t\t// as the gap it is.\n\t\t\t\t\tif (!reached) throw new Error(`group ended before frame ${startFrame}`);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\t// A group that ends exactly at the start is a valid, empty range.\n\t\t\t\t\tif (read.sequence + 1 >= startFrame) reached = true;\n\t\t\t\t\t// Frames below the requested start were excluded, and the receiver\n\t\t\t\t\t// numbers what it gets from `startFrame`.\n\t\t\t\t\tif (read.sequence < startFrame) continue;\n\t\t\t\t\tif (endFrame !== undefined && read.sequence > endFrame) break;\n\n\t\t\t\t\tif (timestamps) {\n\t\t\t\t\t\t// Convert each frame to the track's advertised timescale.\n\t\t\t\t\t\tconst ts = BigInt(Math.round(read.frame.timestamp.as(timescale)));\n\t\t\t\t\t\tawait hooks.guardGroup(group, () => stream.u62(zigzag(ts - prevTs)));\n\t\t\t\t\t\tprevTs = ts;\n\t\t\t\t\t}\n\n\t\t\t\t\tawait hooks.guardGroup(group, () => stream.u53(read.frame.payload.byteLength));\n\t\t\t\t\tawait hooks.guardGroup(group, () => stream.write(read.frame.payload));\n\t\t\t\t} finally {\n\t\t\t\t\tread.complete();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstream.close();\n\t\t\tgroup.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tstream.reset(e);\n\t\t\tgroup.close(e);\n\t\t} finally {\n\t\t\tpriority.remove(stream);\n\t\t}\n\t}\n\n\t/**\n\t * Handles a probe stream by periodically reporting estimated bitrate.\n\t * @param stream - The probe bidi stream\n\t *\n\t * @internal\n\t */\n\tasync runProbe(stream: Stream) {\n\t\t// getStats is not yet in the TypeScript WebTransport type definitions.\n\t\tconst quic = this.#quic as unknown as {\n\t\t\tgetStats?: () => Promise<{ estimatedSendRate: number | null; smoothedRtt?: number | null }>;\n\t\t};\n\t\tif (!quic.getStats) {\n\t\t\t// Best-effort: we can't supply bandwidth estimates, so close the\n\t\t\t// whole bidi (FIN + STOP_SENDING) to let the peer release its end.\n\t\t\tstream.close();\n\t\t\treturn;\n\t\t}\n\n\t\tlet lastSent: Probe | undefined;\n\t\tlet lastSentTime: number | undefined;\n\n\t\t// Whether a metric moved enough to be worth another report. Gaining or\n\t\t// losing a value always counts; both unknown never does.\n\t\tconst moved = (prev?: number, next?: number, threshold = 0): boolean => {\n\t\t\tif (prev === undefined && next === undefined) return false;\n\t\t\tif (prev === undefined || next === undefined) return true;\n\t\t\tif (prev === 0) return next !== 0;\n\t\t\treturn Math.abs(next - prev) / prev >= threshold;\n\t\t};\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst timeout = new Promise<\"timeout\">((resolve) =>\n\t\t\t\t\tsetTimeout(() => resolve(\"timeout\"), PROBE_INTERVAL),\n\t\t\t\t);\n\t\t\t\tconst result = await race([timeout, stream.reader.closed]);\n\t\t\t\tif (result !== \"timeout\") break;\n\n\t\t\t\t// The two fields are independent on the wire, each using 0 for\n\t\t\t\t// unknown, so a transport exposing only one still has something to\n\t\t\t\t// report. Anything this version can't carry is dropped here rather\n\t\t\t\t// than by the encoder, so it reads as unknown to every check below.\n\t\t\t\tconst stats = await quic.getStats();\n\t\t\t\t// `smoothedRtt` is a DOMHighResTimeStamp, i.e. a double, but the wire\n\t\t\t\t// carries whole milliseconds and the varint encoder throws on a\n\t\t\t\t// fractional value. Round before it ever reaches `Probe`.\n\t\t\t\tconst rtt = stats.smoothedRtt != null ? Math.round(stats.smoothedRtt) : undefined;\n\t\t\t\tconst report = new Probe({\n\t\t\t\t\tbitrate: stats.estimatedSendRate ?? undefined,\n\t\t\t\t\trtt: hasProbeRtt(this.version) ? rtt : undefined,\n\t\t\t\t});\n\n\t\t\t\t// Nothing left to report. Say so once if it retracts a value the peer\n\t\t\t\t// is still holding, then stay quiet rather than repeating \"unknown\"\n\t\t\t\t// every time the max age comes around.\n\t\t\t\tif (report.bitrate === undefined && report.rtt === undefined) {\n\t\t\t\t\tconst retracts =\n\t\t\t\t\t\tlastSent !== undefined && (lastSent.bitrate !== undefined || lastSent.rtt !== undefined);\n\t\t\t\t\tif (!retracts) continue;\n\t\t\t\t}\n\n\t\t\t\tlet shouldSend: boolean;\n\t\t\t\tif (lastSent === undefined || lastSentTime === undefined) {\n\t\t\t\t\tshouldSend = true;\n\t\t\t\t} else {\n\t\t\t\t\tconst elapsed = performance.now() - lastSentTime;\n\t\t\t\t\t// The bitrate threshold decays to zero as the last report ages: a\n\t\t\t\t\t// stale estimate is worth refreshing for a smaller move.\n\t\t\t\t\tconst t = Math.max(PROBE_INTERVAL, Math.min(PROBE_MAX_AGE, elapsed));\n\t\t\t\t\tconst range = PROBE_MAX_AGE - PROBE_INTERVAL;\n\t\t\t\t\tconst threshold = (PROBE_MAX_DELTA * (PROBE_MAX_AGE - t)) / range;\n\t\t\t\t\tshouldSend =\n\t\t\t\t\t\telapsed >= PROBE_MAX_AGE ||\n\t\t\t\t\t\tmoved(lastSent.bitrate, report.bitrate, threshold) ||\n\t\t\t\t\t\tmoved(lastSent.rtt, report.rtt, PROBE_RTT_DELTA);\n\t\t\t\t}\n\n\t\t\t\tif (shouldSend) {\n\t\t\t\t\tawait report.encode(stream.writer, this.version);\n\t\t\t\t\tlastSent = report;\n\t\t\t\t\tlastSentTime = performance.now();\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tconsole.warn(\"probe stream error\", err);\n\t\t\tstream.close();\n\t\t}\n\t}\n\n\tclose() {\n\t\t// The broadcasts belong to the origin, which outlives this session; closing here\n\t\t// only drops the borrow. The peer sees the unannounce when the streams die.\n\n\t\t// Release the datagram writer's lock so the stream can be torn down.\n\t\tthis.#datagramWriter?.releaseLock();\n\t\tthis.#datagramWriter = undefined;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["../../src/lite/subscribe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAgE,OAAO,EAAE,MAAM,cAAc,CAAC;AA2GrG;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAExE;AAED,qFAAqF;AACrF,eAAO,MAAM,WAAW,+CAA+C,CAAC;AAExE;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAIxE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAExG;AAED,qBAAa,eAAe;;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,0FAA0F;IAC1F,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,YAAY,KAAK,EAAE;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,C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C;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IAEd,YAAY,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAI/D;IAYK,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErC;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAErD;CACD;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GAC1B;IAAE,EAAE,EAAE,WAAW,CAAA;CAAE,GACnB;IAAE,KAAK,EAAE,cAAc,CAAA;CAAE,GACzB;IAAE,GAAG,EAAE,YAAY,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC;AAE3B,wBAAsB,uBAAuB,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAsCjH;AAED,wBAAsB,uBAAuB,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAgCrG;AAED,oFAAoF;AACpF,wBAAsB,4BAA4B,CACjD,CAAC,EAAE,MAAM,EACT,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAGxC"}
package/lite/subscribe.js CHANGED
@@ -5,17 +5,16 @@ import { hasFrameBounds, hasGroupOrder, hasStreamCount, resolvesStart, Version }
5
5
  /**
6
6
  * Encode the `Group Start` field shared by SUBSCRIBE and SUBSCRIBE_UPDATE.
7
7
  *
8
- * Lite-06 writes the raw floor (`undefined` and 0 are the same absence of a constraint),
9
- * while a pre-06 wire encodes the sequence + 1 and gets a vacuous floor folded back to
10
- * absent: an explicit group 0 there means "replay from the beginning", which is not what
11
- * a floor of 0 asks for.
8
+ * Lite-06 writes the raw floor (`undefined` and 0 are both group 0). A pre-06 wire
9
+ * encodes the sequence + 1: omitting the floor is 0 (the latest group, where the
10
+ * publisher starts) and an explicit 0 is 1, replay from the beginning.
12
11
  */
13
12
  async function encodeStartGroup(w, version, startGroup) {
14
13
  if (resolvesStart(version)) {
15
14
  await w.u53(startGroup ?? 0);
16
15
  return;
17
16
  }
18
- await w.u53(startGroup !== undefined && startGroup > 0 ? startGroup + 1 : 0);
17
+ await w.u53(startGroup === undefined ? 0 : startGroup + 1);
19
18
  }
20
19
  /**
21
20
  * Decode the `Group Start` field shared by SUBSCRIBE and SUBSCRIBE_UPDATE.