@moq/net 0.1.9 → 0.2.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 (252) hide show
  1. package/announced.d.ts +40 -24
  2. package/announced.d.ts.map +1 -1
  3. package/announced.js +74 -40
  4. package/announced.js.map +1 -1
  5. package/announced.test.d.ts +2 -0
  6. package/announced.test.d.ts.map +1 -0
  7. package/announced.test.js +37 -0
  8. package/announced.test.js.map +1 -0
  9. package/broadcast.d.ts +80 -25
  10. package/broadcast.d.ts.map +1 -1
  11. package/broadcast.js +266 -49
  12. package/broadcast.js.map +1 -1
  13. package/broadcast.test.d.ts +2 -0
  14. package/broadcast.test.d.ts.map +1 -0
  15. package/broadcast.test.js +219 -0
  16. package/broadcast.test.js.map +1 -0
  17. package/connection/accept.d.ts +6 -0
  18. package/connection/accept.d.ts.map +1 -1
  19. package/connection/accept.js +30 -10
  20. package/connection/accept.js.map +1 -1
  21. package/connection/browser.d.ts +5 -0
  22. package/connection/browser.d.ts.map +1 -0
  23. package/connection/browser.js +25 -0
  24. package/connection/browser.js.map +1 -0
  25. package/connection/browser.test.d.ts +2 -0
  26. package/connection/browser.test.d.ts.map +1 -0
  27. package/connection/browser.test.js +29 -0
  28. package/connection/browser.test.js.map +1 -0
  29. package/connection/connect.d.ts +43 -1
  30. package/connection/connect.d.ts.map +1 -1
  31. package/connection/connect.js +96 -107
  32. package/connection/connect.js.map +1 -1
  33. package/connection/connect.test.d.ts +2 -0
  34. package/connection/connect.test.d.ts.map +1 -0
  35. package/connection/connect.test.js +118 -0
  36. package/connection/connect.test.js.map +1 -0
  37. package/connection/established.d.ts +29 -15
  38. package/connection/established.d.ts.map +1 -1
  39. package/connection/established.js.map +1 -1
  40. package/connection/index.d.ts +8 -0
  41. package/connection/index.d.ts.map +1 -1
  42. package/connection/index.js +6 -0
  43. package/connection/index.js.map +1 -1
  44. package/connection/reload.d.ts +43 -7
  45. package/connection/reload.d.ts.map +1 -1
  46. package/connection/reload.js +159 -62
  47. package/connection/reload.js.map +1 -1
  48. package/connection/reload.test.js +65 -0
  49. package/connection/reload.test.js.map +1 -1
  50. package/connection/stats.d.ts +92 -0
  51. package/connection/stats.d.ts.map +1 -0
  52. package/connection/stats.js +35 -0
  53. package/connection/stats.js.map +1 -0
  54. package/connection/stats.test.d.ts +2 -0
  55. package/connection/stats.test.d.ts.map +1 -0
  56. package/connection/stats.test.js +120 -0
  57. package/connection/stats.test.js.map +1 -0
  58. package/connection/transport.d.ts +10 -0
  59. package/connection/transport.d.ts.map +1 -0
  60. package/connection/transport.js +12 -0
  61. package/connection/transport.js.map +1 -0
  62. package/consume.d.ts +26 -0
  63. package/consume.d.ts.map +1 -0
  64. package/consume.js +40 -0
  65. package/consume.js.map +1 -0
  66. package/datagram.d.ts +23 -0
  67. package/datagram.d.ts.map +1 -0
  68. package/datagram.js +3 -0
  69. package/datagram.js.map +1 -0
  70. package/group.d.ts +125 -36
  71. package/group.d.ts.map +1 -1
  72. package/group.js +244 -67
  73. package/group.js.map +1 -1
  74. package/group.test.js +121 -35
  75. package/group.test.js.map +1 -1
  76. package/ietf/adapter.d.ts +2 -2
  77. package/ietf/adapter.d.ts.map +1 -1
  78. package/ietf/adapter.js +15 -5
  79. package/ietf/adapter.js.map +1 -1
  80. package/ietf/connection.d.ts +19 -6
  81. package/ietf/connection.d.ts.map +1 -1
  82. package/ietf/connection.js +23 -8
  83. package/ietf/connection.js.map +1 -1
  84. package/ietf/ietf.test.js +58 -1
  85. package/ietf/ietf.test.js.map +1 -1
  86. package/ietf/object.d.ts +12 -4
  87. package/ietf/object.d.ts.map +1 -1
  88. package/ietf/object.js +92 -9
  89. package/ietf/object.js.map +1 -1
  90. package/ietf/publisher.d.ts +2 -2
  91. package/ietf/publisher.d.ts.map +1 -1
  92. package/ietf/publisher.js +12 -12
  93. package/ietf/publisher.js.map +1 -1
  94. package/ietf/subscribe_namespace.d.ts +0 -4
  95. package/ietf/subscribe_namespace.d.ts.map +1 -1
  96. package/ietf/subscribe_namespace.js +0 -5
  97. package/ietf/subscribe_namespace.js.map +1 -1
  98. package/ietf/subscriber.d.ts +8 -4
  99. package/ietf/subscriber.d.ts.map +1 -1
  100. package/ietf/subscriber.js +171 -93
  101. package/ietf/subscriber.js.map +1 -1
  102. package/index.d.ts +8 -5
  103. package/index.d.ts.map +1 -1
  104. package/index.js +8 -5
  105. package/index.js.map +1 -1
  106. package/integration.test.js +598 -12
  107. package/integration.test.js.map +1 -1
  108. package/internal.d.ts +14 -0
  109. package/internal.d.ts.map +1 -0
  110. package/internal.js +8 -0
  111. package/internal.js.map +1 -0
  112. package/lite/announce.d.ts +55 -13
  113. package/lite/announce.d.ts.map +1 -1
  114. package/lite/announce.js +221 -68
  115. package/lite/announce.js.map +1 -1
  116. package/lite/announce.test.d.ts +2 -0
  117. package/lite/announce.test.d.ts.map +1 -0
  118. package/lite/announce.test.js +71 -0
  119. package/lite/announce.test.js.map +1 -0
  120. package/lite/connection.d.ts +45 -19
  121. package/lite/connection.d.ts.map +1 -1
  122. package/lite/connection.js +85 -80
  123. package/lite/connection.js.map +1 -1
  124. package/lite/datagram.d.ts +23 -0
  125. package/lite/datagram.d.ts.map +1 -0
  126. package/lite/datagram.js +57 -0
  127. package/lite/datagram.js.map +1 -0
  128. package/lite/datagram.test.d.ts +2 -0
  129. package/lite/datagram.test.d.ts.map +1 -0
  130. package/lite/datagram.test.js +26 -0
  131. package/lite/datagram.test.js.map +1 -0
  132. package/lite/datagram_stream.d.ts +8 -0
  133. package/lite/datagram_stream.d.ts.map +1 -0
  134. package/lite/datagram_stream.js +44 -0
  135. package/lite/datagram_stream.js.map +1 -0
  136. package/lite/datagram_stream.test.d.ts +2 -0
  137. package/lite/datagram_stream.test.d.ts.map +1 -0
  138. package/lite/datagram_stream.test.js +15 -0
  139. package/lite/datagram_stream.test.js.map +1 -0
  140. package/lite/fetch.d.ts.map +1 -1
  141. package/lite/fetch.js +2 -2
  142. package/lite/fetch.js.map +1 -1
  143. package/lite/fetch.test.d.ts +2 -0
  144. package/lite/fetch.test.d.ts.map +1 -0
  145. package/lite/fetch.test.js +41 -0
  146. package/lite/fetch.test.js.map +1 -0
  147. package/lite/index.d.ts +3 -0
  148. package/lite/index.d.ts.map +1 -1
  149. package/lite/index.js +3 -0
  150. package/lite/index.js.map +1 -1
  151. package/lite/publisher.d.ts +13 -6
  152. package/lite/publisher.d.ts.map +1 -1
  153. package/lite/publisher.js +274 -64
  154. package/lite/publisher.js.map +1 -1
  155. package/lite/publisher.test.d.ts +2 -0
  156. package/lite/publisher.test.d.ts.map +1 -0
  157. package/lite/publisher.test.js +65 -0
  158. package/lite/publisher.test.js.map +1 -0
  159. package/lite/setup.d.ts +72 -6
  160. package/lite/setup.d.ts.map +1 -1
  161. package/lite/setup.js +184 -31
  162. package/lite/setup.js.map +1 -1
  163. package/lite/setup.test.d.ts +2 -0
  164. package/lite/setup.test.d.ts.map +1 -0
  165. package/lite/setup.test.js +122 -0
  166. package/lite/setup.test.js.map +1 -0
  167. package/lite/stream.d.ts +12 -3
  168. package/lite/stream.d.ts.map +1 -1
  169. package/lite/stream.js +7 -4
  170. package/lite/stream.js.map +1 -1
  171. package/lite/subscribe.d.ts +37 -23
  172. package/lite/subscribe.d.ts.map +1 -1
  173. package/lite/subscribe.js +70 -55
  174. package/lite/subscribe.js.map +1 -1
  175. package/lite/subscribe.test.d.ts +2 -0
  176. package/lite/subscribe.test.d.ts.map +1 -0
  177. package/lite/subscribe.test.js +68 -0
  178. package/lite/subscribe.test.js.map +1 -0
  179. package/lite/subscriber.d.ts +24 -17
  180. package/lite/subscriber.d.ts.map +1 -1
  181. package/lite/subscriber.js +515 -90
  182. package/lite/subscriber.js.map +1 -1
  183. package/lite/subscriber.test.js +2 -2
  184. package/lite/subscriber.test.js.map +1 -1
  185. package/lite/track.d.ts +25 -13
  186. package/lite/track.d.ts.map +1 -1
  187. package/lite/track.js +60 -35
  188. package/lite/track.js.map +1 -1
  189. package/lite/track.test.js +12 -10
  190. package/lite/track.test.js.map +1 -1
  191. package/lite/version.d.ts +17 -4
  192. package/lite/version.d.ts.map +1 -1
  193. package/lite/version.js +88 -17
  194. package/lite/version.js.map +1 -1
  195. package/mock.d.ts +42 -3
  196. package/mock.d.ts.map +1 -1
  197. package/mock.js +88 -17
  198. package/mock.js.map +1 -1
  199. package/package.json +3 -3
  200. package/path.d.ts +30 -0
  201. package/path.d.ts.map +1 -1
  202. package/path.js +49 -0
  203. package/path.js.map +1 -1
  204. package/path.test.js +41 -0
  205. package/path.test.js.map +1 -1
  206. package/stream.test.js +10 -0
  207. package/stream.test.js.map +1 -1
  208. package/time.d.ts +109 -86
  209. package/time.d.ts.map +1 -1
  210. package/time.js +80 -30
  211. package/time.js.map +1 -1
  212. package/time.test.d.ts +2 -0
  213. package/time.test.d.ts.map +1 -0
  214. package/time.test.js +12 -0
  215. package/time.test.js.map +1 -0
  216. package/track.d.ts +225 -45
  217. package/track.d.ts.map +1 -1
  218. package/track.js +505 -93
  219. package/track.js.map +1 -1
  220. package/track.test.js +138 -29
  221. package/track.test.js.map +1 -1
  222. package/util/error.d.ts +9 -0
  223. package/util/error.d.ts.map +1 -1
  224. package/util/error.js +21 -0
  225. package/util/error.js.map +1 -1
  226. package/util/error.test.d.ts +2 -0
  227. package/util/error.test.d.ts.map +1 -0
  228. package/util/error.test.js +45 -0
  229. package/util/error.test.js.map +1 -0
  230. package/util/index.d.ts +1 -0
  231. package/util/index.d.ts.map +1 -1
  232. package/util/index.js +1 -0
  233. package/util/index.js.map +1 -1
  234. package/util/timeout.d.ts +5 -0
  235. package/util/timeout.d.ts.map +1 -0
  236. package/util/timeout.js +18 -0
  237. package/util/timeout.js.map +1 -0
  238. package/util/timeout.test.d.ts +2 -0
  239. package/util/timeout.test.d.ts.map +1 -0
  240. package/util/timeout.test.js +18 -0
  241. package/util/timeout.test.js.map +1 -0
  242. package/varint.d.ts +6 -0
  243. package/varint.d.ts.map +1 -1
  244. package/varint.js +6 -2
  245. package/varint.js.map +1 -1
  246. package/zod.d.ts +4 -4
  247. package/zod.d.ts.map +1 -1
  248. package/zod.js.map +1 -1
  249. package/bandwidth.d.ts +0 -11
  250. package/bandwidth.d.ts.map +0 -1
  251. package/bandwidth.js +0 -7
  252. package/bandwidth.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"subscriber.js","sourceRoot":"","sources":["../../src/lite/subscriber.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAqB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGzE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACnH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAgBvD;;;;GAIG;AACH,MAAM,OAAO,UAAU;IACtB,KAAK,CAAe;IAEpB,iCAAiC;IACxB,OAAO,CAAU;IAE1B,uEAAuE;IACvE,wEAAwE;IAC/D,MAAM,CAAS;IAExB,yBAAyB;IACzB,WAAW,GAAG,IAAI,GAAG,EAAiB,CAAC;IACvC,cAAc,GAAG,EAAE,CAAC;IAEpB,0CAA0C;IAC1C,cAAc,CAAa;IAE3B,+BAA+B;IAC/B,IAAI,CAAkC;IAEtC,uEAAuE;IACvE,OAAO,GAAG,IAAI,eAAe,EAA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AAC,KAAK,CAAC,CAAC;YAC7C,MAAM,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAExC,SAAS,CAAC;gBACT,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBACnE,IAAI,CAAC,KAAK;oBAAE,MAAM;gBAClB,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,IAAI,SAAS,CAAC,CAAC;gBACpD,IAAI,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;oBAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAiB,CAAC,CAAC;gBACxC,CAAC;YACF,CAAC;QACF,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBAClC,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;YACzC,CAAC;QACF,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACnC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC;IACF,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAErB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC;YAC/C,KAAK,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACD","sourcesContent":["import type { Signal } from \"@moq/signals\";\nimport { Announced } from \"../announced.ts\";\nimport type { Bandwidth } from \"../bandwidth.ts\";\nimport { Broadcast, type TrackRequest } from \"../broadcast.ts\";\nimport { Group } from \"../group.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Reader, Stream } from \"../stream.ts\";\nimport type * as Time from \"../time.ts\";\nimport type { Track } from \"../track.ts\";\nimport { error } from \"../util/error.ts\";\nimport { Announce, AnnounceInit, AnnounceInterest } from \"./announce.ts\";\nimport type { Group as GroupMessage } from \"./group.ts\";\nimport type { Origin } from \"./origin.ts\";\nimport { Probe } from \"./probe.ts\";\nimport { StreamId } from \"./stream.ts\";\nimport { decodeSubscribeResponse, decodeSubscribeResponseMaybe, Subscribe, SubscribeUpdate } from \"./subscribe.ts\";\nimport { hasTrackStream, Version } from \"./version.ts\";\n\n/**\n * Options accepted by {@link Subscriber.announced}.\n */\nexport interface AnnouncedOptions {\n\t/**\n\t * If true, skip announcements whose hop chain contains this connection's\n\t * own origin id — useful for meshes that reflect announces back. Defaults\n\t * to false for backwards compatibility: existing code (notably hang.live)\n\t * relies on seeing its own publishes as the signal that a namespace\n\t * published successfully.\n\t */\n\tignoreSelf?: boolean;\n}\n\n/**\n * Handles subscribing to broadcasts and managing their lifecycle.\n *\n * @internal\n */\nexport class Subscriber {\n\t#quic: WebTransport;\n\n\t// The version of the connection.\n\treadonly version: Version;\n\n\t// Shared with the Publisher so callers can optionally filter out their\n\t// own announcements on a per-call basis (see {@link AnnouncedOptions}).\n\treadonly origin: Origin;\n\n\t// Our subscribed tracks.\n\t#subscribes = new Map<bigint, Track>();\n\t#subscribeNext = 0n;\n\n\t// Recv bandwidth producer (Lite03+ only).\n\t#recvBandwidth?: Bandwidth;\n\n\t// RTT producer (Lite04+ only).\n\t#rtt?: Signal<Time.Milli | undefined>;\n\n\t// Distinguishes failures from streams torn down by Subscriber.close().\n\t#closed = new AbortController();\n\n\t/**\n\t * Creates a new Subscriber instance.\n\t * @param quic - The WebTransport session to use\n\t * @param version - The protocol version\n\t * @param origin - Origin id shared with the Publisher\n\t * @param recvBandwidth - Optional bandwidth producer for PROBE\n\t * @param rtt - Optional RTT signal for PROBE\n\t *\n\t * @internal\n\t */\n\tconstructor(\n\t\tquic: WebTransport,\n\t\tversion: Version,\n\t\torigin: Origin,\n\t\trecvBandwidth?: Bandwidth,\n\t\trtt?: Signal<Time.Milli | undefined>,\n\t) {\n\t\tthis.#quic = quic;\n\t\tthis.version = version;\n\t\tthis.origin = origin;\n\t\tthis.#recvBandwidth = recvBandwidth;\n\t\tthis.#rtt = rtt;\n\t}\n\n\t/**\n\t * Subscribe to broadcast announcements under `prefix`.\n\t *\n\t * Pass `{ ignoreSelf: true }` to skip announces that have already traversed\n\t * this connection's {@link origin}.\n\t */\n\tannounced(prefix = Path.empty(), options: AnnouncedOptions = {}): Announced {\n\t\tconst announced = new Announced();\n\t\tvoid this.#runAnnounced(announced, prefix, options);\n\t\treturn announced;\n\t}\n\n\tasync #runAnnounced(announced: Announced, prefix: Path.Valid, options: AnnouncedOptions): Promise<void> {\n\t\tconsole.debug(`announced: prefix=${prefix}`);\n\t\t// Send our own session-level origin id so the peer can skip announces\n\t\t// whose hop chain already passed through us. Matches the Rust subscriber's\n\t\t// `exclude_hop: self.self_origin.id` in `run_announce_prefix`.\n\t\tconst msg = new AnnounceInterest(prefix, this.origin);\n\n\t\ttry {\n\t\t\t// Open a stream and send the announce interest.\n\t\t\tconst stream = await Stream.open(this.#quic);\n\t\t\tawait stream.writer.u53(StreamId.Announce);\n\t\t\tawait msg.encode(stream.writer, this.version);\n\n\t\t\tswitch (this.version) {\n\t\t\t\tcase Version.DRAFT_01:\n\t\t\t\tcase Version.DRAFT_02: {\n\t\t\t\t\t// Receive ANNOUNCE_INIT first\n\t\t\t\t\tconst init = await AnnounceInit.decode(stream.reader, this.version);\n\n\t\t\t\t\t// Process initial announcements\n\t\t\t\t\tfor (const suffix of init.suffixes) {\n\t\t\t\t\t\tconst path = Path.join(prefix, suffix);\n\t\t\t\t\t\tconsole.debug(`announced: broadcast=${path} active=true`);\n\t\t\t\t\t\tannounced.append({ path, active: true });\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\t// Draft03+: no AnnounceInit, initial state comes via Announce messages.\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Receive announce updates (for Draft03, this includes initial state)\n\t\t\tfor (;;) {\n\t\t\t\tconst announce = await Promise.race([\n\t\t\t\t\tAnnounce.decodeMaybe(stream.reader, this.version),\n\t\t\t\t\tannounced.closed,\n\t\t\t\t]);\n\t\t\t\tif (!announce) break;\n\t\t\t\tif (announce instanceof Error) throw announce;\n\n\t\t\t\t// Optionally drop reflected announces so callers asking for\n\t\t\t\t// \"someone else's broadcasts\" don't re-see their own publishes.\n\t\t\t\tif (options.ignoreSelf && announce.hops.includes(this.origin)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst path = Path.join(prefix, announce.suffix);\n\n\t\t\t\tconsole.debug(`announced: broadcast=${path} active=${announce.active}`);\n\t\t\t\tannounced.append({ path, active: announce.active });\n\t\t\t}\n\n\t\t\tannounced.close();\n\t\t} catch (err: unknown) {\n\t\t\tannounced.close(error(err));\n\t\t}\n\t}\n\n\t/**\n\t * Consumes a broadcast from the connection.\n\t *\n\t * @param name - The name of the broadcast to consume\n\t * @returns A Broadcast instance\n\t */\n\tconsume(path: Path.Valid): Broadcast {\n\t\tconst broadcast = new Broadcast();\n\n\t\tvoid (async () => {\n\t\t\tfor (;;) {\n\t\t\t\tconst request = await broadcast.requested();\n\t\t\t\tif (!request) break;\n\t\t\t\tvoid this.#runSubscribe(path, request);\n\t\t\t}\n\t\t})();\n\n\t\treturn broadcast;\n\t}\n\n\tasync #runSubscribe(broadcast: Path.Valid, request: TrackRequest) {\n\t\tconst id = this.#subscribeNext++;\n\n\t\t// Save the writer so we can append groups to it.\n\t\tthis.#subscribes.set(id, request.track);\n\n\t\tconsole.debug(`subscribe start: id=${id} broadcast=${broadcast} track=${request.track.name}`);\n\n\t\tconst msg = new Subscribe({ id, broadcast, track: request.track.name, priority: request.priority });\n\n\t\tconst stream = await Stream.open(this.#quic);\n\t\tawait stream.writer.u53(StreamId.Subscribe);\n\t\tawait msg.encode(stream.writer, this.version);\n\n\t\ttry {\n\t\t\t// The first response MUST be a SUBSCRIBE_OK.\n\t\t\tconst resp = await decodeSubscribeResponse(stream.reader, this.version);\n\t\t\tif (!(\"ok\" in resp)) {\n\t\t\t\tthrow new Error(\"first subscribe response must be SUBSCRIBE_OK\");\n\t\t\t}\n\t\t\tconsole.debug(`subscribe ok: id=${id} broadcast=${broadcast} track=${request.track.name}`);\n\n\t\t\t// Watch for priority changes and send SUBSCRIBE_UPDATE. Lite01/Lite02\n\t\t\t// don't carry SUBSCRIBE_UPDATE on the wire, so skip the watcher there\n\t\t\t// and just wait on the stream/track like before.\n\t\t\t// Draining responses also consumes any SUBSCRIBE_END / SUBSCRIBE_DROP and\n\t\t\t// resolves when the publisher FINs.\n\t\t\tconst waits: Promise<unknown>[] = [this.#drainResponses(stream), request.track.closed];\n\t\t\tswitch (this.version) {\n\t\t\t\tcase Version.DRAFT_01:\n\t\t\t\tcase Version.DRAFT_02:\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\twaits.push(this.#runPriorityUpdates(id, broadcast, request.track, msg, stream));\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tawait Promise.race(waits);\n\n\t\t\trequest.track.close();\n\t\t\tstream.close();\n\t\t\tconsole.debug(`subscribe close: id=${id} broadcast=${broadcast} track=${request.track.name}`);\n\t\t} catch (err) {\n\t\t\tconst e = error(err);\n\t\t\trequest.track.close(e);\n\t\t\tconsole.warn(\n\t\t\t\t`subscribe error: id=${id} broadcast=${broadcast} track=${request.track.name} error=${e.message}`,\n\t\t\t);\n\t\t\tstream.abort(e);\n\t\t} finally {\n\t\t\tthis.#subscribes.delete(id);\n\t\t}\n\t}\n\n\t/**\n\t * Drain responses on the subscribe stream until the publisher FINs.\n\t *\n\t * The first SUBSCRIBE_OK is consumed by the caller; this reads any further\n\t * SUBSCRIBE_END / SUBSCRIBE_DROP. They aren't acted on yet (groups arrive on\n\t * their own streams regardless), but consuming them keeps the stream aligned.\n\t */\n\tasync #drainResponses(stream: Stream): Promise<void> {\n\t\tfor (;;) {\n\t\t\tconst resp = await decodeSubscribeResponseMaybe(stream.reader, this.version);\n\t\t\tif (!resp) break;\n\t\t}\n\t}\n\n\t/**\n\t * Send SUBSCRIBE_UPDATE messages whenever the track's priority signal changes.\n\t *\n\t * Resolves cleanly when the stream or track closes, so the caller can include\n\t * this in Promise.race without leaving a dangling pending write that would\n\t * become an unhandled rejection if the user calls updatePriority after close.\n\t *\n\t * Peeks the signal at the top of every iteration so that updates which landed\n\t * before SubscribeOk arrived (or between iterations, before .next() registered\n\t * its listener) aren't lost.\n\t */\n\tasync #runPriorityUpdates(\n\t\tid: bigint,\n\t\tbroadcast: Path.Valid,\n\t\ttrack: Track,\n\t\tmsg: Subscribe,\n\t\tstream: Stream,\n\t): Promise<void> {\n\t\tconst stopped: Promise<null> = Promise.race([track.closed, stream.reader.closed]).then(() => null);\n\t\tlet lastSent: number | undefined;\n\n\t\tfor (;;) {\n\t\t\tconst current = track.state.priority.peek();\n\t\t\tif (current === undefined || current === lastSent) {\n\t\t\t\t// Nothing new to send; wait for a change or termination.\n\t\t\t\tconst next = await Promise.race([track.state.priority.next(), stopped]);\n\t\t\t\tif (next === null) return;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Round-trip the other Subscribe parameters so the publisher doesn't\n\t\t\t// interpret SUBSCRIBE_UPDATE as a reset of ordered/maxLatency/etc.\n\t\t\tconst update = new SubscribeUpdate({\n\t\t\t\tpriority: current,\n\t\t\t\tordered: msg.ordered,\n\t\t\t\tmaxLatency: msg.maxLatency,\n\t\t\t\tstartGroup: msg.startGroup,\n\t\t\t\tendGroup: msg.endGroup,\n\t\t\t});\n\t\t\tawait update.encode(stream.writer, this.version);\n\t\t\tlastSent = current;\n\t\t\tconsole.debug(`subscribe update: id=${id} broadcast=${broadcast} track=${track.name} priority=${current}`);\n\t\t}\n\t}\n\n\t/**\n\t * Handles a group message.\n\t * @param group - The group message\n\t * @param stream - The stream to read frames from\n\t *\n\t * @internal\n\t */\n\tasync runGroup(group: GroupMessage, stream: Reader) {\n\t\tconst subscribe = this.#subscribes.get(group.subscribe);\n\t\tif (!subscribe) {\n\t\t\tif (group.subscribe >= this.#subscribeNext) {\n\t\t\t\tthrow new Error(`unknown subscription: id=${group.subscribe}`);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst producer = new Group(group.sequence);\n\t\tsubscribe.writeGroup(producer);\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst done = await Promise.race([stream.done(), subscribe.closed, producer.closed]);\n\t\t\t\tif (done !== false) break;\n\n\t\t\t\tif (hasTrackStream(this.version)) {\n\t\t\t\t\t// moq-lite-05+ prefixes each frame with a zigzag timestamp delta. Decode it\n\t\t\t\t\t// to stay aligned with the wire, but don't surface it yet.\n\t\t\t\t\tawait stream.u62();\n\t\t\t\t}\n\n\t\t\t\tconst size = await stream.u53();\n\t\t\t\tconst payload = await stream.read(size);\n\t\t\t\tif (!payload) break;\n\n\t\t\t\tproducer.writeFrame(payload);\n\t\t\t}\n\n\t\t\tproducer.close();\n\t\t\tstream.stop(new Error(\"cancel\"));\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tproducer.close(e);\n\t\t\tstream.stop(e);\n\t\t}\n\t}\n\n\t/**\n\t * Opens a PROBE bidi stream to receive bandwidth estimates from the publisher.\n\t * Returns immediately if recv bandwidth is not supported.\n\t *\n\t * Probe is best-effort telemetry: a stream-level failure (peer reset, FIN,\n\t * missing peer support, transport hiccup) is caught and logged, never\n\t * propagated to the connection. On exit the bandwidth/RTT signals are\n\t * cleared so consumers see them as stale.\n\t *\n\t * @internal\n\t */\n\tasync runProbe(): Promise<void> {\n\t\tif (!this.#recvBandwidth) return;\n\t\tif (this.version === Version.DRAFT_01 || this.version === Version.DRAFT_02) return;\n\n\t\t// Probe is best-effort: any failure (stream reset by peer, missing peer support,\n\t\t// transport hiccup) MUST NOT tear down the connection. On error, drop the\n\t\t// bandwidth/RTT estimates so consumers know they're stale.\n\t\ttry {\n\t\t\tconst stream = await Stream.open(this.#quic);\n\t\t\tawait stream.writer.u53(StreamId.Probe);\n\n\t\t\tfor (;;) {\n\t\t\t\tconst probe = await Probe.decodeMaybe(stream.reader, this.version);\n\t\t\t\tif (!probe) break;\n\t\t\t\tthis.#recvBandwidth.set(probe.bitrate ?? undefined);\n\t\t\t\tif (this.#rtt && probe.rtt !== undefined) {\n\t\t\t\t\tthis.#rtt.set(probe.rtt as Time.Milli);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tif (!this.#closed.signal.aborted) {\n\t\t\t\tconsole.warn(\"probe stream error\", err);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.#recvBandwidth.set(undefined);\n\t\t\tthis.#rtt?.set(undefined);\n\t\t}\n\t}\n\n\tclose() {\n\t\tthis.#closed.abort();\n\n\t\tfor (const track of this.#subscribes.values()) {\n\t\t\ttrack.close();\n\t\t}\n\n\t\tthis.#subscribes.clear();\n\t}\n}\n"]}
1
+ {"version":3,"file":"subscriber.js","sourceRoot":"","sources":["../../src/lite/subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,QAAQ,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,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;IAC5D,CAAC;IAEQ,UAAU,CAAC,IAAY,EAAE,QAAgB,EAAE,OAAiC;QACpF,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzE,CAAC;CACD","sourcesContent":["import { Signal } from \"@moq/signals\";\nimport * as announce from \"../announced.ts\";\nimport * as broadcast from \"../broadcast.ts\";\nimport type { Probe as ProbeStats } from \"../connection/stats.ts\";\nimport { BroadcastCache } from \"../consume.ts\";\nimport * as netGroup from \"../group.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Reader, Stream } from \"../stream.ts\";\nimport * as Time from \"../time.ts\";\nimport type * as track from \"../track.ts\";\nimport { error, reason } from \"../util/error.ts\";\nimport { withTimeout } from \"../util/timeout.ts\";\nimport { AnnounceInit, AnnounceOk, AnnounceRequest, decodeAnnounceBroadcastMaybe } from \"./announce.ts\";\nimport { Datagram as DatagramMessage } from \"./datagram.ts\";\nimport * as DatagramStream from \"./datagram_stream.ts\";\nimport { Fetch as FetchMessage } from \"./fetch.ts\";\nimport type { Group as GroupMessage } from \"./group.ts\";\nimport type { Origin } from \"./origin.ts\";\nimport { Probe } from \"./probe.ts\";\nimport { ProbeLevel, type Setup } from \"./setup.ts\";\nimport { StreamId } from \"./stream.ts\";\nimport { decodeSubscribeResponse, decodeSubscribeResponseMaybe, Subscribe, SubscribeUpdate } from \"./subscribe.ts\";\nimport { TrackInfo, Track as TrackMessage } from \"./track.ts\";\nimport { hasAnnounceId, hasAnnounceOk, hasDatagrams, Version } from \"./version.ts\";\n\n// Bound on how long stream-open plus the first response (SUBSCRIBE_OK on older\n// drafts, or TRACK_INFO on lite-05+) may take. Browsers cap concurrent QUIC\n// streams (Chrome ~100); past the cap createBidirectionalStream silently blocks.\n// The timeout turns that into a clear error.\nconst SUBSCRIBE_SETUP_TIMEOUT_MS = 10_000;\n\n/** Decode an unsigned zigzag varint back to a signed delta (mirrors Rust `VarInt::to_zigzag`). */\nfunction unzigzag(v: bigint): bigint {\n\treturn (v >> 1n) ^ -(v & 1n);\n}\n\n// The TRACK stream and implicit SUBSCRIBE acceptance are lite-05+.\nfunction supportsTrackStream(version: Version): boolean {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/**\n * Options accepted by {@link Subscriber.announced}.\n */\nexport interface AnnouncedOptions {\n\t/**\n\t * If true, skip announcements whose hop chain contains this connection's\n\t * own origin id. Useful for meshes that reflect announces back. Defaults\n\t * to false for backwards compatibility: existing code (notably hang.live)\n\t * relies on seeing its own publishes as the signal that a namespace\n\t * published successfully.\n\t */\n\tignoreSelf?: boolean;\n}\n\ninterface SubscribeEntry {\n\t// The write side: incoming GROUP streams are routed here. The application reads\n\t// the matching track.Subscriber it got from broadcast.Consumer.subscribe.\n\ttrack: track.Producer;\n\t// Per-frame timestamp scale (0 = none). undefined until it's known (from TRACK_INFO\n\t// on lite-05+, or implicit defaults on older drafts). A non-zero value means each\n\t// frame on the group stream is prefixed with a zigzag-delta timestamp varint that\n\t// runGroup must consume to stay in sync; group streams block on it before decoding,\n\t// since a group's QUIC stream can race ahead of the subscribe stream.\n\ttimescale: Signal<number | undefined>;\n}\n\n/**\n * Handles subscribing to broadcasts and managing their lifecycle.\n *\n * @internal\n */\nexport class Subscriber {\n\t#quic: WebTransport;\n\n\t// The version of the connection.\n\treadonly version: Version;\n\n\t// Shared with the Publisher so callers can optionally filter out their\n\t// own announcements on a per-call basis (see {@link AnnouncedOptions}).\n\treadonly origin: Origin;\n\n\t// Our subscribed tracks. `timescale` resolves once known (from TRACK_INFO on\n\t// lite-05+, or implicit defaults on older drafts); group streams block on it\n\t// before decoding any frame, since a group's QUIC stream can race ahead.\n\t#subscribes = new Map<bigint, SubscribeEntry>();\n\t#subscribeNext = 0n;\n\n\t// Dedup consumed broadcasts per path: repeat consume() calls share one subscription.\n\t#consumes = new BroadcastCache();\n\n\t// Dedup in-flight one-shot fetches, keyed by [broadcast, track, sequence]. Concurrent (or\n\t// repeat, while still open) fetchGroup() calls for the same group share one FETCH stream and\n\t// each get an independent mirror; the entry is evicted once the group closes.\n\t#fetches = new Map<string, netGroup.Producer>();\n\n\t// The peer's PROBE estimates, written as they arrive (Lite03+ only).\n\t#probe?: Signal<ProbeStats>;\n\n\t// The peer's SETUP (lite-05+), undefined until it arrives. Gates opening the PROBE\n\t// stream on the peer having advertised Probe >= Report.\n\t#peerSetup?: Signal<Setup | undefined>;\n\n\t// Distinguishes failures from streams torn down by Subscriber.close().\n\t#closed = new AbortController();\n\t/**\n\t * Creates a new Subscriber instance.\n\t * @param quic - The WebTransport session to use\n\t * @param version - The protocol version\n\t * @param origin - Origin id shared with the Publisher\n\t * @param probe - Optional sink for the peer's PROBE estimates\n\t * @param peerSetup - Optional peer SETUP slot for capability gating (lite-05+)\n\t *\n\t * @internal\n\t */\n\tconstructor(\n\t\tquic: WebTransport,\n\t\tversion: Version,\n\t\torigin: Origin,\n\t\tprobe?: Signal<ProbeStats>,\n\t\tpeerSetup?: Signal<Setup | undefined>,\n\t) {\n\t\tthis.#quic = quic;\n\t\tthis.version = version;\n\t\tthis.origin = origin;\n\t\tthis.#probe = probe;\n\t\tthis.#peerSetup = peerSetup;\n\t}\n\n\t/**\n\t * Subscribe to broadcast announcements under `prefix`.\n\t *\n\t * Pass `{ ignoreSelf: true }` to skip announces that have already traversed\n\t * this connection's {@link origin}.\n\t */\n\tannounced(prefix = Path.empty(), options: AnnouncedOptions = {}): announce.Consumer {\n\t\tconst announced = new announce.Producer(prefix);\n\t\tvoid this.#runAnnounced(announced, prefix, options);\n\t\treturn announced.consume();\n\t}\n\n\tasync #runAnnounced(announced: announce.Producer, prefix: Path.Valid, options: AnnouncedOptions): Promise<void> {\n\t\tconsole.debug(`announced: prefix=${prefix}`);\n\t\t// Send our own session-level origin id so the peer can skip announces\n\t\t// whose hop chain already passed through us. Matches the Rust subscriber's\n\t\t// `exclude_hop: self.self_origin.id` in `run_announce_prefix`.\n\t\tconst msg = new AnnounceRequest(prefix, this.origin);\n\n\t\ttry {\n\t\t\t// Open a stream and send the announce interest.\n\t\t\tconst stream = await Stream.open(this.#quic);\n\t\t\tawait stream.writer.u53(StreamId.Announce);\n\t\t\tawait msg.encode(stream.writer, this.version);\n\n\t\t\t// Lite05+: the publisher reports its own origin id before any announces.\n\t\t\t// It no longer stamps itself onto each hop chain, so we append it here to\n\t\t\t// keep the ignoreSelf loop check seeing the full chain.\n\t\t\tlet responderOrigin: Origin | undefined;\n\t\t\tif (hasAnnounceOk(this.version)) {\n\t\t\t\tconst ok = await AnnounceOk.decode(stream.reader, this.version);\n\t\t\t\tresponderOrigin = ok.origin;\n\t\t\t}\n\n\t\t\tswitch (this.version) {\n\t\t\t\tcase Version.DRAFT_01:\n\t\t\t\tcase Version.DRAFT_02: {\n\t\t\t\t\t// Receive ANNOUNCE_INIT first\n\t\t\t\t\tconst init = await AnnounceInit.decode(stream.reader, this.version);\n\n\t\t\t\t\t// Process initial announcements\n\t\t\t\t\tfor (const suffix of init.suffixes) {\n\t\t\t\t\t\tconst path = Path.join(prefix, suffix);\n\t\t\t\t\t\tconsole.debug(`announced: broadcast=${path} active=true`);\n\t\t\t\t\t\tannounced.append({ path: suffix, active: true });\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\t// Draft03+: no AnnounceInit, initial state comes via Announce messages.\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Lite06+: announce ids. Each received `active` implicitly assigns the next\n\t\t\t// per-stream ordinal; `endedId`/`restart` reference it. Tracked even for\n\t\t\t// announces we skip via ignoreSelf, since the sender doesn't know we skipped.\n\t\t\tlet nextAnnounceId = 0n;\n\t\t\tconst announcedById = new Map<bigint, Path.Valid>();\n\n\t\t\t// Receive announce updates (for Draft03, this includes initial state)\n\t\t\tfor (;;) {\n\t\t\t\tconst announce = await Promise.race([\n\t\t\t\t\tdecodeAnnounceBroadcastMaybe(stream.reader, this.version),\n\t\t\t\t\tannounced.closed,\n\t\t\t\t]);\n\t\t\t\t// undefined: the stream ended. null: the consumer closed cleanly.\n\t\t\t\tif (!announce) break;\n\t\t\t\tif (announce instanceof Error) throw announce;\n\n\t\t\t\tlet suffix: Path.Valid;\n\t\t\t\tlet active: boolean;\n\t\t\t\t// Present on active/restart; ended messages never carry hops worth checking.\n\t\t\t\tlet hops: Origin[] | undefined;\n\n\t\t\t\tswitch (announce.status) {\n\t\t\t\t\tcase \"active\":\n\t\t\t\t\t\tsuffix = announce.suffix;\n\t\t\t\t\t\tactive = true;\n\t\t\t\t\t\thops = announce.hops;\n\t\t\t\t\t\tif (hasAnnounceId(this.version)) {\n\t\t\t\t\t\t\tannouncedById.set(nextAnnounceId++, announce.suffix);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"ended\":\n\t\t\t\t\t\tsuffix = announce.suffix;\n\t\t\t\t\t\tactive = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"endedId\": {\n\t\t\t\t\t\t// Resolve and retire the id; an unknown or retired id is a protocol violation.\n\t\t\t\t\t\tconst path = announcedById.get(announce.id);\n\t\t\t\t\t\tif (path === undefined) throw new Error(`unknown announce id: ${announce.id}`);\n\t\t\t\t\t\tannouncedById.delete(announce.id);\n\t\t\t\t\t\tsuffix = path;\n\t\t\t\t\t\tactive = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"restart\": {\n\t\t\t\t\t\t// Resolve the id; it stays live (the replacement reuses it).\n\t\t\t\t\t\tconst path = announcedById.get(announce.id);\n\t\t\t\t\t\tif (path === undefined) throw new Error(`unknown announce id: ${announce.id}`);\n\t\t\t\t\t\tsuffix = path;\n\t\t\t\t\t\tactive = true;\n\t\t\t\t\t\thops = announce.hops;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Optionally drop reflected announces so callers asking for\n\t\t\t\t// \"someone else's broadcasts\" don't re-see their own publishes. In\n\t\t\t\t// Lite05+ the sender's origin arrives via AnnounceOk, not in each hop\n\t\t\t\t// list, so fold it back in before checking.\n\t\t\t\tif (hops !== undefined && options.ignoreSelf) {\n\t\t\t\t\tconst full = responderOrigin !== undefined ? [...hops, responderOrigin] : hops;\n\t\t\t\t\tif (full.includes(this.origin)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst path = Path.join(prefix, suffix);\n\n\t\t\t\tconsole.debug(`announced: broadcast=${path} active=${active}`);\n\t\t\t\tannounced.append({ path: suffix, active });\n\t\t\t}\n\n\t\t\tannounced.close();\n\t\t} catch (err: unknown) {\n\t\t\tannounced.close(error(err));\n\t\t}\n\t}\n\n\t/**\n\t * Consumes a broadcast from the connection.\n\t *\n\t * Deduplicated per path: repeat calls for the same still-live path share one reference-counted\n\t * broadcast (and one upstream subscription). The shared broadcast closes once every caller has\n\t * closed its handle, so callers close normally.\n\t *\n\t * @param name - The name of the broadcast to consume\n\t * @returns A Broadcast instance\n\t */\n\tconsume(path: Path.Valid): broadcast.Consumer {\n\t\treturn this.#consumes.get(path) ?? this.#consumes.insert(path, this.#createConsume(path));\n\t}\n\n\t#createConsume(path: Path.Valid): broadcast.Consumer {\n\t\t// A consumed broadcast resolves info() and fetchGroup() over the wire by reaching\n\t\t// back into this Subscriber (see ConsumeBroadcast below), rather than the wire\n\t\t// installing callbacks on the broadcast.\n\t\tconst consumer = new ConsumeBroadcast(this, path);\n\n\t\tvoid (async () => {\n\t\t\tfor (;;) {\n\t\t\t\tconst request = await consumer.requested();\n\t\t\t\tif (!request) break;\n\t\t\t\tvoid this.#runSubscribe(path, request);\n\t\t\t}\n\t\t})();\n\n\t\treturn consumer;\n\t}\n\n\tasync #runSubscribe(broadcast: Path.Valid, request: track.Request) {\n\t\tconst id = this.#subscribeNext++;\n\n\t\t// `timescale` stays undefined until TRACK_INFO (or, on older drafts,\n\t\t// implicit defaults) resolves it; runGroup blocks on it before decoding.\n\t\tconst timescale = new Signal<number | undefined>(undefined);\n\n\t\tconsole.debug(`subscribe start: id=${id} broadcast=${broadcast} track=${request.name}`);\n\n\t\tconst msg = new Subscribe({ id, broadcast, track: request.name, priority: request.priority });\n\n\t\t// Open the stream under a timeout. The stream handle flows back via `state`\n\t\t// so the timeout path can abort it if it finishes opening after the deadline.\n\t\tconst state: { stream?: Stream } = {};\n\t\tconst setup = this.#openSubscribe(state, msg, request, id, timescale);\n\n\t\tlet opened: { stream: Stream; producer: track.Producer };\n\t\ttry {\n\t\t\topened = await withTimeout(\n\t\t\t\tsetup,\n\t\t\t\tSUBSCRIBE_SETUP_TIMEOUT_MS,\n\t\t\t\t`subscribe timed out after ${SUBSCRIBE_SETUP_TIMEOUT_MS}ms waiting for the first response (browser stream limit reached?)`,\n\t\t\t);\n\t\t\tconsole.debug(`subscribe ok: id=${id} broadcast=${broadcast} track=${request.name}`);\n\t\t} catch (err) {\n\t\t\tconst e = error(err);\n\t\t\trequest.reject(e);\n\t\t\tthis.#subscribes.delete(id);\n\t\t\tconsole.warn(`subscribe error: id=${id} broadcast=${broadcast} track=${request.name} error=${reason(e)}`);\n\t\t\t// If the stream eventually opens after the timeout, abort it so we\n\t\t\t// don't leak it. Cover both branches: setup may resolve late, or it\n\t\t\t// may reject (e.g. encode/decode failure) after the stream is open.\n\t\t\tsetup.then(\n\t\t\t\t() => state.stream?.abort(e),\n\t\t\t\t() => state.stream?.abort(e),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst { stream, producer } = opened;\n\t\ttry {\n\t\t\t// Watch for priority changes and send SUBSCRIBE_UPDATE. Lite01/Lite02\n\t\t\t// don't carry SUBSCRIBE_UPDATE on the wire, so skip the watcher there\n\t\t\t// and just wait on the stream/track like before.\n\t\t\t//\n\t\t\t// On lite-05+ the publisher sends SUBSCRIBE_START/END/DROP on this stream;\n\t\t\t// drain them (we don't drive delivery off the resolved range) so the FIN is\n\t\t\t// observed. Older drafts just wait for the stream to close.\n\t\t\tconst closed = supportsTrackStream(this.version) ? this.#drainResponses(stream) : stream.reader.closed;\n\t\t\tconst priorityUpdates =\n\t\t\t\tthis.version === Version.DRAFT_01 || this.version === Version.DRAFT_02\n\t\t\t\t\t? undefined\n\t\t\t\t\t: this.#runPriorityUpdates(id, broadcast, producer, msg, stream);\n\n\t\t\t// Terminal conditions (stream end, track close, a failed priority update) settle at most\n\t\t\t// once; race them into one stable promise so the demand loop doesn't re-subscribe each pass.\n\t\t\tconst terminal: PromiseLike<unknown>[] = [closed, producer.closed];\n\t\t\tif (priorityUpdates !== undefined) terminal.push(priorityUpdates);\n\t\t\tconst done = Promise.race(terminal);\n\n\t\t\t// Serve until a terminal condition fires or the last local subscriber leaves. The unused\n\t\t\t// wake is level-triggered: re-check demand so a subscriber that returns before we tear\n\t\t\t// down (e.g. a quickly unmuted tile) resumes on the same subscription.\n\t\t\tconst idle = Symbol(\"idle\");\n\t\t\tfor (;;) {\n\t\t\t\tconst reason = await Promise.race([done, producer.unused().then(() => idle)]);\n\t\t\t\tif (reason === idle && producer.closed.peek() === undefined && producer.used.peek()) continue;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tproducer.close();\n\t\t\tstream.close();\n\t\t\tconsole.debug(`subscribe close: id=${id} broadcast=${broadcast} track=${request.name}`);\n\t\t} catch (err) {\n\t\t\tconst e = error(err);\n\t\t\tproducer.close(e);\n\t\t\tconsole.warn(`subscribe error: id=${id} broadcast=${broadcast} track=${request.name} error=${reason(e)}`);\n\t\t\tstream.abort(e);\n\t\t} finally {\n\t\t\tthis.#subscribes.delete(id);\n\t\t}\n\t}\n\n\t// Determine the track's immutable properties, accept the request (so the\n\t// application's track.Subscriber resolves and incoming groups have a producer to\n\t// write into), register it, then open the subscribe stream. `state.stream` is\n\t// populated as soon as the subscribe stream opens so the caller can clean it up\n\t// on timeout even before this promise settles.\n\t//\n\t// On lite-05+ the properties come from a TRACK stream opened first, and the\n\t// SUBSCRIBE is accepted implicitly (no SUBSCRIBE_OK). Older drafts carry no\n\t// per-track properties, so they resolve to defaults and just drain SUBSCRIBE_OK.\n\tasync #openSubscribe(\n\t\tstate: { stream?: Stream },\n\t\tmsg: Subscribe,\n\t\trequest: track.Request,\n\t\tid: bigint,\n\t\ttimescale: Signal<number | undefined>,\n\t): Promise<{ stream: Stream; producer: track.Producer }> {\n\t\tlet producer: track.Producer;\n\t\tlet drainOk = false;\n\n\t\tif (supportsTrackStream(this.version)) {\n\t\t\t// Fetch the immutable properties once via the TRACK stream.\n\t\t\tconst info = await this.#trackInfo(msg.broadcast, msg.track);\n\t\t\tproducer = request.accept(this.#toModelInfo(info));\n\t\t\ttimescale.set(info.timescale);\n\t\t} else {\n\t\t\t// Older drafts negotiate nothing per-track: verbatim frames, no timescale.\n\t\t\tproducer = request.accept();\n\t\t\ttimescale.set(0);\n\t\t\tdrainOk = true;\n\t\t}\n\n\t\t// Register before opening SUBSCRIBE so a racing GROUP stream finds the entry.\n\t\tthis.#subscribes.set(id, { track: producer, timescale });\n\n\t\tstate.stream = await Stream.open(this.#quic);\n\t\tawait state.stream.writer.u53(StreamId.Subscribe);\n\t\tawait msg.encode(state.stream.writer, this.version);\n\n\t\tif (drainOk) {\n\t\t\t// The first response MUST be a SUBSCRIBE_OK (older drafts only).\n\t\t\tconst resp = await decodeSubscribeResponse(state.stream.reader, this.version);\n\t\t\tif (!(\"ok\" in resp)) {\n\t\t\t\tthrow new Error(\"first subscribe response must be SUBSCRIBE_OK\");\n\t\t\t}\n\t\t}\n\n\t\treturn { stream: state.stream, producer };\n\t}\n\n\t// Opens a TRACK stream, reads the single TRACK_INFO, and FINs. Lite-05+ only.\n\tasync #trackInfo(broadcast: Path.Valid, track: string): Promise<TrackInfo> {\n\t\tconst stream = await Stream.open(this.#quic);\n\t\ttry {\n\t\t\tawait stream.writer.u53(StreamId.Track);\n\t\t\tawait new TrackMessage(broadcast, track).encode(stream.writer, this.version);\n\t\t\tconst info = await TrackInfo.decode(stream.reader, this.version);\n\t\t\t// The publisher FINs after TRACK_INFO; FIN our side too.\n\t\t\tstream.close();\n\t\t\treturn info;\n\t\t} catch (err) {\n\t\t\tstream.abort(error(err));\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\t// Map the wire TRACK_INFO onto the model track.Info a producer/consumer holds.\n\t#toModelInfo(info: TrackInfo): track.Info {\n\t\treturn {\n\t\t\ttimescale: Time.Timescale(info.timescale),\n\t\t\t// Publisher Max Latency rides on the wire, so the local retention window\n\t\t\t// matches what the upstream advertises (relays re-serve with the same bound).\n\t\t\tlatencyMax: info.latencyMax,\n\t\t\tpriority: info.priority,\n\t\t\tordered: info.ordered,\n\t\t};\n\t}\n\n\t// Resolve a track's immutable model info via a TRACK stream (lite-05+), for the\n\t// ConsumeBroadcast backing track.Consumer.info(). On older drafts there's no TRACK\n\t// stream, so this rejects rather than fabricating defaults.\n\tasync resolveTrackInfo(broadcast: Path.Valid, track: string): Promise<track.Info> {\n\t\tif (!supportsTrackStream(this.version)) {\n\t\t\tthrow new Error(\"track info requires moq-lite-05 or newer\");\n\t\t}\n\t\treturn this.#toModelInfo(await this.#trackInfo(broadcast, track));\n\t}\n\n\t// Open a FETCH stream for one group and stream its bare frames into a group, for the\n\t// ConsumeBroadcast backing track.Consumer.fetchGroup() (lite-05+).\n\tfetchGroup(\n\t\tbroadcast: Path.Valid,\n\t\ttrack: string,\n\t\tsequence: number,\n\t\toptions: track.FetchGroupOptions = {},\n\t): Promise<netGroup.Consumer> {\n\t\t// Coalesce onto a still-open fetch of the same group so we don't open a second FETCH\n\t\t// stream (and re-download it); each caller reads an independent mirror.\n\t\tconst key = JSON.stringify([broadcast, track, sequence]);\n\t\tconst existing = this.#fetches.get(key);\n\t\tif (existing && !existing.isClosed) return Promise.resolve(existing.mirror());\n\n\t\t// Create and cache the group synchronously (before any await) so a concurrent fetch for\n\t\t// the same group finds it and coalesces rather than racing to open its own stream.\n\t\tconst group = new netGroup.Producer(sequence);\n\t\tthis.#fetches.set(key, group);\n\t\tvoid group.closed.then(() => {\n\t\t\tif (this.#fetches.get(key) === group) this.#fetches.delete(key);\n\t\t});\n\n\t\treturn this.#runFetch(broadcast, track, sequence, options, group);\n\t}\n\n\t// Open the FETCH stream and pump the response into the shared group. Setup errors close the\n\t// group (so coalesced mirrors observe them and the entry evicts) and reject this caller.\n\tasync #runFetch(\n\t\tbroadcast: Path.Valid,\n\t\ttrack: string,\n\t\tsequence: number,\n\t\toptions: track.FetchGroupOptions,\n\t\tgroup: netGroup.Producer,\n\t): Promise<netGroup.Consumer> {\n\t\ttry {\n\t\t\tif (!supportsTrackStream(this.version)) {\n\t\t\t\tthrow new Error(\"fetch group requires moq-lite-05 or newer\");\n\t\t\t}\n\n\t\t\tconst info = await this.#trackInfo(broadcast, track);\n\t\t\tconst priority = options.priority ?? 0;\n\t\t\tconst stream = await Stream.open(this.#quic, undefined, priority);\n\n\t\t\ttry {\n\t\t\t\tawait stream.writer.u53(StreamId.Fetch);\n\t\t\t\tawait new FetchMessage(broadcast, track, priority, sequence).encode(stream.writer, this.version);\n\t\t\t} catch (err: unknown) {\n\t\t\t\tstream.abort(error(err));\n\t\t\t\tthrow err;\n\t\t\t}\n\n\t\t\t// Mint this caller's reader before starting the pump, so the group has demand when the\n\t\t\t// pump begins watching it (an abandoned fetch cancels once every reader has left).\n\t\t\tconst consumer = group.mirror();\n\t\t\tvoid this.#runFetchResponse(stream, group, Time.Timescale(info.timescale));\n\t\t\treturn consumer;\n\t\t} catch (err: unknown) {\n\t\t\tgroup.close(error(err));\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\t// Read the FETCH response (bare zigzag-delta-timestamped frames) into the group, then\n\t// FIN. A stream-level failure aborts the group so its reader observes the gap.\n\tasync #runFetchResponse(stream: Stream, group: netGroup.Producer, timescale: Time.Timescale): Promise<void> {\n\t\ttry {\n\t\t\tlet prevTs = 0n;\n\n\t\t\t// Serve until the stream FINs, the group closes, or every reader leaves. A group can\n\t\t\t// stay open indefinitely (a catalog or JSON stream), so an abandoned fetch is stopped by\n\t\t\t// demand, not by the stream ending. `closed` and `unused` are watched across frames as\n\t\t\t// stable promises (not re-subscribed to the signals each frame); the unused check is\n\t\t\t// level-triggered, so a coalesced fetch that arrives before we cancel re-arms and resumes.\n\t\t\tconst idle = Symbol(\"idle\");\n\t\t\tconst closed = Promise.resolve<Error | null>(group.closed);\n\t\t\tlet unused = group.unused().then(() => idle);\n\t\t\tfor (;;) {\n\t\t\t\tconst done = await Promise.race([stream.reader.done(), closed, unused]);\n\t\t\t\tif (done === idle) {\n\t\t\t\t\tif (!group.isClosed && group.used.peek()) {\n\t\t\t\t\t\tunused = group.unused().then(() => idle);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (done !== false) break;\n\n\t\t\t\tprevTs += unzigzag(await stream.reader.u62());\n\t\t\t\tconst timestamp = new Time.Timestamp(Number(prevTs), timescale);\n\t\t\t\tconst size = await stream.reader.u53();\n\t\t\t\tconst payload = await stream.reader.read(size);\n\t\t\t\tif (!payload) break;\n\t\t\t\tgroup.writeFrame({ payload, timestamp });\n\t\t\t}\n\n\t\t\tgroup.close();\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tgroup.close(e);\n\t\t\tstream.abort(e);\n\t\t}\n\t}\n\n\t// Drains SUBSCRIBE_START/END/DROP on the subscribe stream until FIN (lite-05+).\n\t// The resolved range is informational here; the producer already orders groups.\n\t// Resolves (never rejects) on FIN or on the stream being reset out from under it,\n\t// so it's safe to drop from a Promise.race without an unhandled rejection.\n\tasync #drainResponses(stream: Stream): Promise<void> {\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst resp = await decodeSubscribeResponseMaybe(stream.reader, this.version);\n\t\t\t\tif (!resp) return;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Stream closed or reset; nothing more to drain.\n\t\t}\n\t}\n\n\t/**\n\t * Send SUBSCRIBE_UPDATE messages whenever the track's priority signal changes.\n\t *\n\t * Resolves cleanly when the stream or track closes, so the caller can include\n\t * this in Promise.race without leaving a dangling pending write that would\n\t * become an unhandled rejection if the user calls updatePriority after close.\n\t *\n\t * Peeks the signal at the top of every iteration so that updates which landed\n\t * before SubscribeOk arrived (or between iterations, before .next() registered\n\t * its listener) aren't lost.\n\t */\n\tasync #runPriorityUpdates(\n\t\tid: bigint,\n\t\tbroadcast: Path.Valid,\n\t\ttrack: track.Producer,\n\t\tmsg: Subscribe,\n\t\tstream: Stream,\n\t): Promise<void> {\n\t\tconst stopped: Promise<null> = Promise.race([track.closed, stream.reader.closed]).then(() => null);\n\t\tlet lastSent: number | undefined;\n\n\t\tfor (;;) {\n\t\t\tconst current = track.subscription.peek()?.priority;\n\t\t\tif (current === undefined || current === lastSent) {\n\t\t\t\t// Nothing new to send; wait for a change or termination.\n\t\t\t\tconst next = await Promise.race([track.subscription.changed(), stopped]);\n\t\t\t\tif (next === null) return;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Round-trip the other Subscribe parameters so the publisher doesn't\n\t\t\t// interpret SUBSCRIBE_UPDATE as a reset of ordered/maxLatency/etc.\n\t\t\tconst update = new SubscribeUpdate({\n\t\t\t\tpriority: current,\n\t\t\t\tordered: msg.ordered,\n\t\t\t\tmaxLatency: msg.maxLatency,\n\t\t\t\tstartGroup: msg.startGroup,\n\t\t\t\tendGroup: msg.endGroup,\n\t\t\t});\n\t\t\tawait update.encode(stream.writer, this.version);\n\t\t\tlastSent = current;\n\t\t\tconsole.debug(`subscribe update: id=${id} broadcast=${broadcast} track=${track.name} priority=${current}`);\n\t\t}\n\t}\n\n\t/**\n\t * Handles a group message.\n\t * @param group - The group message\n\t * @param stream - The stream to read frames from\n\t *\n\t * @internal\n\t */\n\tasync runGroup(group: GroupMessage, stream: Reader) {\n\t\tconst entry = this.#subscribes.get(group.subscribe);\n\t\tif (!entry) {\n\t\t\tif (group.subscribe >= this.#subscribeNext) {\n\t\t\t\tthrow new Error(`unknown subscription: id=${group.subscribe}`);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst { track, timescale } = entry;\n\t\tconst producer = new netGroup.Producer(group.sequence);\n\t\ttrack.writeGroup(producer);\n\n\t\ttry {\n\t\t\t// Block until the timescale is known; the group's stream can arrive before\n\t\t\t// TRACK_INFO (or implicit defaults) resolves it on the subscribe stream.\n\t\t\tlet scale = timescale.peek();\n\t\t\twhile (scale === undefined) {\n\t\t\t\tif (track.closed.peek() !== undefined) {\n\t\t\t\t\t// Subscription ended before the scale resolved; nothing to decode.\n\t\t\t\t\tproducer.close();\n\t\t\t\t\tstream.stop(new Error(\"cancel\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tawait Signal.race(timescale, track.closed);\n\t\t\t\tscale = timescale.peek();\n\t\t\t}\n\n\t\t\t// A non-zero scale means every frame is prefixed with a zigzag-delta timestamp\n\t\t\t// (the lite-05 FRAME format), which we decode into a Timestamp at that scale.\n\t\t\t// Scale 0 (pre-lite-05) carries no timestamp, so we wall-clock-stamp.\n\t\t\tlet prevTs = 0n;\n\n\t\t\tfor (;;) {\n\t\t\t\tconst done = await Promise.race([stream.done(), track.closed, producer.closed]);\n\t\t\t\tif (done !== false) break;\n\n\t\t\t\tlet timestamp: Time.Timestamp;\n\t\t\t\tif (scale !== 0) {\n\t\t\t\t\tprevTs += unzigzag(await stream.u62());\n\t\t\t\t\ttimestamp = new Time.Timestamp(Number(prevTs), Time.Timescale(scale));\n\t\t\t\t} else {\n\t\t\t\t\ttimestamp = Time.Timestamp.now();\n\t\t\t\t}\n\n\t\t\t\tconst size = await stream.u53();\n\t\t\t\tconst payload = await stream.read(size);\n\t\t\t\tif (!payload) break;\n\n\t\t\t\tproducer.writeFrame({ payload, timestamp });\n\t\t\t}\n\n\t\t\tproducer.close();\n\t\t\tstream.stop(new Error(\"cancel\"));\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tproducer.close(e);\n\t\t\tstream.stop(e);\n\t\t}\n\t}\n\n\t/**\n\t * Receives QUIC datagrams and routes each to its subscription's track producer (lite-05 §6.4).\n\t *\n\t * Returns immediately on a non-datagram transport or pre-lite-05 version. A decode error or an\n\t * unknown subscribe id drops that datagram without tearing down the session (best-effort); the\n\t * loop ends only when the datagram stream closes.\n\t *\n\t * @internal\n\t */\n\tasync runDatagrams(): Promise<void> {\n\t\tif (!hasDatagrams(this.version) || DatagramStream.maxDatagramSize(this.#quic) === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Never reject: this loop is awaited alongside the connection's other tasks, so a\n\t\t// datagram-stream failure must not tear the whole session down (it's best-effort).\n\t\tconst reader = DatagramStream.datagramReader(this.#quic);\n\t\tif (!reader) return;\n\n\t\ttry {\n\t\t\ttry {\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst { value, done } = await reader.read();\n\t\t\t\t\tif (done) break;\n\t\t\t\t\tif (!value) continue;\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait this.#routeDatagram(value);\n\t\t\t\t\t} catch (err: unknown) {\n\t\t\t\t\t\tconsole.debug(`dropping datagram: ${reason(err)}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\treader.releaseLock();\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tif (e.message === \"The session is closed.\") {\n\t\t\t\tconsole.debug(`datagram receive stopped: ${e.message}`);\n\t\t\t} else {\n\t\t\t\tconsole.warn(\"datagram stream error\", err);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Decode one datagram body and hand it to the matching subscription's producer. Drops the\n\t// datagram (best-effort) if the subscription is unknown/closed or its timescale isn't resolved.\n\tasync #routeDatagram(payload: Uint8Array): Promise<void> {\n\t\tconst dg = await DatagramMessage.decode(payload);\n\n\t\tconst entry = this.#subscribes.get(dg.subscribe);\n\t\tif (!entry) return; // Unknown or already-closed subscription.\n\n\t\t// Datagrams are lite-05+, which always negotiates a timescale; if it hasn't resolved\n\t\t// yet (the datagram raced ahead of TRACK_INFO), drop rather than guess.\n\t\tconst scale = entry.timescale.peek();\n\t\tif (!scale) return;\n\n\t\tconst timestamp = new Time.Timestamp(dg.timestamp, Time.Timescale(scale));\n\t\tentry.track.writeDatagram({ sequence: dg.sequence, timestamp, payload: dg.payload });\n\t}\n\n\t/**\n\t * Opens a PROBE bidi stream to receive bandwidth estimates from the publisher.\n\t * Returns immediately if recv bandwidth is not supported.\n\t *\n\t * Probe is best-effort telemetry: a stream-level failure (peer reset, FIN,\n\t * missing peer support, transport hiccup) is caught and logged, never\n\t * propagated to the connection. On exit the bandwidth/RTT signals are\n\t * cleared so consumers see them as stale.\n\t *\n\t * @internal\n\t */\n\t// Await the peer's advertised probe level, blocking until its SETUP arrives. The peer\n\t// MUST send exactly one SETUP, so this resolves once that stream is read.\n\tasync #peerProbeLevel(peerSetup: Signal<Setup | undefined>): Promise<ProbeLevel> {\n\t\tlet setup = peerSetup.peek();\n\t\twhile (setup === undefined) {\n\t\t\tsetup = await peerSetup.changed();\n\t\t}\n\t\treturn setup.probe;\n\t}\n\n\tasync runProbe(): Promise<void> {\n\t\tif (!this.#probe) return;\n\t\tif (this.version === Version.DRAFT_01 || this.version === Version.DRAFT_02) return;\n\n\t\t// Lite-05+ gates the PROBE stream on the peer advertising Probe >= Report in its\n\t\t// SETUP. Wait for the SETUP, then bail if the peer can't report bitrate. Older\n\t\t// drafts have no SETUP, so they keep probing unconditionally.\n\t\tif (this.#peerSetup) {\n\t\t\tconst probe = await this.#peerProbeLevel(this.#peerSetup);\n\t\t\tif (probe < ProbeLevel.Report) return;\n\t\t}\n\n\t\t// Probe is best-effort: any failure (stream reset by peer, missing peer support,\n\t\t// transport hiccup) MUST NOT tear down the connection. On error, drop the\n\t\t// estimates so consumers know they're stale.\n\t\ttry {\n\t\t\tconst stream = await Stream.open(this.#quic);\n\t\t\tawait stream.writer.u53(StreamId.Probe);\n\n\t\t\tfor (;;) {\n\t\t\t\tconst probe = await Probe.decodeMaybe(stream.reader, this.version);\n\t\t\t\tif (!probe) break;\n\t\t\t\t// A message that omits the RTT leaves the last one standing, so a\n\t\t\t\t// bitrate-only report doesn't blank it.\n\t\t\t\tconst prev = this.#probe.peek();\n\t\t\t\tthis.#probe.set({\n\t\t\t\t\testimatedRecvRate: probe.bitrate ?? undefined,\n\t\t\t\t\trtt: probe.rtt !== undefined ? Time.Milli(probe.rtt) : prev.rtt,\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tif (!this.#closed.signal.aborted) {\n\t\t\t\tconsole.warn(\"probe stream error\", err);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.#probe.set({});\n\t\t}\n\t}\n\n\tclose() {\n\t\tthis.#closed.abort();\n\n\t\tfor (const { track } of this.#subscribes.values()) {\n\t\t\ttrack.close();\n\t\t}\n\n\t\tthis.#subscribes.clear();\n\t}\n}\n\n/**\n * A broadcast consumed from a lite session. It resolves `track.Consumer.info()` and\n * `.fetchGroup()` over the wire (lite-05+ TRACK / FETCH streams) by reaching into the\n * {@link Subscriber} it was opened from, the way the Rust `BroadcastConsumer` holds its\n * session. Live subscribes still flow through the inherited requested() queue.\n */\nclass ConsumeBroadcast extends broadcast.Consumer {\n\t#subscriber: Subscriber;\n\t#path: Path.Valid;\n\n\tconstructor(subscriber: Subscriber, path: Path.Valid, state?: never) {\n\t\tsuper(state);\n\t\tthis.#subscriber = subscriber;\n\t\tthis.#path = path;\n\t}\n\n\t// Preserve the subclass (and its wire-backed info/fetchGroup) when the consume cache shares\n\t// this broadcast across callers.\n\toverride clone(): ConsumeBroadcast {\n\t\treturn new ConsumeBroadcast(this.#subscriber, this.#path, this.shareState());\n\t}\n\n\toverride resolveTrackInfo(name: string): Promise<track.Info> {\n\t\treturn this.#subscriber.resolveTrackInfo(this.#path, name);\n\t}\n\n\toverride fetchGroup(name: string, sequence: number, options?: track.FetchGroupOptions): Promise<netGroup.Consumer> {\n\t\treturn this.#subscriber.fetchGroup(this.#path, name, sequence, options);\n\t}\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  /* @ts-self-types="./subscriber.test.d.ts" */
2
2
  import { expect, spyOn, test } from "bun:test";
3
- import { createBandwidth } from "../bandwidth.js";
3
+ import { Signal } from "@moq/signals";
4
4
  import { OriginSchema } from "./origin.js";
5
5
  import { Subscriber } from "./subscriber.js";
6
6
  import { Version } from "./version.js";
@@ -12,7 +12,7 @@ test("closing the subscriber suppresses probe stream warnings", async () => {
12
12
  writable: new WritableStream(),
13
13
  }),
14
14
  };
15
- const subscriber = new Subscriber(quic, Version.DRAFT_03, OriginSchema.parse(1n), createBandwidth());
15
+ const subscriber = new Subscriber(quic, Version.DRAFT_03, OriginSchema.parse(1n), new Signal({}));
16
16
  const warn = spyOn(console, "warn").mockImplementation(() => { });
17
17
  try {
18
18
  const probe = subscriber.runProbe();
@@ -1 +1 @@
1
- {"version":3,"file":"subscriber.test.js","sourceRoot":"","sources":["../../src/lite/subscriber.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,IAAI,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;IAC1E,IAAI,QAAsD,CAAC;IAC3D,MAAM,IAAI,GAAG;QACZ,yBAAyB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YACvC,QAAQ,EAAE,IAAI,cAAc,CAAa,EAAE,KAAK,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,QAAQ,GAAG,UAAU,CAAC,EAAE,CAAC;YAC5F,QAAQ,EAAE,IAAI,cAAc,EAAc;SAC1C,CAAC;KACyB,CAAC;IAC7B,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC;IACrG,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAEjE,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;QAEpC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QACxB,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QACxB,UAAU,CAAC,KAAK,EAAE,CAAC;QACnB,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAC5C,MAAM,KAAK,CAAC;QAEZ,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IACrC,CAAC;YAAS,CAAC;QACV,IAAI,CAAC,WAAW,EAAE,CAAC;IACpB,CAAC;AACF,CAAC,CAAC,CAAC","sourcesContent":["import { expect, spyOn, test } from \"bun:test\";\nimport { createBandwidth } from \"../bandwidth.ts\";\nimport { OriginSchema } from \"./origin.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { Version } from \"./version.ts\";\n\ntest(\"closing the subscriber suppresses probe stream warnings\", async () => {\n\tlet readable!: ReadableStreamDefaultController<Uint8Array>;\n\tconst quic = {\n\t\tcreateBidirectionalStream: async () => ({\n\t\t\treadable: new ReadableStream<Uint8Array>({ start: (controller) => (readable = controller) }),\n\t\t\twritable: new WritableStream<Uint8Array>(),\n\t\t}),\n\t} as unknown as WebTransport;\n\tconst subscriber = new Subscriber(quic, Version.DRAFT_03, OriginSchema.parse(1n), createBandwidth());\n\tconst warn = spyOn(console, \"warn\").mockImplementation(() => {});\n\n\ttry {\n\t\tconst probe = subscriber.runProbe();\n\n\t\tawait Promise.resolve();\n\t\tawait Promise.resolve();\n\t\tsubscriber.close();\n\t\treadable.error(new Error(\"session closed\"));\n\t\tawait probe;\n\n\t\texpect(warn).not.toHaveBeenCalled();\n\t} finally {\n\t\twarn.mockRestore();\n\t}\n});\n"]}
1
+ {"version":3,"file":"subscriber.test.js","sourceRoot":"","sources":["../../src/lite/subscriber.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,IAAI,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;IAC1E,IAAI,QAAsD,CAAC;IAC3D,MAAM,IAAI,GAAG;QACZ,yBAAyB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YACvC,QAAQ,EAAE,IAAI,cAAc,CAAa,EAAE,KAAK,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,QAAQ,GAAG,UAAU,CAAC,EAAE,CAAC;YAC5F,QAAQ,EAAE,IAAI,cAAc,EAAc;SAC1C,CAAC;KACyB,CAAC;IAC7B,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,IAAI,MAAM,CAAQ,EAAE,CAAC,CAAC,CAAC;IACzG,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAEjE,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;QAEpC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QACxB,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QACxB,UAAU,CAAC,KAAK,EAAE,CAAC;QACnB,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAC5C,MAAM,KAAK,CAAC;QAEZ,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IACrC,CAAC;YAAS,CAAC;QACV,IAAI,CAAC,WAAW,EAAE,CAAC;IACpB,CAAC;AACF,CAAC,CAAC,CAAC","sourcesContent":["import { expect, spyOn, test } from \"bun:test\";\nimport { Signal } from \"@moq/signals\";\nimport type { Probe } from \"../connection/stats.ts\";\nimport { OriginSchema } from \"./origin.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { Version } from \"./version.ts\";\n\ntest(\"closing the subscriber suppresses probe stream warnings\", async () => {\n\tlet readable!: ReadableStreamDefaultController<Uint8Array>;\n\tconst quic = {\n\t\tcreateBidirectionalStream: async () => ({\n\t\t\treadable: new ReadableStream<Uint8Array>({ start: (controller) => (readable = controller) }),\n\t\t\twritable: new WritableStream<Uint8Array>(),\n\t\t}),\n\t} as unknown as WebTransport;\n\tconst subscriber = new Subscriber(quic, Version.DRAFT_03, OriginSchema.parse(1n), new Signal<Probe>({}));\n\tconst warn = spyOn(console, \"warn\").mockImplementation(() => {});\n\n\ttry {\n\t\tconst probe = subscriber.runProbe();\n\n\t\tawait Promise.resolve();\n\t\tawait Promise.resolve();\n\t\tsubscriber.close();\n\t\treadable.error(new Error(\"session closed\"));\n\t\tawait probe;\n\n\t\texpect(warn).not.toHaveBeenCalled();\n\t} finally {\n\t\twarn.mockRestore();\n\t}\n});\n"]}
package/lite/track.d.ts CHANGED
@@ -1,36 +1,48 @@
1
1
  import * as Path from "../path";
2
2
  import type { Reader, Writer } from "../stream";
3
- import { type Version } from "./version";
3
+ import { Version } from "./version";
4
4
  /**
5
- * Sent by a subscriber on a Track stream (moq-lite-05+) to request a track's
6
- * immutable publisher properties without subscribing or fetching.
5
+ * TRACK request: the first (and only) subscriber message on a Track Stream (0x6).
6
+ * Asks for a track's immutable publisher properties without subscribing or fetching.
7
7
  */
8
8
  export declare class Track {
9
9
  #private;
10
10
  broadcast: Path.Valid;
11
11
  track: string;
12
- constructor(props: {
13
- broadcast: Path.Valid;
14
- track: string;
15
- });
12
+ constructor(broadcast: Path.Valid, track: string);
16
13
  encode(w: Writer, version: Version): Promise<void>;
17
14
  static decode(r: Reader, version: Version): Promise<Track>;
18
15
  }
19
16
  /**
20
- * The publisher's reply on a Track stream (moq-lite-05+): the track's immutable
21
- * properties. Sent once, then the publisher FINs the stream.
17
+ * TRACK_INFO reply: the publisher's sole message on a Track Stream, carrying the
18
+ * track's immutable properties. Fetched once and reused across every SUBSCRIBE and
19
+ * FETCH for the track.
22
20
  */
23
21
  export declare class TrackInfo {
24
22
  #private;
23
+ /** The publisher's tie-break priority for this track. */
25
24
  priority: number;
25
+ /**
26
+ * Whether groups are prioritized in sequence order. Groups may always arrive
27
+ * out-of-order (or not at all) over the network.
28
+ */
26
29
  ordered: boolean;
27
- maxLatency: number;
30
+ /**
31
+ * Publisher Max Latency: an upper bound (milliseconds) on how long the publisher
32
+ * caches a non-latest group past the arrival of a newer one.
33
+ */
34
+ latencyMax: number;
35
+ /**
36
+ * Per-frame timestamp scale (units per second). Mandatory on Lite05: a real
37
+ * (non-zero) scale, and every frame on the wire is prefixed with a zigzag-delta
38
+ * timestamp at this scale.
39
+ */
28
40
  timescale: number;
29
- constructor(props: {
41
+ constructor({ priority, ordered, latencyMax, timescale, }: {
30
42
  priority?: number;
31
43
  ordered?: boolean;
32
- maxLatency?: number;
33
- timescale: number;
44
+ latencyMax?: number;
45
+ timescale?: number;
34
46
  });
35
47
  encode(w: Writer, version: Version): Promise<void>;
36
48
  static decode(r: Reader, version: Version): Promise<TrackInfo>;
@@ -1 +1 @@
1
- {"version":3,"file":"track.d.ts","sourceRoot":"","sources":["../../src/lite/track.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5D;;;GAGG;AACH,qBAAa,KAAK;;IACjB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IAEd,YAAY,KAAK,EAAE;QAAE,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAG1D;IAaK,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvD;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAG/D;CACD;AAED;;;GAGG;AACH,qBAAa,SAAS;;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAElB,YAAY,KAAK,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,EAQlG;IAmBK,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC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AAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAMvD;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAGnE;CACD"}
package/lite/track.js CHANGED
@@ -1,17 +1,29 @@
1
1
  /* @ts-self-types="./track.d.ts" */
2
2
  import * as Path from "../path.js";
3
3
  import * as Message from "./message.js";
4
- import { hasTrackStream } from "./version.js";
4
+ import { Version } from "./version.js";
5
+ // The Track Stream (0x6) is draft-05+ only.
6
+ function guardTrack(version) {
7
+ switch (version) {
8
+ case Version.DRAFT_01:
9
+ case Version.DRAFT_02:
10
+ case Version.DRAFT_03:
11
+ case Version.DRAFT_04:
12
+ throw new Error("track stream not supported for this version");
13
+ default:
14
+ break;
15
+ }
16
+ }
5
17
  /**
6
- * Sent by a subscriber on a Track stream (moq-lite-05+) to request a track's
7
- * immutable publisher properties without subscribing or fetching.
18
+ * TRACK request: the first (and only) subscriber message on a Track Stream (0x6).
19
+ * Asks for a track's immutable publisher properties without subscribing or fetching.
8
20
  */
9
21
  export class Track {
10
22
  broadcast;
11
23
  track;
12
- constructor(props) {
13
- this.broadcast = props.broadcast;
14
- this.track = props.track;
24
+ constructor(broadcast, track) {
25
+ this.broadcast = broadcast;
26
+ this.track = track;
15
27
  }
16
28
  async #encode(w) {
17
29
  await w.string(Path.encode(this.broadcast));
@@ -20,62 +32,75 @@ export class Track {
20
32
  static async #decode(r) {
21
33
  const broadcast = Path.decode(await r.string());
22
34
  const track = await r.string();
23
- return new Track({ broadcast, track });
35
+ return new Track(broadcast, track);
24
36
  }
25
37
  async encode(w, version) {
26
- if (!hasTrackStream(version))
27
- throw new Error("TRACK requires moq-lite-05+");
28
- return Message.encode(w, this.#encode.bind(this));
38
+ guardTrack(version);
39
+ return Message.encode(w, (w) => this.#encode(w));
29
40
  }
30
41
  static async decode(r, version) {
31
- if (!hasTrackStream(version))
32
- throw new Error("TRACK requires moq-lite-05+");
33
- return Message.decode(r, Track.#decode);
42
+ guardTrack(version);
43
+ return Message.decode(r, (r) => Track.#decode(r));
34
44
  }
35
45
  }
36
46
  /**
37
- * The publisher's reply on a Track stream (moq-lite-05+): the track's immutable
38
- * properties. Sent once, then the publisher FINs the stream.
47
+ * TRACK_INFO reply: the publisher's sole message on a Track Stream, carrying the
48
+ * track's immutable properties. Fetched once and reused across every SUBSCRIBE and
49
+ * FETCH for the track.
39
50
  */
40
51
  export class TrackInfo {
52
+ /** The publisher's tie-break priority for this track. */
41
53
  priority;
54
+ /**
55
+ * Whether groups are prioritized in sequence order. Groups may always arrive
56
+ * out-of-order (or not at all) over the network.
57
+ */
42
58
  ordered;
43
- maxLatency;
59
+ /**
60
+ * Publisher Max Latency: an upper bound (milliseconds) on how long the publisher
61
+ * caches a non-latest group past the arrival of a newer one.
62
+ */
63
+ latencyMax;
64
+ /**
65
+ * Per-frame timestamp scale (units per second). Mandatory on Lite05: a real
66
+ * (non-zero) scale, and every frame on the wire is prefixed with a zigzag-delta
67
+ * timestamp at this scale.
68
+ */
44
69
  timescale;
45
- constructor(props) {
46
- if (!Number.isInteger(props.timescale) || props.timescale <= 0) {
47
- throw new Error("TRACK_INFO timescale must be a positive integer");
48
- }
49
- this.priority = props.priority ?? 0;
50
- this.ordered = props.ordered ?? false;
51
- this.maxLatency = props.maxLatency ?? 0;
52
- this.timescale = props.timescale;
70
+ constructor({ priority = 0, ordered = false, latencyMax = 0, timescale = 0, }) {
71
+ this.priority = priority;
72
+ this.ordered = ordered;
73
+ this.latencyMax = latencyMax;
74
+ this.timescale = timescale;
53
75
  }
54
76
  async #encode(w) {
55
77
  await w.u8(this.priority);
56
78
  await w.bool(this.ordered);
57
- await w.u53(this.maxLatency);
79
+ await w.u53(this.latencyMax);
58
80
  await w.u53(this.timescale);
59
81
  }
60
82
  static async #decode(r) {
61
83
  const priority = await r.u8();
62
84
  const ordered = await r.bool();
63
- const maxLatency = await r.u53();
85
+ const latencyMax = await r.u53();
64
86
  const timescale = await r.u53();
65
- // A zero timescale is a protocol violation: every track has a media timeline.
87
+ // Mandatory on Lite05: a zero scale is invalid (mirrors Rust's Timescale::new rejection),
88
+ // and would otherwise throw later when wrapped in Timescale().
66
89
  if (timescale === 0)
67
- throw new Error("TRACK_INFO timescale must be a positive integer");
68
- return new TrackInfo({ priority, ordered, maxLatency, timescale });
90
+ throw new Error("track timescale must be non-zero");
91
+ return new TrackInfo({ priority, ordered, latencyMax, timescale });
69
92
  }
70
93
  async encode(w, version) {
71
- if (!hasTrackStream(version))
72
- throw new Error("TRACK_INFO requires moq-lite-05+");
73
- return Message.encode(w, this.#encode.bind(this));
94
+ guardTrack(version);
95
+ // Reject a zero timescale on encode too, so an invalid TrackInfo fails fast on
96
+ // the sender rather than only at the peer's decoder.
97
+ if (this.timescale === 0)
98
+ throw new Error("track timescale must be non-zero");
99
+ return Message.encode(w, (w) => this.#encode(w));
74
100
  }
75
101
  static async decode(r, version) {
76
- if (!hasTrackStream(version))
77
- throw new Error("TRACK_INFO requires moq-lite-05+");
78
- return Message.decode(r, TrackInfo.#decode);
102
+ guardTrack(version);
103
+ return Message.decode(r, (r) => TrackInfo.#decode(r));
79
104
  }
80
105
  }
81
106
  //# sourceMappingURL=track.js.map
package/lite/track.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"track.js","sourceRoot":"","sources":["../../src/lite/track.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,cAAc,EAAgB,MAAM,cAAc,CAAC;AAE5D;;;GAGG;AACH,MAAM,OAAO,KAAK;IACjB,SAAS,CAAa;IACtB,KAAK,CAAS;IAEd,YAAY,KAA+C;QAC1D,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC1B,CAAC;IAED,KAAK,CA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O,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAClF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAClF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;CACD","sourcesContent":["import * as Path from \"../path.ts\";\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { hasTrackStream, type Version } from \"./version.ts\";\n\n/**\n * Sent by a subscriber on a Track stream (moq-lite-05+) to request a track's\n * immutable publisher properties without subscribing or fetching.\n */\nexport class Track {\n\tbroadcast: Path.Valid;\n\ttrack: string;\n\n\tconstructor(props: { broadcast: Path.Valid; track: string }) {\n\t\tthis.broadcast = props.broadcast;\n\t\tthis.track = props.track;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.string(Path.encode(this.broadcast));\n\t\tawait w.string(this.track);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Track> {\n\t\tconst broadcast = Path.decode(await r.string());\n\t\tconst track = await r.string();\n\t\treturn new Track({ broadcast, track });\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tif (!hasTrackStream(version)) throw new Error(\"TRACK requires moq-lite-05+\");\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<Track> {\n\t\tif (!hasTrackStream(version)) throw new Error(\"TRACK requires moq-lite-05+\");\n\t\treturn Message.decode(r, Track.#decode);\n\t}\n}\n\n/**\n * The publisher's reply on a Track stream (moq-lite-05+): the track's immutable\n * properties. Sent once, then the publisher FINs the stream.\n */\nexport class TrackInfo {\n\tpriority: number;\n\tordered: boolean;\n\tmaxLatency: number;\n\ttimescale: number;\n\n\tconstructor(props: { priority?: number; ordered?: boolean; maxLatency?: number; timescale: number }) {\n\t\tif (!Number.isInteger(props.timescale) || props.timescale <= 0) {\n\t\t\tthrow new Error(\"TRACK_INFO timescale must be a positive integer\");\n\t\t}\n\t\tthis.priority = props.priority ?? 0;\n\t\tthis.ordered = props.ordered ?? false;\n\t\tthis.maxLatency = props.maxLatency ?? 0;\n\t\tthis.timescale = props.timescale;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u8(this.priority);\n\t\tawait w.bool(this.ordered);\n\t\tawait w.u53(this.maxLatency);\n\t\tawait w.u53(this.timescale);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<TrackInfo> {\n\t\tconst priority = await r.u8();\n\t\tconst ordered = await r.bool();\n\t\tconst maxLatency = await r.u53();\n\t\tconst timescale = await r.u53();\n\t\t// A zero timescale is a protocol violation: every track has a media timeline.\n\t\tif (timescale === 0) throw new Error(\"TRACK_INFO timescale must be a positive integer\");\n\t\treturn new TrackInfo({ priority, ordered, maxLatency, timescale });\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tif (!hasTrackStream(version)) throw new Error(\"TRACK_INFO requires moq-lite-05+\");\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<TrackInfo> {\n\t\tif (!hasTrackStream(version)) throw new Error(\"TRACK_INFO requires moq-lite-05+\");\n\t\treturn Message.decode(r, TrackInfo.#decode);\n\t}\n}\n"]}
1
+ {"version":3,"file":"track.js","sourceRoot":"","sources":["../../src/lite/track.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CA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EAAE,CAAC;QACjC,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;QAChC,0FAA0F;QAC1F,+DAA+D;QAC/D,IAAI,SAAS,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACzE,OAAO,IAAI,SAAS,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC;IACpE,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QACvC,UAAU,CAAC,OAAO,CAAC,CAAC;QACpB,+EAA+E;QAC/E,qDAAqD;QACrD,IAAI,IAAI,CAAC,SAAS,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAC9E,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,UAAU,CAAC,OAAO,CAAC,CAAC;QACpB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACvD,CAAC;CACD","sourcesContent":["import * as Path from \"../path.ts\";\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { Version } from \"./version.ts\";\n\n// The Track Stream (0x6) is draft-05+ only.\nfunction guardTrack(version: Version) {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\tthrow new Error(\"track stream not supported for this version\");\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n\n/**\n * TRACK request: the first (and only) subscriber message on a Track Stream (0x6).\n * Asks for a track's immutable publisher properties without subscribing or fetching.\n */\nexport class Track {\n\tbroadcast: Path.Valid;\n\ttrack: string;\n\n\tconstructor(broadcast: Path.Valid, track: string) {\n\t\tthis.broadcast = broadcast;\n\t\tthis.track = track;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.string(Path.encode(this.broadcast));\n\t\tawait w.string(this.track);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Track> {\n\t\tconst broadcast = Path.decode(await r.string());\n\t\tconst track = await r.string();\n\t\treturn new Track(broadcast, track);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tguardTrack(version);\n\t\treturn Message.encode(w, (w) => this.#encode(w));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<Track> {\n\t\tguardTrack(version);\n\t\treturn Message.decode(r, (r) => Track.#decode(r));\n\t}\n}\n\n/**\n * TRACK_INFO reply: the publisher's sole message on a Track Stream, carrying the\n * track's immutable properties. Fetched once and reused across every SUBSCRIBE and\n * FETCH for the track.\n */\nexport class TrackInfo {\n\t/** The publisher's tie-break priority for this track. */\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.\n\t */\n\tordered: boolean;\n\t/**\n\t * Publisher Max Latency: an upper bound (milliseconds) on how long the publisher\n\t * caches a non-latest group past the arrival of a newer one.\n\t */\n\tlatencyMax: number;\n\t/**\n\t * Per-frame timestamp scale (units per second). Mandatory on Lite05: a real\n\t * (non-zero) scale, and every frame on the wire is prefixed with a zigzag-delta\n\t * timestamp at this scale.\n\t */\n\ttimescale: number;\n\n\tconstructor({\n\t\tpriority = 0,\n\t\tordered = false,\n\t\tlatencyMax = 0,\n\t\ttimescale = 0,\n\t}: {\n\t\tpriority?: number;\n\t\tordered?: boolean;\n\t\tlatencyMax?: number;\n\t\ttimescale?: number;\n\t}) {\n\t\tthis.priority = priority;\n\t\tthis.ordered = ordered;\n\t\tthis.latencyMax = latencyMax;\n\t\tthis.timescale = timescale;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u8(this.priority);\n\t\tawait w.bool(this.ordered);\n\t\tawait w.u53(this.latencyMax);\n\t\tawait w.u53(this.timescale);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<TrackInfo> {\n\t\tconst priority = await r.u8();\n\t\tconst ordered = await r.bool();\n\t\tconst latencyMax = await r.u53();\n\t\tconst timescale = await r.u53();\n\t\t// Mandatory on Lite05: a zero scale is invalid (mirrors Rust's Timescale::new rejection),\n\t\t// and would otherwise throw later when wrapped in Timescale().\n\t\tif (timescale === 0) throw new Error(\"track timescale must be non-zero\");\n\t\treturn new TrackInfo({ priority, ordered, latencyMax, timescale });\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tguardTrack(version);\n\t\t// Reject a zero timescale on encode too, so an invalid TrackInfo fails fast on\n\t\t// the sender rather than only at the peer's decoder.\n\t\tif (this.timescale === 0) throw new Error(\"track timescale must be non-zero\");\n\t\treturn Message.encode(w, (w) => this.#encode(w));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<TrackInfo> {\n\t\tguardTrack(version);\n\t\treturn Message.decode(r, (r) => TrackInfo.#decode(r));\n\t}\n}\n"]}
@@ -2,6 +2,7 @@
2
2
  import { expect, test } from "bun:test";
3
3
  import * as Path from "../path.js";
4
4
  import { Reader, Writer } from "../stream.js";
5
+ import { infoDefaults } from "../track.js";
5
6
  import { Track, TrackInfo } from "./track.js";
6
7
  import { Version } from "./version.js";
7
8
  function concat(chunks) {
@@ -26,26 +27,27 @@ test("TrackInfo round-trips on draft-05", async () => {
26
27
  const info = new TrackInfo({
27
28
  priority: 7,
28
29
  ordered: false,
29
- maxLatency: 2000,
30
+ latencyMax: 2000,
30
31
  timescale: 90000,
31
32
  });
32
- const reader = new Reader(undefined, await bytes((w) => info.encode(w, Version.DRAFT_05_WIP)));
33
- const got = await TrackInfo.decode(reader, Version.DRAFT_05_WIP);
33
+ const reader = new Reader(undefined, await bytes((w) => info.encode(w, Version.DRAFT_05)));
34
+ const got = await TrackInfo.decode(reader, Version.DRAFT_05);
34
35
  expect(got.priority).toBe(7);
35
36
  expect(got.ordered).toBe(false);
36
- expect(got.maxLatency).toBe(2000);
37
+ expect(got.latencyMax).toBe(2000);
37
38
  expect(got.timescale).toBe(90000);
38
39
  });
40
+ test("TrackInfo defaults match cross-language wire bytes", async () => {
41
+ const info = new TrackInfo(infoDefaults());
42
+ expect(await bytes((w) => info.encode(w, Version.DRAFT_05))).toEqual(new Uint8Array([0x06, 0x00, 0x00, 0x53, 0x88, 0x43, 0xe8]));
43
+ });
39
44
  test("Track request round-trips on draft-05", async () => {
40
- const msg = new Track({ broadcast: Path.from("room"), track: "video" });
41
- const reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05_WIP)));
42
- const got = await Track.decode(reader, Version.DRAFT_05_WIP);
45
+ const msg = new Track(Path.from("room"), "video");
46
+ const reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05)));
47
+ const got = await Track.decode(reader, Version.DRAFT_05);
43
48
  expect(got.broadcast).toBe(Path.from("room"));
44
49
  expect(got.track).toBe("video");
45
50
  });
46
- test("TrackInfo rejects zero timescale", () => {
47
- expect(() => new TrackInfo({ timescale: 0 })).toThrow(/timescale/);
48
- });
49
51
  test("TRACK_INFO is rejected before draft-05", async () => {
50
52
  const info = new TrackInfo({ timescale: 90000 });
51
53
  await expect(bytes((w) => info.encode(w, Version.DRAFT_04))).rejects.toThrow();
@@ -1 +1 @@
1
- {"version":3,"file":"track.test.js","sourceRoot":"","sources":["../../src/lite/track.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAA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AAO,CAAC,CAAC;AACjC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAC7C,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AACpE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;IACzD,MAAM,IAAI,GAAG,IAAI,SAAS,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IACjD,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AAChF,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport * as Path from \"../path.ts\";\nimport { Reader, Writer } from \"../stream.ts\";\nimport { Track, TrackInfo } from \"./track.ts\";\nimport { Version } from \"./version.ts\";\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n\tconst total = chunks.reduce((sum, c) => sum + c.byteLength, 0);\n\tconst out = new Uint8Array(total);\n\tlet offset = 0;\n\tfor (const c of chunks) {\n\t\tout.set(c, offset);\n\t\toffset += c.byteLength;\n\t}\n\treturn out;\n}\n\nasync function bytes(f: (w: Writer) => Promise<void>): Promise<Uint8Array> {\n\tconst written: Uint8Array[] = [];\n\tconst writer = new Writer(\n\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void written.push(new Uint8Array(chunk)) }),\n\t);\n\tawait f(writer);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\ntest(\"TrackInfo round-trips on draft-05\", async () => {\n\tconst info = new TrackInfo({\n\t\tpriority: 7,\n\t\tordered: false,\n\t\tmaxLatency: 2000,\n\t\ttimescale: 90000,\n\t});\n\tconst reader = new Reader(undefined, await bytes((w) => info.encode(w, Version.DRAFT_05_WIP)));\n\tconst got = await TrackInfo.decode(reader, Version.DRAFT_05_WIP);\n\texpect(got.priority).toBe(7);\n\texpect(got.ordered).toBe(false);\n\texpect(got.maxLatency).toBe(2000);\n\texpect(got.timescale).toBe(90000);\n});\n\ntest(\"Track request round-trips on draft-05\", async () => {\n\tconst msg = new Track({ broadcast: Path.from(\"room\"), track: \"video\" });\n\tconst reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05_WIP)));\n\tconst got = await Track.decode(reader, Version.DRAFT_05_WIP);\n\texpect(got.broadcast).toBe(Path.from(\"room\"));\n\texpect(got.track).toBe(\"video\");\n});\n\ntest(\"TrackInfo rejects zero timescale\", () => {\n\texpect(() => new TrackInfo({ timescale: 0 })).toThrow(/timescale/);\n});\n\ntest(\"TRACK_INFO is rejected before draft-05\", async () => {\n\tconst info = new TrackInfo({ timescale: 90000 });\n\tawait expect(bytes((w) => info.encode(w, Version.DRAFT_04))).rejects.toThrow();\n});\n"]}
1
+ {"version":3,"file":"track.test.js","sourceRoot":"","sources":["../../src/lite/track.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,SAAS,MAAM,CAAC,MAAoB;IACnC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAA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AC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;IACzD,MAAM,IAAI,GAAG,IAAI,SAAS,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IACjD,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AAChF,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport * as Path from \"../path.ts\";\nimport { Reader, Writer } from \"../stream.ts\";\nimport { infoDefaults } from \"../track.ts\";\nimport { Track, TrackInfo } from \"./track.ts\";\nimport { Version } from \"./version.ts\";\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n\tconst total = chunks.reduce((sum, c) => sum + c.byteLength, 0);\n\tconst out = new Uint8Array(total);\n\tlet offset = 0;\n\tfor (const c of chunks) {\n\t\tout.set(c, offset);\n\t\toffset += c.byteLength;\n\t}\n\treturn out;\n}\n\nasync function bytes(f: (w: Writer) => Promise<void>): Promise<Uint8Array> {\n\tconst written: Uint8Array[] = [];\n\tconst writer = new Writer(\n\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void written.push(new Uint8Array(chunk)) }),\n\t);\n\tawait f(writer);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\ntest(\"TrackInfo round-trips on draft-05\", async () => {\n\tconst info = new TrackInfo({\n\t\tpriority: 7,\n\t\tordered: false,\n\t\tlatencyMax: 2000,\n\t\ttimescale: 90000,\n\t});\n\tconst reader = new Reader(undefined, await bytes((w) => info.encode(w, Version.DRAFT_05)));\n\tconst got = await TrackInfo.decode(reader, Version.DRAFT_05);\n\texpect(got.priority).toBe(7);\n\texpect(got.ordered).toBe(false);\n\texpect(got.latencyMax).toBe(2000);\n\texpect(got.timescale).toBe(90000);\n});\n\ntest(\"TrackInfo defaults match cross-language wire bytes\", async () => {\n\tconst info = new TrackInfo(infoDefaults());\n\texpect(await bytes((w) => info.encode(w, Version.DRAFT_05))).toEqual(\n\t\tnew Uint8Array([0x06, 0x00, 0x00, 0x53, 0x88, 0x43, 0xe8]),\n\t);\n});\n\ntest(\"Track request round-trips on draft-05\", async () => {\n\tconst msg = new Track(Path.from(\"room\"), \"video\");\n\tconst reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05)));\n\tconst got = await Track.decode(reader, Version.DRAFT_05);\n\texpect(got.broadcast).toBe(Path.from(\"room\"));\n\texpect(got.track).toBe(\"video\");\n});\n\ntest(\"TRACK_INFO is rejected before draft-05\", async () => {\n\tconst info = new TrackInfo({ timescale: 90000 });\n\tawait expect(bytes((w) => info.encode(w, Version.DRAFT_04))).rejects.toThrow();\n});\n"]}
package/lite/version.d.ts CHANGED
@@ -3,14 +3,27 @@ export declare const Version: {
3
3
  readonly DRAFT_02: 4279086338;
4
4
  readonly DRAFT_03: 4279086339;
5
5
  readonly DRAFT_04: 4279086340;
6
- readonly DRAFT_05_WIP: 4279086341;
6
+ readonly DRAFT_05: 4279086341;
7
+ readonly DRAFT_06: 4279086342;
7
8
  };
8
9
  export type Version = (typeof Version)[keyof typeof Version];
10
+ export declare function hasSetupStream(version: Version): boolean;
11
+ export declare function hasDatagrams(version: Version): boolean;
12
+ /** Whether announce streams begin with ANNOUNCE_OK and omit the sender's origin from each hop chain. */
13
+ export declare function hasAnnounceOk(version: Version): boolean;
14
+ /** Whether announcements carry implicit announce ids: each `active` assigns the next
15
+ * per-stream ordinal, and `ended`/`restart` reference that id instead of repeating the
16
+ * path. Added in lite-06. */
17
+ export declare function hasAnnounceId(version: Version): boolean;
18
+ /** Whether announcements carry a route cost varint alongside the hop chain: the
19
+ * marginal cost of pulling the broadcast via this route, accumulated per link.
20
+ * Added in lite-06. Older versions carry nothing, so a received route stays at
21
+ * zero and routing falls back to the hop-count tie-break. */
22
+ export declare function hasRouteCost(version: Version): boolean;
9
23
  export declare const ALPN = "moql";
10
24
  export declare const ALPN_03 = "moq-lite-03";
11
25
  export declare const ALPN_04 = "moq-lite-04";
12
- export declare const ALPN_05_WIP = "moq-lite-05-wip";
26
+ export declare const ALPN_05 = "moq-lite-05";
27
+ export declare const ALPN_06_WIP = "moq-lite-06-wip";
13
28
  export declare function versionName(v: Version): string;
14
- export declare function hasSetupStream(v: Version): boolean;
15
- export declare function hasTrackStream(v: Version): boolean;
16
29
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/lite/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO;aACnB,QAAQ,EAAE,UAAU;aACpB,QAAQ,EAAE,UAAU;aACpB,QAAQ,EAAE,UAAU;aACpB,QAAQ,EAAE,UAAU;aAGpB,YAAY,EAAE,UAAU;CACf,CAAC;AAEX,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;AAI7D,eAAO,MAAM,IAAI,SAAS,CAAC;AAG3B,eAAO,MAAM,OAAO,gBAAgB,CAAC;AAGrC,eAAO,MAAM,OAAO,gBAAgB,CAAC;AAIrC,eAAO,MAAM,WAAW,oBAAoB,CAAC;AAU7C,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAE9C;AAGD,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAElD;AAKD,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAElD"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/lite/version.ts"],"names":[],"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