@moq/net 0.3.2 → 0.3.3
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.
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +3 -2
- package/broadcast.js.map +1 -1
- package/ietf/aliases.d.ts +73 -5
- package/ietf/aliases.d.ts.map +1 -1
- package/ietf/aliases.js +121 -14
- package/ietf/aliases.js.map +1 -1
- package/ietf/publisher.d.ts.map +1 -1
- package/ietf/publisher.js +4 -2
- package/ietf/publisher.js.map +1 -1
- package/ietf/subscriber.d.ts.map +1 -1
- package/ietf/subscriber.js +121 -31
- package/ietf/subscriber.js.map +1 -1
- package/internal.d.ts +16 -1
- package/internal.d.ts.map +1 -1
- package/internal.js.map +1 -1
- package/lite/publisher.d.ts.map +1 -1
- package/lite/publisher.js +4 -2
- package/lite/publisher.js.map +1 -1
- package/package.json +1 -1
- package/track.d.ts.map +1 -1
- package/track.js +35 -14
- package/track.js.map +1 -1
package/ietf/publisher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publisher.js","sourceRoot":"","sources":["../../src/ietf/publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,gBAAgB,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K,EAAE,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,KAAK;QACJ,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;YACtC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;gBACpD,SAAS,CAAC,KAAK,EAAE,CAAC;YACnB,CAAC;YACD,OAAO,SAAS,CAAC;QAClB,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import { type Dispose, Signal } from \"@moq/signals\";\nimport type * as broadcast from \"../broadcast.ts\";\nimport { error, reason } from \"../error.ts\";\nimport type * as group from \"../group.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Stream, Writer } from \"../stream.ts\";\nimport type { Timescale } from \"../time.ts\";\nimport { withTimeout } from \"../util/timeout.ts\";\nimport type { Session } from \"./adapter.ts\";\nimport * as Cluster from \"./cluster.ts\";\nimport { Frame, Group as GroupMessage } from \"./object.ts\";\nimport { fromWire } from \"./priority.ts\";\nimport { PublishDone } from \"./publish.ts\";\nimport { PublishNamespace, PublishNamespaceDone, PublishNamespaceOk } from \"./publish_namespace.ts\";\nimport { RequestError, RequestOk } from \"./request.ts\";\nimport { type Subscribe, SubscribeError, SubscribeOk } from \"./subscribe.ts\";\nimport {\n\ttype SubscribeNamespace,\n\tSubscribeNamespaceEntry,\n\tSubscribeNamespaceEntryDone,\n\tSubscribeNamespaceOk,\n} from \"./subscribe_namespace.ts\";\nimport { TrackStatus, type TrackStatusRequest } from \"./track.ts\";\nimport { Version } from \"./version.ts\";\n\n/** First wait before re-offering a namespace the peer refused or we couldn't open for. */\nconst RETRY_BASE = 100;\n\n/** Ceiling on that wait. The loop retries for the life of the session, so it must not spin. */\nconst RETRY_MAX = 5000;\n\n/**\n * How long one advertisement may take to be answered. Matches the Rust publisher, and the\n * peer accepting the stream is only half the exchange: one it never answers on holds the\n * loop just as effectively as one it never grants.\n */\nconst ADVERTISE_TIMEOUT_MS = 5000;\n\n/** Sleep `delay`, jittered, so a relay's namespaces don't all retry on the same tick. */\nfunction retryAfter(delay: number): Promise<void> {\n\treturn new Promise((resolve) => setTimeout(resolve, delay * (0.5 + Math.random() / 2)));\n}\n\n/**\n * What a refusal said about re-offering the namespace.\n *\n * A peer answers a request it declines with a retry interval, and ignoring it is how a\n * permanent refusal (unauthorized, uninterested) turns into a request every few seconds\n * for the life of the session. `\"never\"` is an interval of 0; a number is the epoch\n * milliseconds before which we must not come back.\n */\ntype Refused = \"never\" | number;\n\n/** What {@link Publisher.runGroup} needs to serve one group. */\ninterface RunGroup {\n\t/** The subscription's request ID, doubling as the track alias. */\n\trequestId: 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/** Settles when the subscriber leaves, dropping a group still queued for a stream slot. */\n\tunsubscribed: Promise<void>;\n}\n\n/**\n * Handles publishing broadcasts using moq-transport protocol.\n * Uses the stream-per-request pattern (real bidi streams for v17, virtual for v14-v16).\n *\n * @internal\n */\nexport class Publisher {\n\t#quic: WebTransport;\n\t#session: Session;\n\t#requiresSolicitation: boolean;\n\n\t// What every advertisement carries on a session that negotiated the MoQ Cluster\n\t// extension: a hop path holding our own id, so the peer can tell that what it hears\n\t// back came from us. `undefined` when nothing negotiated it.\n\t#advert?: Cluster.Advert;\n\n\t// Our published broadcasts.\n\t// It's a signal so we can live update any subscribe_namespace streams.\n\t#broadcasts = new Signal<Map<Path.Valid, broadcast.Producer> | undefined>(new Map());\n\n\t/**\n\t * Creates a new Publisher instance.\n\t *\n\t * @internal\n\t */\n\tconstructor({\n\t\tquic,\n\t\tsession,\n\t\trequiresSolicitation,\n\t\tcluster,\n\t}: {\n\t\t/** The WebTransport session, for uni streams. */\n\t\tquic: WebTransport;\n\t\t/** The session abstraction for bidi streams and request IDs. */\n\t\tsession: Session;\n\t\t/** Whether the peer's SETUP asked to be told on request (MoQ Solicit). */\n\t\trequiresSolicitation: boolean;\n\t\t/** The Hop IDs the SETUP exchange settled (MoQ Cluster). */\n\t\tcluster?: Cluster.Hops;\n\t}) {\n\t\tthis.#quic = quic;\n\t\tthis.#session = session;\n\t\tthis.#requiresSolicitation = requiresSolicitation;\n\t\tthis.#advert = Cluster.advertise(cluster);\n\t}\n\n\t/**\n\t * Publishes a broadcast with any associated tracks.\n\t * The namespace is advertised with an unsolicited PUBLISH_NAMESPACE, or on request\n\t * if the peer asked for that (see {@link runPublishNamespaces}).\n\t */\n\tpublish(path: Path.Valid, broadcast: broadcast.Producer) {\n\t\tthis.#broadcasts.mutate((broadcasts) => {\n\t\t\tif (!broadcasts) throw new Error(\"closed\");\n\t\t\tbroadcasts.set(path, broadcast);\n\t\t});\n\n\t\t// Remove the broadcast from the lookup when it's closed.\n\t\tvoid broadcast.closed.then(() => {\n\t\t\tthis.#broadcasts.mutate((broadcasts) => {\n\t\t\t\tbroadcasts?.delete(path);\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Handles an incoming SUBSCRIBE request on a bidi stream.\n\t * Owns the full lifecycle: sends response, serves track data, waits for close.\n\t *\n\t * @internal\n\t */\n\tasync runSubscribe(msg: Subscribe, stream: Stream) {\n\t\tconst version = this.#session.version;\n\t\tconst name = msg.trackNamespace;\n\t\tconst broadcast = this.#broadcasts.peek()?.get(name);\n\n\t\tif (!broadcast) {\n\t\t\t// Write error response\n\t\t\tif (version === Version.DRAFT_14) {\n\t\t\t\tawait stream.writer.u53(SubscribeError.id);\n\t\t\t\tconst err = new SubscribeError({\n\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\terrorCode: 404,\n\t\t\t\t\treasonPhrase: \"Broadcast not found\",\n\t\t\t\t});\n\t\t\t\tawait err.encode(stream.writer, version);\n\t\t\t} else {\n\t\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\t\tconst err = new RequestError({\n\t\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t\t\terrorCode: 404,\n\t\t\t\t\treasonPhrase: \"Broadcast not found\",\n\t\t\t\t});\n\t\t\t\tawait err.encode(stream.writer, version);\n\t\t\t}\n\t\t\tstream.close();\n\t\t\treturn;\n\t\t}\n\n\t\tconst track = broadcast.subscribe(msg.trackName, { priority: fromWire(msg.subscriberPriority) });\n\n\t\ttry {\n\t\t\t// Declaring the timescale is what opts the track into timestamps; every object\n\t\t\t// Timestamp below is in these units.\n\t\t\tconst timescale = (await track.info()).timescale;\n\n\t\t\t// Send SUBSCRIBE_OK\n\t\t\tawait stream.writer.u53(SubscribeOk.id);\n\t\t\tconst ok = new SubscribeOk({\n\t\t\t\trequestId:\n\t\t\t\t\tversion === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16\n\t\t\t\t\t\t? msg.requestId\n\t\t\t\t\t\t: undefined,\n\t\t\t\ttrackAlias: msg.requestId,\n\t\t\t\ttimescale,\n\t\t\t});\n\t\t\tawait ok.encode(stream.writer, version);\n\t\t\tconsole.debug(`publish ok: broadcast=${name} track=${track.name}`);\n\n\t\t\t// Cancels groups still queued for a stream slot. Only the subscriber leaving counts:\n\t\t\t// a track that ran out of groups still has to flush the ones already queued, and we\n\t\t\t// close the stream ourselves below to say so.\n\t\t\tlet finished = false;\n\t\t\tlet unsubscribe!: () => void;\n\t\t\tconst unsubscribed = new Promise<void>((resolve) => {\n\t\t\t\tunsubscribe = resolve;\n\t\t\t});\n\t\t\tvoid stream.reader.closed.then(\n\t\t\t\t() => {\n\t\t\t\t\tif (!finished) unsubscribe();\n\t\t\t\t},\n\t\t\t\t// A reset is always the peer.\n\t\t\t\t() => unsubscribe(),\n\t\t\t);\n\n\t\t\t// Serve track groups, racing with stream close (= Unsubscribe)\n\t\t\tconst serving = (async () => {\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst group = await track.recvGroup();\n\t\t\t\t\tif (!group) return;\n\t\t\t\t\tvoid this.#runGroup({ requestId: msg.requestId, group, timescale, unsubscribed });\n\t\t\t\t}\n\t\t\t})();\n\n\t\t\tawait Promise.race([serving, stream.reader.closed]);\n\n\t\t\tconsole.debug(`publish done: broadcast=${name} track=${track.name}`);\n\n\t\t\t// v14-v16: send PublishDone before closing\n\t\t\tif (version === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16) {\n\t\t\t\ttry {\n\t\t\t\t\tawait stream.writer.u53(PublishDone.id);\n\t\t\t\t\tconst done = new PublishDone({\n\t\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\t\tstatusCode: 200,\n\t\t\t\t\t\treasonPhrase: \"OK\",\n\t\t\t\t\t});\n\t\t\t\t\tawait done.encode(stream.writer, version);\n\t\t\t\t} catch {\n\t\t\t\t\t// Stream might already be closed by peer\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Only now is the close below ours. Claiming it any earlier would read a peer FIN\n\t\t\t// that lands while PublishDone is still going out as our own completion, leaving\n\t\t\t// queued groups to open for a subscriber that has already left.\n\t\t\tfinished = true;\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(`publish error: broadcast=${name} track=${track.name} error=${reason(e)}`);\n\t\t\tstream.abort(e);\n\t\t} finally {\n\t\t\ttrack.close();\n\t\t}\n\t}\n\n\t/**\n\t * Runs a group and sends its frames using ObjectStream (Subgroup delivery mode).\n\t */\n\tasync #runGroup(options: RunGroup) {\n\t\tconst { requestId, group, timescale, unsubscribed } = options;\n\t\ttry {\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\tcancel: unsubscribed,\n\t\t\t\tversion: this.#session.version,\n\t\t\t\twaitUntilAvailable: false,\n\t\t\t});\n\t\t\tif (!stream) {\n\t\t\t\tgroup.close(new Error(\"no stream slot\"));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst header = new GroupMessage({\n\t\t\t\ttrackAlias: requestId,\n\t\t\t\tgroupId: group.sequence,\n\t\t\t\tsubGroupId: 0,\n\t\t\t\tpublisherPriority: 0,\n\t\t\t\tflags: {\n\t\t\t\t\thasExtensions: true,\n\t\t\t\t\thasSubgroup: false,\n\t\t\t\t\thasSubgroupObject: false,\n\t\t\t\t\thasEnd: true,\n\t\t\t\t\thasPriority: true,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tawait header.encode(stream, this.#session.version);\n\n\t\t\ttry {\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst frame = await Promise.race([group.readFrame(), stream.closed]);\n\t\t\t\t\tif (!frame) break;\n\n\t\t\t\t\tconst obj = new Frame({ payload: frame.payload, timestamp: frame.timestamp });\n\t\t\t\t\tawait obj.encode(stream, header.flags, timescale, this.#session.version);\n\t\t\t\t}\n\n\t\t\t\tstream.close();\n\t\t\t} catch (err: unknown) {\n\t\t\t\tstream.reset(error(err));\n\t\t\t}\n\t\t} finally {\n\t\t\tgroup.close();\n\t\t}\n\t}\n\n\t/**\n\t * Handles an incoming SUBSCRIBE_NAMESPACE on a bidi stream.\n\t *\n\t * This carries the advertisements only when the peer asked to be told on request\n\t * (MoQ Solicit); otherwise {@link runPublishNamespaces} has already announced\n\t * everything and repeating it here would leave the peer holding two sources for one\n\t * broadcast. Draft-16+ streams Namespace entries inline; draft-14/15 predate those\n\t * messages, so each advertisement is a PUBLISH_NAMESPACE request of its own.\n\t *\n\t * @internal\n\t */\n\tasync runSubscribeNamespace(msg: SubscribeNamespace, stream: Stream) {\n\t\tconst version = this.#session.version;\n\t\tconst prefix = msg.namespace;\n\t\tconst legacy = version === Version.DRAFT_14 || version === Version.DRAFT_15;\n\n\t\t// Draft-14/15: the open PUBLISH_NAMESPACE request per advertised suffix.\n\t\tconst requests = new Map<Path.Valid, { path: Path.Valid; requestId: bigint; stream: Stream }>();\n\n\t\ttry {\n\t\t\t// Send OK response\n\t\t\tif (version === Version.DRAFT_14) {\n\t\t\t\tawait stream.writer.u53(SubscribeNamespaceOk.id);\n\t\t\t\tconst ok = new SubscribeNamespaceOk({ requestId: msg.requestId });\n\t\t\t\tawait ok.encode(stream.writer, version);\n\t\t\t} else {\n\t\t\t\tawait stream.writer.u53(RequestOk.id);\n\t\t\t\tconst ok = new RequestOk({\n\t\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t\t});\n\t\t\t\tawait ok.encode(stream.writer, version);\n\t\t\t}\n\n\t\t\tif (!this.#requiresSolicitation) {\n\t\t\t\t// Already announced, unasked. Hold the stream open until the peer is done.\n\t\t\t\tawait stream.reader.closed;\n\t\t\t\tstream.close();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Reports whether the peer now holds the namespace: an inline entry always\n\t\t\t// lands, but a PUBLISH_NAMESPACE request can be declined.\n\t\t\tconst advertise = async (suffix: Path.Valid): Promise<boolean> => {\n\t\t\t\tif (legacy) {\n\t\t\t\t\treturn await this.#advertise(Path.join(prefix, suffix), requests, refused);\n\t\t\t\t}\n\n\t\t\t\tawait stream.writer.u53(SubscribeNamespaceEntry.id);\n\t\t\t\tawait new SubscribeNamespaceEntry({ suffix, cluster: this.#advert }).encode(stream.writer, version);\n\t\t\t\treturn true;\n\t\t\t};\n\t\t\tconst withdraw = async (suffix: Path.Valid) => {\n\t\t\t\tif (legacy) {\n\t\t\t\t\tawait this.#withdraw(Path.join(prefix, suffix), requests);\n\t\t\t\t} else {\n\t\t\t\t\tawait stream.writer.u53(SubscribeNamespaceEntryDone.id);\n\t\t\t\t\tawait new SubscribeNamespaceEntryDone({ suffix }).encode(stream.writer, version);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tlet active = new Set<Path.Valid>();\n\t\t\tlet retry = 0;\n\t\t\t// What the peer refused, and whether coming back is worth anything.\n\t\t\tconst refused = new Map<Path.Valid, Refused>();\n\n\t\t\tfor (;;) {\n\t\t\t\t// Subscribe BEFORE reconciling, for the same reason as\n\t\t\t\t// {@link runPublishNamespaces}: a publish landing while an advertisement\n\t\t\t\t// waits for its reply only notifies listeners already registered.\n\t\t\t\t// TODO Make a better helper within Signals.\n\t\t\t\tlet dispose!: Dispose;\n\t\t\t\tconst changed = new Promise<Map<Path.Valid, broadcast.Producer> | undefined>((resolve) => {\n\t\t\t\t\tdispose = this.#broadcasts.changed(resolve);\n\t\t\t\t});\n\n\t\t\t\tconst broadcasts = this.#broadcasts.peek();\n\t\t\t\tif (!broadcasts) {\n\t\t\t\t\tdispose();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst updated = new Set<Path.Valid>();\n\t\t\t\tfor (const name of broadcasts.keys()) {\n\t\t\t\t\tconst suffix = Path.stripPrefix(prefix, name);\n\t\t\t\t\tif (suffix === null) continue;\n\t\t\t\t\tupdated.add(suffix);\n\t\t\t\t}\n\n\t\t\t\t// A namespace that is gone takes its refusal with it, so re-announcing the\n\t\t\t\t// path offers it again.\n\t\t\t\tconst live = new Set<Path.Valid>([...updated].map((suffix) => Path.join(prefix, suffix)));\n\t\t\t\tfor (const path of [...refused.keys()]) {\n\t\t\t\t\tif (!live.has(path)) refused.delete(path);\n\t\t\t\t}\n\n\t\t\t\t// Track what the peer holds rather than what we attempted: a declined\n\t\t\t\t// advertisement stays out of `held`, so the next turn retries it instead of\n\t\t\t\t// believing the namespace is already up.\n\t\t\t\tconst held = new Set<Path.Valid>(active);\n\t\t\t\tfor (const added of updated.difference(active)) {\n\t\t\t\t\tif (this.#offerable(Path.join(prefix, added), refused)) {\n\t\t\t\t\t\tif (await advertise(added)) held.add(added);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const removed of active.difference(updated)) {\n\t\t\t\t\tawait withdraw(removed);\n\t\t\t\t\theld.delete(removed);\n\t\t\t\t}\n\n\t\t\t\tactive = held;\n\n\t\t\t\t// Whatever we wanted up and could not get up, as {@link runPublishNamespaces}\n\t\t\t\t// does: only a legacy request can be declined, and nothing about the peer\n\t\t\t\t// starting to answer raises a signal this loop is watching.\n\t\t\t\tconst outstanding = [...updated.difference(active)].some((suffix) =>\n\t\t\t\t\tthis.#pending(Path.join(prefix, suffix), refused),\n\t\t\t\t);\n\t\t\t\tretry = outstanding ? Math.min(retry ? retry * 2 : RETRY_BASE, RETRY_MAX) : 0;\n\n\t\t\t\t// Wait for the next change, or for the peer to unsubscribe.\n\t\t\t\tconst next = await (retry\n\t\t\t\t\t? Promise.race([changed, stream.reader.closed, retryAfter(retry).then(() => broadcasts)])\n\t\t\t\t\t: Promise.race([changed, stream.reader.closed]));\n\t\t\t\tdispose();\n\t\t\t\tif (!next) break;\n\t\t\t}\n\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.debug(`subscribe_namespace stream error: ${reason(e)}`);\n\t\t\tstream.abort(e);\n\t\t} finally {\n\t\t\t// This subscription's advertisements die with it.\n\t\t\tfor (const path of [...requests.keys()]) {\n\t\t\t\tawait this.#withdraw(path, requests);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Advertise every published broadcast with an unsolicited PUBLISH_NAMESPACE, until\n\t * the publisher is closed.\n\t *\n\t * The peers that never send SUBSCRIBE_NAMESPACE are exactly the ones expecting a\n\t * publisher to announce itself, so announcing is the default. A peer that would\n\t * rather ask says so in its SETUP (MoQ Solicit) and this does nothing, leaving\n\t * {@link runSubscribeNamespace} to carry the advertisements instead. Exactly one of\n\t * the two is live, so the peer never hears a namespace twice.\n\t *\n\t * @internal\n\t */\n\tasync runPublishNamespaces() {\n\t\tif (this.#requiresSolicitation) {\n\t\t\t// The peer asked to be told on request; runSubscribeNamespace answers it.\n\t\t\treturn;\n\t\t}\n\n\t\t// The open PUBLISH_NAMESPACE request per advertised path.\n\t\tconst requests = new Map<Path.Valid, { path: Path.Valid; requestId: bigint; stream: Stream }>();\n\n\t\ttry {\n\t\t\tlet active = new Set<Path.Valid>();\n\t\t\tlet retry = 0;\n\t\t\t// What the peer refused, and whether coming back is worth anything.\n\t\t\tconst refused = new Map<Path.Valid, Refused>();\n\n\t\t\tfor (;;) {\n\t\t\t\t// Subscribe BEFORE reconciling. Each advertisement below waits a round trip\n\t\t\t\t// for the peer's reply, and a publish that lands in that window notifies\n\t\t\t\t// only the listeners already registered; one created afterwards would sleep\n\t\t\t\t// through it and leave the namespace unadvertised until something unrelated\n\t\t\t\t// changed.\n\t\t\t\t// TODO Make a better helper within Signals.\n\t\t\t\tlet dispose!: Dispose;\n\t\t\t\tconst changed = new Promise<Map<Path.Valid, broadcast.Producer> | undefined>((resolve) => {\n\t\t\t\t\tdispose = this.#broadcasts.changed(resolve);\n\t\t\t\t});\n\n\t\t\t\tconst broadcasts = this.#broadcasts.peek();\n\t\t\t\tif (!broadcasts) {\n\t\t\t\t\tdispose();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst updated = new Set<Path.Valid>(broadcasts.keys());\n\n\t\t\t\t// A namespace that is gone takes its refusal with it, so re-announcing the\n\t\t\t\t// path offers it again. Rust gets this by rebuilding the watched entry.\n\t\t\t\tfor (const path of [...refused.keys()]) {\n\t\t\t\t\tif (!updated.has(path)) refused.delete(path);\n\t\t\t\t}\n\n\t\t\t\tfor (const added of updated.difference(active)) {\n\t\t\t\t\tif (this.#offerable(added, refused)) {\n\t\t\t\t\t\tawait this.#advertise(added, requests, refused);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const removed of active.difference(updated)) {\n\t\t\t\t\tawait this.#withdraw(removed, requests);\n\t\t\t\t}\n\n\t\t\t\t// What the peer holds, not what we attempted: a declined PUBLISH_NAMESPACE\n\t\t\t\t// leaves no request behind, so it stays outstanding below.\n\t\t\t\tactive = new Set<Path.Valid>(requests.keys());\n\n\t\t\t\t// Whatever we wanted up and could not get up. Stream credit freeing, a\n\t\t\t\t// transient failure clearing, or the peer starting to answer raises no\n\t\t\t\t// signal of its own, so the only way back is to ask again on a timer.\n\t\t\t\tconst outstanding = [...updated.difference(active)].some((path) => this.#pending(path, refused));\n\t\t\t\tretry = outstanding ? Math.min(retry ? retry * 2 : RETRY_BASE, RETRY_MAX) : 0;\n\n\t\t\t\t// Wait for the next change, which has already fired if one landed above.\n\t\t\t\tconst next = await (retry\n\t\t\t\t\t? Promise.race([changed, retryAfter(retry).then(() => broadcasts)])\n\t\t\t\t\t: changed);\n\t\t\t\tdispose();\n\t\t\t\tif (!next) break;\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\t// Nothing restarts this loop, so whatever got us here cost the session its\n\t\t\t// discovery. Not a debug-level event.\n\t\t\tconsole.warn(`publish_namespace loop failed: ${reason(error(err))}`);\n\t\t} finally {\n\t\t\t// Close out every open PUBLISH_NAMESPACE request.\n\t\t\tfor (const path of [...requests.keys()]) {\n\t\t\t\tawait this.#withdraw(path, requests);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Whether a namespace may be offered to the peer right now.\n\t *\n\t * A peer that asked never to be offered it again means it, whatever brought us back;\n\t * one that named a minimum wait gets it, even when our own backoff comes round sooner.\n\t */\n\t#offerable(path: Path.Valid, refused: Map<Path.Valid, Refused>): boolean {\n\t\tconst entry = refused.get(path);\n\t\tif (entry === undefined) return true;\n\t\treturn entry !== \"never\" && Date.now() >= entry;\n\t}\n\n\t/**\n\t * Whether the loop should keep coming back to a namespace the peer does not hold.\n\t *\n\t * Distinct from {@link offerable}, and the difference is what arms the retry: a\n\t * namespace waiting out a minimum is not offerable yet but is still pending, and\n\t * gating the timer on offerable instead would disarm it for exactly the wait it is\n\t * supposed to be counting. Only a refusal that forbids retrying ends it.\n\t */\n\t#pending(path: Path.Valid, refused: Map<Path.Valid, Refused>): boolean {\n\t\treturn refused.get(path) !== \"never\";\n\t}\n\n\t/**\n\t * Advertise one namespace on its own PUBLISH_NAMESPACE request. A declined request\n\t * is logged and skipped: a peer that wants none of this rejects each one and stays\n\t * connected.\n\t *\n\t * `refused` records what a refusal said about coming back, so a peer that asked not to\n\t * be offered a namespace again is not re-offered it by the retry above.\n\t */\n\tasync #advertise(\n\t\tpath: Path.Valid,\n\t\trequests: Map<Path.Valid, { path: Path.Valid; requestId: bigint; stream: Stream }>,\n\t\trefused: Map<Path.Valid, Refused>,\n\t): Promise<boolean> {\n\t\tconst requestId = await this.#session.nextRequestId();\n\t\tif (requestId === undefined) return false;\n\n\t\t// Opening is inside the try because it fails like any other advertisement does:\n\t\t// a peer out of stream credit rejects here, and letting that escape would unwind\n\t\t// the announce loop and take discovery down for the whole session, rather than\n\t\t// costing this one namespace a turn.\n\t\tlet request: Stream | undefined;\n\t\ttry {\n\t\t\trequest = await this.#session.openBi();\n\t\t\tconst stream = request;\n\n\t\t\t// Bounded, like the subscriber's own request: the loop is single-threaded over\n\t\t\t// advertisements, so a peer that takes the stream and answers nothing strands\n\t\t\t// every publish and withdrawal behind it. Timing out costs this namespace a\n\t\t\t// turn and leaves it outstanding, which the retry above re-offers.\n\t\t\tawait withTimeout(\n\t\t\t\t(async () => {\n\t\t\t\t\tawait stream.writer.u53(PublishNamespace.id);\n\t\t\t\t\tconst msg = new PublishNamespace({ requestId, trackNamespace: path, cluster: this.#advert });\n\t\t\t\t\tawait msg.encode(stream.writer, this.#session.version);\n\n\t\t\t\t\t// Read response (RequestOk and PublishNamespaceOk share 0x07)\n\t\t\t\t\tconst respTypeId = await stream.reader.u53();\n\t\t\t\t\tif (respTypeId === RequestError.id) {\n\t\t\t\t\t\t// The peer named how long to stay away, in milliseconds. Draft-14/15\n\t\t\t\t\t\t// carry no such field, so a 0 there says nothing and our own backoff\n\t\t\t\t\t\t// stands; everywhere else 0 means it does not want this again.\n\t\t\t\t\t\tconst err = await RequestError.decode(stream.reader, this.#session.version);\n\t\t\t\t\t\tconst legacy =\n\t\t\t\t\t\t\tthis.#session.version === Version.DRAFT_14 || this.#session.version === Version.DRAFT_15;\n\t\t\t\t\t\tif (!legacy) {\n\t\t\t\t\t\t\trefused.set(\n\t\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\t\terr.retryInterval === 0n ? \"never\" : Date.now() + Number(err.retryInterval),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow new Error(`PublishNamespace rejected: ${err.errorCode} ${err.reasonPhrase}`);\n\t\t\t\t\t}\n\t\t\t\t\tif (respTypeId !== RequestOk.id) {\n\t\t\t\t\t\tthrow new Error(`PublishNamespace rejected: typeId=0x${respTypeId.toString(16)}`);\n\t\t\t\t\t}\n\t\t\t\t\t// Draft-14 sends PublishNamespaceOk (requestId only, no parameters)\n\t\t\t\t\tif (this.#session.version === Version.DRAFT_14) {\n\t\t\t\t\t\tawait PublishNamespaceOk.decode(stream.reader, this.#session.version);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tawait RequestOk.decode(stream.reader, this.#session.version);\n\t\t\t\t\t}\n\t\t\t\t})(),\n\t\t\t\tADVERTISE_TIMEOUT_MS,\n\t\t\t\t`advertisement timed out after ${ADVERTISE_TIMEOUT_MS}ms waiting for the peer's answer`,\n\t\t\t);\n\n\t\t\trequests.set(path, { path, requestId, stream: request });\n\t\t\treturn true;\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(`announce failed: broadcast=${path} error=${reason(e)}`);\n\t\t\trequest?.abort(e);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Close out a namespace's PUBLISH_NAMESPACE request with PUBLISH_NAMESPACE_DONE.\n\t */\n\tasync #withdraw(\n\t\tpath: Path.Valid,\n\t\trequests: Map<Path.Valid, { path: Path.Valid; requestId: bigint; stream: Stream }>,\n\t) {\n\t\tconst request = requests.get(path);\n\t\tif (!request) return;\n\t\trequests.delete(path);\n\n\t\t// Draft-17+ removed PUBLISH_NAMESPACE_DONE: the close below is the whole\n\t\t// withdrawal. Sending it anyway puts the type on the wire before the body throws,\n\t\t// and a receiver reading 0x09 there has no choice but to treat it as a protocol\n\t\t// violation.\n\t\tconst version = this.#session.version;\n\t\tif (version === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16) {\n\t\t\ttry {\n\t\t\t\tawait request.stream.writer.u53(PublishNamespaceDone.id);\n\t\t\t\tconst done = new PublishNamespaceDone({ trackNamespace: request.path, requestId: request.requestId });\n\t\t\t\tawait done.encode(request.stream.writer, version);\n\t\t\t} catch {\n\t\t\t\t// Stream might already be closed\n\t\t\t}\n\t\t}\n\t\trequest.stream.close();\n\t}\n\n\t/**\n\t * Handles an incoming TRACK_STATUS_REQUEST on a bidi stream.\n\t *\n\t * @internal\n\t */\n\tasync runTrackStatusRequest(msg: TrackStatusRequest, stream: Stream) {\n\t\tconst version = this.#session.version;\n\n\t\tif (version === Version.DRAFT_14) {\n\t\t\t// v14: respond with TrackStatus (0x0E = TRACK_STATUS_OK)\n\t\t\tawait stream.writer.u53(TrackStatus.id);\n\t\t\tconst status = new TrackStatus({\n\t\t\t\ttrackNamespace: msg.trackNamespace,\n\t\t\t\ttrackName: msg.trackName,\n\t\t\t\tstatusCode: TrackStatus.STATUS_NOT_FOUND,\n\t\t\t\tlastGroupId: 0n,\n\t\t\t\tlastObjectId: 0n,\n\t\t\t});\n\t\t\tawait status.encode(stream.writer, version);\n\t\t} else {\n\t\t\t// v15+: respond with RequestOk (0x07)\n\t\t\tawait stream.writer.u53(RequestOk.id);\n\t\t\tconst ok = new RequestOk({\n\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t});\n\t\t\tawait ok.encode(stream.writer, version);\n\t\t}\n\t\tstream.close();\n\t}\n\n\t/**\n\t * Closes every published broadcast and stops accepting new ones.\n\t *\n\t * @internal\n\t */\n\tclose() {\n\t\tthis.#broadcasts.update((broadcasts) => {\n\t\t\tfor (const broadcast of broadcasts?.values() ?? []) {\n\t\t\t\tbroadcast.close();\n\t\t\t}\n\t\t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;gBAC9B,cAAc,EAAE,GAAG,CAAC,cAAc;gBAClC,SAAS,EAAE,GAAG,CAAC,SAAS;gBACxB,UAAU,EAAE,WAAW,CAAC,gBAAgB;gBACxC,WAAW,EAAE,EAAE;gBACf,YAAY,EAAE,EAAE;aAChB,CAAC,CAAC;YACH,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7C,CAAC;aAAM,CAAC;YACP,sCAAsC;YACtC,MAAM,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;YACtC,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC;gBACxB,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;aACnG,CAAC,CAAC;YACH,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACzC,CAAC;QACD,MAAM,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,KAAK;QACJ,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;YACtC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;gBACpD,SAAS,CAAC,KAAK,EAAE,CAAC;YACnB,CAAC;YACD,OAAO,SAAS,CAAC;QAClB,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import { type Dispose, Signal } from \"@moq/signals\";\nimport type * as broadcast from \"../broadcast.ts\";\nimport { error, reason } from \"../error.ts\";\nimport type * as group from \"../group.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Stream, Writer } from \"../stream.ts\";\nimport type { Timescale } from \"../time.ts\";\nimport { withTimeout } from \"../util/timeout.ts\";\nimport type { Session } from \"./adapter.ts\";\nimport * as Cluster from \"./cluster.ts\";\nimport { Frame, Group as GroupMessage } from \"./object.ts\";\nimport { fromWire } from \"./priority.ts\";\nimport { PublishDone } from \"./publish.ts\";\nimport { PublishNamespace, PublishNamespaceDone, PublishNamespaceOk } from \"./publish_namespace.ts\";\nimport { RequestError, RequestOk } from \"./request.ts\";\nimport { type Subscribe, SubscribeError, SubscribeOk } from \"./subscribe.ts\";\nimport {\n\ttype SubscribeNamespace,\n\tSubscribeNamespaceEntry,\n\tSubscribeNamespaceEntryDone,\n\tSubscribeNamespaceOk,\n} from \"./subscribe_namespace.ts\";\nimport { TrackStatus, type TrackStatusRequest } from \"./track.ts\";\nimport { Version } from \"./version.ts\";\n\n/** First wait before re-offering a namespace the peer refused or we couldn't open for. */\nconst RETRY_BASE = 100;\n\n/** Ceiling on that wait. The loop retries for the life of the session, so it must not spin. */\nconst RETRY_MAX = 5000;\n\n/**\n * How long one advertisement may take to be answered. Matches the Rust publisher, and the\n * peer accepting the stream is only half the exchange: one it never answers on holds the\n * loop just as effectively as one it never grants.\n */\nconst ADVERTISE_TIMEOUT_MS = 5000;\n\n/** Sleep `delay`, jittered, so a relay's namespaces don't all retry on the same tick. */\nfunction retryAfter(delay: number): Promise<void> {\n\treturn new Promise((resolve) => setTimeout(resolve, delay * (0.5 + Math.random() / 2)));\n}\n\n/**\n * What a refusal said about re-offering the namespace.\n *\n * A peer answers a request it declines with a retry interval, and ignoring it is how a\n * permanent refusal (unauthorized, uninterested) turns into a request every few seconds\n * for the life of the session. `\"never\"` is an interval of 0; a number is the epoch\n * milliseconds before which we must not come back.\n */\ntype Refused = \"never\" | number;\n\n/** What {@link Publisher.runGroup} needs to serve one group. */\ninterface RunGroup {\n\t/** The subscription's request ID, doubling as the track alias. */\n\trequestId: 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/** Settles when the subscriber leaves, dropping a group still queued for a stream slot. */\n\tunsubscribed: Promise<void>;\n}\n\n/**\n * Handles publishing broadcasts using moq-transport protocol.\n * Uses the stream-per-request pattern (real bidi streams for v17, virtual for v14-v16).\n *\n * @internal\n */\nexport class Publisher {\n\t#quic: WebTransport;\n\t#session: Session;\n\t#requiresSolicitation: boolean;\n\n\t// What every advertisement carries on a session that negotiated the MoQ Cluster\n\t// extension: a hop path holding our own id, so the peer can tell that what it hears\n\t// back came from us. `undefined` when nothing negotiated it.\n\t#advert?: Cluster.Advert;\n\n\t// Our published broadcasts.\n\t// It's a signal so we can live update any subscribe_namespace streams.\n\t#broadcasts = new Signal<Map<Path.Valid, broadcast.Producer> | undefined>(new Map());\n\n\t/**\n\t * Creates a new Publisher instance.\n\t *\n\t * @internal\n\t */\n\tconstructor({\n\t\tquic,\n\t\tsession,\n\t\trequiresSolicitation,\n\t\tcluster,\n\t}: {\n\t\t/** The WebTransport session, for uni streams. */\n\t\tquic: WebTransport;\n\t\t/** The session abstraction for bidi streams and request IDs. */\n\t\tsession: Session;\n\t\t/** Whether the peer's SETUP asked to be told on request (MoQ Solicit). */\n\t\trequiresSolicitation: boolean;\n\t\t/** The Hop IDs the SETUP exchange settled (MoQ Cluster). */\n\t\tcluster?: Cluster.Hops;\n\t}) {\n\t\tthis.#quic = quic;\n\t\tthis.#session = session;\n\t\tthis.#requiresSolicitation = requiresSolicitation;\n\t\tthis.#advert = Cluster.advertise(cluster);\n\t}\n\n\t/**\n\t * Publishes a broadcast with any associated tracks.\n\t * The namespace is advertised with an unsolicited PUBLISH_NAMESPACE, or on request\n\t * if the peer asked for that (see {@link runPublishNamespaces}).\n\t */\n\tpublish(path: Path.Valid, broadcast: broadcast.Producer) {\n\t\tthis.#broadcasts.mutate((broadcasts) => {\n\t\t\tif (!broadcasts) throw new Error(\"closed\");\n\t\t\tbroadcasts.set(path, broadcast);\n\t\t});\n\n\t\t// Remove the broadcast from the lookup when it's closed, unless the path was republished.\n\t\tvoid broadcast.closed.then(() => {\n\t\t\tthis.#broadcasts.mutate((broadcasts) => {\n\t\t\t\tif (broadcasts?.get(path) === broadcast) {\n\t\t\t\t\tbroadcasts.delete(path);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Handles an incoming SUBSCRIBE request on a bidi stream.\n\t * Owns the full lifecycle: sends response, serves track data, waits for close.\n\t *\n\t * @internal\n\t */\n\tasync runSubscribe(msg: Subscribe, stream: Stream) {\n\t\tconst version = this.#session.version;\n\t\tconst name = msg.trackNamespace;\n\t\tconst broadcast = this.#broadcasts.peek()?.get(name);\n\n\t\tif (!broadcast) {\n\t\t\t// Write error response\n\t\t\tif (version === Version.DRAFT_14) {\n\t\t\t\tawait stream.writer.u53(SubscribeError.id);\n\t\t\t\tconst err = new SubscribeError({\n\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\terrorCode: 404,\n\t\t\t\t\treasonPhrase: \"Broadcast not found\",\n\t\t\t\t});\n\t\t\t\tawait err.encode(stream.writer, version);\n\t\t\t} else {\n\t\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\t\tconst err = new RequestError({\n\t\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t\t\terrorCode: 404,\n\t\t\t\t\treasonPhrase: \"Broadcast not found\",\n\t\t\t\t});\n\t\t\t\tawait err.encode(stream.writer, version);\n\t\t\t}\n\t\t\tstream.close();\n\t\t\treturn;\n\t\t}\n\n\t\tconst track = broadcast.subscribe(msg.trackName, { priority: fromWire(msg.subscriberPriority) });\n\n\t\ttry {\n\t\t\t// Declaring the timescale is what opts the track into timestamps; every object\n\t\t\t// Timestamp below is in these units.\n\t\t\tconst timescale = (await track.info()).timescale;\n\n\t\t\t// Send SUBSCRIBE_OK\n\t\t\tawait stream.writer.u53(SubscribeOk.id);\n\t\t\tconst ok = new SubscribeOk({\n\t\t\t\trequestId:\n\t\t\t\t\tversion === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16\n\t\t\t\t\t\t? msg.requestId\n\t\t\t\t\t\t: undefined,\n\t\t\t\ttrackAlias: msg.requestId,\n\t\t\t\ttimescale,\n\t\t\t});\n\t\t\tawait ok.encode(stream.writer, version);\n\t\t\tconsole.debug(`publish ok: broadcast=${name} track=${track.name}`);\n\n\t\t\t// Cancels groups still queued for a stream slot. Only the subscriber leaving counts:\n\t\t\t// a track that ran out of groups still has to flush the ones already queued, and we\n\t\t\t// close the stream ourselves below to say so.\n\t\t\tlet finished = false;\n\t\t\tlet unsubscribe!: () => void;\n\t\t\tconst unsubscribed = new Promise<void>((resolve) => {\n\t\t\t\tunsubscribe = resolve;\n\t\t\t});\n\t\t\tvoid stream.reader.closed.then(\n\t\t\t\t() => {\n\t\t\t\t\tif (!finished) unsubscribe();\n\t\t\t\t},\n\t\t\t\t// A reset is always the peer.\n\t\t\t\t() => unsubscribe(),\n\t\t\t);\n\n\t\t\t// Serve track groups, racing with stream close (= Unsubscribe)\n\t\t\tconst serving = (async () => {\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst group = await track.recvGroup();\n\t\t\t\t\tif (!group) return;\n\t\t\t\t\tvoid this.#runGroup({ requestId: msg.requestId, group, timescale, unsubscribed });\n\t\t\t\t}\n\t\t\t})();\n\n\t\t\tawait Promise.race([serving, stream.reader.closed]);\n\n\t\t\tconsole.debug(`publish done: broadcast=${name} track=${track.name}`);\n\n\t\t\t// v14-v16: send PublishDone before closing\n\t\t\tif (version === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16) {\n\t\t\t\ttry {\n\t\t\t\t\tawait stream.writer.u53(PublishDone.id);\n\t\t\t\t\tconst done = new PublishDone({\n\t\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\t\tstatusCode: 200,\n\t\t\t\t\t\treasonPhrase: \"OK\",\n\t\t\t\t\t});\n\t\t\t\t\tawait done.encode(stream.writer, version);\n\t\t\t\t} catch {\n\t\t\t\t\t// Stream might already be closed by peer\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Only now is the close below ours. Claiming it any earlier would read a peer FIN\n\t\t\t// that lands while PublishDone is still going out as our own completion, leaving\n\t\t\t// queued groups to open for a subscriber that has already left.\n\t\t\tfinished = true;\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(`publish error: broadcast=${name} track=${track.name} error=${reason(e)}`);\n\t\t\tstream.abort(e);\n\t\t} finally {\n\t\t\ttrack.close();\n\t\t}\n\t}\n\n\t/**\n\t * Runs a group and sends its frames using ObjectStream (Subgroup delivery mode).\n\t */\n\tasync #runGroup(options: RunGroup) {\n\t\tconst { requestId, group, timescale, unsubscribed } = options;\n\t\ttry {\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\tcancel: unsubscribed,\n\t\t\t\tversion: this.#session.version,\n\t\t\t\twaitUntilAvailable: false,\n\t\t\t});\n\t\t\tif (!stream) {\n\t\t\t\tgroup.close(new Error(\"no stream slot\"));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst header = new GroupMessage({\n\t\t\t\ttrackAlias: requestId,\n\t\t\t\tgroupId: group.sequence,\n\t\t\t\tsubGroupId: 0,\n\t\t\t\tpublisherPriority: 0,\n\t\t\t\tflags: {\n\t\t\t\t\thasExtensions: true,\n\t\t\t\t\thasSubgroup: false,\n\t\t\t\t\thasSubgroupObject: false,\n\t\t\t\t\thasEnd: true,\n\t\t\t\t\thasPriority: true,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tawait header.encode(stream, this.#session.version);\n\n\t\t\ttry {\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst frame = await Promise.race([group.readFrame(), stream.closed]);\n\t\t\t\t\tif (!frame) break;\n\n\t\t\t\t\tconst obj = new Frame({ payload: frame.payload, timestamp: frame.timestamp });\n\t\t\t\t\tawait obj.encode(stream, header.flags, timescale, this.#session.version);\n\t\t\t\t}\n\n\t\t\t\tstream.close();\n\t\t\t} catch (err: unknown) {\n\t\t\t\tstream.reset(error(err));\n\t\t\t}\n\t\t} finally {\n\t\t\tgroup.close();\n\t\t}\n\t}\n\n\t/**\n\t * Handles an incoming SUBSCRIBE_NAMESPACE on a bidi stream.\n\t *\n\t * This carries the advertisements only when the peer asked to be told on request\n\t * (MoQ Solicit); otherwise {@link runPublishNamespaces} has already announced\n\t * everything and repeating it here would leave the peer holding two sources for one\n\t * broadcast. Draft-16+ streams Namespace entries inline; draft-14/15 predate those\n\t * messages, so each advertisement is a PUBLISH_NAMESPACE request of its own.\n\t *\n\t * @internal\n\t */\n\tasync runSubscribeNamespace(msg: SubscribeNamespace, stream: Stream) {\n\t\tconst version = this.#session.version;\n\t\tconst prefix = msg.namespace;\n\t\tconst legacy = version === Version.DRAFT_14 || version === Version.DRAFT_15;\n\n\t\t// Draft-14/15: the open PUBLISH_NAMESPACE request per advertised suffix.\n\t\tconst requests = new Map<Path.Valid, { path: Path.Valid; requestId: bigint; stream: Stream }>();\n\n\t\ttry {\n\t\t\t// Send OK response\n\t\t\tif (version === Version.DRAFT_14) {\n\t\t\t\tawait stream.writer.u53(SubscribeNamespaceOk.id);\n\t\t\t\tconst ok = new SubscribeNamespaceOk({ requestId: msg.requestId });\n\t\t\t\tawait ok.encode(stream.writer, version);\n\t\t\t} else {\n\t\t\t\tawait stream.writer.u53(RequestOk.id);\n\t\t\t\tconst ok = new RequestOk({\n\t\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t\t});\n\t\t\t\tawait ok.encode(stream.writer, version);\n\t\t\t}\n\n\t\t\tif (!this.#requiresSolicitation) {\n\t\t\t\t// Already announced, unasked. Hold the stream open until the peer is done.\n\t\t\t\tawait stream.reader.closed;\n\t\t\t\tstream.close();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Reports whether the peer now holds the namespace: an inline entry always\n\t\t\t// lands, but a PUBLISH_NAMESPACE request can be declined.\n\t\t\tconst advertise = async (suffix: Path.Valid): Promise<boolean> => {\n\t\t\t\tif (legacy) {\n\t\t\t\t\treturn await this.#advertise(Path.join(prefix, suffix), requests, refused);\n\t\t\t\t}\n\n\t\t\t\tawait stream.writer.u53(SubscribeNamespaceEntry.id);\n\t\t\t\tawait new SubscribeNamespaceEntry({ suffix, cluster: this.#advert }).encode(stream.writer, version);\n\t\t\t\treturn true;\n\t\t\t};\n\t\t\tconst withdraw = async (suffix: Path.Valid) => {\n\t\t\t\tif (legacy) {\n\t\t\t\t\tawait this.#withdraw(Path.join(prefix, suffix), requests);\n\t\t\t\t} else {\n\t\t\t\t\tawait stream.writer.u53(SubscribeNamespaceEntryDone.id);\n\t\t\t\t\tawait new SubscribeNamespaceEntryDone({ suffix }).encode(stream.writer, version);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tlet active = new Set<Path.Valid>();\n\t\t\tlet retry = 0;\n\t\t\t// What the peer refused, and whether coming back is worth anything.\n\t\t\tconst refused = new Map<Path.Valid, Refused>();\n\n\t\t\tfor (;;) {\n\t\t\t\t// Subscribe BEFORE reconciling, for the same reason as\n\t\t\t\t// {@link runPublishNamespaces}: a publish landing while an advertisement\n\t\t\t\t// waits for its reply only notifies listeners already registered.\n\t\t\t\t// TODO Make a better helper within Signals.\n\t\t\t\tlet dispose!: Dispose;\n\t\t\t\tconst changed = new Promise<Map<Path.Valid, broadcast.Producer> | undefined>((resolve) => {\n\t\t\t\t\tdispose = this.#broadcasts.changed(resolve);\n\t\t\t\t});\n\n\t\t\t\tconst broadcasts = this.#broadcasts.peek();\n\t\t\t\tif (!broadcasts) {\n\t\t\t\t\tdispose();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst updated = new Set<Path.Valid>();\n\t\t\t\tfor (const name of broadcasts.keys()) {\n\t\t\t\t\tconst suffix = Path.stripPrefix(prefix, name);\n\t\t\t\t\tif (suffix === null) continue;\n\t\t\t\t\tupdated.add(suffix);\n\t\t\t\t}\n\n\t\t\t\t// A namespace that is gone takes its refusal with it, so re-announcing the\n\t\t\t\t// path offers it again.\n\t\t\t\tconst live = new Set<Path.Valid>([...updated].map((suffix) => Path.join(prefix, suffix)));\n\t\t\t\tfor (const path of [...refused.keys()]) {\n\t\t\t\t\tif (!live.has(path)) refused.delete(path);\n\t\t\t\t}\n\n\t\t\t\t// Track what the peer holds rather than what we attempted: a declined\n\t\t\t\t// advertisement stays out of `held`, so the next turn retries it instead of\n\t\t\t\t// believing the namespace is already up.\n\t\t\t\tconst held = new Set<Path.Valid>(active);\n\t\t\t\tfor (const added of updated.difference(active)) {\n\t\t\t\t\tif (this.#offerable(Path.join(prefix, added), refused)) {\n\t\t\t\t\t\tif (await advertise(added)) held.add(added);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const removed of active.difference(updated)) {\n\t\t\t\t\tawait withdraw(removed);\n\t\t\t\t\theld.delete(removed);\n\t\t\t\t}\n\n\t\t\t\tactive = held;\n\n\t\t\t\t// Whatever we wanted up and could not get up, as {@link runPublishNamespaces}\n\t\t\t\t// does: only a legacy request can be declined, and nothing about the peer\n\t\t\t\t// starting to answer raises a signal this loop is watching.\n\t\t\t\tconst outstanding = [...updated.difference(active)].some((suffix) =>\n\t\t\t\t\tthis.#pending(Path.join(prefix, suffix), refused),\n\t\t\t\t);\n\t\t\t\tretry = outstanding ? Math.min(retry ? retry * 2 : RETRY_BASE, RETRY_MAX) : 0;\n\n\t\t\t\t// Wait for the next change, or for the peer to unsubscribe.\n\t\t\t\tconst next = await (retry\n\t\t\t\t\t? Promise.race([changed, stream.reader.closed, retryAfter(retry).then(() => broadcasts)])\n\t\t\t\t\t: Promise.race([changed, stream.reader.closed]));\n\t\t\t\tdispose();\n\t\t\t\tif (!next) break;\n\t\t\t}\n\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.debug(`subscribe_namespace stream error: ${reason(e)}`);\n\t\t\tstream.abort(e);\n\t\t} finally {\n\t\t\t// This subscription's advertisements die with it.\n\t\t\tfor (const path of [...requests.keys()]) {\n\t\t\t\tawait this.#withdraw(path, requests);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Advertise every published broadcast with an unsolicited PUBLISH_NAMESPACE, until\n\t * the publisher is closed.\n\t *\n\t * The peers that never send SUBSCRIBE_NAMESPACE are exactly the ones expecting a\n\t * publisher to announce itself, so announcing is the default. A peer that would\n\t * rather ask says so in its SETUP (MoQ Solicit) and this does nothing, leaving\n\t * {@link runSubscribeNamespace} to carry the advertisements instead. Exactly one of\n\t * the two is live, so the peer never hears a namespace twice.\n\t *\n\t * @internal\n\t */\n\tasync runPublishNamespaces() {\n\t\tif (this.#requiresSolicitation) {\n\t\t\t// The peer asked to be told on request; runSubscribeNamespace answers it.\n\t\t\treturn;\n\t\t}\n\n\t\t// The open PUBLISH_NAMESPACE request per advertised path.\n\t\tconst requests = new Map<Path.Valid, { path: Path.Valid; requestId: bigint; stream: Stream }>();\n\n\t\ttry {\n\t\t\tlet active = new Set<Path.Valid>();\n\t\t\tlet retry = 0;\n\t\t\t// What the peer refused, and whether coming back is worth anything.\n\t\t\tconst refused = new Map<Path.Valid, Refused>();\n\n\t\t\tfor (;;) {\n\t\t\t\t// Subscribe BEFORE reconciling. Each advertisement below waits a round trip\n\t\t\t\t// for the peer's reply, and a publish that lands in that window notifies\n\t\t\t\t// only the listeners already registered; one created afterwards would sleep\n\t\t\t\t// through it and leave the namespace unadvertised until something unrelated\n\t\t\t\t// changed.\n\t\t\t\t// TODO Make a better helper within Signals.\n\t\t\t\tlet dispose!: Dispose;\n\t\t\t\tconst changed = new Promise<Map<Path.Valid, broadcast.Producer> | undefined>((resolve) => {\n\t\t\t\t\tdispose = this.#broadcasts.changed(resolve);\n\t\t\t\t});\n\n\t\t\t\tconst broadcasts = this.#broadcasts.peek();\n\t\t\t\tif (!broadcasts) {\n\t\t\t\t\tdispose();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst updated = new Set<Path.Valid>(broadcasts.keys());\n\n\t\t\t\t// A namespace that is gone takes its refusal with it, so re-announcing the\n\t\t\t\t// path offers it again. Rust gets this by rebuilding the watched entry.\n\t\t\t\tfor (const path of [...refused.keys()]) {\n\t\t\t\t\tif (!updated.has(path)) refused.delete(path);\n\t\t\t\t}\n\n\t\t\t\tfor (const added of updated.difference(active)) {\n\t\t\t\t\tif (this.#offerable(added, refused)) {\n\t\t\t\t\t\tawait this.#advertise(added, requests, refused);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const removed of active.difference(updated)) {\n\t\t\t\t\tawait this.#withdraw(removed, requests);\n\t\t\t\t}\n\n\t\t\t\t// What the peer holds, not what we attempted: a declined PUBLISH_NAMESPACE\n\t\t\t\t// leaves no request behind, so it stays outstanding below.\n\t\t\t\tactive = new Set<Path.Valid>(requests.keys());\n\n\t\t\t\t// Whatever we wanted up and could not get up. Stream credit freeing, a\n\t\t\t\t// transient failure clearing, or the peer starting to answer raises no\n\t\t\t\t// signal of its own, so the only way back is to ask again on a timer.\n\t\t\t\tconst outstanding = [...updated.difference(active)].some((path) => this.#pending(path, refused));\n\t\t\t\tretry = outstanding ? Math.min(retry ? retry * 2 : RETRY_BASE, RETRY_MAX) : 0;\n\n\t\t\t\t// Wait for the next change, which has already fired if one landed above.\n\t\t\t\tconst next = await (retry\n\t\t\t\t\t? Promise.race([changed, retryAfter(retry).then(() => broadcasts)])\n\t\t\t\t\t: changed);\n\t\t\t\tdispose();\n\t\t\t\tif (!next) break;\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\t// Nothing restarts this loop, so whatever got us here cost the session its\n\t\t\t// discovery. Not a debug-level event.\n\t\t\tconsole.warn(`publish_namespace loop failed: ${reason(error(err))}`);\n\t\t} finally {\n\t\t\t// Close out every open PUBLISH_NAMESPACE request.\n\t\t\tfor (const path of [...requests.keys()]) {\n\t\t\t\tawait this.#withdraw(path, requests);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Whether a namespace may be offered to the peer right now.\n\t *\n\t * A peer that asked never to be offered it again means it, whatever brought us back;\n\t * one that named a minimum wait gets it, even when our own backoff comes round sooner.\n\t */\n\t#offerable(path: Path.Valid, refused: Map<Path.Valid, Refused>): boolean {\n\t\tconst entry = refused.get(path);\n\t\tif (entry === undefined) return true;\n\t\treturn entry !== \"never\" && Date.now() >= entry;\n\t}\n\n\t/**\n\t * Whether the loop should keep coming back to a namespace the peer does not hold.\n\t *\n\t * Distinct from {@link offerable}, and the difference is what arms the retry: a\n\t * namespace waiting out a minimum is not offerable yet but is still pending, and\n\t * gating the timer on offerable instead would disarm it for exactly the wait it is\n\t * supposed to be counting. Only a refusal that forbids retrying ends it.\n\t */\n\t#pending(path: Path.Valid, refused: Map<Path.Valid, Refused>): boolean {\n\t\treturn refused.get(path) !== \"never\";\n\t}\n\n\t/**\n\t * Advertise one namespace on its own PUBLISH_NAMESPACE request. A declined request\n\t * is logged and skipped: a peer that wants none of this rejects each one and stays\n\t * connected.\n\t *\n\t * `refused` records what a refusal said about coming back, so a peer that asked not to\n\t * be offered a namespace again is not re-offered it by the retry above.\n\t */\n\tasync #advertise(\n\t\tpath: Path.Valid,\n\t\trequests: Map<Path.Valid, { path: Path.Valid; requestId: bigint; stream: Stream }>,\n\t\trefused: Map<Path.Valid, Refused>,\n\t): Promise<boolean> {\n\t\tconst requestId = await this.#session.nextRequestId();\n\t\tif (requestId === undefined) return false;\n\n\t\t// Opening is inside the try because it fails like any other advertisement does:\n\t\t// a peer out of stream credit rejects here, and letting that escape would unwind\n\t\t// the announce loop and take discovery down for the whole session, rather than\n\t\t// costing this one namespace a turn.\n\t\tlet request: Stream | undefined;\n\t\ttry {\n\t\t\trequest = await this.#session.openBi();\n\t\t\tconst stream = request;\n\n\t\t\t// Bounded, like the subscriber's own request: the loop is single-threaded over\n\t\t\t// advertisements, so a peer that takes the stream and answers nothing strands\n\t\t\t// every publish and withdrawal behind it. Timing out costs this namespace a\n\t\t\t// turn and leaves it outstanding, which the retry above re-offers.\n\t\t\tawait withTimeout(\n\t\t\t\t(async () => {\n\t\t\t\t\tawait stream.writer.u53(PublishNamespace.id);\n\t\t\t\t\tconst msg = new PublishNamespace({ requestId, trackNamespace: path, cluster: this.#advert });\n\t\t\t\t\tawait msg.encode(stream.writer, this.#session.version);\n\n\t\t\t\t\t// Read response (RequestOk and PublishNamespaceOk share 0x07)\n\t\t\t\t\tconst respTypeId = await stream.reader.u53();\n\t\t\t\t\tif (respTypeId === RequestError.id) {\n\t\t\t\t\t\t// The peer named how long to stay away, in milliseconds. Draft-14/15\n\t\t\t\t\t\t// carry no such field, so a 0 there says nothing and our own backoff\n\t\t\t\t\t\t// stands; everywhere else 0 means it does not want this again.\n\t\t\t\t\t\tconst err = await RequestError.decode(stream.reader, this.#session.version);\n\t\t\t\t\t\tconst legacy =\n\t\t\t\t\t\t\tthis.#session.version === Version.DRAFT_14 || this.#session.version === Version.DRAFT_15;\n\t\t\t\t\t\tif (!legacy) {\n\t\t\t\t\t\t\trefused.set(\n\t\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\t\terr.retryInterval === 0n ? \"never\" : Date.now() + Number(err.retryInterval),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow new Error(`PublishNamespace rejected: ${err.errorCode} ${err.reasonPhrase}`);\n\t\t\t\t\t}\n\t\t\t\t\tif (respTypeId !== RequestOk.id) {\n\t\t\t\t\t\tthrow new Error(`PublishNamespace rejected: typeId=0x${respTypeId.toString(16)}`);\n\t\t\t\t\t}\n\t\t\t\t\t// Draft-14 sends PublishNamespaceOk (requestId only, no parameters)\n\t\t\t\t\tif (this.#session.version === Version.DRAFT_14) {\n\t\t\t\t\t\tawait PublishNamespaceOk.decode(stream.reader, this.#session.version);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tawait RequestOk.decode(stream.reader, this.#session.version);\n\t\t\t\t\t}\n\t\t\t\t})(),\n\t\t\t\tADVERTISE_TIMEOUT_MS,\n\t\t\t\t`advertisement timed out after ${ADVERTISE_TIMEOUT_MS}ms waiting for the peer's answer`,\n\t\t\t);\n\n\t\t\trequests.set(path, { path, requestId, stream: request });\n\t\t\treturn true;\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(`announce failed: broadcast=${path} error=${reason(e)}`);\n\t\t\trequest?.abort(e);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Close out a namespace's PUBLISH_NAMESPACE request with PUBLISH_NAMESPACE_DONE.\n\t */\n\tasync #withdraw(\n\t\tpath: Path.Valid,\n\t\trequests: Map<Path.Valid, { path: Path.Valid; requestId: bigint; stream: Stream }>,\n\t) {\n\t\tconst request = requests.get(path);\n\t\tif (!request) return;\n\t\trequests.delete(path);\n\n\t\t// Draft-17+ removed PUBLISH_NAMESPACE_DONE: the close below is the whole\n\t\t// withdrawal. Sending it anyway puts the type on the wire before the body throws,\n\t\t// and a receiver reading 0x09 there has no choice but to treat it as a protocol\n\t\t// violation.\n\t\tconst version = this.#session.version;\n\t\tif (version === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16) {\n\t\t\ttry {\n\t\t\t\tawait request.stream.writer.u53(PublishNamespaceDone.id);\n\t\t\t\tconst done = new PublishNamespaceDone({ trackNamespace: request.path, requestId: request.requestId });\n\t\t\t\tawait done.encode(request.stream.writer, version);\n\t\t\t} catch {\n\t\t\t\t// Stream might already be closed\n\t\t\t}\n\t\t}\n\t\trequest.stream.close();\n\t}\n\n\t/**\n\t * Handles an incoming TRACK_STATUS_REQUEST on a bidi stream.\n\t *\n\t * @internal\n\t */\n\tasync runTrackStatusRequest(msg: TrackStatusRequest, stream: Stream) {\n\t\tconst version = this.#session.version;\n\n\t\tif (version === Version.DRAFT_14) {\n\t\t\t// v14: respond with TrackStatus (0x0E = TRACK_STATUS_OK)\n\t\t\tawait stream.writer.u53(TrackStatus.id);\n\t\t\tconst status = new TrackStatus({\n\t\t\t\ttrackNamespace: msg.trackNamespace,\n\t\t\t\ttrackName: msg.trackName,\n\t\t\t\tstatusCode: TrackStatus.STATUS_NOT_FOUND,\n\t\t\t\tlastGroupId: 0n,\n\t\t\t\tlastObjectId: 0n,\n\t\t\t});\n\t\t\tawait status.encode(stream.writer, version);\n\t\t} else {\n\t\t\t// v15+: respond with RequestOk (0x07)\n\t\t\tawait stream.writer.u53(RequestOk.id);\n\t\t\tconst ok = new RequestOk({\n\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t});\n\t\t\tawait ok.encode(stream.writer, version);\n\t\t}\n\t\tstream.close();\n\t}\n\n\t/**\n\t * Closes every published broadcast and stops accepting new ones.\n\t *\n\t * @internal\n\t */\n\tclose() {\n\t\tthis.#broadcasts.update((broadcasts) => {\n\t\t\tfor (const broadcast of broadcasts?.values() ?? []) {\n\t\t\t\tbroadcast.close();\n\t\t\t}\n\t\t\treturn undefined;\n\t\t});\n\t}\n}\n"]}
|
package/ietf/subscriber.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscriber.d.ts","sourceRoot":"","sources":["../../src/ietf/subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAI7C,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAInD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,O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G;IACG,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,iBA4B5C;IAED;;;;OAIG;IACG,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,iBAwCpD;CACD"}
|
package/ietf/subscriber.js
CHANGED
|
@@ -7,7 +7,7 @@ import * as netGroup from "../group.js";
|
|
|
7
7
|
import * as Path from "../path.js";
|
|
8
8
|
import { Timestamp } from "../time.js";
|
|
9
9
|
import { withTimeout } from "../util/timeout.js";
|
|
10
|
-
import { TrackAliases } from "./aliases.js";
|
|
10
|
+
import { DuplicateTrackAlias, RetiredTrackAlias, TrackAliases } from "./aliases.js";
|
|
11
11
|
import * as Cluster from "./cluster.js";
|
|
12
12
|
import { Frame } from "./object.js";
|
|
13
13
|
import { toWire } from "./priority.js";
|
|
@@ -317,7 +317,6 @@ export class Subscriber {
|
|
|
317
317
|
return consumer;
|
|
318
318
|
}
|
|
319
319
|
async #runSubscribe(broadcast, request) {
|
|
320
|
-
const version = this.#session.version;
|
|
321
320
|
const requestId = await this.#session.nextRequestId();
|
|
322
321
|
if (requestId === undefined) {
|
|
323
322
|
request.reject(new Error("session closed"));
|
|
@@ -335,10 +334,25 @@ export class Subscriber {
|
|
|
335
334
|
// and any registration if setup eventually finishes.
|
|
336
335
|
const state = {};
|
|
337
336
|
const setup = this.#openSubscribe(state, broadcast, request, producer, requestId);
|
|
337
|
+
// The publisher can be serving before it answers, so waiting only on the response
|
|
338
|
+
// would miss the local side going away and leave it serving a track nobody reads.
|
|
339
|
+
// Demand returning before we commit is not abandonment, matching the serving loop.
|
|
340
|
+
const waitAbandoned = async () => {
|
|
341
|
+
for (;;) {
|
|
342
|
+
await producer.unused();
|
|
343
|
+
if (producer.closed.peek() !== undefined || !producer.used.peek())
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
338
347
|
let stream;
|
|
339
348
|
let trackAlias;
|
|
340
349
|
try {
|
|
341
|
-
const result = await
|
|
350
|
+
const result = await Promise.race([
|
|
351
|
+
withTimeout(setup, SUBSCRIBE_OK_TIMEOUT_MS, `subscribe timed out after ${SUBSCRIBE_OK_TIMEOUT_MS}ms waiting for SUBSCRIBE_OK (browser stream limit reached?)`),
|
|
352
|
+
waitAbandoned(),
|
|
353
|
+
]);
|
|
354
|
+
if (result === null)
|
|
355
|
+
throw new Error("subscribe abandoned before it was accepted");
|
|
342
356
|
stream = result.stream;
|
|
343
357
|
trackAlias = result.alias;
|
|
344
358
|
console.debug(`subscribe ok: id=${requestId} broadcast=${broadcast} track=${request.name}`);
|
|
@@ -347,43 +361,68 @@ export class Subscriber {
|
|
|
347
361
|
const e = error(err);
|
|
348
362
|
producer.close(e);
|
|
349
363
|
console.warn(`subscribe error: id=${requestId} broadcast=${broadcast} track=${request.name} error=${reason(e)}`);
|
|
350
|
-
//
|
|
351
|
-
//
|
|
352
|
-
//
|
|
353
|
-
|
|
354
|
-
const cleanup = () => {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
364
|
+
// Runs now for whatever is already open, and again if `setup` settles late.
|
|
365
|
+
// Retirement is repeated because a late SUBSCRIBE_OK can register an alias after
|
|
366
|
+
// the first pass; the stream is torn down once.
|
|
367
|
+
let torn = false;
|
|
368
|
+
const cleanup = async (afterSetup) => {
|
|
369
|
+
state.cancelled = true;
|
|
370
|
+
if (state.registeredAlias !== undefined && this.#aliases.retire(state.registeredAlias, producer)) {
|
|
371
|
+
this.#timescales.delete(state.registeredAlias);
|
|
372
|
+
}
|
|
373
|
+
if (!state.stream || torn)
|
|
374
|
+
return;
|
|
375
|
+
// A SUBSCRIBE still being written must not be torn down from here. Aborting a
|
|
376
|
+
// Web Stream waits for the in-flight write, so the request can still reach the
|
|
377
|
+
// peer while the abort destroys the stream we would have cancelled on. Setup
|
|
378
|
+
// unwinds on the cancelled flag once that write lands, and its pass below has
|
|
379
|
+
// the finished picture.
|
|
380
|
+
if (!state.sent && !afterSetup)
|
|
381
|
+
return;
|
|
382
|
+
torn = true;
|
|
383
|
+
// Once the SUBSCRIBE is out the publisher may be serving, whether or not it has
|
|
384
|
+
// answered yet: data streams are independent of the request stream. Aborting says
|
|
385
|
+
// nothing on v14-16, where the request rides a virtual stream whose reset is
|
|
386
|
+
// local, so the UNSUBSCRIBE has to go out explicitly.
|
|
387
|
+
if (state.sent && !state.rejected)
|
|
388
|
+
await this.#cancelSubscribe(state.stream, requestId);
|
|
389
|
+
state.stream.abort(e);
|
|
358
390
|
};
|
|
359
|
-
setup
|
|
391
|
+
// Tear down what is already open rather than waiting on `setup`. A peer that
|
|
392
|
+
// opened the stream and then went quiet never settles it, and deferring would
|
|
393
|
+
// leave the request outstanding for the life of the session -- which is the
|
|
394
|
+
// timeout case, not a rare one.
|
|
395
|
+
void cleanup(false);
|
|
396
|
+
setup.then(() => cleanup(true), () => cleanup(true));
|
|
360
397
|
return;
|
|
361
398
|
}
|
|
362
399
|
try {
|
|
400
|
+
// Which terminal fired decides whether we owe the publisher a cancellation, so
|
|
401
|
+
// tag them rather than racing bare promises.
|
|
402
|
+
const publisherEnded = Symbol("publisher");
|
|
403
|
+
const localEnded = Symbol("local");
|
|
404
|
+
const idle = Symbol("idle");
|
|
363
405
|
// Terminal conditions settle at most once (stream close = PublishDone, track close =
|
|
364
406
|
// local unsubscribe); race them once so the demand loop doesn't re-subscribe each pass.
|
|
365
|
-
const done = Promise.race([
|
|
407
|
+
const done = Promise.race([
|
|
408
|
+
stream.reader.closed.then(() => publisherEnded),
|
|
409
|
+
producer.closed.then(() => localEnded),
|
|
410
|
+
]);
|
|
366
411
|
// Serve until a terminal condition fires or the last local subscriber leaves. The unused
|
|
367
412
|
// wake is level-triggered: re-check demand so a subscriber that returns before we tear
|
|
368
413
|
// down resumes on the same stream.
|
|
369
|
-
|
|
414
|
+
let terminal = localEnded;
|
|
370
415
|
for (;;) {
|
|
371
416
|
const reason = await Promise.race([done, producer.unused().then(() => idle)]);
|
|
372
417
|
if (reason === idle && producer.closed.peek() === undefined && producer.used.peek())
|
|
373
418
|
continue;
|
|
419
|
+
terminal = reason;
|
|
374
420
|
break;
|
|
375
421
|
}
|
|
376
|
-
//
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
const unsub = new Unsubscribe({ requestId });
|
|
381
|
-
await unsub.encode(stream.writer, version);
|
|
382
|
-
}
|
|
383
|
-
catch {
|
|
384
|
-
// Stream might already be closed
|
|
385
|
-
}
|
|
386
|
-
}
|
|
422
|
+
// The publisher already ended the request, so there is nothing to cancel. Sending
|
|
423
|
+
// UNSUBSCRIBE here would name a request it has already torn down.
|
|
424
|
+
if (terminal !== publisherEnded)
|
|
425
|
+
await this.#cancelSubscribe(stream, requestId);
|
|
387
426
|
producer.close();
|
|
388
427
|
stream.close();
|
|
389
428
|
console.debug(`subscribe close: id=${requestId} broadcast=${broadcast} track=${request.name}`);
|
|
@@ -395,8 +434,31 @@ export class Subscriber {
|
|
|
395
434
|
console.warn(`subscribe error: id=${requestId} broadcast=${broadcast} track=${request.name} error=${reason(e)}`);
|
|
396
435
|
}
|
|
397
436
|
finally {
|
|
398
|
-
|
|
399
|
-
|
|
437
|
+
// Only the owner tears down the alias metadata: a later subscription may have
|
|
438
|
+
// reclaimed the alias and installed its own timescale.
|
|
439
|
+
if (this.#aliases.retire(trackAlias, producer))
|
|
440
|
+
this.#timescales.delete(trackAlias);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Tell the publisher to stop serving a subscription we are walking away from.
|
|
445
|
+
*
|
|
446
|
+
* v14-16 cancel with UNSUBSCRIBE (draft-16 section 9.12), which is what lets the
|
|
447
|
+
* publisher destroy the subscription (section 5.1.1); v17+ removed the message and
|
|
448
|
+
* rely on the stream reset instead. Every path that abandons an Established
|
|
449
|
+
* subscription goes through here, because those versions carry the request over a
|
|
450
|
+
* virtual stream whose reset never reaches the peer.
|
|
451
|
+
*/
|
|
452
|
+
async #cancelSubscribe(stream, requestId) {
|
|
453
|
+
const version = this.#session.version;
|
|
454
|
+
if (version !== Version.DRAFT_14 && version !== Version.DRAFT_15 && version !== Version.DRAFT_16)
|
|
455
|
+
return;
|
|
456
|
+
try {
|
|
457
|
+
await stream.writer.u53(Unsubscribe.id);
|
|
458
|
+
await new Unsubscribe({ requestId }).encode(stream.writer, version);
|
|
459
|
+
}
|
|
460
|
+
catch {
|
|
461
|
+
// The stream may already be gone; there is nothing further to tell the peer.
|
|
400
462
|
}
|
|
401
463
|
}
|
|
402
464
|
// Opens the subscribe stream, sends SUBSCRIBE, and reads the response.
|
|
@@ -406,6 +468,11 @@ export class Subscriber {
|
|
|
406
468
|
async #openSubscribe(state, broadcast, request, producer, requestId) {
|
|
407
469
|
const version = this.#session.version;
|
|
408
470
|
state.stream = await this.#session.openBi();
|
|
471
|
+
// The timeout can fire while the open is still in flight, in which case cleanup ran
|
|
472
|
+
// with nothing to release. Bail now that the stream is recorded, so settling this
|
|
473
|
+
// promise hands it back to be torn down.
|
|
474
|
+
if (state.cancelled)
|
|
475
|
+
throw new Error("subscribe cancelled before it was sent");
|
|
409
476
|
await state.stream.writer.u53(Subscribe.id);
|
|
410
477
|
const msg = new Subscribe({
|
|
411
478
|
requestId,
|
|
@@ -414,6 +481,12 @@ export class Subscriber {
|
|
|
414
481
|
subscriberPriority: toWire(request.priority),
|
|
415
482
|
});
|
|
416
483
|
await msg.encode(state.stream.writer, version);
|
|
484
|
+
state.sent = true;
|
|
485
|
+
// The caller may have given up while that write was in flight. It deliberately left
|
|
486
|
+
// the stream alone, so unwind here and let its cleanup send the cancellation now that
|
|
487
|
+
// the SUBSCRIBE has actually reached the peer.
|
|
488
|
+
if (state.cancelled)
|
|
489
|
+
throw new Error("subscribe cancelled while it was being sent");
|
|
417
490
|
console.debug(`subscribe written: id=${requestId} broadcast=${broadcast} track=${request.name}`);
|
|
418
491
|
const respTypeId = await state.stream.reader.u53();
|
|
419
492
|
if (respTypeId !== SubscribeOk.id) {
|
|
@@ -429,17 +502,22 @@ export class Subscriber {
|
|
|
429
502
|
catch {
|
|
430
503
|
// Decoding error response failed, use default message
|
|
431
504
|
}
|
|
505
|
+
state.rejected = true;
|
|
432
506
|
throw new Error(`SUBSCRIBE error: ${reasonPhrase}`);
|
|
433
507
|
}
|
|
434
508
|
const ok = await SubscribeOk.decode(state.stream.reader, version);
|
|
435
509
|
try {
|
|
436
|
-
this.#aliases.set(ok.trackAlias, producer);
|
|
510
|
+
this.#aliases.set(ok.trackAlias, producer, { broadcast, name: request.name });
|
|
437
511
|
if (ok.timescale !== undefined) {
|
|
438
512
|
this.#timescales.set(ok.trackAlias, ok.timescale);
|
|
439
513
|
}
|
|
440
514
|
}
|
|
441
515
|
catch (err) {
|
|
442
|
-
|
|
516
|
+
// Only one alias naming two different tracks is the session's problem. A publisher
|
|
517
|
+
// sharing an alias between subscriptions to one track is allowed to do that, and
|
|
518
|
+
// disconnecting over it would drop every other broadcast on the session.
|
|
519
|
+
if (err instanceof DuplicateTrackAlias)
|
|
520
|
+
this.#session.close();
|
|
443
521
|
throw err;
|
|
444
522
|
}
|
|
445
523
|
state.registeredAlias = ok.trackAlias;
|
|
@@ -581,11 +659,17 @@ export class Subscriber {
|
|
|
581
659
|
*/
|
|
582
660
|
async runPublish(msg, stream) {
|
|
583
661
|
const version = this.#session.version;
|
|
662
|
+
// NOT_SUPPORTED, from the PUBLISH error codes in draft-19 section 10.10. We decline
|
|
663
|
+
// the method itself rather than this particular track, which is UNINTERESTED (0x4).
|
|
664
|
+
//
|
|
665
|
+
// The alias the message carries is deliberately not recorded. Nothing will ever bind
|
|
666
|
+
// it, and a rejected request has no lifetime of ours to hang the cleanup on.
|
|
667
|
+
const NOT_SUPPORTED = 0x3;
|
|
584
668
|
if (version === Version.DRAFT_14) {
|
|
585
669
|
await stream.writer.u53(PublishError.id);
|
|
586
670
|
const err = new PublishError({
|
|
587
671
|
requestId: msg.requestId,
|
|
588
|
-
errorCode:
|
|
672
|
+
errorCode: NOT_SUPPORTED,
|
|
589
673
|
reasonPhrase: "publish not supported",
|
|
590
674
|
});
|
|
591
675
|
await err.encode(stream.writer, version);
|
|
@@ -594,7 +678,7 @@ export class Subscriber {
|
|
|
594
678
|
await stream.writer.u53(RequestError.id);
|
|
595
679
|
const err = new RequestError({
|
|
596
680
|
requestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,
|
|
597
|
-
errorCode:
|
|
681
|
+
errorCode: NOT_SUPPORTED,
|
|
598
682
|
reasonPhrase: "publish not supported",
|
|
599
683
|
});
|
|
600
684
|
await err.encode(stream.writer, version);
|
|
@@ -628,6 +712,12 @@ export class Subscriber {
|
|
|
628
712
|
}
|
|
629
713
|
catch (err) {
|
|
630
714
|
const e = error(err);
|
|
715
|
+
// Ours: we cancelled the subscription and the publisher has not stopped yet.
|
|
716
|
+
// Anything else on this alias is the publisher sending data for a track it never
|
|
717
|
+
// acknowledged, which is worth seeing.
|
|
718
|
+
if (e instanceof RetiredTrackAlias) {
|
|
719
|
+
console.debug(`dropping group for a cancelled subscription: alias=${group.trackAlias}`);
|
|
720
|
+
}
|
|
631
721
|
producer.close(e);
|
|
632
722
|
stream.stop(e);
|
|
633
723
|
}
|