@moq/net 0.2.7 → 0.3.0

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.
Files changed (170) hide show
  1. package/connection/accept.js +8 -3
  2. package/connection/accept.js.map +1 -1
  3. package/connection/connect.d.ts.map +1 -1
  4. package/connection/connect.js +5 -2
  5. package/connection/connect.js.map +1 -1
  6. package/connection/handshake.d.ts +9 -1
  7. package/connection/handshake.d.ts.map +1 -1
  8. package/connection/handshake.js +18 -14
  9. package/connection/handshake.js.map +1 -1
  10. package/consume.d.ts +1 -1
  11. package/consume.js +1 -1
  12. package/consume.js.map +1 -1
  13. package/ietf/connection.d.ts +7 -1
  14. package/ietf/connection.d.ts.map +1 -1
  15. package/ietf/connection.js +23 -3
  16. package/ietf/connection.js.map +1 -1
  17. package/ietf/index.d.ts +1 -0
  18. package/ietf/index.d.ts.map +1 -1
  19. package/ietf/index.js +1 -0
  20. package/ietf/index.js.map +1 -1
  21. package/ietf/parameters.d.ts +1 -0
  22. package/ietf/parameters.d.ts.map +1 -1
  23. package/ietf/parameters.js +2 -0
  24. package/ietf/parameters.js.map +1 -1
  25. package/ietf/publisher.d.ts +22 -8
  26. package/ietf/publisher.d.ts.map +1 -1
  27. package/ietf/publisher.js +294 -77
  28. package/ietf/publisher.js.map +1 -1
  29. package/ietf/solicit.d.ts +41 -0
  30. package/ietf/solicit.d.ts.map +1 -0
  31. package/ietf/solicit.js +47 -0
  32. package/ietf/solicit.js.map +1 -0
  33. package/ietf/subscriber.d.ts +4 -0
  34. package/ietf/subscriber.d.ts.map +1 -1
  35. package/ietf/subscriber.js +122 -50
  36. package/ietf/subscriber.js.map +1 -1
  37. package/lite/publisher.d.ts.map +1 -1
  38. package/lite/publisher.js +43 -9
  39. package/lite/publisher.js.map +1 -1
  40. package/lite/subscriber.js +3 -3
  41. package/lite/subscriber.js.map +1 -1
  42. package/package.json +2 -2
  43. package/path.d.ts +19 -11
  44. package/path.d.ts.map +1 -1
  45. package/path.js +43 -15
  46. package/path.js.map +1 -1
  47. package/stream.d.ts +46 -2
  48. package/stream.d.ts.map +1 -1
  49. package/stream.js +71 -6
  50. package/stream.js.map +1 -1
  51. package/track.d.ts +20 -7
  52. package/track.d.ts.map +1 -1
  53. package/track.js +63 -27
  54. package/track.js.map +1 -1
  55. package/announced.test.d.ts +0 -2
  56. package/announced.test.d.ts.map +0 -1
  57. package/announced.test.js +0 -37
  58. package/announced.test.js.map +0 -1
  59. package/broadcast.test.d.ts +0 -2
  60. package/broadcast.test.d.ts.map +0 -1
  61. package/broadcast.test.js +0 -243
  62. package/broadcast.test.js.map +0 -1
  63. package/connection/browser.test.d.ts +0 -2
  64. package/connection/browser.test.d.ts.map +0 -1
  65. package/connection/browser.test.js +0 -29
  66. package/connection/browser.test.js.map +0 -1
  67. package/connection/cert.test.d.ts +0 -2
  68. package/connection/cert.test.d.ts.map +0 -1
  69. package/connection/cert.test.js +0 -26
  70. package/connection/cert.test.js.map +0 -1
  71. package/connection/connect.test.d.ts +0 -2
  72. package/connection/connect.test.d.ts.map +0 -1
  73. package/connection/connect.test.js +0 -118
  74. package/connection/connect.test.js.map +0 -1
  75. package/connection/reload.test.d.ts +0 -2
  76. package/connection/reload.test.d.ts.map +0 -1
  77. package/connection/reload.test.js +0 -160
  78. package/connection/reload.test.js.map +0 -1
  79. package/connection/stats.test.d.ts +0 -2
  80. package/connection/stats.test.d.ts.map +0 -1
  81. package/connection/stats.test.js +0 -120
  82. package/connection/stats.test.js.map +0 -1
  83. package/error.test.d.ts +0 -2
  84. package/error.test.d.ts.map +0 -1
  85. package/error.test.js +0 -89
  86. package/error.test.js.map +0 -1
  87. package/group.test.d.ts +0 -2
  88. package/group.test.d.ts.map +0 -1
  89. package/group.test.js +0 -152
  90. package/group.test.js.map +0 -1
  91. package/ietf/aliases.test.d.ts +0 -2
  92. package/ietf/aliases.test.d.ts.map +0 -1
  93. package/ietf/aliases.test.js +0 -30
  94. package/ietf/aliases.test.js.map +0 -1
  95. package/ietf/ietf.test.d.ts +0 -2
  96. package/ietf/ietf.test.d.ts.map +0 -1
  97. package/ietf/ietf.test.js +0 -983
  98. package/ietf/ietf.test.js.map +0 -1
  99. package/ietf/priority.test.d.ts +0 -2
  100. package/ietf/priority.test.d.ts.map +0 -1
  101. package/ietf/priority.test.js +0 -18
  102. package/ietf/priority.test.js.map +0 -1
  103. package/integration.test.d.ts +0 -2
  104. package/integration.test.d.ts.map +0 -1
  105. package/integration.test.js +0 -1006
  106. package/integration.test.js.map +0 -1
  107. package/lite/announce.test.d.ts +0 -2
  108. package/lite/announce.test.d.ts.map +0 -1
  109. package/lite/announce.test.js +0 -91
  110. package/lite/announce.test.js.map +0 -1
  111. package/lite/datagram.test.d.ts +0 -2
  112. package/lite/datagram.test.d.ts.map +0 -1
  113. package/lite/datagram.test.js +0 -26
  114. package/lite/datagram.test.js.map +0 -1
  115. package/lite/datagram_stream.test.d.ts +0 -2
  116. package/lite/datagram_stream.test.d.ts.map +0 -1
  117. package/lite/datagram_stream.test.js +0 -15
  118. package/lite/datagram_stream.test.js.map +0 -1
  119. package/lite/fetch.test.d.ts +0 -2
  120. package/lite/fetch.test.d.ts.map +0 -1
  121. package/lite/fetch.test.js +0 -41
  122. package/lite/fetch.test.js.map +0 -1
  123. package/lite/priority.test.d.ts +0 -2
  124. package/lite/priority.test.d.ts.map +0 -1
  125. package/lite/priority.test.js +0 -77
  126. package/lite/priority.test.js.map +0 -1
  127. package/lite/publisher.test.d.ts +0 -2
  128. package/lite/publisher.test.d.ts.map +0 -1
  129. package/lite/publisher.test.js +0 -334
  130. package/lite/publisher.test.js.map +0 -1
  131. package/lite/setup.test.d.ts +0 -2
  132. package/lite/setup.test.d.ts.map +0 -1
  133. package/lite/setup.test.js +0 -134
  134. package/lite/setup.test.js.map +0 -1
  135. package/lite/subscribe.test.d.ts +0 -2
  136. package/lite/subscribe.test.d.ts.map +0 -1
  137. package/lite/subscribe.test.js +0 -110
  138. package/lite/subscribe.test.js.map +0 -1
  139. package/lite/subscriber.test.d.ts +0 -2
  140. package/lite/subscriber.test.d.ts.map +0 -1
  141. package/lite/subscriber.test.js +0 -108
  142. package/lite/subscriber.test.js.map +0 -1
  143. package/lite/track.test.d.ts +0 -2
  144. package/lite/track.test.d.ts.map +0 -1
  145. package/lite/track.test.js +0 -55
  146. package/lite/track.test.js.map +0 -1
  147. package/path.test.d.ts +0 -2
  148. package/path.test.d.ts.map +0 -1
  149. package/path.test.js +0 -210
  150. package/path.test.js.map +0 -1
  151. package/stream.test.d.ts +0 -2
  152. package/stream.test.d.ts.map +0 -1
  153. package/stream.test.js +0 -252
  154. package/stream.test.js.map +0 -1
  155. package/time.test.d.ts +0 -2
  156. package/time.test.d.ts.map +0 -1
  157. package/time.test.js +0 -12
  158. package/time.test.js.map +0 -1
  159. package/track.test.d.ts +0 -2
  160. package/track.test.d.ts.map +0 -1
  161. package/track.test.js +0 -212
  162. package/track.test.js.map +0 -1
  163. package/util/timeout.test.d.ts +0 -2
  164. package/util/timeout.test.d.ts.map +0 -1
  165. package/util/timeout.test.js +0 -18
  166. package/util/timeout.test.js.map +0 -1
  167. package/varint.test.d.ts +0 -2
  168. package/varint.test.d.ts.map +0 -1
  169. package/varint.test.js +0 -106
  170. package/varint.test.js.map +0 -1
package/track.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"track.js","sourceRoot":"","sources":["../src/track.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAgC,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE1E,OAAO,EAA8C,QAAQ,IAAI,aAAa,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC3G,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,SAAS,EAAkB,MAAM,WAAW,CAAC;AAItD,iGAAiG;AACjG,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,mBAAmB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K,CAAC,QAAQ;QACb,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,OAAO,CAAC,UAAU,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAC/G,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAAqB;QAC3B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;IACvD,CAAC;CACD","sourcesContent":["/**\n * Track role handles: a live stream of groups (and best-effort datagrams) within a broadcast.\n *\n * @module\n */\nimport { type GetPromise, type Getter, Once, Signal } from \"@moq/signals\";\nimport type { Datagram } from \"./datagram.ts\";\nimport { type Frame, type Consumer as GroupConsumer, Producer as GroupProducer, Lagged } from \"./group.ts\";\nimport { hooks } from \"./internal.ts\";\nimport { Timescale, type Timestamp } from \"./time.ts\";\n\nexport type { Datagram } from \"./datagram.ts\";\n\n/** Default {@link Info.latencyMax} window (milliseconds) when the publisher does not set one. */\nexport const DEFAULT_LATENCY_MAX_MS = 5000;\n\n/**\n * How long (milliseconds) a datagram stays in the per-subscriber buffer before it is dropped.\n *\n * Datagrams are a best-effort send buffer, not a replay cache (unlike groups): only the last few\n * tens of milliseconds are kept, so a consumer that stalls loses stale datagrams instead of\n * replaying them. Mirrors the Rust `MAX_DATAGRAM_AGE`.\n */\nconst MAX_DATAGRAM_AGE_MS = 50;\n\n/** A datagram buffered with its arrival time, so the send buffer can evict by age. */\ntype BufferedDatagram = { datagram: Datagram; time: number };\n\n/**\n * Sanity cap on a datagram payload: the QUIC DATAGRAM frame ceiling. The real limit is\n * per-hop (the negotiated transport datagram size minus a small header) and oversize\n * datagrams are dropped there; a payload above this cap could never fit anywhere.\n */\nconst MAX_DATAGRAM_BYTES = 65535;\n\n/**\n * A track's immutable publisher properties, fixed for the lifetime of the track.\n *\n * A producer declares these once (via {@link Request.accept} or\n * {@link Producer.accept}); a consumer awaits them via {@link Subscriber.info}\n * (resolved from the wire TRACK_INFO on lite-05+). They map 1:1 onto TRACK_INFO.\n */\nexport interface Info {\n\t/**\n\t * Units per second for this track's frame timestamps (reported in TRACK_INFO on\n\t * Lite05+). Defaults to milliseconds; set it finer (e.g. {@link Timescale.MICRO})\n\t * for media that needs sub-millisecond timing.\n\t */\n\ttimescale: Timescale;\n\t/**\n\t * Publisher Max Latency: the maximum age (milliseconds) of a non-latest group before\n\t * the publisher evicts it. Reported in TRACK_INFO (Lite05+) so relays re-serve with the\n\t * same bound. The publisher-side half of the budget a subscriber sets for itself.\n\t */\n\tlatencyMax: number;\n\t/** Tie-break priority between subscriptions of equal subscriber priority. */\n\tpriority: number;\n\t/**\n\t * Whether groups are prioritized in sequence order. Groups may always arrive\n\t * out-of-order (or not at all) over the network. Defaults to `false` (newest-first).\n\t */\n\tordered: boolean;\n}\n\n/** Fill in any unset {@link Info} fields with their defaults. */\nexport function infoDefaults(info: Partial<Info> = {}): Info {\n\treturn {\n\t\ttimescale: info.timescale ?? Timescale.MILLI,\n\t\tlatencyMax: info.latencyMax ?? DEFAULT_LATENCY_MAX_MS,\n\t\tpriority: info.priority ?? 0,\n\t\tordered: info.ordered ?? false,\n\t};\n}\n\n/**\n * Per-subscription options, requested when a subscription opens and adjustable later via\n * {@link Subscriber.update}. Mirrors the Rust `Subscription`.\n */\nexport interface Subscription {\n\t/** Delivery priority relative to this session's other subscriptions. Defaults to `0`. */\n\tpriority?: number;\n\t/** Whether groups are prioritized in sequence order. Defaults to `false` (newest-first). */\n\tordered?: boolean;\n\t/** Maximum age (milliseconds) of a non-latest group before it is skipped. Defaults to `0`. */\n\tlatencyMax?: number;\n\t/** First group the publisher should deliver, or omit to start at the latest group. */\n\tstartGroup?: number;\n\t/** Last group the publisher should deliver (inclusive), or omit for no end. */\n\tendGroup?: number;\n}\n\n// Materialize the defaults at the model boundary so every layer observes a complete\n// subscription rather than interpreting an omitted field differently.\nfunction subscriptionDefaults(subscription: Subscription = {}): Subscription {\n\treturn {\n\t\tpriority: subscription.priority ?? 0,\n\t\tordered: subscription.ordered ?? false,\n\t\tlatencyMax: subscription.latencyMax ?? 0,\n\t\tstartGroup: subscription.startGroup,\n\t\tendGroup: subscription.endGroup,\n\t};\n}\n\n// Aggregate the preferences of every live subscriber, matching Rust's Subscription::poll_combined.\nfunction combineSubscriptions(states: Iterable<TrackState>): Subscription | undefined {\n\tlet combined: Subscription | undefined;\n\tfor (const state of states) {\n\t\tconst subscription = state.update.peek();\n\t\tif (!subscription) continue;\n\t\tif (!combined) {\n\t\t\tcombined = { ...subscription };\n\t\t\tcontinue;\n\t\t}\n\n\t\tcombined.priority = Math.max(combined.priority ?? 0, subscription.priority ?? 0);\n\t\tcombined.ordered = (combined.ordered ?? false) && (subscription.ordered ?? false);\n\t\tcombined.latencyMax = Math.max(combined.latencyMax ?? 0, subscription.latencyMax ?? 0);\n\n\t\tif (subscription.startGroup !== undefined) {\n\t\t\tcombined.startGroup =\n\t\t\t\tcombined.startGroup === undefined\n\t\t\t\t\t? subscription.startGroup\n\t\t\t\t\t: Math.min(combined.startGroup, subscription.startGroup);\n\t\t}\n\n\t\tif (combined.endGroup === undefined || subscription.endGroup === undefined) {\n\t\t\tcombined.endGroup = undefined;\n\t\t} else {\n\t\t\tcombined.endGroup = Math.max(combined.endGroup, subscription.endGroup);\n\t\t}\n\t}\n\treturn combined;\n}\n\n/**\n * A request for a track the peer wants, yielded by `Broadcast.Producer.requested`.\n *\n * Created internally by the broadcast when a subscription (or info lookup) needs a track\n * served; answer it with {@link accept} or {@link reject}.\n *\n * @public\n */\nexport class Request {\n\t/** The requested track name. */\n\treadonly name: string;\n\n\t#producer: Producer;\n\n\tprivate constructor(name: string, producer: Producer) {\n\t\tthis.name = name;\n\t\tthis.#producer = producer;\n\t}\n\n\tstatic {\n\t\thooks.makeRequest = (name, producer) => new Request(name, producer);\n\t}\n\n\t/** The aggregate subscription requested for this track. */\n\tget subscription(): Readonly<Subscription> {\n\t\treturn this.#producer.subscription.peek() ?? subscriptionDefaults();\n\t}\n\n\t/** The subscriber's priority for this track. */\n\tget priority(): number {\n\t\treturn this.subscription.priority ?? 0;\n\t}\n\n\t/** Accept the request, committing the track's immutable {@link Info}. */\n\taccept(info: Partial<Info> = {}): Producer {\n\t\treturn this.#producer.accept(info);\n\t}\n\n\t/** Reject the request, closing the track optionally with an error. */\n\treject(err?: Error): void {\n\t\tthis.#producer.close(err);\n\t}\n}\n\n/** Options for {@link Consumer.fetchGroup}. */\nexport interface FetchGroupOptions {\n\t/** Delivery priority for the fetch stream. Defaults to `0`. */\n\tpriority?: number;\n}\n\n/**\n * The per-track operations a lazy {@link Consumer} delegates to the broadcast it came from.\n *\n * Implemented by `broadcast.Producer` / `broadcast.Consumer` (and the wire-layer subclasses\n * that resolve them over the network), so a track handle holds a reference to its broadcast\n * and calls methods on it rather than capturing a bag of callbacks.\n */\nexport interface Broadcast {\n\t/** Open a live subscription to the named track. */\n\tsubscribe(name: string, options?: Subscription): Subscriber;\n\t/** Resolve the named track's immutable info. */\n\tresolveTrackInfo(name: string): Promise<Info>;\n\t/** Fetch a single group of the named track by sequence. */\n\tfetchGroup(name: string, sequence: number, options?: FetchGroupOptions): Promise<GroupConsumer>;\n}\n\n/**\n * A lazy handle to a track on a consumed broadcast.\n *\n * @public\n */\nexport class Consumer {\n\t/** The track name. */\n\treadonly name: string;\n\n\t#broadcast: Broadcast;\n\n\tconstructor(name: string, broadcast: Broadcast) {\n\t\tthis.name = name;\n\t\tthis.#broadcast = broadcast;\n\t}\n\n\t/** Open a live subscription to the track. */\n\tsubscribe(options?: Subscription): Subscriber {\n\t\treturn this.#broadcast.subscribe(this.name, options);\n\t}\n\n\t/** Fetch the track's immutable publisher properties without subscribing. */\n\tinfo(): Promise<Info> {\n\t\treturn this.#broadcast.resolveTrackInfo(this.name);\n\t}\n\n\t/** Fetch a single group by sequence without holding a live subscription. */\n\tfetchGroup(sequence: number, options?: FetchGroupOptions): Promise<GroupConsumer> {\n\t\treturn this.#broadcast.fetchGroup(this.name, sequence, options);\n\t}\n}\n\n// The shared state behind a Producer / Subscriber pair. Package-internal\n// wiring, unexported so it never appears in the published type declarations.\nclass TrackState {\n\tgroups = new Signal<GroupConsumer[]>([]);\n\t/** Best-effort datagram channel, parallel to {@link groups}; an age-evicted send buffer per subscriber. */\n\tdatagrams = new Signal<BufferedDatagram[]>([]);\n\tlatest?: number;\n\tclosed = new Once<Error | null>();\n\tupdate: Signal<Subscription | undefined>;\n\t/** Resolved once the producer commits the immutable properties. */\n\tinfo = new Signal<Info | undefined>(undefined);\n\n\tconstructor(subscription?: Subscription) {\n\t\tthis.update = new Signal(subscription === undefined ? undefined : subscriptionDefaults(subscription));\n\t}\n}\n\n// Settle a track state's closed Once. Idempotent: Once.set throws on a second settle, and a\n// Producer closing its sinks races the Subscriber closing itself (the sink is only removed from\n// #sinks a microtask later, via the closed subscription below).\nfunction closeTrackState(state: TrackState, abort?: Error): boolean {\n\tif (state.closed.peek() !== undefined) return false;\n\tstate.closed.set(abort ?? null);\n\treturn true;\n}\n\n// Resolve the track's immutable publisher properties, or reject if it closes first.\n// On a producer this resolves once info is committed (at accept time); on a consumer\n// once the wire layer commits the TRACK_INFO it received (lite-05+) or defaults (older\n// drafts), so awaiting it never yields a placeholder.\nasync function resolveInfo(state: TrackState): Promise<Info> {\n\tfor (;;) {\n\t\tconst info = state.info.peek();\n\t\tif (info) return info;\n\n\t\tconst closed = state.closed.peek();\n\t\tif (closed instanceof Error) throw closed;\n\t\tif (closed !== undefined) throw new Error(\"track closed before info was known\");\n\n\t\tawait Signal.race(state.info, state.closed);\n\t}\n}\n\n// A source group retained in the producer cache, with the mirror handed to each sink\n// so eviction can drop them together.\ntype CachedGroup = { group: GroupProducer; time: number; mirrors: Map<TrackState, GroupConsumer> };\n\n// Constructs a Subscriber from within this module without exposing a public\n// constructor that would leak the unexported TrackState. Assigned in the class's\n// static block.\nlet makeSubscriber: (name: string, state: TrackState) => Subscriber;\n\n/**\n * The write side of a track, mirroring the Rust `Producer`.\n *\n * A producer is a fan-out source: every {@link subscribe} (including each wire\n * subscription the publisher serves from it) gets an independent\n * {@link Subscriber} that receives a full copy of the groups, each with its own\n * read cursor. Groups are mirrored into every live subscriber and retained for the\n * track's `latencyMax` window so a late subscriber replays the recent groups.\n *\n * Obtained from {@link Request.accept} (the wire asks the application for a track to\n * serve) or constructed directly for an in-process track.\n */\nexport class Producer {\n\t/** The track name. */\n\treadonly name: string;\n\n\t// The producer's own state is the source of truth (info/closed); subscribers\n\t// read mirrored sinks, never this state directly.\n\t#state = new TrackState();\n\n\t#next?: number;\n\n\t// Recently written source groups, retained for replay to late subscribers and\n\t// pruned once closed and older than the cache window. Each entry tracks the mirror\n\t// it handed to every sink so eviction can drop them too: otherwise a slow consumer\n\t// that never reads would pin old groups (and their frame bytes) forever.\n\t#cache: CachedGroup[] = [];\n\n\t// One independent downstream state per live subscriber.\n\t#sinks = new Set<TrackState>();\n\n\t// Whether any subscriber is currently attached. Exposed as {@link used}; the consumer wire\n\t// watches it to tear down an idle upstream, and a publisher can watch it for on-demand capture.\n\t#used = new Signal<boolean>(false);\n\n\tconstructor(name: string) {\n\t\tthis.name = name;\n\t}\n\n\t/**\n\t * Resolve this track's immutable publisher properties, committed at accept time.\n\t * Rejects if the track is closed before the properties are known.\n\t */\n\tinfo(): Promise<Info> {\n\t\treturn resolveInfo(this.#state);\n\t}\n\n\t/**\n\t * Settles once the track closes: `null` on a clean close, or the abort {@link Error}.\n\t * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/**\n\t * The aggregate subscription across live subscribers, or `undefined` when there are none.\n\t * The wire layer watches this to emit SUBSCRIBE_UPDATE.\n\t */\n\tget subscription(): Getter<Subscription | undefined> {\n\t\treturn this.#state.update;\n\t}\n\n\t/** Commit the immutable publisher properties, resolving {@link info}. Returns `this`. */\n\taccept(info: Partial<Info> = {}): this {\n\t\tconst resolved = infoDefaults(info);\n\t\tthis.#state.info.set(resolved);\n\t\t// Propagate to any sink handed out before accept (the on-demand path).\n\t\tfor (const sink of this.#sinks) sink.info.set(resolved);\n\t\treturn this;\n\t}\n\n\t/** An independent {@link Subscriber} receiving a full copy of this track's groups. */\n\tsubscribe(options: Subscription = {}): Subscriber {\n\t\tconst sink = new TrackState(options);\n\t\tthis.#addSink(sink);\n\t\treturn makeSubscriber(this.name, sink);\n\t}\n\n\t/**\n\t * Whether the track currently has any subscribers.\n\t *\n\t * Watch it (`effect.get` / `.peek()`) to drive on-demand work: a publisher can start and stop\n\t * capture with demand, and the consumer wire watches it to tear an idle upstream subscription\n\t * down instead of downloading to nobody. Pairs with {@link unused}. Mirrors the Rust `Demand`.\n\t */\n\tget used(): Getter<boolean> {\n\t\treturn this.#used;\n\t}\n\n\t/** Resolves once the track has no subscribers (or has closed). Await it to react to demand ending. */\n\tasync unused(): Promise<void> {\n\t\twhile (this.#used.peek() && this.#state.closed.peek() === undefined) {\n\t\t\tawait Signal.race(this.#used, this.#state.closed);\n\t\t}\n\t}\n\n\t// Register a downstream sink: seed its info, replay the retained window, and (while\n\t// the track is open) mirror future groups into it. A late subscriber to a closed\n\t// track still drains the buffered groups before seeing the end.\n\t#addSink(sink: TrackState): void {\n\t\tconst info = this.#state.info.peek();\n\t\tif (info) sink.info.set(info);\n\n\t\tconst closed = this.#state.closed.peek();\n\t\tif (closed === undefined) {\n\t\t\tthis.#sinks.add(sink);\n\t\t\tthis.#used.set(true);\n\n\t\t\t// Forward subscription updates from the sink's Subscriber to the producer's own\n\t\t\t// state, which the wire layer (or the serving application) watches.\n\t\t\tconst forward = sink.update.subscribe(() => this.#updateSubscription());\n\t\t\tthis.#updateSubscription();\n\n\t\t\t// Drop the sink once its consumer goes away, closing its mirrors so source\n\t\t\t// groups stop teeing into them, so a long-lived producer doesn't leak. This\n\t\t\t// covers mirrors already handed out via recvGroup (no longer in sink.groups)\n\t\t\t// by closing them through the cache's per-sink tracking.\n\t\t\tconst dispose = sink.closed.subscribe((c) => {\n\t\t\t\tif (c === undefined) return;\n\t\t\t\tconst abort = c instanceof Error ? c : undefined;\n\t\t\t\tforward();\n\t\t\t\tthis.#sinks.delete(sink);\n\t\t\t\tthis.#updateSubscription();\n\t\t\t\tfor (const entry of this.#cache) {\n\t\t\t\t\tconst mirror = entry.mirrors.get(sink);\n\t\t\t\t\tif (mirror) {\n\t\t\t\t\t\tmirror.close(abort);\n\t\t\t\t\t\tentry.mirrors.delete(sink);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const group of sink.groups.peek()) group.close(abort);\n\t\t\t\tdispose();\n\n\t\t\t\t// Update demand: once the last subscriber leaves, the consumer wire (watching\n\t\t\t\t// {@link unused}) tears the upstream down instead of downloading to nobody.\n\t\t\t\tthis.#used.set(this.#sinks.size > 0);\n\t\t\t});\n\t\t}\n\n\t\tthis.#prune();\n\t\tfor (const entry of this.#cache) this.#mirror(entry, sink);\n\n\t\tif (closed !== undefined) closeTrackState(sink, closed instanceof Error ? closed : undefined);\n\t}\n\n\t// Recompute from every live sink because an update or close can narrow as well as widen\n\t// the aggregate. The wire layer observes this signal and emits SUBSCRIBE_UPDATE.\n\t#updateSubscription(): void {\n\t\tthis.#state.update.set(combineSubscriptions(this.#sinks));\n\t}\n\n\t// Mirror a cached source group into a sink. The mirror fills synchronously as the\n\t// source is written and keeps its own read cursor; frame bytes are shared by\n\t// reference. Tracked on the entry so eviction can drop it from the sink.\n\t#mirror(entry: CachedGroup, sink: TrackState): void {\n\t\tconst dst = entry.group.mirror();\n\t\tentry.mirrors.set(sink, dst);\n\t\tsink.latest = Math.max(sink.latest ?? 0, dst.sequence);\n\t\tsink.groups.mutate((groups) => {\n\t\t\tgroups.push(dst);\n\t\t\tgroups.sort((a, b) => a.sequence - b.sequence);\n\t\t});\n\t}\n\n\t// Evict cached groups that are closed and older than the cache window, dropping\n\t// each evicted group's mirror from every sink so no consumer can pin it.\n\t#prune(): void {\n\t\tconst latencyMaxMs = this.#state.info.peek()?.latencyMax ?? DEFAULT_LATENCY_MAX_MS;\n\t\tconst cutoff = Date.now() - latencyMaxMs;\n\n\t\tconst retained: CachedGroup[] = [];\n\t\tfor (const entry of this.#cache) {\n\t\t\tif (entry.time > cutoff || entry.group.closed.peek() === undefined) {\n\t\t\t\tretained.push(entry);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const [sink, mirror] of entry.mirrors) {\n\t\t\t\tsink.groups.mutate((groups) => {\n\t\t\t\t\tconst i = groups.indexOf(mirror);\n\t\t\t\t\tif (i >= 0) groups.splice(i, 1);\n\t\t\t\t});\n\t\t\t\tmirror.close();\n\t\t\t}\n\t\t\tentry.mirrors.clear();\n\t\t}\n\t\tthis.#cache = retained;\n\t}\n\n\t// Retain a source group and fan it out to every live sink.\n\t#publish(group: GroupProducer): void {\n\t\tconst entry: CachedGroup = { group, time: Date.now(), mirrors: new Map<TrackState, GroupConsumer>() };\n\t\tthis.#cache.push(entry);\n\t\tthis.#prune();\n\t\tfor (const sink of this.#sinks) this.#mirror(entry, sink);\n\t}\n\n\t/** Append a new group with the next sequence number. */\n\tappendGroup(): GroupProducer {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\n\t\tconst group = new GroupProducer(this.#next ?? 0);\n\t\tthis.#next = group.sequence + 1;\n\t\tthis.#publish(group);\n\n\t\treturn group;\n\t}\n\n\t/** Insert an existing group into the track. */\n\twriteGroup(group: GroupProducer) {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\n\t\t// Only advance #next upward (for appendGroup auto-increment).\n\t\tif (group.sequence >= (this.#next ?? 0)) {\n\t\t\tthis.#next = group.sequence + 1;\n\t\t}\n\n\t\tthis.#publish(group);\n\t}\n\n\t// Fan a datagram out to every live subscriber, dropping the oldest once the ring is full.\n\t// Late subscribers do NOT replay old datagrams (best-effort, unlike the group cache).\n\t#publishDatagram(datagram: Datagram): void {\n\t\tconst now = performance.now();\n\t\tfor (const sink of this.#sinks) {\n\t\t\tsink.datagrams.mutate((list) => {\n\t\t\t\tlist.push({ datagram, time: now });\n\t\t\t\t// Drop anything older than the send-buffer window.\n\t\t\t\twhile (list.length > 0 && now - list[0].time > MAX_DATAGRAM_AGE_MS) list.shift();\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Append a datagram with the next sequence number, returning the assigned sequence.\n\t *\n\t * A datagram is delivered best-effort over a single QUIC datagram, parallel to the track's\n\t * groups but drawing from the same sequence namespace (interleaving with {@link appendGroup}\n\t * never reuses a number). The payload must fit the negotiated transport datagram size minus\n\t * a small header; an oversize payload is dropped at each hop (there is no group fallback), so\n\t * keep datagram payloads small (e.g. a single audio frame). Datagrams are never delivered\n\t * over IETF moq-transport or stream-only transports (the WebSocket fallback). A payload over\n\t * 65535 bytes (the QUIC datagram frame ceiling) throws. An origin publisher uses this; a\n\t * relay preserving upstream numbering uses {@link writeDatagram}.\n\t */\n\tappendDatagram(timestamp: Timestamp, payload: Uint8Array): number {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\t\tif (payload.byteLength > MAX_DATAGRAM_BYTES) throw new Error(\"datagram payload too large\");\n\n\t\tconst sequence = this.#next ?? 0;\n\t\tthis.#next = sequence + 1;\n\t\tthis.#publishDatagram({ sequence, timestamp, payload });\n\t\treturn sequence;\n\t}\n\n\t/**\n\t * Write a datagram with an explicit sequence number.\n\t *\n\t * Preserves the supplied sequence (advancing the shared counter if needed) so a relay can\n\t * forward a datagram without renumbering it. The size limits of {@link appendDatagram}\n\t * apply. Most origin publishers want {@link appendDatagram} instead.\n\t */\n\twriteDatagram(datagram: Datagram) {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\t\tif (datagram.payload.byteLength > MAX_DATAGRAM_BYTES) throw new Error(\"datagram payload too large\");\n\n\t\tif (datagram.sequence >= (this.#next ?? 0)) {\n\t\t\tthis.#next = datagram.sequence + 1;\n\t\t}\n\t\tthis.#publishDatagram(datagram);\n\t}\n\n\t/** Close the track and every subscriber, mirroring the abort to their groups. Idempotent. */\n\tclose(abort?: Error) {\n\t\tcloseTrackState(this.#state, abort);\n\t\tfor (const { group } of this.#cache) group.close(abort);\n\t\tfor (const sink of this.#sinks) {\n\t\t\tfor (const group of sink.groups.peek()) group.close(abort);\n\t\t\tcloseTrackState(sink, abort);\n\t\t}\n\t\tthis.#sinks.clear();\n\t}\n\n\t/** Append a frame as its own single-frame group. */\n\twriteFrame(frame: Frame) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeFrame(frame);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a string to the track as its own single-frame group. */\n\twriteString(str: string) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeString(str);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a JSON value to the track as its own single-frame group. */\n\twriteJson(json: unknown) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeJson(json);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a boolean to the track as its own single-frame group. */\n\twriteBool(bool: boolean) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeBool(bool);\n\t\tgroup.close();\n\t}\n}\n\n/**\n * The read side of a live track subscription, mirroring the Rust `Subscriber`.\n *\n * Obtained from `Broadcast.Consumer.subscribe` / `Track.Consumer.subscribe`, or from\n * {@link Producer.subscribe} for an in-process track. Reads the groups a\n * {@link Producer} on the same underlying state writes.\n */\nexport class Subscriber {\n\t/** The track name. */\n\treadonly name: string;\n\n\t#state: TrackState;\n\t#nextSequence = 0;\n\t#cursor = new Signal<{ start: number; end?: number }>({ start: 0 });\n\n\tprivate constructor(name: string, state: TrackState) {\n\t\tthis.name = name;\n\t\tthis.#state = state;\n\t}\n\n\tstatic {\n\t\tmakeSubscriber = (name, state) => new Subscriber(name, state);\n\t}\n\n\t/**\n\t * Resolve this track's immutable publisher properties.\n\t *\n\t * Resolves once the wire layer commits the TRACK_INFO it received (lite-05+) or\n\t * defaults (older drafts), so awaiting it never yields a placeholder. Rejects if\n\t * the track is closed before the properties are known (e.g. a rejected subscription).\n\t */\n\tinfo(): Promise<Info> {\n\t\treturn resolveInfo(this.#state);\n\t}\n\n\t/** Settles once the track closes; see {@link Producer.closed}. */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/** This subscriber's current options, including defaults and the last {@link update}. */\n\tget subscription(): Getter<Subscription | undefined> {\n\t\treturn this.#state.update;\n\t}\n\n\t/** Return the latest group sequence observed on this track, if any. */\n\tlatest(): number | undefined {\n\t\treturn this.#state.latest;\n\t}\n\n\t/** Start this subscriber's local read cursor at `sequence`, without changing its wire request. */\n\tstartAt(sequence: number): void {\n\t\tthis.#cursor.update((cursor) => ({ ...cursor, start: sequence }));\n\t}\n\n\t/**\n\t * Cap {@link nextGroup} at `sequence` inclusively, or omit it to remove the cap.\n\t * Groups above the cap remain buffered and become readable if the cap is raised.\n\t * This local cursor does not change the subscription's wire request.\n\t */\n\tendAt(sequence?: number): void {\n\t\tthis.#cursor.update((cursor) => ({ ...cursor, end: sequence }));\n\t}\n\n\t/** Close the track (optionally with an error), closing any pending groups. Idempotent. */\n\tclose(abort?: Error) {\n\t\tif (!closeTrackState(this.#state, abort)) return;\n\t\tfor (const group of this.#state.groups.peek()) {\n\t\t\tgroup.close(abort);\n\t\t}\n\t}\n\n\t/**\n\t * Receive the next group available on this track, in arrival order.\n\t *\n\t * Groups may arrive out of order or with gaps due to network conditions.\n\t * Use {@link nextGroup} for sequence order, skipping those that arrive too late.\n\t */\n\tasync recvGroup(): Promise<GroupConsumer | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.#state.groups.peek();\n\t\t\tconst { start } = this.#cursor.peek();\n\t\t\twhile (groups.length > 0 && groups[0].sequence < start) groups.shift()?.close();\n\t\t\tif (groups.length > 0) {\n\t\t\t\treturn groups.shift();\n\t\t\t}\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) return undefined;\n\n\t\t\tawait Signal.race(this.#state.groups, this.#cursor, this.#state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * Receive the next datagram in arrival order.\n\t *\n\t * Datagrams are a separate best-effort channel from groups (see\n\t * {@link Producer.appendDatagram}); they share only the sequence namespace. A consumer\n\t * that falls too far behind silently loses the oldest datagrams. Read this alongside\n\t * {@link recvGroup} (e.g. in a separate loop) to receive both channels concurrently. Returning\n\t * a datagram advances {@link nextGroup} past that sequence.\n\t */\n\tasync recvDatagram(): Promise<Datagram | undefined> {\n\t\tfor (;;) {\n\t\t\tconst datagrams = this.#state.datagrams.peek();\n\n\t\t\t// Evict datagrams older than the send-buffer window (also enforced on write), so a\n\t\t\t// reader that stalled skips stale datagrams instead of replaying them.\n\t\t\tconst cutoff = performance.now() - MAX_DATAGRAM_AGE_MS;\n\t\t\twhile (datagrams.length > 0 && datagrams[0].time < cutoff) datagrams.shift();\n\n\t\t\tif (datagrams.length > 0) {\n\t\t\t\tconst datagram = datagrams.shift()?.datagram;\n\t\t\t\tif (datagram) {\n\t\t\t\t\tthis.#nextSequence = Math.max(this.#nextSequence, datagram.sequence + 1);\n\t\t\t\t}\n\t\t\t\treturn datagram;\n\t\t\t}\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) return undefined;\n\n\t\t\tawait Signal.race(this.#state.datagrams, this.#state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * Return the next group with a strictly-greater sequence number than the last returned.\n\t *\n\t * Late arrivals (sequence at or below the last returned) are silently skipped.\n\t * Use {@link recvGroup} to see every group in arrival order instead.\n\t */\n\tasync nextGroup(): Promise<GroupConsumer | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.#state.groups.peek();\n\t\t\tconst cursor = this.#cursor.peek();\n\t\t\tconst start = Math.max(cursor.start, this.#nextSequence);\n\t\t\twhile (groups.length > 0 && groups[0].sequence < start) groups.shift()?.close();\n\n\t\t\tconst group = groups[0];\n\t\t\tif (group && (cursor.end === undefined || group.sequence <= cursor.end)) {\n\t\t\t\tgroups.shift();\n\t\t\t\tthis.#nextSequence = group.sequence + 1;\n\t\t\t\treturn group;\n\t\t\t}\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined && !group) return undefined;\n\n\t\t\tawait Signal.race(this.#state.groups, this.#cursor, this.#state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * Reads the next frame across all groups, discarding older groups.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t */\n\tasync readFrame(): Promise<Frame | undefined> {\n\t\tconst next = await this.readFrameSequence();\n\t\treturn next ? { payload: next.payload, timestamp: next.timestamp } : undefined;\n\t}\n\n\t/**\n\t * Reads the next frame along with its group and frame sequence numbers.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t */\n\tasync readFrameSequence(): Promise<({ group: number; frame: number } & Frame) | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.#state.groups.peek();\n\t\t\tconst { start } = this.#cursor.peek();\n\t\t\twhile (groups.length > 0 && groups[0].sequence < start) groups.shift()?.close();\n\n\t\t\t// Drain older groups first, dropping each once empty.\n\t\t\twhile (groups.length > 1) {\n\t\t\t\tif (groups[0].skipped) {\n\t\t\t\t\t// The reader fell behind this group's eviction window. Drop it and\n\t\t\t\t\t// signal the gap; the next read resyncs from the following group.\n\t\t\t\t\tgroups.shift()?.close();\n\t\t\t\t\tthrow new Lagged();\n\t\t\t\t}\n\t\t\t\tconst next = groups[0].tryReadFrameSequence();\n\t\t\t\tif (next) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tgroup: groups[0].sequence,\n\t\t\t\t\t\tframe: next.sequence,\n\t\t\t\t\t\tpayload: next.payload,\n\t\t\t\t\t\ttimestamp: next.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tgroups.shift()?.close();\n\t\t\t}\n\n\t\t\tif (groups.length === 0) {\n\t\t\t\tconst closed = this.#state.closed.peek();\n\t\t\t\tif (closed instanceof Error) throw closed;\n\t\t\t\tif (closed !== undefined) return undefined;\n\t\t\t\tawait Signal.race(this.#state.groups, this.#cursor, this.#state.closed);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst group = groups[0];\n\t\t\tif (group.skipped) {\n\t\t\t\t// Fell behind this group's eviction window. Drop it and signal the gap;\n\t\t\t\t// the next read resyncs from the following group.\n\t\t\t\tgroups.shift()?.close();\n\t\t\t\tthrow new Lagged();\n\t\t\t}\n\t\t\tconst next = group.tryReadFrameSequence();\n\t\t\tif (next)\n\t\t\t\treturn {\n\t\t\t\t\tgroup: group.sequence,\n\t\t\t\t\tframe: next.sequence,\n\t\t\t\t\tpayload: next.payload,\n\t\t\t\t\ttimestamp: next.timestamp,\n\t\t\t\t};\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) return undefined;\n\n\t\t\t// A finished (drained + closed) group has nothing left: drop it and loop, rather than\n\t\t\t// busy-waiting on its already-resolved readable() (which would livelock and starve the\n\t\t\t// macrotask that delivers the next group).\n\t\t\tif (group.done) {\n\t\t\t\tgroups.shift()?.close();\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Lone open group with nothing buffered yet: wait for a frame on it, a new group, or\n\t\t\t// the track closing.\n\t\t\tawait Promise.race([Signal.race(this.#state.groups, this.#cursor, this.#state.closed), group.readable()]);\n\t\t}\n\t}\n\n\t/** Reads the next frame and decodes it as a UTF-8 string. */\n\tasync readString(): Promise<string | undefined> {\n\t\tconst next = await this.readFrame();\n\t\tif (!next) return undefined;\n\t\treturn new TextDecoder().decode(next.payload);\n\t}\n\n\t/** Reads the next frame and parses it as JSON. */\n\tasync readJson(): Promise<unknown | undefined> {\n\t\tconst next = await this.readString();\n\t\tif (!next) return undefined;\n\t\treturn JSON.parse(next);\n\t}\n\n\t/** Reads the next frame and decodes it as a one-byte boolean, throwing on a malformed frame. */\n\tasync readBool(): Promise<boolean | undefined> {\n\t\tconst next = await this.readFrame();\n\t\tif (!next) return undefined;\n\t\tconst payload = next.payload;\n\t\tif (payload.byteLength !== 1 || !(payload[0] === 0 || payload[0] === 1)) throw new Error(\"invalid bool frame\");\n\t\treturn payload[0] === 1;\n\t}\n\n\t/**\n\t * Update this subscription's options (e.g. priority), triggering a SUBSCRIBE_UPDATE to the\n\t * publisher. Mirrors the Rust `Subscriber::update`.\n\t */\n\tupdate(options: Subscription) {\n\t\tthis.#state.update.set(subscriptionDefaults(options));\n\t}\n}\n"]}
1
+ {"version":3,"file":"track.js","sourceRoot":"","sources":["../src/track.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAgC,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE1E,OAAO,EAA8C,QAAQ,IAAI,aAAa,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC3G,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,SAAS,EAAkB,MAAM,WAAW,CAAC;AAItD,iGAAiG;AACjG,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAK/B;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,KAAK,CAAC;AA+BjC,iEAAiE;AACjE,MAAM,UAAU,YAAY,CAAC,IAAI,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,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAC/G,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAAqB;QAC3B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;IACvD,CAAC;CACD","sourcesContent":["/**\n * Track role handles: a live stream of groups (and best-effort datagrams) within a broadcast.\n *\n * @module\n */\nimport { type GetPromise, type Getter, Once, Signal } from \"@moq/signals\";\nimport type { Datagram } from \"./datagram.ts\";\nimport { type Frame, type Consumer as GroupConsumer, Producer as GroupProducer, Lagged } from \"./group.ts\";\nimport { hooks } from \"./internal.ts\";\nimport { Timescale, type Timestamp } from \"./time.ts\";\n\nexport type { Datagram } from \"./datagram.ts\";\n\n/** Default {@link Info.latencyMax} window (milliseconds) when the publisher does not set one. */\nexport const DEFAULT_LATENCY_MAX_MS = 5000;\n\n/**\n * How long (milliseconds) a datagram stays in the per-subscriber buffer before it is dropped.\n *\n * Datagrams are a best-effort send buffer, not a replay cache (unlike groups): only the last few\n * tens of milliseconds are kept, so a consumer that stalls loses stale datagrams instead of\n * replaying them. Mirrors the Rust `MAX_DATAGRAM_AGE`.\n */\nconst MAX_DATAGRAM_AGE_MS = 50;\n\n/** A datagram buffered with its arrival time, so the send buffer can evict by age. */\ntype BufferedDatagram = { datagram: Datagram; time: number };\n\n/**\n * Sanity cap on a datagram payload: the QUIC DATAGRAM frame ceiling. The real limit is\n * per-hop (the negotiated transport datagram size minus a small header) and oversize\n * datagrams are dropped there; a payload above this cap could never fit anywhere.\n */\nconst MAX_DATAGRAM_BYTES = 65535;\n\n/**\n * A track's immutable publisher properties, fixed for the lifetime of the track.\n *\n * A producer declares these once (via {@link Request.accept} or\n * {@link Producer.accept}); a consumer awaits them via {@link Subscriber.info}\n * (resolved from the wire TRACK_INFO on lite-05+). They map 1:1 onto TRACK_INFO.\n */\nexport interface Info {\n\t/**\n\t * Units per second for this track's frame timestamps (reported in TRACK_INFO on\n\t * Lite05+). Defaults to milliseconds; set it finer (e.g. {@link Timescale.MICRO})\n\t * for media that needs sub-millisecond timing.\n\t */\n\ttimescale: Timescale;\n\t/**\n\t * Publisher Max Latency: the maximum age (milliseconds) of a non-latest group before\n\t * the publisher evicts it. Reported in TRACK_INFO (Lite05+) so relays re-serve with the\n\t * same bound. The publisher-side half of the budget a subscriber sets for itself.\n\t */\n\tlatencyMax: number;\n\t/** Tie-break priority between subscriptions of equal subscriber priority. */\n\tpriority: number;\n\t/**\n\t * Whether groups are prioritized in sequence order. Groups may always arrive\n\t * out-of-order (or not at all) over the network. Defaults to `false` (newest-first).\n\t */\n\tordered: boolean;\n}\n\n/** Fill in any unset {@link Info} fields with their defaults. */\nexport function infoDefaults(info: Partial<Info> = {}): Info {\n\treturn {\n\t\ttimescale: info.timescale ?? Timescale.MILLI,\n\t\tlatencyMax: info.latencyMax ?? DEFAULT_LATENCY_MAX_MS,\n\t\tpriority: info.priority ?? 0,\n\t\tordered: info.ordered ?? false,\n\t};\n}\n\n/**\n * Per-subscription options, requested when a subscription opens and adjustable later via\n * {@link Subscriber.update}. Mirrors the Rust `Subscription`.\n */\nexport interface Subscription {\n\t/** Delivery priority relative to this session's other subscriptions. Defaults to `0`. */\n\tpriority?: number;\n\t/** Whether groups are prioritized in sequence order. Defaults to `false` (newest-first). */\n\tordered?: boolean;\n\t/** Maximum age (milliseconds) of a non-latest group before it is skipped. Defaults to `0`. */\n\tlatencyMax?: number;\n\t/** First group the publisher should deliver, or omit to start at the latest group. */\n\tstartGroup?: number;\n\t/** Last group the publisher should deliver (inclusive), or omit for no end. */\n\tendGroup?: number;\n}\n\n// Materialize the defaults at the model boundary so every layer observes a complete\n// subscription rather than interpreting an omitted field differently.\nfunction subscriptionDefaults(subscription: Subscription = {}): Subscription {\n\treturn {\n\t\tpriority: subscription.priority ?? 0,\n\t\tordered: subscription.ordered ?? false,\n\t\tlatencyMax: subscription.latencyMax ?? 0,\n\t\tstartGroup: subscription.startGroup,\n\t\tendGroup: subscription.endGroup,\n\t};\n}\n\n// Aggregate the preferences of every live subscriber, matching Rust's Subscription::poll_combined.\nfunction combineSubscriptions(states: Iterable<TrackState>): Subscription | undefined {\n\tlet combined: Subscription | undefined;\n\tfor (const state of states) {\n\t\tconst subscription = state.update.peek();\n\t\tif (!subscription) continue;\n\t\tif (!combined) {\n\t\t\tcombined = { ...subscription };\n\t\t\tcontinue;\n\t\t}\n\n\t\tcombined.priority = Math.max(combined.priority ?? 0, subscription.priority ?? 0);\n\t\tcombined.ordered = (combined.ordered ?? false) && (subscription.ordered ?? false);\n\t\tcombined.latencyMax = Math.max(combined.latencyMax ?? 0, subscription.latencyMax ?? 0);\n\n\t\tif (subscription.startGroup !== undefined) {\n\t\t\tcombined.startGroup =\n\t\t\t\tcombined.startGroup === undefined\n\t\t\t\t\t? subscription.startGroup\n\t\t\t\t\t: Math.min(combined.startGroup, subscription.startGroup);\n\t\t}\n\n\t\tif (combined.endGroup === undefined || subscription.endGroup === undefined) {\n\t\t\tcombined.endGroup = undefined;\n\t\t} else {\n\t\t\tcombined.endGroup = Math.max(combined.endGroup, subscription.endGroup);\n\t\t}\n\t}\n\treturn combined;\n}\n\n/**\n * A request for a track the peer wants, yielded by `Broadcast.Producer.requested`.\n *\n * Created internally by the broadcast when a subscription (or info lookup) needs a track\n * served; answer it with {@link accept} or {@link reject}.\n *\n * @public\n */\nexport class Request {\n\t/** The requested track name. */\n\treadonly name: string;\n\n\t#producer: Producer;\n\n\tprivate constructor(name: string, producer: Producer) {\n\t\tthis.name = name;\n\t\tthis.#producer = producer;\n\t}\n\n\tstatic {\n\t\thooks.makeRequest = (name, producer) => new Request(name, producer);\n\t}\n\n\t/** The aggregate subscription requested for this track. */\n\tget subscription(): Readonly<Subscription> {\n\t\treturn this.#producer.subscription.peek() ?? subscriptionDefaults();\n\t}\n\n\t/** The subscriber's priority for this track. */\n\tget priority(): number {\n\t\treturn this.subscription.priority ?? 0;\n\t}\n\n\t/** Accept the request, committing the track's immutable {@link Info}. */\n\taccept(info: Partial<Info> = {}): Producer {\n\t\treturn this.#producer.accept(info);\n\t}\n\n\t/** Reject the request, closing the track optionally with an error. */\n\treject(err?: Error): void {\n\t\tthis.#producer.close(err);\n\t}\n}\n\n/** Options for {@link Consumer.fetchGroup}. */\nexport interface FetchGroupOptions {\n\t/** Delivery priority for the fetch stream. Defaults to `0`. */\n\tpriority?: number;\n}\n\n/**\n * The per-track operations a lazy {@link Consumer} delegates to the broadcast it came from.\n *\n * Implemented by `broadcast.Producer` / `broadcast.Consumer` (and the wire-layer subclasses\n * that resolve them over the network), so a track handle holds a reference to its broadcast\n * and calls methods on it rather than capturing a bag of callbacks.\n */\nexport interface Broadcast {\n\t/** Open a live subscription to the named track. */\n\tsubscribe(name: string, options?: Subscription): Subscriber;\n\t/** Resolve the named track's immutable info. */\n\tresolveTrackInfo(name: string): Promise<Info>;\n\t/** Fetch a single group of the named track by sequence. */\n\tfetchGroup(name: string, sequence: number, options?: FetchGroupOptions): Promise<GroupConsumer>;\n}\n\n/**\n * A lazy handle to a track on a consumed broadcast.\n *\n * @public\n */\nexport class Consumer {\n\t/** The track name. */\n\treadonly name: string;\n\n\t#broadcast: Broadcast;\n\n\tconstructor(name: string, broadcast: Broadcast) {\n\t\tthis.name = name;\n\t\tthis.#broadcast = broadcast;\n\t}\n\n\t/** Open a live subscription to the track. */\n\tsubscribe(options?: Subscription): Subscriber {\n\t\treturn this.#broadcast.subscribe(this.name, options);\n\t}\n\n\t/** Fetch the track's immutable publisher properties without subscribing. */\n\tinfo(): Promise<Info> {\n\t\treturn this.#broadcast.resolveTrackInfo(this.name);\n\t}\n\n\t/** Fetch a single group by sequence without holding a live subscription. */\n\tfetchGroup(sequence: number, options?: FetchGroupOptions): Promise<GroupConsumer> {\n\t\treturn this.#broadcast.fetchGroup(this.name, sequence, options);\n\t}\n}\n\n// The shared state behind a Producer / Subscriber pair. Package-internal\n// wiring, unexported so it never appears in the published type declarations.\nclass TrackState {\n\tgroups = new Signal<GroupConsumer[]>([]);\n\t/** Best-effort datagram channel, parallel to {@link groups}; an age-evicted send buffer per subscriber. */\n\tdatagrams = new Signal<BufferedDatagram[]>([]);\n\tlatest?: number;\n\tclosed = new Once<Error | null>();\n\tupdate: Signal<Subscription | undefined>;\n\t/** Resolved once the producer commits the immutable properties. */\n\tinfo = new Signal<Info | undefined>(undefined);\n\n\tconstructor(subscription?: Subscription) {\n\t\tthis.update = new Signal(subscription === undefined ? undefined : subscriptionDefaults(subscription));\n\t}\n}\n\n// Settle a track state's closed Once. Idempotent: Once.set throws on a second settle, and a\n// Producer closing its sinks races the Subscriber closing itself (the sink is only removed from\n// #sinks a microtask later, via the closed subscription below).\nfunction closeTrackState(state: TrackState, abort?: Error): boolean {\n\tif (state.closed.peek() !== undefined) return false;\n\tstate.closed.set(abort ?? null);\n\treturn true;\n}\n\n// Resolve the track's immutable publisher properties, or reject if it closes first.\n// On a producer this resolves once info is committed (at accept time); on a consumer\n// once the wire layer commits the TRACK_INFO it received (lite-05+) or defaults (older\n// drafts), so awaiting it never yields a placeholder.\nasync function resolveInfo(state: TrackState): Promise<Info> {\n\tfor (;;) {\n\t\tconst info = state.info.peek();\n\t\tif (info) return info;\n\n\t\tconst closed = state.closed.peek();\n\t\tif (closed instanceof Error) throw closed;\n\t\tif (closed !== undefined) throw new Error(\"track closed before info was known\");\n\n\t\tawait Signal.race(state.info, state.closed);\n\t}\n}\n\n// A source group retained in the producer cache, with the mirror handed to each sink\n// so eviction can drop them together.\ntype CachedGroup = { group: GroupProducer; time: number; mirrors: Map<TrackState, GroupConsumer> };\n\n// Constructs a Subscriber from within this module without exposing a public\n// constructor that would leak the unexported TrackState. Assigned in the class's\n// static block.\nlet makeSubscriber: (name: string, state: TrackState) => Subscriber;\n\n/**\n * The write side of a track, mirroring the Rust `Producer`.\n *\n * A producer is a fan-out source: every {@link subscribe} (including each wire\n * subscription the publisher serves from it) gets an independent\n * {@link Subscriber} that receives a full copy of the groups, each with its own\n * read cursor. Groups are mirrored into every live subscriber and retained for the\n * track's `latencyMax` window so a late subscriber replays the recent groups.\n *\n * Obtained from {@link Request.accept} (the wire asks the application for a track to\n * serve) or constructed directly for an in-process track.\n */\nexport class Producer {\n\t/** The track name. */\n\treadonly name: string;\n\n\t// The producer's own state is the source of truth (info/closed); subscribers\n\t// read mirrored sinks, never this state directly.\n\t#state = new TrackState();\n\n\t#next?: number;\n\n\t// Recently written source groups, retained for replay to late subscribers and\n\t// pruned once closed and older than the cache window. Each entry tracks the mirror\n\t// it handed to every sink so eviction can drop them too: otherwise a slow consumer\n\t// that never reads would pin old groups (and their frame bytes) forever.\n\t#cache: CachedGroup[] = [];\n\n\t// One independent downstream state per live subscriber.\n\t#sinks = new Set<TrackState>();\n\n\t// Whether any subscriber is currently attached. Exposed as {@link used}; the consumer wire\n\t// watches it to tear down an idle upstream, and a publisher can watch it for on-demand capture.\n\t#used = new Signal<boolean>(false);\n\n\tconstructor(name: string) {\n\t\tthis.name = name;\n\t}\n\n\t/**\n\t * Resolve this track's immutable publisher properties, committed at accept time.\n\t * Rejects if the track is closed before the properties are known.\n\t */\n\tinfo(): Promise<Info> {\n\t\treturn resolveInfo(this.#state);\n\t}\n\n\t/**\n\t * Settles once the track closes: `null` on a clean close, or the abort {@link Error}.\n\t * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/**\n\t * The aggregate subscription across live subscribers, or `undefined` when there are none.\n\t * The wire layer watches this to emit SUBSCRIBE_UPDATE.\n\t */\n\tget subscription(): Getter<Subscription | undefined> {\n\t\treturn this.#state.update;\n\t}\n\n\t/** Commit the immutable publisher properties, resolving {@link info}. Returns `this`. */\n\taccept(info: Partial<Info> = {}): this {\n\t\tconst resolved = infoDefaults(info);\n\t\tthis.#state.info.set(resolved);\n\t\t// Propagate to any sink handed out before accept (the on-demand path).\n\t\tfor (const sink of this.#sinks) sink.info.set(resolved);\n\t\treturn this;\n\t}\n\n\t/** An independent {@link Subscriber} receiving a full copy of this track's groups. */\n\tsubscribe(options: Subscription = {}): Subscriber {\n\t\tconst sink = new TrackState(options);\n\t\tthis.#addSink(sink);\n\t\treturn makeSubscriber(this.name, sink);\n\t}\n\n\t/**\n\t * Whether the track currently has any subscribers.\n\t *\n\t * Watch it (`effect.get` / `.peek()`) to drive on-demand work: a publisher can start and stop\n\t * capture with demand, and the consumer wire watches it to tear an idle upstream subscription\n\t * down instead of downloading to nobody. Pairs with {@link unused}. Mirrors the Rust `Demand`.\n\t */\n\tget used(): Getter<boolean> {\n\t\treturn this.#used;\n\t}\n\n\t/** Resolves once the track has no subscribers (or has closed). Await it to react to demand ending. */\n\tasync unused(): Promise<void> {\n\t\twhile (this.#used.peek() && this.#state.closed.peek() === undefined) {\n\t\t\tawait Signal.race(this.#used, this.#state.closed);\n\t\t}\n\t}\n\n\t// Register a downstream sink: seed its info, replay the retained window, and (while\n\t// the track is open) mirror future groups into it. A late subscriber to a closed\n\t// track still drains the buffered groups before seeing the end.\n\t#addSink(sink: TrackState): void {\n\t\tconst info = this.#state.info.peek();\n\t\tif (info) sink.info.set(info);\n\n\t\tconst closed = this.#state.closed.peek();\n\t\tif (closed === undefined) {\n\t\t\tthis.#sinks.add(sink);\n\t\t\tthis.#used.set(true);\n\n\t\t\t// Forward subscription updates from the sink's Subscriber to the producer's own\n\t\t\t// state, which the wire layer (or the serving application) watches.\n\t\t\tconst forward = sink.update.subscribe(() => this.#updateSubscription());\n\t\t\tthis.#updateSubscription();\n\n\t\t\t// Drop the sink once its consumer goes away, closing its mirrors so source\n\t\t\t// groups stop teeing into them, so a long-lived producer doesn't leak. This\n\t\t\t// covers mirrors already handed out via recvGroup (no longer in sink.groups)\n\t\t\t// by closing them through the cache's per-sink tracking.\n\t\t\tconst dispose = sink.closed.subscribe((c) => {\n\t\t\t\tif (c === undefined) return;\n\t\t\t\tconst abort = c instanceof Error ? c : undefined;\n\t\t\t\tforward();\n\t\t\t\tthis.#sinks.delete(sink);\n\t\t\t\tthis.#updateSubscription();\n\t\t\t\tfor (const entry of this.#cache) {\n\t\t\t\t\tconst mirror = entry.mirrors.get(sink);\n\t\t\t\t\tif (mirror) {\n\t\t\t\t\t\tmirror.close(abort);\n\t\t\t\t\t\tentry.mirrors.delete(sink);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const group of sink.groups.peek()) group.close(abort);\n\t\t\t\tdispose();\n\n\t\t\t\t// Update demand: once the last subscriber leaves, the consumer wire (watching\n\t\t\t\t// {@link unused}) tears the upstream down instead of downloading to nobody.\n\t\t\t\tthis.#used.set(this.#sinks.size > 0);\n\t\t\t});\n\t\t}\n\n\t\tthis.#prune();\n\t\tfor (const entry of this.#cache) this.#mirror(entry, sink);\n\n\t\tif (closed !== undefined) closeTrackState(sink, closed instanceof Error ? closed : undefined);\n\t}\n\n\t// Recompute from every live sink because an update or close can narrow as well as widen\n\t// the aggregate. The wire layer observes this signal and emits SUBSCRIBE_UPDATE.\n\t#updateSubscription(): void {\n\t\tthis.#state.update.set(combineSubscriptions(this.#sinks));\n\t}\n\n\t// Mirror a cached source group into a sink. The mirror fills synchronously as the\n\t// source is written and keeps its own read cursor; frame bytes are shared by\n\t// reference. Tracked on the entry so eviction can drop it from the sink.\n\t#mirror(entry: CachedGroup, sink: TrackState): void {\n\t\tconst dst = entry.group.mirror();\n\t\tentry.mirrors.set(sink, dst);\n\t\tsink.latest = Math.max(sink.latest ?? 0, dst.sequence);\n\t\tsink.groups.mutate((groups) => {\n\t\t\tgroups.push(dst);\n\t\t\tgroups.sort((a, b) => a.sequence - b.sequence);\n\t\t});\n\t}\n\n\t// Drop a cached group's mirror from every sink so no consumer can pin it.\n\t#evict(entry: CachedGroup): void {\n\t\tfor (const [sink, mirror] of entry.mirrors) {\n\t\t\tsink.groups.mutate((groups) => {\n\t\t\t\tconst i = groups.indexOf(mirror);\n\t\t\t\tif (i >= 0) groups.splice(i, 1);\n\t\t\t});\n\t\t\tmirror.close();\n\t\t}\n\t\tentry.mirrors.clear();\n\t}\n\n\t// Evict cached groups that are closed and older than the cache window.\n\t#prune(): void {\n\t\tconst latencyMaxMs = this.#state.info.peek()?.latencyMax ?? DEFAULT_LATENCY_MAX_MS;\n\t\tconst cutoff = Date.now() - latencyMaxMs;\n\n\t\tconst retained: CachedGroup[] = [];\n\t\tfor (const entry of this.#cache) {\n\t\t\tif (entry.time > cutoff || entry.group.closed.peek() === undefined) {\n\t\t\t\tretained.push(entry);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.#evict(entry);\n\t\t}\n\t\tthis.#cache = retained;\n\t}\n\n\t// Retain a source group and fan it out to every live sink.\n\t#publish(group: GroupProducer): void {\n\t\tconst entry: CachedGroup = { group, time: Date.now(), mirrors: new Map<TrackState, GroupConsumer>() };\n\t\tthis.#cache.push(entry);\n\t\tthis.#prune();\n\t\tfor (const sink of this.#sinks) this.#mirror(entry, sink);\n\t}\n\n\t/** Append a new group with the next sequence number. */\n\tappendGroup(): GroupProducer {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\n\t\tconst group = new GroupProducer(this.#next ?? 0);\n\t\tthis.#next = group.sequence + 1;\n\t\tthis.#publish(group);\n\n\t\treturn group;\n\t}\n\n\t/**\n\t * Insert an existing group into the track.\n\t *\n\t * Throws on a sequence that is still cached: a live duplicate would fan out to every\n\t * subscriber twice. An aborted incarnation is evicted so a fresh group can serve the\n\t * sequence again. Best effort (mirrors Rust): nothing remembers a sequence whose cache\n\t * entry is already gone, so a long-evicted sequence is accepted as new.\n\t */\n\twriteGroup(group: GroupProducer) {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\n\t\tconst existing = this.#cache.findIndex((entry) => entry.group.sequence === group.sequence);\n\t\tif (existing >= 0) {\n\t\t\tconst entry = this.#cache[existing];\n\t\t\tif (!(entry.group.closed.peek() instanceof Error)) {\n\t\t\t\tthrow new Error(`duplicate group: sequence=${group.sequence}`);\n\t\t\t}\n\t\t\tthis.#evict(entry);\n\t\t\tthis.#cache.splice(existing, 1);\n\t\t}\n\n\t\t// Only advance #next upward (for appendGroup auto-increment).\n\t\tif (group.sequence >= (this.#next ?? 0)) {\n\t\t\tthis.#next = group.sequence + 1;\n\t\t}\n\n\t\tthis.#publish(group);\n\t}\n\n\t// Fan a datagram out to every live subscriber, dropping the oldest once the ring is full.\n\t// Late subscribers do NOT replay old datagrams (best-effort, unlike the group cache).\n\t#publishDatagram(datagram: Datagram): void {\n\t\tconst now = performance.now();\n\t\tfor (const sink of this.#sinks) {\n\t\t\tsink.datagrams.mutate((list) => {\n\t\t\t\tlist.push({ datagram, time: now });\n\t\t\t\t// Drop anything older than the send-buffer window.\n\t\t\t\twhile (list.length > 0 && now - list[0].time > MAX_DATAGRAM_AGE_MS) list.shift();\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Append a datagram with the next sequence number, returning the assigned sequence.\n\t *\n\t * A datagram is delivered best-effort over a single QUIC datagram, parallel to the track's\n\t * groups but drawing from the same sequence namespace (interleaving with {@link appendGroup}\n\t * never reuses a number). The payload must fit the negotiated transport datagram size minus\n\t * a small header; an oversize payload is dropped at each hop (there is no group fallback), so\n\t * keep datagram payloads small (e.g. a single audio frame). Datagrams are never delivered\n\t * over IETF moq-transport or stream-only transports (the WebSocket fallback). A payload over\n\t * 65535 bytes (the QUIC datagram frame ceiling) throws. An origin publisher uses this; a\n\t * relay preserving upstream numbering uses {@link writeDatagram}.\n\t */\n\tappendDatagram(timestamp: Timestamp, payload: Uint8Array): number {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\t\tif (payload.byteLength > MAX_DATAGRAM_BYTES) throw new Error(\"datagram payload too large\");\n\n\t\tconst sequence = this.#next ?? 0;\n\t\tthis.#next = sequence + 1;\n\t\tthis.#publishDatagram({ sequence, timestamp, payload });\n\t\treturn sequence;\n\t}\n\n\t/**\n\t * Write a datagram with an explicit sequence number.\n\t *\n\t * Preserves the supplied sequence (advancing the shared counter if needed) so a relay can\n\t * forward a datagram without renumbering it. The size limits of {@link appendDatagram}\n\t * apply. Most origin publishers want {@link appendDatagram} instead.\n\t */\n\twriteDatagram(datagram: Datagram) {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\t\tif (datagram.payload.byteLength > MAX_DATAGRAM_BYTES) throw new Error(\"datagram payload too large\");\n\n\t\tif (datagram.sequence >= (this.#next ?? 0)) {\n\t\t\tthis.#next = datagram.sequence + 1;\n\t\t}\n\t\tthis.#publishDatagram(datagram);\n\t}\n\n\t/** Close the track and every subscriber, mirroring the abort to their groups. Idempotent. */\n\tclose(abort?: Error) {\n\t\tcloseTrackState(this.#state, abort);\n\t\tfor (const { group } of this.#cache) group.close(abort);\n\t\tfor (const sink of this.#sinks) {\n\t\t\tfor (const group of sink.groups.peek()) group.close(abort);\n\t\t\tcloseTrackState(sink, abort);\n\t\t}\n\t\tthis.#sinks.clear();\n\t}\n\n\t/** Append a frame as its own single-frame group. */\n\twriteFrame(frame: Frame) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeFrame(frame);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a string to the track as its own single-frame group. */\n\twriteString(str: string) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeString(str);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a JSON value to the track as its own single-frame group. */\n\twriteJson(json: unknown) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeJson(json);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a boolean to the track as its own single-frame group. */\n\twriteBool(bool: boolean) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeBool(bool);\n\t\tgroup.close();\n\t}\n}\n\n/**\n * The read side of a live track subscription, mirroring the Rust `Subscriber`.\n *\n * Obtained from `Broadcast.Consumer.subscribe` / `Track.Consumer.subscribe`, or from\n * {@link Producer.subscribe} for an in-process track. Reads the groups a\n * {@link Producer} on the same underlying state writes.\n */\nexport class Subscriber {\n\t/** The track name. */\n\treadonly name: string;\n\n\t#state: TrackState;\n\t#nextSequence = 0;\n\t#cursor = new Signal<{ start: number; end?: number }>({ start: 0 });\n\n\tprivate constructor(name: string, state: TrackState) {\n\t\tthis.name = name;\n\t\tthis.#state = state;\n\t}\n\n\tstatic {\n\t\tmakeSubscriber = (name, state) => new Subscriber(name, state);\n\t}\n\n\t/**\n\t * Resolve this track's immutable publisher properties.\n\t *\n\t * Resolves once the wire layer commits the TRACK_INFO it received (lite-05+) or\n\t * defaults (older drafts), so awaiting it never yields a placeholder. Rejects if\n\t * the track is closed before the properties are known (e.g. a rejected subscription).\n\t */\n\tinfo(): Promise<Info> {\n\t\treturn resolveInfo(this.#state);\n\t}\n\n\t/** Settles once the track closes; see {@link Producer.closed}. */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/** This subscriber's current options, including defaults and the last {@link update}. */\n\tget subscription(): Getter<Subscription | undefined> {\n\t\treturn this.#state.update;\n\t}\n\n\t/** Return the latest group sequence observed on this track, if any. */\n\tlatest(): number | undefined {\n\t\treturn this.#state.latest;\n\t}\n\n\t/** Start this subscriber's local read cursor at `sequence`, without changing its wire request. */\n\tstartAt(sequence: number): void {\n\t\tthis.#cursor.update((cursor) => ({ ...cursor, start: sequence }));\n\t}\n\n\t/**\n\t * Cap {@link nextGroup} and {@link recvGroup} at `sequence` inclusively, or omit it to\n\t * remove the cap. Groups above the cap remain buffered and become readable if the cap\n\t * is raised. This local cursor does not change the subscription's wire request.\n\t */\n\tendAt(sequence?: number): void {\n\t\tthis.#cursor.update((cursor) => ({ ...cursor, end: sequence }));\n\t}\n\n\t/** Close the track (optionally with an error), closing any pending groups. Idempotent. */\n\tclose(abort?: Error) {\n\t\t// Settle if we're first (the producer may already have); either way drop anything\n\t\t// still buffered. Groups parked at the endAt cap deliberately outlive a clean\n\t\t// producer close, so the subscriber leaving is what must release them: closing\n\t\t// and clearing wakes a pending read to observe the end instead of hanging.\n\t\tcloseTrackState(this.#state, abort);\n\t\tthis.#state.groups.mutate((groups) => {\n\t\t\tfor (const group of groups) group.close(abort);\n\t\t\tgroups.length = 0;\n\t\t});\n\t}\n\n\t/**\n\t * Receive every group on this track exactly once, as it becomes available.\n\t *\n\t * Groups may arrive out of order or with gaps due to network conditions; unlike\n\t * {@link nextGroup}, one that arrives after a newer group was already returned is\n\t * still delivered. When several groups are buffered, the lowest sequence is\n\t * returned first.\n\t *\n\t * Honors the floor set by {@link startAt} and the cap set by {@link endAt}: a group\n\t * beyond the cap stays buffered (not dropped) and is offered once the cap rises, even\n\t * after a clean close, without blocking in-range groups that arrive behind it.\n\t */\n\tasync recvGroup(): Promise<GroupConsumer | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.#state.groups.peek();\n\t\t\tconst { start, end } = this.#cursor.peek();\n\t\t\twhile (groups.length > 0 && groups[0].sequence < start) groups.shift()?.close();\n\n\t\t\t// The buffer is sequence-sorted, so an in-range group that arrives behind a\n\t\t\t// beyond-cap one sorts in front of it and is never blocked by it.\n\t\t\tconst group = groups[0];\n\t\t\tif (group && (end === undefined || group.sequence <= end)) {\n\t\t\t\tgroups.shift();\n\t\t\t\treturn group;\n\t\t\t}\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\t// A group beyond the cap outlives a clean close: it becomes deliverable if\n\t\t\t// the cap rises, so the track isn't over while any are held.\n\t\t\tif (closed !== undefined && !group) return undefined;\n\n\t\t\tawait Signal.race(this.#state.groups, this.#cursor, this.#state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * Receive the next datagram in arrival order.\n\t *\n\t * Datagrams are a separate best-effort channel from groups (see\n\t * {@link Producer.appendDatagram}); they share only the sequence namespace. A consumer\n\t * that falls too far behind silently loses the oldest datagrams. Read this alongside\n\t * {@link recvGroup} (e.g. in a separate loop) to receive both channels concurrently. Returning\n\t * a datagram advances {@link nextGroup} past that sequence.\n\t */\n\tasync recvDatagram(): Promise<Datagram | undefined> {\n\t\tfor (;;) {\n\t\t\tconst datagrams = this.#state.datagrams.peek();\n\n\t\t\t// Evict datagrams older than the send-buffer window (also enforced on write), so a\n\t\t\t// reader that stalled skips stale datagrams instead of replaying them.\n\t\t\tconst cutoff = performance.now() - MAX_DATAGRAM_AGE_MS;\n\t\t\twhile (datagrams.length > 0 && datagrams[0].time < cutoff) datagrams.shift();\n\n\t\t\tif (datagrams.length > 0) {\n\t\t\t\tconst datagram = datagrams.shift()?.datagram;\n\t\t\t\tif (datagram) {\n\t\t\t\t\tthis.#nextSequence = Math.max(this.#nextSequence, datagram.sequence + 1);\n\t\t\t\t}\n\t\t\t\treturn datagram;\n\t\t\t}\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) return undefined;\n\n\t\t\tawait Signal.race(this.#state.datagrams, this.#state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * Return the next group with a strictly-greater sequence number than the last returned.\n\t *\n\t * Late arrivals (sequence at or below the last returned) are silently skipped.\n\t * Use {@link recvGroup} to see every group in arrival order instead.\n\t */\n\tasync nextGroup(): Promise<GroupConsumer | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.#state.groups.peek();\n\t\t\tconst cursor = this.#cursor.peek();\n\t\t\tconst start = Math.max(cursor.start, this.#nextSequence);\n\t\t\twhile (groups.length > 0 && groups[0].sequence < start) groups.shift()?.close();\n\n\t\t\tconst group = groups[0];\n\t\t\tif (group && (cursor.end === undefined || group.sequence <= cursor.end)) {\n\t\t\t\tgroups.shift();\n\t\t\t\tthis.#nextSequence = group.sequence + 1;\n\t\t\t\treturn group;\n\t\t\t}\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined && !group) return undefined;\n\n\t\t\tawait Signal.race(this.#state.groups, this.#cursor, this.#state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * Reads the next frame across all groups, discarding older groups.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t */\n\tasync readFrame(): Promise<Frame | undefined> {\n\t\tconst next = await this.readFrameSequence();\n\t\treturn next ? { payload: next.payload, timestamp: next.timestamp } : undefined;\n\t}\n\n\t/**\n\t * Reads the next frame along with its group and frame sequence numbers.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t */\n\tasync readFrameSequence(): Promise<({ group: number; frame: number } & Frame) | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.#state.groups.peek();\n\t\t\tconst { start } = this.#cursor.peek();\n\t\t\twhile (groups.length > 0 && groups[0].sequence < start) groups.shift()?.close();\n\n\t\t\t// Drain older groups first, dropping each once empty.\n\t\t\twhile (groups.length > 1) {\n\t\t\t\tif (groups[0].skipped) {\n\t\t\t\t\t// The reader fell behind this group's eviction window. Drop it and\n\t\t\t\t\t// signal the gap; the next read resyncs from the following group.\n\t\t\t\t\tgroups.shift()?.close();\n\t\t\t\t\tthrow new Lagged();\n\t\t\t\t}\n\t\t\t\tconst next = groups[0].tryReadFrameSequence();\n\t\t\t\tif (next) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tgroup: groups[0].sequence,\n\t\t\t\t\t\tframe: next.sequence,\n\t\t\t\t\t\tpayload: next.payload,\n\t\t\t\t\t\ttimestamp: next.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tgroups.shift()?.close();\n\t\t\t}\n\n\t\t\tif (groups.length === 0) {\n\t\t\t\tconst closed = this.#state.closed.peek();\n\t\t\t\tif (closed instanceof Error) throw closed;\n\t\t\t\tif (closed !== undefined) return undefined;\n\t\t\t\tawait Signal.race(this.#state.groups, this.#cursor, this.#state.closed);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst group = groups[0];\n\t\t\tif (group.skipped) {\n\t\t\t\t// Fell behind this group's eviction window. Drop it and signal the gap;\n\t\t\t\t// the next read resyncs from the following group.\n\t\t\t\tgroups.shift()?.close();\n\t\t\t\tthrow new Lagged();\n\t\t\t}\n\t\t\tconst next = group.tryReadFrameSequence();\n\t\t\tif (next)\n\t\t\t\treturn {\n\t\t\t\t\tgroup: group.sequence,\n\t\t\t\t\tframe: next.sequence,\n\t\t\t\t\tpayload: next.payload,\n\t\t\t\t\ttimestamp: next.timestamp,\n\t\t\t\t};\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) return undefined;\n\n\t\t\t// A finished (drained + closed) group has nothing left: drop it and loop, rather than\n\t\t\t// busy-waiting on its already-resolved readable() (which would livelock and starve the\n\t\t\t// macrotask that delivers the next group).\n\t\t\tif (group.done) {\n\t\t\t\tgroups.shift()?.close();\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Lone open group with nothing buffered yet: wait for a frame on it, a new group, or\n\t\t\t// the track closing.\n\t\t\tawait Promise.race([Signal.race(this.#state.groups, this.#cursor, this.#state.closed), group.readable()]);\n\t\t}\n\t}\n\n\t/** Reads the next frame and decodes it as a UTF-8 string. */\n\tasync readString(): Promise<string | undefined> {\n\t\tconst next = await this.readFrame();\n\t\tif (!next) return undefined;\n\t\treturn new TextDecoder().decode(next.payload);\n\t}\n\n\t/** Reads the next frame and parses it as JSON. */\n\tasync readJson(): Promise<unknown | undefined> {\n\t\tconst next = await this.readString();\n\t\tif (!next) return undefined;\n\t\treturn JSON.parse(next);\n\t}\n\n\t/** Reads the next frame and decodes it as a one-byte boolean, throwing on a malformed frame. */\n\tasync readBool(): Promise<boolean | undefined> {\n\t\tconst next = await this.readFrame();\n\t\tif (!next) return undefined;\n\t\tconst payload = next.payload;\n\t\tif (payload.byteLength !== 1 || !(payload[0] === 0 || payload[0] === 1)) throw new Error(\"invalid bool frame\");\n\t\treturn payload[0] === 1;\n\t}\n\n\t/**\n\t * Update this subscription's options (e.g. priority), triggering a SUBSCRIBE_UPDATE to the\n\t * publisher. Mirrors the Rust `Subscriber::update`.\n\t */\n\tupdate(options: Subscription) {\n\t\tthis.#state.update.set(subscriptionDefaults(options));\n\t}\n}\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=announced.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"announced.test.d.ts","sourceRoot":"","sources":["../src/announced.test.ts"],"names":[],"mappings":""}
package/announced.test.js DELETED
@@ -1,37 +0,0 @@
1
- /* @ts-self-types="./announced.test.d.ts" */
2
- import { expect, test } from "bun:test";
3
- import * as Announce from "./announced.js";
4
- import * as Path from "./path.js";
5
- const p = (s) => Path.from(s);
6
- test("next streams every appended event in order", async () => {
7
- const producer = new Announce.Producer();
8
- const consumer = producer.consume();
9
- producer.append({ path: p("a"), active: true });
10
- producer.append({ path: p("a"), active: false });
11
- expect(await consumer.next()).toEqual({ path: p("a"), active: true });
12
- expect(await consumer.next()).toEqual({ path: p("a"), active: false });
13
- });
14
- test("a same-name re-announce is a distinct update", async () => {
15
- const producer = new Announce.Producer();
16
- const consumer = producer.consume();
17
- // The stream is a log, not a set: it carries a redundant active:true as its own update rather
18
- // than collapsing it. Deciding what a repeat means belongs to the session layer, which resolves
19
- // a restart into either nothing (a route change) or an end + start (a new publisher).
20
- producer.append({ path: p("a"), active: true });
21
- producer.append({ path: p("a"), active: true });
22
- expect(await consumer.next()).toEqual({ path: p("a"), active: true });
23
- expect(await consumer.next()).toEqual({ path: p("a"), active: true });
24
- });
25
- test("closing resolves next with undefined", async () => {
26
- const producer = new Announce.Producer();
27
- const consumer = producer.consume();
28
- producer.close();
29
- expect(await consumer.next()).toBeUndefined();
30
- });
31
- test("aborting rejects next", async () => {
32
- const producer = new Announce.Producer();
33
- const consumer = producer.consume();
34
- producer.close(new Error("boom"));
35
- await expect(consumer.next()).rejects.toThrow("boom");
36
- });
37
- //# sourceMappingURL=announced.test.js.map
@@ -1 +0,0 @@
1
-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,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport * as Announce from \"./announced.ts\";\nimport * as Path from \"./path.ts\";\n\nconst p = (s: string) => Path.from(s);\n\ntest(\"next streams every appended event in order\", async () => {\n\tconst producer = new Announce.Producer();\n\tconst consumer = producer.consume();\n\n\tproducer.append({ path: p(\"a\"), active: true });\n\tproducer.append({ path: p(\"a\"), active: false });\n\n\texpect(await consumer.next()).toEqual({ path: p(\"a\"), active: true });\n\texpect(await consumer.next()).toEqual({ path: p(\"a\"), active: false });\n});\n\ntest(\"a same-name re-announce is a distinct update\", async () => {\n\tconst producer = new Announce.Producer();\n\tconst consumer = producer.consume();\n\n\t// The stream is a log, not a set: it carries a redundant active:true as its own update rather\n\t// than collapsing it. Deciding what a repeat means belongs to the session layer, which resolves\n\t// a restart into either nothing (a route change) or an end + start (a new publisher).\n\tproducer.append({ path: p(\"a\"), active: true });\n\tproducer.append({ path: p(\"a\"), active: true });\n\n\texpect(await consumer.next()).toEqual({ path: p(\"a\"), active: true });\n\texpect(await consumer.next()).toEqual({ path: p(\"a\"), active: true });\n});\n\ntest(\"closing resolves next with undefined\", async () => {\n\tconst producer = new Announce.Producer();\n\tconst consumer = producer.consume();\n\n\tproducer.close();\n\texpect(await consumer.next()).toBeUndefined();\n});\n\ntest(\"aborting rejects next\", async () => {\n\tconst producer = new Announce.Producer();\n\tconst consumer = producer.consume();\n\n\tproducer.close(new Error(\"boom\"));\n\tawait expect(consumer.next()).rejects.toThrow(\"boom\");\n});\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=broadcast.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"broadcast.test.d.ts","sourceRoot":"","sources":["../src/broadcast.test.ts"],"names":[],"mappings":""}
package/broadcast.test.js DELETED
@@ -1,243 +0,0 @@
1
- /* @ts-self-types="./broadcast.test.d.ts" */
2
- import { expect, setSystemTime, test } from "bun:test";
3
- import { Consumer as BroadcastConsumer, Producer as BroadcastProducer } from "./broadcast.js";
4
- import { Lagged, MAX_GROUP_FRAMES } from "./group.js";
5
- import { Timestamp } from "./time.js";
6
- import { Producer as TrackProducer } from "./track.js";
7
- // The public API mints consumers internally (Producer.consume, the wire layers); tests act
8
- // as a wire layer by subclassing, the same way lite's ConsumeBroadcast does.
9
- class TestConsumer extends BroadcastConsumer {
10
- // biome-ignore lint/complexity/noUselessConstructor: widens the protected base constructor to public
11
- constructor() {
12
- super();
13
- }
14
- }
15
- // Observe whether an on-demand track request is pending without blocking: returns the
16
- // next request if one has already been emitted, or undefined if none is (yet) waiting.
17
- async function pendingRequest(broadcast) {
18
- const none = Symbol("none");
19
- const result = await Promise.race([broadcast.requested(), Promise.resolve(none)]);
20
- return result === none ? undefined : result;
21
- }
22
- test("consumer dedupes repeat subscriptions onto one upstream request", async () => {
23
- const consumer = new TestConsumer();
24
- // Two subscriptions to the same track share one upstream subscription...
25
- const a = consumer.track("video").subscribe();
26
- const b = consumer.subscribe("video");
27
- const request = await pendingRequest(consumer);
28
- expect(request?.name).toBe("video");
29
- // ...so only one on-demand request is emitted for it.
30
- expect(await pendingRequest(consumer)).toBeUndefined();
31
- // Serving that single request fans out to both subscribers.
32
- if (!request)
33
- throw new Error("expected request");
34
- const producer = request.accept();
35
- producer.writeString("hello");
36
- expect(await a.readString()).toBe("hello");
37
- expect(await b.readString()).toBe("hello");
38
- // A different track still opens its own request.
39
- consumer.subscribe("audio");
40
- expect((await pendingRequest(consumer))?.name).toBe("audio");
41
- // Once the shared track closes, a later subscribe re-opens it.
42
- producer.close();
43
- consumer.subscribe("video");
44
- expect((await pendingRequest(consumer))?.name).toBe("video");
45
- });
46
- test("a request exposes the aggregate subscription options", async () => {
47
- const consumer = new TestConsumer();
48
- consumer.subscribe("video", { priority: 3, ordered: true, latencyMax: 100, startGroup: 10, endGroup: 20 });
49
- consumer.subscribe("video", { priority: 7, ordered: true, latencyMax: 250, startGroup: 0, endGroup: 30 });
50
- const request = await pendingRequest(consumer);
51
- expect(request?.subscription).toEqual({
52
- priority: 7,
53
- ordered: true,
54
- latencyMax: 250,
55
- startGroup: 0,
56
- endGroup: 30,
57
- });
58
- expect(request?.priority).toBe(7);
59
- });
60
- test("requested selects the highest current priority", async () => {
61
- const consumer = new TestConsumer();
62
- const first = consumer.subscribe("first", { priority: 1 });
63
- consumer.subscribe("second", { priority: 5 });
64
- const updated = first.subscription.changed();
65
- first.update({ priority: 9 });
66
- await updated;
67
- expect((await consumer.requested())?.name).toBe("first");
68
- expect((await consumer.requested())?.name).toBe("second");
69
- });
70
- test("a consumer clone shares the broadcast until every handle closes", () => {
71
- const consumer = new TestConsumer();
72
- const clone = consumer.clone();
73
- // Closing one handle leaves the shared broadcast live for the other...
74
- consumer.close();
75
- expect(consumer.closed.peek()).toBeUndefined();
76
- expect(clone.closed.peek()).toBeUndefined();
77
- // ...and closing the last handle closes it for both.
78
- clone.close();
79
- expect(consumer.closed.peek()).toBeDefined();
80
- expect(clone.closed.peek()).toBeDefined();
81
- });
82
- test("double-closing a consumer handle does not prematurely close the broadcast", () => {
83
- const consumer = new TestConsumer();
84
- const clone = consumer.clone();
85
- // The double close must decrement the shared count only once...
86
- clone.close();
87
- clone.close();
88
- expect(consumer.closed.peek()).toBeUndefined();
89
- // ...so the broadcast still stays live until the other handle closes.
90
- consumer.close();
91
- expect(consumer.closed.peek()).toBeDefined();
92
- });
93
- test("consumer track subscriptions fan out and close independently", async () => {
94
- const consumer = new TestConsumer();
95
- // Two subscriptions to one track dedupe onto a single upstream request...
96
- const a = consumer.subscribe("video");
97
- const b = consumer.subscribe("video");
98
- const request = await pendingRequest(consumer);
99
- if (!request)
100
- throw new Error("expected request");
101
- expect(await pendingRequest(consumer)).toBeUndefined();
102
- const producer = request.accept();
103
- producer.writeString("one");
104
- expect(await a.readString()).toBe("one");
105
- expect(await b.readString()).toBe("one");
106
- // ...and closing one subscriber leaves the other (and the shared upstream) delivering.
107
- a.close();
108
- producer.writeString("two");
109
- expect(await b.readString()).toBe("two");
110
- });
111
- test("subscribe serves a statically inserted track without a request", async () => {
112
- const broadcast = new BroadcastProducer();
113
- const track1 = new TrackProducer("track1").accept();
114
- broadcast.insertTrack(track1);
115
- track1.appendGroup().close();
116
- // The track already exists, so subscribe resolves immediately (no requested()).
117
- const sub1 = broadcast.track("track1").subscribe();
118
- expect((await sub1.nextGroup())?.sequence).toBe(0);
119
- // No on-demand request was emitted for it.
120
- expect(await pendingRequest(broadcast)).toBeUndefined();
121
- // A second static track behaves the same.
122
- const track2 = new TrackProducer("track2").accept();
123
- broadcast.insertTrack(track2);
124
- const sub2 = broadcast.track("track2").subscribe();
125
- track2.appendGroup().close();
126
- expect((await sub2.nextGroup())?.sequence).toBe(0);
127
- });
128
- test("two subscribers to one inserted track each get a full copy", async () => {
129
- const broadcast = new BroadcastProducer();
130
- const producer = broadcast.createTrack("video");
131
- const a = broadcast.track("video").subscribe();
132
- const b = broadcast.track("video").subscribe();
133
- producer.writeString("hello");
134
- producer.writeString("world");
135
- // Neither subscriber steals from the other: both see every frame in order.
136
- expect(await a.readString()).toBe("hello");
137
- expect(await b.readString()).toBe("hello");
138
- expect(await a.readString()).toBe("world");
139
- expect(await b.readString()).toBe("world");
140
- });
141
- test("a late subscriber replays the cached window", async () => {
142
- const broadcast = new BroadcastProducer();
143
- const producer = broadcast.createTrack("video");
144
- // Written before anyone subscribes; retained in the cache for replay.
145
- producer.writeString("early");
146
- const late = broadcast.track("video").subscribe();
147
- expect(await late.readString()).toBe("early");
148
- producer.writeString("later");
149
- expect(await late.readString()).toBe("later");
150
- });
151
- test("a read throws Lagged on a gap, then resyncs to the next group", async () => {
152
- const broadcast = new BroadcastProducer();
153
- const producer = broadcast.createTrack("video");
154
- const sub = broadcast.track("video").subscribe();
155
- // Group 0 overflows its frame cap without being read, evicting the front: a gap.
156
- const g0 = producer.appendGroup();
157
- for (let i = 0; i < MAX_GROUP_FRAMES + 10; i++)
158
- g0.writeFrame({ payload: new Uint8Array([i & 0xff]), timestamp: Timestamp.now() });
159
- g0.close();
160
- // Group 1 is clean.
161
- const g1 = producer.appendGroup();
162
- g1.writeFrame({ payload: new TextEncoder().encode("ok"), timestamp: Timestamp.now() });
163
- g1.close();
164
- // The reader hits the gap in group 0 (error, not a silent skip), then the next
165
- // read resyncs from group 1.
166
- expect(sub.readFrame()).rejects.toBeInstanceOf(Lagged);
167
- expect(await sub.readString()).toBe("ok");
168
- });
169
- test("a stalled consumer does not pin evicted groups", async () => {
170
- try {
171
- setSystemTime(new Date(10_000));
172
- const broadcast = new BroadcastProducer();
173
- const producer = broadcast.createTrack("video", { latencyMax: 1000 });
174
- // A subscriber that never reads. Its sink must not grow without bound.
175
- const stalled = broadcast.track("video").subscribe();
176
- producer.writeString("old");
177
- // Advance past the cache window and write again to trigger a prune. The old
178
- // (closed, aged-out) group is dropped from the stalled sink, not retained.
179
- setSystemTime(new Date(12_000));
180
- producer.writeString("fresh");
181
- // The next group in arrival order is the fresh one (seq 1): the old (seq 0) group
182
- // was evicted, not still buffered ahead of it.
183
- expect((await stalled.recvGroup())?.sequence).toBe(1);
184
- // Nothing else is buffered: a second recvGroup stays pending (the track is open),
185
- // proving exactly one group remained in the sink rather than two.
186
- const pending = Symbol("pending");
187
- const next = await Promise.race([stalled.recvGroup(), Promise.resolve(pending)]);
188
- expect(next).toBe(pending);
189
- }
190
- finally {
191
- setSystemTime();
192
- }
193
- });
194
- test("createTrack commits info up front", async () => {
195
- const broadcast = new BroadcastProducer();
196
- const producer = broadcast.createTrack("video", { latencyMax: 2000, priority: 3 });
197
- expect(producer.name).toBe("video");
198
- const info = await broadcast.track("video").info();
199
- expect(info.latencyMax).toBe(2000);
200
- expect(info.priority).toBe(3);
201
- });
202
- test("insertTrack rejects a duplicate live name", () => {
203
- const broadcast = new BroadcastProducer();
204
- broadcast.createTrack("dup");
205
- expect(() => broadcast.insertTrack(new TrackProducer("dup").accept())).toThrow();
206
- });
207
- test("a closed track is evicted and re-subscribing falls through to a request", async () => {
208
- const broadcast = new BroadcastProducer();
209
- const track1 = broadcast.createTrack("track1");
210
- track1.close();
211
- // The stale entry is gone, so subscribe creates an on-demand request instead.
212
- const pending = broadcast.track("track1").subscribe();
213
- expect(pending).toBeDefined();
214
- // That on-demand request is now waiting to be answered.
215
- const request = await broadcast.requested();
216
- expect(request?.name).toBe("track1");
217
- });
218
- test("removeTrack drops the static entry", async () => {
219
- // While the static entry exists, subscribing takes the fast path: no on-demand request.
220
- const kept = new BroadcastProducer();
221
- kept.createTrack("track1");
222
- kept.track("track1").subscribe();
223
- expect(await pendingRequest(kept)).toBeUndefined();
224
- // With the entry removed, subscribing falls through to an on-demand request.
225
- const removed = new BroadcastProducer();
226
- removed.createTrack("track1");
227
- removed.removeTrack("track1");
228
- removed.track("track1").subscribe();
229
- expect((await pendingRequest(removed))?.name).toBe("track1");
230
- });
231
- test("close rejects a still-pending track request so its subscriber unblocks", async () => {
232
- const broadcast = new TestConsumer();
233
- // Subscribing with no static entry queues an on-demand request; the subscriber
234
- // blocks on info() until that request is answered.
235
- const subscriber = broadcast.track("video").subscribe();
236
- const info = subscriber.info();
237
- // Closing must reject the still-queued request rather than silently dropping it,
238
- // so the awaiting subscriber rejects instead of hanging on a producer that will
239
- // never be served.
240
- broadcast.close();
241
- await expect(info).rejects.toThrow();
242
- });
243
- //# sourceMappingURL=broadcast.test.js.map