@moq/net 0.1.8 → 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 (264) 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 +165 -63
  47. package/connection/reload.js.map +1 -1
  48. package/connection/reload.test.d.ts +2 -0
  49. package/connection/reload.test.d.ts.map +1 -0
  50. package/connection/reload.test.js +104 -0
  51. package/connection/reload.test.js.map +1 -0
  52. package/connection/stats.d.ts +92 -0
  53. package/connection/stats.d.ts.map +1 -0
  54. package/connection/stats.js +35 -0
  55. package/connection/stats.js.map +1 -0
  56. package/connection/stats.test.d.ts +2 -0
  57. package/connection/stats.test.d.ts.map +1 -0
  58. package/connection/stats.test.js +120 -0
  59. package/connection/stats.test.js.map +1 -0
  60. package/connection/transport.d.ts +10 -0
  61. package/connection/transport.d.ts.map +1 -0
  62. package/connection/transport.js +12 -0
  63. package/connection/transport.js.map +1 -0
  64. package/consume.d.ts +26 -0
  65. package/consume.d.ts.map +1 -0
  66. package/consume.js +40 -0
  67. package/consume.js.map +1 -0
  68. package/datagram.d.ts +23 -0
  69. package/datagram.d.ts.map +1 -0
  70. package/datagram.js +3 -0
  71. package/datagram.js.map +1 -0
  72. package/group.d.ts +125 -36
  73. package/group.d.ts.map +1 -1
  74. package/group.js +244 -67
  75. package/group.js.map +1 -1
  76. package/group.test.js +121 -35
  77. package/group.test.js.map +1 -1
  78. package/ietf/adapter.d.ts +5 -3
  79. package/ietf/adapter.d.ts.map +1 -1
  80. package/ietf/adapter.js +19 -5
  81. package/ietf/adapter.js.map +1 -1
  82. package/ietf/aliases.d.ts +11 -0
  83. package/ietf/aliases.d.ts.map +1 -0
  84. package/ietf/aliases.js +52 -0
  85. package/ietf/aliases.js.map +1 -0
  86. package/ietf/aliases.test.d.ts +2 -0
  87. package/ietf/aliases.test.d.ts.map +1 -0
  88. package/ietf/aliases.test.js +30 -0
  89. package/ietf/aliases.test.js.map +1 -0
  90. package/ietf/connection.d.ts +19 -6
  91. package/ietf/connection.d.ts.map +1 -1
  92. package/ietf/connection.js +24 -9
  93. package/ietf/connection.js.map +1 -1
  94. package/ietf/ietf.test.js +58 -1
  95. package/ietf/ietf.test.js.map +1 -1
  96. package/ietf/object.d.ts +12 -4
  97. package/ietf/object.d.ts.map +1 -1
  98. package/ietf/object.js +92 -9
  99. package/ietf/object.js.map +1 -1
  100. package/ietf/publisher.d.ts +2 -2
  101. package/ietf/publisher.d.ts.map +1 -1
  102. package/ietf/publisher.js +12 -12
  103. package/ietf/publisher.js.map +1 -1
  104. package/ietf/subscribe_namespace.d.ts +0 -4
  105. package/ietf/subscribe_namespace.d.ts.map +1 -1
  106. package/ietf/subscribe_namespace.js +0 -5
  107. package/ietf/subscribe_namespace.js.map +1 -1
  108. package/ietf/subscriber.d.ts +8 -4
  109. package/ietf/subscriber.d.ts.map +1 -1
  110. package/ietf/subscriber.js +176 -105
  111. package/ietf/subscriber.js.map +1 -1
  112. package/index.d.ts +8 -5
  113. package/index.d.ts.map +1 -1
  114. package/index.js +8 -5
  115. package/index.js.map +1 -1
  116. package/integration.test.js +598 -12
  117. package/integration.test.js.map +1 -1
  118. package/internal.d.ts +14 -0
  119. package/internal.d.ts.map +1 -0
  120. package/internal.js +8 -0
  121. package/internal.js.map +1 -0
  122. package/lite/announce.d.ts +55 -13
  123. package/lite/announce.d.ts.map +1 -1
  124. package/lite/announce.js +221 -68
  125. package/lite/announce.js.map +1 -1
  126. package/lite/announce.test.d.ts +2 -0
  127. package/lite/announce.test.d.ts.map +1 -0
  128. package/lite/announce.test.js +71 -0
  129. package/lite/announce.test.js.map +1 -0
  130. package/lite/connection.d.ts +45 -19
  131. package/lite/connection.d.ts.map +1 -1
  132. package/lite/connection.js +85 -80
  133. package/lite/connection.js.map +1 -1
  134. package/lite/datagram.d.ts +23 -0
  135. package/lite/datagram.d.ts.map +1 -0
  136. package/lite/datagram.js +57 -0
  137. package/lite/datagram.js.map +1 -0
  138. package/lite/datagram.test.d.ts +2 -0
  139. package/lite/datagram.test.d.ts.map +1 -0
  140. package/lite/datagram.test.js +26 -0
  141. package/lite/datagram.test.js.map +1 -0
  142. package/lite/datagram_stream.d.ts +8 -0
  143. package/lite/datagram_stream.d.ts.map +1 -0
  144. package/lite/datagram_stream.js +44 -0
  145. package/lite/datagram_stream.js.map +1 -0
  146. package/lite/datagram_stream.test.d.ts +2 -0
  147. package/lite/datagram_stream.test.d.ts.map +1 -0
  148. package/lite/datagram_stream.test.js +15 -0
  149. package/lite/datagram_stream.test.js.map +1 -0
  150. package/lite/fetch.d.ts.map +1 -1
  151. package/lite/fetch.js +2 -2
  152. package/lite/fetch.js.map +1 -1
  153. package/lite/fetch.test.d.ts +2 -0
  154. package/lite/fetch.test.d.ts.map +1 -0
  155. package/lite/fetch.test.js +41 -0
  156. package/lite/fetch.test.js.map +1 -0
  157. package/lite/index.d.ts +3 -0
  158. package/lite/index.d.ts.map +1 -1
  159. package/lite/index.js +3 -0
  160. package/lite/index.js.map +1 -1
  161. package/lite/publisher.d.ts +13 -6
  162. package/lite/publisher.d.ts.map +1 -1
  163. package/lite/publisher.js +274 -64
  164. package/lite/publisher.js.map +1 -1
  165. package/lite/publisher.test.d.ts +2 -0
  166. package/lite/publisher.test.d.ts.map +1 -0
  167. package/lite/publisher.test.js +65 -0
  168. package/lite/publisher.test.js.map +1 -0
  169. package/lite/setup.d.ts +72 -6
  170. package/lite/setup.d.ts.map +1 -1
  171. package/lite/setup.js +184 -31
  172. package/lite/setup.js.map +1 -1
  173. package/lite/setup.test.d.ts +2 -0
  174. package/lite/setup.test.d.ts.map +1 -0
  175. package/lite/setup.test.js +122 -0
  176. package/lite/setup.test.js.map +1 -0
  177. package/lite/stream.d.ts +12 -3
  178. package/lite/stream.d.ts.map +1 -1
  179. package/lite/stream.js +7 -4
  180. package/lite/stream.js.map +1 -1
  181. package/lite/subscribe.d.ts +37 -23
  182. package/lite/subscribe.d.ts.map +1 -1
  183. package/lite/subscribe.js +70 -55
  184. package/lite/subscribe.js.map +1 -1
  185. package/lite/subscribe.test.d.ts +2 -0
  186. package/lite/subscribe.test.d.ts.map +1 -0
  187. package/lite/subscribe.test.js +68 -0
  188. package/lite/subscribe.test.js.map +1 -0
  189. package/lite/subscriber.d.ts +24 -17
  190. package/lite/subscriber.d.ts.map +1 -1
  191. package/lite/subscriber.js +521 -91
  192. package/lite/subscriber.js.map +1 -1
  193. package/lite/subscriber.test.d.ts +2 -0
  194. package/lite/subscriber.test.d.ts.map +1 -0
  195. package/lite/subscriber.test.js +30 -0
  196. package/lite/subscriber.test.js.map +1 -0
  197. package/lite/track.d.ts +25 -13
  198. package/lite/track.d.ts.map +1 -1
  199. package/lite/track.js +60 -35
  200. package/lite/track.js.map +1 -1
  201. package/lite/track.test.js +12 -10
  202. package/lite/track.test.js.map +1 -1
  203. package/lite/version.d.ts +17 -4
  204. package/lite/version.d.ts.map +1 -1
  205. package/lite/version.js +88 -17
  206. package/lite/version.js.map +1 -1
  207. package/mock.d.ts +42 -3
  208. package/mock.d.ts.map +1 -1
  209. package/mock.js +88 -17
  210. package/mock.js.map +1 -1
  211. package/package.json +3 -3
  212. package/path.d.ts +30 -0
  213. package/path.d.ts.map +1 -1
  214. package/path.js +49 -0
  215. package/path.js.map +1 -1
  216. package/path.test.js +41 -0
  217. package/path.test.js.map +1 -1
  218. package/stream.test.js +10 -0
  219. package/stream.test.js.map +1 -1
  220. package/time.d.ts +109 -86
  221. package/time.d.ts.map +1 -1
  222. package/time.js +80 -30
  223. package/time.js.map +1 -1
  224. package/time.test.d.ts +2 -0
  225. package/time.test.d.ts.map +1 -0
  226. package/time.test.js +12 -0
  227. package/time.test.js.map +1 -0
  228. package/track.d.ts +225 -45
  229. package/track.d.ts.map +1 -1
  230. package/track.js +505 -93
  231. package/track.js.map +1 -1
  232. package/track.test.js +138 -29
  233. package/track.test.js.map +1 -1
  234. package/util/error.d.ts +9 -0
  235. package/util/error.d.ts.map +1 -1
  236. package/util/error.js +21 -0
  237. package/util/error.js.map +1 -1
  238. package/util/error.test.d.ts +2 -0
  239. package/util/error.test.d.ts.map +1 -0
  240. package/util/error.test.js +45 -0
  241. package/util/error.test.js.map +1 -0
  242. package/util/index.d.ts +1 -0
  243. package/util/index.d.ts.map +1 -1
  244. package/util/index.js +1 -0
  245. package/util/index.js.map +1 -1
  246. package/util/timeout.d.ts +5 -0
  247. package/util/timeout.d.ts.map +1 -0
  248. package/util/timeout.js +18 -0
  249. package/util/timeout.js.map +1 -0
  250. package/util/timeout.test.d.ts +2 -0
  251. package/util/timeout.test.d.ts.map +1 -0
  252. package/util/timeout.test.js +18 -0
  253. package/util/timeout.test.js.map +1 -0
  254. package/varint.d.ts +6 -0
  255. package/varint.d.ts.map +1 -1
  256. package/varint.js +6 -2
  257. package/varint.js.map +1 -1
  258. package/zod.d.ts +4 -4
  259. package/zod.d.ts.map +1 -1
  260. package/zod.js.map +1 -1
  261. package/bandwidth.d.ts +0 -11
  262. package/bandwidth.d.ts.map +0 -1
  263. package/bandwidth.js +0 -7
  264. package/bandwidth.js.map +0 -1
package/track.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"track.js","sourceRoot":"","sources":["../src/track.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,iHAAiH;AACjH,MAAM,OAAO,UAAU;IACtB,MAAM,GAAG,IAAI,MAAM,CAAU,EAAE,CAAC,CAAC;IACjC,MAAM,GAAG,IAAI,MAAM,CAAkB,KAAK,CAAC,CAAC;IAC5C,QAAQ,GAAG,IAAI,MAAM,CAAqB,SAAS,CAAC,CAAC;CACrD;AAED,sEAAsE;AACtE,MAAM,OAAO,KAAK;IACjB,+CAA+C;IACtC,IAAI,CAAS;IAEtB,8BAA8B;IAC9B,KAAK,GAAG,IAAI,UAAU,EAAE,CAAC;IACzB,KAAK,CAAU;IACf,aAAa,GAAG,CAAC,CAAC;IAElB,gEAAgE;IACvD,MAAM,CAA6B;IAE5C,YAAY,IAAY;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAEjB,IAAI,CAAC,MAAM,GAAG,IAAI,OA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AC,oBAAoB,CAAC,CAAC;QACtG,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,cAAc,CAAC,QAAgB;QAC9B,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAa;QAClB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;QAErC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;YAC9C,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACF,CAAC;CACD","sourcesContent":["import { Signal } from \"@moq/signals\";\nimport { Group } from \"./group.ts\";\n\n/** Reactive backing state for a {@link Track}: buffered groups, a closed flag, and the subscription priority. */\nexport class TrackState {\n\tgroups = new Signal<Group[]>([]);\n\tclosed = new Signal<boolean | Error>(false);\n\tpriority = new Signal<number | undefined>(undefined);\n}\n\n/** A live stream of groups within a broadcast, identified by name. */\nexport class Track {\n\t/** Name of this track within its broadcast. */\n\treadonly name: string;\n\n\t/** Reactive backing state. */\n\tstate = new TrackState();\n\t#next?: number;\n\t#nextSequence = 0;\n\n\t/** Resolves with the abort error (or undefined) once closed. */\n\treadonly closed: Promise<Error | undefined>;\n\n\tconstructor(name: string) {\n\t\tthis.name = name;\n\n\t\tthis.closed = new Promise((resolve) => {\n\t\t\tconst dispose = this.state.closed.subscribe((closed) => {\n\t\t\t\tif (!closed) return;\n\t\t\t\tresolve(closed instanceof Error ? closed : undefined);\n\t\t\t\tdispose();\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Appends a new group to the track.\n\t * @returns A GroupProducer for the new group\n\t */\n\tappendGroup(): Group {\n\t\tif (this.state.closed.peek()) throw new Error(\"track is closed\");\n\n\t\tconst group = new Group(this.#next ?? 0);\n\n\t\tthis.#next = group.sequence + 1;\n\t\tthis.state.groups.mutate((groups) => {\n\t\t\tgroups.push(group);\n\t\t\tgroups.sort((a, b) => a.sequence - b.sequence);\n\t\t});\n\n\t\treturn group;\n\t}\n\n\t/**\n\t * Inserts an existing group into the track.\n\t * @param group - The group to insert\n\t */\n\twriteGroup(group: Group) {\n\t\tif (this.state.closed.peek()) throw new Error(\"track is closed\");\n\n\t\t// Only advance #next upward (for appendGroup auto-increment).\n\t\tif (group.sequence >= (this.#next ?? 0)) {\n\t\t\tthis.#next = group.sequence + 1;\n\t\t}\n\n\t\tthis.state.groups.mutate((groups) => {\n\t\t\tgroups.push(group);\n\t\t\tgroups.sort((a, b) => a.sequence - b.sequence);\n\t\t});\n\t}\n\n\t/**\n\t * Appends a frame to the track in its own group.\n\t *\n\t * @param frame - The frame to append\n\t */\n\twriteFrame(frame: Uint8Array) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeFrame(frame);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a string to the track as its own single-frame group. */\n\twriteString(str: string) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeString(str);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a JSON value to the track as its own single-frame group. */\n\twriteJson(json: unknown) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeJson(json);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a boolean to the track as its own single-frame group. */\n\twriteBool(bool: boolean) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeBool(bool);\n\t\tgroup.close();\n\t}\n\n\t/**\n\t * Receive the next group available on this track, in arrival order.\n\t *\n\t * Groups may arrive out of order or with gaps due to network conditions.\n\t * Use {@link nextGroupOrdered} if you need groups in sequence order,\n\t * skipping those that arrive too late.\n\t */\n\tasync recvGroup(): Promise<Group | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.state.groups.peek();\n\t\t\tif (groups.length > 0) {\n\t\t\t\treturn groups.shift();\n\t\t\t}\n\n\t\t\tconst closed = this.state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed) return undefined;\n\n\t\t\tawait Signal.race(this.state.groups, this.state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * @deprecated Use {@link recvGroup} for arrival order, or {@link nextGroupOrdered} for sequence order.\n\t */\n\tasync nextGroup(): Promise<Group | undefined> {\n\t\treturn this.recvGroup();\n\t}\n\n\t/**\n\t * Return the next group with a strictly-greater sequence number than the last returned.\n\t *\n\t * Late arrivals (with a sequence number at or below the last one returned) are silently skipped.\n\t *\n\t * NOTE: This will be renamed to `nextGroup` in the next major version.\n\t */\n\tasync nextGroupOrdered(): Promise<Group | undefined> {\n\t\tfor (;;) {\n\t\t\tconst group = await this.recvGroup();\n\t\t\tif (!group) return undefined;\n\t\t\tif (group.sequence < this.#nextSequence) {\n\t\t\t\tgroup.close();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.#nextSequence = group.sequence + 1;\n\t\t\treturn group;\n\t\t}\n\t}\n\n\t/** Reads the next frame across all groups, discarding older groups. */\n\tasync readFrame(): Promise<Uint8Array | undefined> {\n\t\treturn (await this.readFrameSequence())?.data;\n\t}\n\n\t/** Reads the next frame along with its group and frame sequence numbers. */\n\tasync readFrameSequence(): Promise<{ group: number; frame: number; data: Uint8Array } | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.state.groups.peek();\n\n\t\t\t// Discard old groups.\n\t\t\twhile (groups.length > 1) {\n\t\t\t\tconst next = groups[0].tryReadFrameSequence();\n\t\t\t\tif (next) {\n\t\t\t\t\treturn { group: groups[0].sequence, frame: next.sequence, data: next.data };\n\t\t\t\t}\n\n\t\t\t\t// Skip this old group\n\t\t\t\tgroups.shift()?.close();\n\t\t\t}\n\n\t\t\t// If there's no groups, wait for a new one.\n\t\t\tif (groups.length === 0) {\n\t\t\t\tconst closed = this.state.closed.peek();\n\t\t\t\tif (closed instanceof Error) throw closed;\n\t\t\t\tif (closed) return undefined;\n\n\t\t\t\tawait Signal.race(this.state.groups, this.state.closed);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// If there's a group, wait for a frame.\n\t\t\tconst group = groups[0];\n\t\t\tconst next = group.tryReadFrameSequence();\n\t\t\tif (next) {\n\t\t\t\treturn { group: group.sequence, frame: next.sequence, data: next.data };\n\t\t\t}\n\n\t\t\t// If the track is closed, return undefined.\n\t\t\tconst closed = this.state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed) return undefined;\n\n\t\t\t// Wake on a new group or the track closing. Only fold in the current group's readability\n\t\t\t// while it can still deliver frames: a finished group's readable() resolves immediately, so\n\t\t\t// racing it would busy-loop until a newer group arrives instead of waiting.\n\t\t\tif (group.done) {\n\t\t\t\tawait Signal.race(this.state.groups, this.state.closed);\n\t\t\t} else {\n\t\t\t\tawait Promise.race([Signal.race(this.state.groups, this.state.closed), group.readable()]);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Reads the next frame and decodes it as a UTF-8 string. */\n\tasync readString(): Promise<string | undefined> {\n\t\tconst next = await this.readFrame();\n\t\tif (!next) return undefined;\n\t\treturn new TextDecoder().decode(next);\n\t}\n\n\t/** Reads the next frame and parses it as JSON. */\n\tasync readJson(): Promise<unknown | undefined> {\n\t\tconst next = await this.readString();\n\t\tif (!next) return undefined;\n\t\treturn JSON.parse(next);\n\t}\n\n\t/** Reads the next frame and decodes it as a one-byte boolean, throwing on a malformed frame. */\n\tasync readBool(): Promise<boolean | undefined> {\n\t\tconst next = await this.readFrame();\n\t\tif (!next) return undefined;\n\t\tif (next.byteLength !== 1 || !(next[0] === 0 || next[0] === 1)) throw new Error(\"invalid bool frame\");\n\t\treturn next[0] === 1;\n\t}\n\n\t/**\n\t * Update the subscription priority. Triggers a SUBSCRIBE_UPDATE\n\t * to the publisher when used on a subscribed track.\n\t */\n\tupdatePriority(priority: number) {\n\t\tthis.state.priority.set(priority, true);\n\t}\n\n\t/**\n\t * Closes the publisher and all associated groups.\n\t */\n\tclose(abort?: Error) {\n\t\tthis.state.closed.set(abort ?? true);\n\n\t\tfor (const group of this.state.groups.peek()) {\n\t\t\tgroup.close(abort);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"track.js","sourceRoot":"","sources":["../src/track.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAgC,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE1E,OAAO,EAA8C,QAAQ,IAAI,aAAa,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC3G,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,SAAS,EAAkB,MAAM,WAAW,CAAC;AAItD,iGAAiG;AACjG,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAK/B;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,KAAK,CAAC;AA+BjC,iEAAiE;AACjE,MAAM,UAAU,YAAY,CAAC,IAAI,GAAkB,EAAE;IACpD,OAAO;QACN,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,KAAK;QAC5C,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,sBAAsB;QACrD,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,CAAC;QAC5B,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,KAAK;KAC9B,CAAC;AACH,CAAC;AAWD;;;;;;;GAOG;AACH,MAAM,OAAO,OAAO;IACnB,gCAAgC;IACvB,IAAI,CAAS;IACtB,gDAAgD;IACvC,QAAQ,CAAS;IAE1B,SAAS,CAAW;IAEpB,YAAoB,IAAY,EAAE,QAAkB,EAAE,QAAgB;QACrE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,C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IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACrC,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,gGAAgG;IAChG,KAAK,CAAC,QAAQ;QACb,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,OAAO,CAAC,UAAU,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAC/G,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAAqB;QAC3B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;CACD","sourcesContent":["/**\n * Track role handles: a live stream of groups (and best-effort datagrams) within a broadcast.\n *\n * @module\n */\nimport { type GetPromise, type Getter, Once, Signal } from \"@moq/signals\";\nimport type { Datagram } from \"./datagram.ts\";\nimport { type Frame, type Consumer as GroupConsumer, Producer as GroupProducer, Lagged } from \"./group.ts\";\nimport { hooks } from \"./internal.ts\";\nimport { Timescale, type Timestamp } from \"./time.ts\";\n\nexport type { Datagram } from \"./datagram.ts\";\n\n/** Default {@link Info.latencyMax} window (milliseconds) when the publisher does not set one. */\nexport const DEFAULT_LATENCY_MAX_MS = 5000;\n\n/**\n * How long (milliseconds) a datagram stays in the per-subscriber buffer before it is dropped.\n *\n * Datagrams are a best-effort send buffer, not a replay cache (unlike groups): only the last few\n * tens of milliseconds are kept, so a consumer that stalls loses stale datagrams instead of\n * replaying them. Mirrors the Rust `MAX_DATAGRAM_AGE`.\n */\nconst MAX_DATAGRAM_AGE_MS = 50;\n\n/** A datagram buffered with its arrival time, so the send buffer can evict by age. */\ntype BufferedDatagram = { datagram: Datagram; time: number };\n\n/**\n * Sanity cap on a datagram payload: the QUIC DATAGRAM frame ceiling. The real limit is\n * per-hop (the negotiated transport datagram size minus a small header) and oversize\n * datagrams are dropped there; a payload above this cap could never fit anywhere.\n */\nconst MAX_DATAGRAM_BYTES = 65535;\n\n/**\n * A track's immutable publisher properties, fixed for the lifetime of the track.\n *\n * A producer declares these once (via {@link Request.accept} or\n * {@link Producer.accept}); a consumer awaits them via {@link Subscriber.info}\n * (resolved from the wire TRACK_INFO on lite-05+). They map 1:1 onto TRACK_INFO.\n */\nexport interface Info {\n\t/**\n\t * Units per second for this track's frame timestamps (reported in TRACK_INFO on\n\t * Lite05+). Defaults to milliseconds; set it finer (e.g. {@link Timescale.MICRO})\n\t * for media that needs sub-millisecond timing.\n\t */\n\ttimescale: Timescale;\n\t/**\n\t * Publisher Max Latency: the maximum age (milliseconds) of a non-latest group before\n\t * the publisher evicts it. Reported in TRACK_INFO (Lite05+) so relays re-serve with the\n\t * same bound. The publisher-side half of the budget a subscriber sets for itself.\n\t */\n\tlatencyMax: number;\n\t/** Tie-break priority between subscriptions of equal subscriber priority. */\n\tpriority: number;\n\t/**\n\t * Whether groups are prioritized in sequence order. Groups may always arrive\n\t * out-of-order (or not at all) over the network. Defaults to `false` (newest-first).\n\t */\n\tordered: boolean;\n}\n\n/** Fill in any unset {@link Info} fields with their defaults. */\nexport function infoDefaults(info: Partial<Info> = {}): Info {\n\treturn {\n\t\ttimescale: info.timescale ?? Timescale.MILLI,\n\t\tlatencyMax: info.latencyMax ?? DEFAULT_LATENCY_MAX_MS,\n\t\tpriority: info.priority ?? 0,\n\t\tordered: info.ordered ?? false,\n\t};\n}\n\n/**\n * Per-subscription options, requested when a subscription opens and adjustable later via\n * {@link Subscriber.update}. Mirrors the Rust `Subscription`.\n */\nexport interface Subscription {\n\t/** Delivery priority relative to this session's other subscriptions. Defaults to `0`. */\n\tpriority?: number;\n}\n\n/**\n * A request for a track the peer wants, yielded by `Broadcast.Producer.requested`.\n *\n * Created internally by the broadcast when a subscription (or info lookup) needs a track\n * served; answer it with {@link accept} or {@link reject}.\n *\n * @public\n */\nexport class Request {\n\t/** The requested track name. */\n\treadonly name: string;\n\t/** The subscriber's priority for this track. */\n\treadonly priority: number;\n\n\t#producer: Producer;\n\n\tprivate constructor(name: string, producer: Producer, priority: number) {\n\t\tthis.name = name;\n\t\tthis.#producer = producer;\n\t\tthis.priority = priority;\n\t}\n\n\tstatic {\n\t\thooks.makeRequest = (name, producer, priority) => new Request(name, producer, priority);\n\t}\n\n\t/** Accept the request, committing the track's immutable {@link Info}. */\n\taccept(info: Partial<Info> = {}): Producer {\n\t\treturn this.#producer.accept(info);\n\t}\n\n\t/** Reject the request, closing the track optionally with an error. */\n\treject(err?: Error): void {\n\t\tthis.#producer.close(err);\n\t}\n}\n\n/** Options for {@link Consumer.fetchGroup}. */\nexport interface FetchGroupOptions {\n\t/** Delivery priority for the fetch stream. Defaults to `0`. */\n\tpriority?: number;\n}\n\n/**\n * The per-track operations a lazy {@link Consumer} delegates to the broadcast it came from.\n *\n * Implemented by `broadcast.Producer` / `broadcast.Consumer` (and the wire-layer subclasses\n * that resolve them over the network), so a track handle holds a reference to its broadcast\n * and calls methods on it rather than capturing a bag of callbacks.\n */\nexport interface Broadcast {\n\t/** Open a live subscription to the named track. */\n\tsubscribe(name: string, options?: Subscription): Subscriber;\n\t/** Resolve the named track's immutable info. */\n\tresolveTrackInfo(name: string): Promise<Info>;\n\t/** Fetch a single group of the named track by sequence. */\n\tfetchGroup(name: string, sequence: number, options?: FetchGroupOptions): Promise<GroupConsumer>;\n}\n\n/**\n * A lazy handle to a track on a consumed broadcast.\n *\n * @public\n */\nexport class Consumer {\n\t/** The track name. */\n\treadonly name: string;\n\n\t#broadcast: Broadcast;\n\n\tconstructor(name: string, broadcast: Broadcast) {\n\t\tthis.name = name;\n\t\tthis.#broadcast = broadcast;\n\t}\n\n\t/** Open a live subscription to the track. */\n\tsubscribe(options?: Subscription): Subscriber {\n\t\treturn this.#broadcast.subscribe(this.name, options);\n\t}\n\n\t/** Fetch the track's immutable publisher properties without subscribing. */\n\tinfo(): Promise<Info> {\n\t\treturn this.#broadcast.resolveTrackInfo(this.name);\n\t}\n\n\t/** Fetch a single group by sequence without holding a live subscription. */\n\tfetchGroup(sequence: number, options?: FetchGroupOptions): Promise<GroupConsumer> {\n\t\treturn this.#broadcast.fetchGroup(this.name, sequence, options);\n\t}\n}\n\n// The shared state behind a Producer / Subscriber pair. Package-internal\n// wiring, unexported so it never appears in the published type declarations.\nclass TrackState {\n\tgroups = new Signal<GroupConsumer[]>([]);\n\t/** Best-effort datagram channel, parallel to {@link groups}; an age-evicted send buffer per subscriber. */\n\tdatagrams = new Signal<BufferedDatagram[]>([]);\n\tclosed = new Once<Error | null>();\n\tupdate = new Signal<Subscription | undefined>(undefined);\n\t/** Resolved once the producer commits the immutable properties. */\n\tinfo = new Signal<Info | undefined>(undefined);\n}\n\n// Settle a track state's closed Once. Idempotent: Once.set throws on a second settle, and a\n// Producer closing its sinks races the Subscriber closing itself (the sink is only removed from\n// #sinks a microtask later, via the closed subscription below).\nfunction closeTrackState(state: TrackState, abort?: Error): boolean {\n\tif (state.closed.peek() !== undefined) return false;\n\tstate.closed.set(abort ?? null);\n\treturn true;\n}\n\n// Resolve the track's immutable publisher properties, or reject if it closes first.\n// On a producer this resolves once info is committed (at accept time); on a consumer\n// once the wire layer commits the TRACK_INFO it received (lite-05+) or defaults (older\n// drafts), so awaiting it never yields a placeholder.\nasync function resolveInfo(state: TrackState): Promise<Info> {\n\tfor (;;) {\n\t\tconst info = state.info.peek();\n\t\tif (info) return info;\n\n\t\tconst closed = state.closed.peek();\n\t\tif (closed instanceof Error) throw closed;\n\t\tif (closed !== undefined) throw new Error(\"track closed before info was known\");\n\n\t\tawait Signal.race(state.info, state.closed);\n\t}\n}\n\n// A source group retained in the producer cache, with the mirror handed to each sink\n// so eviction can drop them together.\ntype CachedGroup = { group: GroupProducer; time: number; mirrors: Map<TrackState, GroupConsumer> };\n\n// Constructs a Subscriber from within this module without exposing a public\n// constructor that would leak the unexported TrackState. Assigned in the class's\n// static block.\nlet makeSubscriber: (name: string, state: TrackState) => Subscriber;\n\n/**\n * The write side of a track, mirroring the Rust `Producer`.\n *\n * A producer is a fan-out source: every {@link subscribe} (including each wire\n * subscription the publisher serves from it) gets an independent\n * {@link Subscriber} that receives a full copy of the groups, each with its own\n * read cursor. Groups are mirrored into every live subscriber and retained for the\n * track's `latencyMax` window so a late subscriber replays the recent groups.\n *\n * Obtained from {@link Request.accept} (the wire asks the application for a track to\n * serve) or constructed directly for an in-process track.\n */\nexport class Producer {\n\t/** The track name. */\n\treadonly name: string;\n\n\t// The producer's own state is the source of truth (info/closed); subscribers\n\t// read mirrored sinks, never this state directly.\n\t#state = new TrackState();\n\n\t#next?: number;\n\n\t// Recently written source groups, retained for replay to late subscribers and\n\t// pruned once closed and older than the cache window. Each entry tracks the mirror\n\t// it handed to every sink so eviction can drop them too: otherwise a slow consumer\n\t// that never reads would pin old groups (and their frame bytes) forever.\n\t#cache: CachedGroup[] = [];\n\n\t// One independent downstream state per live subscriber.\n\t#sinks = new Set<TrackState>();\n\n\t// Whether any subscriber is currently attached. Exposed as {@link used}; the consumer wire\n\t// watches it to tear down an idle upstream, and a publisher can watch it for on-demand capture.\n\t#used = new Signal<boolean>(false);\n\n\tconstructor(name: string) {\n\t\tthis.name = name;\n\t}\n\n\t/**\n\t * Resolve this track's immutable publisher properties, committed at accept time.\n\t * Rejects if the track is closed before the properties are known.\n\t */\n\tinfo(): Promise<Info> {\n\t\treturn resolveInfo(this.#state);\n\t}\n\n\t/**\n\t * Settles once the track closes: `null` on a clean close, or the abort {@link Error}.\n\t * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/**\n\t * The current subscription, or `undefined` until a subscriber first calls\n\t * {@link Subscriber.update}. The wire layer watches this to emit SUBSCRIBE_UPDATE.\n\t */\n\tget subscription(): Getter<Subscription | undefined> {\n\t\treturn this.#state.update;\n\t}\n\n\t/** Commit the immutable publisher properties, resolving {@link info}. Returns `this`. */\n\taccept(info: Partial<Info> = {}): this {\n\t\tconst resolved = infoDefaults(info);\n\t\tthis.#state.info.set(resolved);\n\t\t// Propagate to any sink handed out before accept (the on-demand path).\n\t\tfor (const sink of this.#sinks) sink.info.set(resolved);\n\t\treturn this;\n\t}\n\n\t/** An independent {@link Subscriber} receiving a full copy of this track's groups. */\n\tsubscribe(): Subscriber {\n\t\tconst sink = new TrackState();\n\t\tthis.#addSink(sink);\n\t\treturn makeSubscriber(this.name, sink);\n\t}\n\n\t/**\n\t * Whether the track currently has any subscribers.\n\t *\n\t * Watch it (`effect.get` / `.peek()`) to drive on-demand work: a publisher can start and stop\n\t * capture with demand, and the consumer wire watches it to tear an idle upstream subscription\n\t * down instead of downloading to nobody. Pairs with {@link unused}. Mirrors the Rust `Demand`.\n\t */\n\tget used(): Getter<boolean> {\n\t\treturn this.#used;\n\t}\n\n\t/** Resolves once the track has no subscribers (or has closed). Await it to react to demand ending. */\n\tasync unused(): Promise<void> {\n\t\twhile (this.#used.peek() && this.#state.closed.peek() === undefined) {\n\t\t\tawait Signal.race(this.#used, this.#state.closed);\n\t\t}\n\t}\n\n\t// Register a downstream sink: seed its info, replay the retained window, and (while\n\t// the track is open) mirror future groups into it. A late subscriber to a closed\n\t// track still drains the buffered groups before seeing the end.\n\t#addSink(sink: TrackState): void {\n\t\tconst info = this.#state.info.peek();\n\t\tif (info) sink.info.set(info);\n\n\t\tconst closed = this.#state.closed.peek();\n\t\tif (closed === undefined) {\n\t\t\tthis.#sinks.add(sink);\n\t\t\tthis.#used.set(true);\n\n\t\t\t// Forward subscription updates from the sink's Subscriber to the producer's own\n\t\t\t// state, which the wire layer (or the serving application) watches.\n\t\t\tconst forward = sink.update.subscribe((update) => {\n\t\t\t\tif (update) this.#state.update.set(update, true);\n\t\t\t});\n\n\t\t\t// Drop the sink once its consumer goes away, closing its mirrors so source\n\t\t\t// groups stop teeing into them, so a long-lived producer doesn't leak. This\n\t\t\t// covers mirrors already handed out via recvGroup (no longer in sink.groups)\n\t\t\t// by closing them through the cache's per-sink tracking.\n\t\t\tconst dispose = sink.closed.subscribe((c) => {\n\t\t\t\tif (c === undefined) return;\n\t\t\t\tconst abort = c instanceof Error ? c : undefined;\n\t\t\t\tforward();\n\t\t\t\tthis.#sinks.delete(sink);\n\t\t\t\tfor (const entry of this.#cache) {\n\t\t\t\t\tconst mirror = entry.mirrors.get(sink);\n\t\t\t\t\tif (mirror) {\n\t\t\t\t\t\tmirror.close(abort);\n\t\t\t\t\t\tentry.mirrors.delete(sink);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const group of sink.groups.peek()) group.close(abort);\n\t\t\t\tdispose();\n\n\t\t\t\t// Update demand: once the last subscriber leaves, the consumer wire (watching\n\t\t\t\t// {@link unused}) tears the upstream down instead of downloading to nobody.\n\t\t\t\tthis.#used.set(this.#sinks.size > 0);\n\t\t\t});\n\t\t}\n\n\t\tthis.#prune();\n\t\tfor (const entry of this.#cache) this.#mirror(entry, sink);\n\n\t\tif (closed !== undefined) closeTrackState(sink, closed instanceof Error ? closed : undefined);\n\t}\n\n\t// Mirror a cached source group into a sink. The mirror fills synchronously as the\n\t// source is written and keeps its own read cursor; frame bytes are shared by\n\t// reference. Tracked on the entry so eviction can drop it from the sink.\n\t#mirror(entry: CachedGroup, sink: TrackState): void {\n\t\tconst dst = entry.group.mirror();\n\t\tentry.mirrors.set(sink, dst);\n\t\tsink.groups.mutate((groups) => {\n\t\t\tgroups.push(dst);\n\t\t\tgroups.sort((a, b) => a.sequence - b.sequence);\n\t\t});\n\t}\n\n\t// Evict cached groups that are closed and older than the cache window, dropping\n\t// each evicted group's mirror from every sink so no consumer can pin it.\n\t#prune(): void {\n\t\tconst latencyMaxMs = this.#state.info.peek()?.latencyMax ?? DEFAULT_LATENCY_MAX_MS;\n\t\tconst cutoff = Date.now() - latencyMaxMs;\n\n\t\tconst retained: CachedGroup[] = [];\n\t\tfor (const entry of this.#cache) {\n\t\t\tif (entry.time > cutoff || entry.group.closed.peek() === undefined) {\n\t\t\t\tretained.push(entry);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const [sink, mirror] of entry.mirrors) {\n\t\t\t\tsink.groups.mutate((groups) => {\n\t\t\t\t\tconst i = groups.indexOf(mirror);\n\t\t\t\t\tif (i >= 0) groups.splice(i, 1);\n\t\t\t\t});\n\t\t\t\tmirror.close();\n\t\t\t}\n\t\t\tentry.mirrors.clear();\n\t\t}\n\t\tthis.#cache = retained;\n\t}\n\n\t// Retain a source group and fan it out to every live sink.\n\t#publish(group: GroupProducer): void {\n\t\tconst entry: CachedGroup = { group, time: Date.now(), mirrors: new Map<TrackState, GroupConsumer>() };\n\t\tthis.#cache.push(entry);\n\t\tthis.#prune();\n\t\tfor (const sink of this.#sinks) this.#mirror(entry, sink);\n\t}\n\n\t/** Append a new group with the next sequence number. */\n\tappendGroup(): GroupProducer {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\n\t\tconst group = new GroupProducer(this.#next ?? 0);\n\t\tthis.#next = group.sequence + 1;\n\t\tthis.#publish(group);\n\n\t\treturn group;\n\t}\n\n\t/** Insert an existing group into the track. */\n\twriteGroup(group: GroupProducer) {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\n\t\t// Only advance #next upward (for appendGroup auto-increment).\n\t\tif (group.sequence >= (this.#next ?? 0)) {\n\t\t\tthis.#next = group.sequence + 1;\n\t\t}\n\n\t\tthis.#publish(group);\n\t}\n\n\t// Fan a datagram out to every live subscriber, dropping the oldest once the ring is full.\n\t// Late subscribers do NOT replay old datagrams (best-effort, unlike the group cache).\n\t#publishDatagram(datagram: Datagram): void {\n\t\tconst now = performance.now();\n\t\tfor (const sink of this.#sinks) {\n\t\t\tsink.datagrams.mutate((list) => {\n\t\t\t\tlist.push({ datagram, time: now });\n\t\t\t\t// Drop anything older than the send-buffer window.\n\t\t\t\twhile (list.length > 0 && now - list[0].time > MAX_DATAGRAM_AGE_MS) list.shift();\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Append a datagram with the next sequence number, returning the assigned sequence.\n\t *\n\t * A datagram is delivered best-effort over a single QUIC datagram, parallel to the track's\n\t * groups but drawing from the same sequence namespace (interleaving with {@link appendGroup}\n\t * never reuses a number). The payload must fit the negotiated transport datagram size minus\n\t * a small header; an oversize payload is dropped at each hop (there is no group fallback), so\n\t * keep datagram payloads small (e.g. a single audio frame). Datagrams are never delivered\n\t * over IETF moq-transport or stream-only transports (the WebSocket fallback). A payload over\n\t * 65535 bytes (the QUIC datagram frame ceiling) throws. An origin publisher uses this; a\n\t * relay preserving upstream numbering uses {@link writeDatagram}.\n\t */\n\tappendDatagram(timestamp: Timestamp, payload: Uint8Array): number {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\t\tif (payload.byteLength > MAX_DATAGRAM_BYTES) throw new Error(\"datagram payload too large\");\n\n\t\tconst sequence = this.#next ?? 0;\n\t\tthis.#next = sequence + 1;\n\t\tthis.#publishDatagram({ sequence, timestamp, payload });\n\t\treturn sequence;\n\t}\n\n\t/**\n\t * Write a datagram with an explicit sequence number.\n\t *\n\t * Preserves the supplied sequence (advancing the shared counter if needed) so a relay can\n\t * forward a datagram without renumbering it. The size limits of {@link appendDatagram}\n\t * apply. Most origin publishers want {@link appendDatagram} instead.\n\t */\n\twriteDatagram(datagram: Datagram) {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\t\tif (datagram.payload.byteLength > MAX_DATAGRAM_BYTES) throw new Error(\"datagram payload too large\");\n\n\t\tif (datagram.sequence >= (this.#next ?? 0)) {\n\t\t\tthis.#next = datagram.sequence + 1;\n\t\t}\n\t\tthis.#publishDatagram(datagram);\n\t}\n\n\t/** Close the track and every subscriber, mirroring the abort to their groups. Idempotent. */\n\tclose(abort?: Error) {\n\t\tcloseTrackState(this.#state, abort);\n\t\tfor (const { group } of this.#cache) group.close(abort);\n\t\tfor (const sink of this.#sinks) {\n\t\t\tfor (const group of sink.groups.peek()) group.close(abort);\n\t\t\tcloseTrackState(sink, abort);\n\t\t}\n\t\tthis.#sinks.clear();\n\t}\n\n\t/** Append a frame as its own single-frame group. */\n\twriteFrame(frame: Frame) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeFrame(frame);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a string to the track as its own single-frame group. */\n\twriteString(str: string) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeString(str);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a JSON value to the track as its own single-frame group. */\n\twriteJson(json: unknown) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeJson(json);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a boolean to the track as its own single-frame group. */\n\twriteBool(bool: boolean) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeBool(bool);\n\t\tgroup.close();\n\t}\n}\n\n/**\n * The read side of a live track subscription, mirroring the Rust `Subscriber`.\n *\n * Obtained from `Broadcast.Consumer.subscribe` / `Track.Consumer.subscribe`, or from\n * {@link Producer.subscribe} for an in-process track. Reads the groups a\n * {@link Producer} on the same underlying state writes.\n */\nexport class Subscriber {\n\t/** The track name. */\n\treadonly name: string;\n\n\t#state: TrackState;\n\t#nextSequence = 0;\n\n\tprivate constructor(name: string, state: TrackState) {\n\t\tthis.name = name;\n\t\tthis.#state = state;\n\t}\n\n\tstatic {\n\t\tmakeSubscriber = (name, state) => new Subscriber(name, state);\n\t}\n\n\t/**\n\t * Resolve this track's immutable publisher properties.\n\t *\n\t * Resolves once the wire layer commits the TRACK_INFO it received (lite-05+) or\n\t * defaults (older drafts), so awaiting it never yields a placeholder. Rejects if\n\t * the track is closed before the properties are known (e.g. a rejected subscription).\n\t */\n\tinfo(): Promise<Info> {\n\t\treturn resolveInfo(this.#state);\n\t}\n\n\t/** Settles once the track closes; see {@link Producer.closed}. */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/** The last {@link update} requested on this subscriber, or `undefined` if none yet. */\n\tget subscription(): Getter<Subscription | undefined> {\n\t\treturn this.#state.update;\n\t}\n\n\t/** Close the track (optionally with an error), closing any pending groups. Idempotent. */\n\tclose(abort?: Error) {\n\t\tif (!closeTrackState(this.#state, abort)) return;\n\t\tfor (const group of this.#state.groups.peek()) {\n\t\t\tgroup.close(abort);\n\t\t}\n\t}\n\n\t/**\n\t * Receive the next group available on this track, in arrival order.\n\t *\n\t * Groups may arrive out of order or with gaps due to network conditions.\n\t * Use {@link nextGroup} for sequence order, skipping those that arrive too late.\n\t */\n\tasync recvGroup(): Promise<GroupConsumer | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.#state.groups.peek();\n\t\t\tif (groups.length > 0) {\n\t\t\t\treturn groups.shift();\n\t\t\t}\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) return undefined;\n\n\t\t\tawait Signal.race(this.#state.groups, this.#state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * Receive the next datagram in arrival order.\n\t *\n\t * Datagrams are a separate best-effort channel from groups (see\n\t * {@link Producer.appendDatagram}); they share only the sequence namespace. A consumer\n\t * that falls too far behind silently loses the oldest datagrams. Read this alongside\n\t * {@link recvGroup} (e.g. in a separate loop) to receive both channels concurrently. Returning\n\t * a datagram advances {@link nextGroup} past that sequence.\n\t */\n\tasync recvDatagram(): Promise<Datagram | undefined> {\n\t\tfor (;;) {\n\t\t\tconst datagrams = this.#state.datagrams.peek();\n\n\t\t\t// Evict datagrams older than the send-buffer window (also enforced on write), so a\n\t\t\t// reader that stalled skips stale datagrams instead of replaying them.\n\t\t\tconst cutoff = performance.now() - MAX_DATAGRAM_AGE_MS;\n\t\t\twhile (datagrams.length > 0 && datagrams[0].time < cutoff) datagrams.shift();\n\n\t\t\tif (datagrams.length > 0) {\n\t\t\t\tconst datagram = datagrams.shift()?.datagram;\n\t\t\t\tif (datagram) {\n\t\t\t\t\tthis.#nextSequence = Math.max(this.#nextSequence, datagram.sequence + 1);\n\t\t\t\t}\n\t\t\t\treturn datagram;\n\t\t\t}\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) return undefined;\n\n\t\t\tawait Signal.race(this.#state.datagrams, this.#state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * Return the next group with a strictly-greater sequence number than the last returned.\n\t *\n\t * Late arrivals (sequence at or below the last returned) are silently skipped.\n\t * Use {@link recvGroup} to see every group in arrival order instead.\n\t */\n\tasync nextGroup(): Promise<GroupConsumer | undefined> {\n\t\tfor (;;) {\n\t\t\tconst group = await this.recvGroup();\n\t\t\tif (!group) return undefined;\n\t\t\tif (group.sequence < this.#nextSequence) {\n\t\t\t\tgroup.close();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.#nextSequence = group.sequence + 1;\n\t\t\treturn group;\n\t\t}\n\t}\n\n\t/**\n\t * Reads the next frame across all groups, discarding older groups.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t */\n\tasync readFrame(): Promise<Frame | undefined> {\n\t\tconst next = await this.readFrameSequence();\n\t\treturn next ? { payload: next.payload, timestamp: next.timestamp } : undefined;\n\t}\n\n\t/**\n\t * Reads the next frame along with its group and frame sequence numbers.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t */\n\tasync readFrameSequence(): Promise<({ group: number; frame: number } & Frame) | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.#state.groups.peek();\n\n\t\t\t// Drain older groups first, dropping each once empty.\n\t\t\twhile (groups.length > 1) {\n\t\t\t\tif (groups[0].skipped) {\n\t\t\t\t\t// The reader fell behind this group's eviction window. Drop it and\n\t\t\t\t\t// signal the gap; the next read resyncs from the following group.\n\t\t\t\t\tgroups.shift()?.close();\n\t\t\t\t\tthrow new Lagged();\n\t\t\t\t}\n\t\t\t\tconst next = groups[0].tryReadFrameSequence();\n\t\t\t\tif (next) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tgroup: groups[0].sequence,\n\t\t\t\t\t\tframe: next.sequence,\n\t\t\t\t\t\tpayload: next.payload,\n\t\t\t\t\t\ttimestamp: next.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tgroups.shift()?.close();\n\t\t\t}\n\n\t\t\tif (groups.length === 0) {\n\t\t\t\tconst closed = this.#state.closed.peek();\n\t\t\t\tif (closed instanceof Error) throw closed;\n\t\t\t\tif (closed !== undefined) return undefined;\n\t\t\t\tawait Signal.race(this.#state.groups, this.#state.closed);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst group = groups[0];\n\t\t\tif (group.skipped) {\n\t\t\t\t// Fell behind this group's eviction window. Drop it and signal the gap;\n\t\t\t\t// the next read resyncs from the following group.\n\t\t\t\tgroups.shift()?.close();\n\t\t\t\tthrow new Lagged();\n\t\t\t}\n\t\t\tconst next = group.tryReadFrameSequence();\n\t\t\tif (next)\n\t\t\t\treturn {\n\t\t\t\t\tgroup: group.sequence,\n\t\t\t\t\tframe: next.sequence,\n\t\t\t\t\tpayload: next.payload,\n\t\t\t\t\ttimestamp: next.timestamp,\n\t\t\t\t};\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) return undefined;\n\n\t\t\t// A finished (drained + closed) group has nothing left: drop it and loop, rather than\n\t\t\t// busy-waiting on its already-resolved readable() (which would livelock and starve the\n\t\t\t// macrotask that delivers the next group).\n\t\t\tif (group.done) {\n\t\t\t\tgroups.shift()?.close();\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Lone open group with nothing buffered yet: wait for a frame on it, a new group, or\n\t\t\t// the track closing.\n\t\t\tawait Promise.race([Signal.race(this.#state.groups, this.#state.closed), group.readable()]);\n\t\t}\n\t}\n\n\t/** Reads the next frame and decodes it as a UTF-8 string. */\n\tasync readString(): Promise<string | undefined> {\n\t\tconst next = await this.readFrame();\n\t\tif (!next) return undefined;\n\t\treturn new TextDecoder().decode(next.payload);\n\t}\n\n\t/** Reads the next frame and parses it as JSON. */\n\tasync readJson(): Promise<unknown | undefined> {\n\t\tconst next = await this.readString();\n\t\tif (!next) return undefined;\n\t\treturn JSON.parse(next);\n\t}\n\n\t/** Reads the next frame and decodes it as a one-byte boolean, throwing on a malformed frame. */\n\tasync readBool(): Promise<boolean | undefined> {\n\t\tconst next = await this.readFrame();\n\t\tif (!next) return undefined;\n\t\tconst payload = next.payload;\n\t\tif (payload.byteLength !== 1 || !(payload[0] === 0 || payload[0] === 1)) throw new Error(\"invalid bool frame\");\n\t\treturn payload[0] === 1;\n\t}\n\n\t/**\n\t * Update this subscription's options (e.g. priority), triggering a SUBSCRIBE_UPDATE to the\n\t * publisher. Mirrors the Rust `Subscriber::update`.\n\t */\n\tupdate(options: Subscription) {\n\t\tthis.#state.update.set(options, true);\n\t}\n}\n"]}
package/track.test.js CHANGED
@@ -1,55 +1,164 @@
1
1
  /* @ts-self-types="./track.test.d.ts" */
2
2
  import { expect, test } from "bun:test";
3
- import { Group } from "./group.js";
4
- import { Track } from "./track.js";
5
- test("nextGroupOrdered skips late arrivals", async () => {
6
- const track = new Track("test");
7
- track.writeGroup(new Group(5));
8
- const first = await track.nextGroupOrdered();
3
+ import { Producer as GroupProducer } from "./group.js";
4
+ import { Timestamp } from "./time.js";
5
+ import { Producer as TrackProducer } from "./track.js";
6
+ const enc = new TextEncoder();
7
+ const dec = new TextDecoder();
8
+ test("used reflects subscriber demand and unused resolves when the last one leaves", async () => {
9
+ const producer = new TrackProducer("test");
10
+ // No subscribers: no demand.
11
+ expect(producer.used.peek()).toBe(false);
12
+ const a = producer.subscribe();
13
+ const b = producer.subscribe();
14
+ expect(producer.used.peek()).toBe(true);
15
+ // Closing one of two keeps demand, so unused() stays pending.
16
+ a.close();
17
+ expect(producer.used.peek()).toBe(true);
18
+ // Closing the last subscriber drops demand; unused() resolves. The consumer wire awaits this
19
+ // to tear an idle upstream down.
20
+ b.close();
21
+ await producer.unused();
22
+ expect(producer.used.peek()).toBe(false);
23
+ });
24
+ test("a producer never self-closes on zero demand: a publisher keeps serving new subscribers", async () => {
25
+ const producer = new TrackProducer("video");
26
+ // Demand comes and goes...
27
+ const a = producer.subscribe();
28
+ a.close();
29
+ await producer.unused();
30
+ // ...but the producer stays open (only the wire acts on `unused`, not the producer itself),
31
+ // so a publisher writing to a track nobody is watching is unaffected.
32
+ expect(producer.closed.peek()).toBeUndefined();
33
+ // A later subscriber still works and replays the cache.
34
+ producer.writeString("still here");
35
+ const b = producer.subscribe();
36
+ expect(await b.readString()).toBe("still here");
37
+ expect(producer.used.peek()).toBe(true);
38
+ });
39
+ test("unused() resolves immediately when there was never any demand", async () => {
40
+ const producer = new TrackProducer("video");
41
+ // No subscriber was ever attached; unused() must not hang.
42
+ await producer.unused();
43
+ expect(producer.used.peek()).toBe(false);
44
+ });
45
+ test("used stays true across churn while at least one subscriber remains", async () => {
46
+ const producer = new TrackProducer("video");
47
+ const a = producer.subscribe();
48
+ // Rapidly add and drop extra subscribers; `a` keeps demand asserted throughout.
49
+ for (let i = 0; i < 20; i++) {
50
+ const t = producer.subscribe();
51
+ t.close();
52
+ expect(producer.used.peek()).toBe(true);
53
+ }
54
+ a.close();
55
+ await producer.unused();
56
+ expect(producer.used.peek()).toBe(false);
57
+ });
58
+ test("appendDatagram shares the group sequence counter", () => {
59
+ const producer = new TrackProducer("test");
60
+ const ts = Timestamp.fromMillis(10);
61
+ // Interleave groups and datagrams: they draw from one monotonic counter.
62
+ expect(producer.appendGroup().sequence).toBe(0);
63
+ expect(producer.appendDatagram(ts, enc.encode("a"))).toBe(1);
64
+ expect(producer.appendGroup().sequence).toBe(2);
65
+ expect(producer.appendDatagram(ts, enc.encode("b"))).toBe(3);
66
+ });
67
+ test("appendDatagram delivers to a subscriber", async () => {
68
+ const producer = new TrackProducer("test");
69
+ const track = producer.subscribe();
70
+ const ts = Timestamp.fromMillis(42);
71
+ const seq = producer.appendDatagram(ts, enc.encode("hello"));
72
+ const got = await track.recvDatagram();
73
+ expect(got?.sequence).toBe(seq);
74
+ expect(got?.timestamp).toBe(ts);
75
+ expect(got && dec.decode(got.payload)).toBe("hello");
76
+ });
77
+ test("writeDatagram preserves an explicit sequence", async () => {
78
+ const producer = new TrackProducer("test");
79
+ const track = producer.subscribe();
80
+ // A relay forwarding an upstream datagram keeps its sequence number.
81
+ producer.writeDatagram({ sequence: 100, timestamp: Timestamp.fromMillis(5), payload: enc.encode("x") });
82
+ expect((await track.recvDatagram())?.sequence).toBe(100);
83
+ // The shared counter advanced past it, so the next appended group continues from 101.
84
+ expect(producer.appendGroup().sequence).toBe(101);
85
+ });
86
+ test("recvDatagram advances the ordered group cursor", async () => {
87
+ const producer = new TrackProducer("test");
88
+ const track = producer.subscribe();
89
+ producer.writeDatagram({ sequence: 5, timestamp: Timestamp.fromMillis(5), payload: enc.encode("x") });
90
+ expect((await track.recvDatagram())?.sequence).toBe(5);
91
+ // Ordered group reads treat lower sequences as late once a datagram used sequence 5.
92
+ producer.writeGroup(new GroupProducer(3));
93
+ producer.writeGroup(new GroupProducer(6));
94
+ expect((await track.nextGroup())?.sequence).toBe(6);
95
+ });
96
+ test("appendDatagram rejects a payload over the QUIC datagram frame ceiling", () => {
97
+ const producer = new TrackProducer("test");
98
+ expect(() => producer.appendDatagram(Timestamp.fromMillis(0), new Uint8Array(65536))).toThrow();
99
+ });
100
+ test("a subscriber update is forwarded to the producer's update signal", async () => {
101
+ const producer = new TrackProducer("test");
102
+ const track = producer.subscribe();
103
+ // The wire layer watches the producer's signal to emit SUBSCRIBE_UPDATE.
104
+ expect(producer.subscription.peek()).toBeUndefined();
105
+ const next = producer.subscription.changed();
106
+ track.update({ priority: 7 });
107
+ expect((await next)?.priority).toBe(7);
108
+ });
109
+ test("nextGroup skips late arrivals", async () => {
110
+ const producer = new TrackProducer("test");
111
+ const track = producer.subscribe();
112
+ producer.writeGroup(new GroupProducer(5));
113
+ const first = await track.nextGroup();
9
114
  expect(first?.sequence).toBe(5);
10
115
  // Late arrivals with sequence <= last returned are skipped.
11
- track.writeGroup(new Group(3));
12
- track.writeGroup(new Group(4));
13
- track.writeGroup(new Group(7));
14
- const next = await track.nextGroupOrdered();
116
+ producer.writeGroup(new GroupProducer(3));
117
+ producer.writeGroup(new GroupProducer(4));
118
+ producer.writeGroup(new GroupProducer(7));
119
+ const next = await track.nextGroup();
15
120
  expect(next?.sequence).toBe(7);
16
121
  });
17
- test("nextGroupOrdered returns buffered groups in sequence", async () => {
18
- const track = new Track("test");
19
- track.writeGroup(new Group(3));
20
- track.writeGroup(new Group(5));
21
- expect((await track.nextGroupOrdered())?.sequence).toBe(3);
22
- expect((await track.nextGroupOrdered())?.sequence).toBe(5);
122
+ test("nextGroup returns buffered groups in sequence", async () => {
123
+ const producer = new TrackProducer("test");
124
+ const track = producer.subscribe();
125
+ producer.writeGroup(new GroupProducer(3));
126
+ producer.writeGroup(new GroupProducer(5));
127
+ expect((await track.nextGroup())?.sequence).toBe(3);
128
+ expect((await track.nextGroup())?.sequence).toBe(5);
23
129
  });
24
- test("recvGroup after nextGroupOrdered still returns late arrivals", async () => {
25
- const track = new Track("test");
26
- track.writeGroup(new Group(5));
130
+ test("recvGroup after nextGroup still returns late arrivals", async () => {
131
+ const producer = new TrackProducer("test");
132
+ const track = producer.subscribe();
133
+ producer.writeGroup(new GroupProducer(5));
27
134
  // Ordered returns seq 5, advancing its cursor.
28
- const ordered = await track.nextGroupOrdered();
135
+ const ordered = await track.nextGroup();
29
136
  expect(ordered?.sequence).toBe(5);
30
137
  // recvGroup is independent of the ordered cursor: a late seq 3 still surfaces.
31
- track.writeGroup(new Group(3));
138
+ producer.writeGroup(new GroupProducer(3));
32
139
  const recv = await track.recvGroup();
33
140
  expect(recv?.sequence).toBe(3);
34
141
  });
35
- test("nextGroupOrdered returns undefined when track closes", async () => {
36
- const track = new Track("test");
37
- track.close();
38
- expect(await track.nextGroupOrdered()).toBeUndefined();
142
+ test("nextGroup returns undefined when track closes", async () => {
143
+ const producer = new TrackProducer("test");
144
+ const track = producer.subscribe();
145
+ producer.close();
146
+ expect(await track.nextGroup()).toBeUndefined();
39
147
  });
40
148
  test("readFrame does not livelock when a sole group finishes before the next arrives", async () => {
41
- const track = new Track("test");
149
+ const producer = new TrackProducer("test");
150
+ const track = producer.subscribe();
42
151
  // A group is appended then finished empty while the track stays open. A finished group's
43
152
  // readable() resolves immediately, so the reader must not busy-wait on it (which would starve the
44
153
  // macrotask queue and never observe the next group).
45
- const g0 = track.appendGroup();
154
+ const g0 = producer.appendGroup();
46
155
  g0.close();
47
156
  // The next group arrives via a macrotask; if the reader livelocks on microtasks it never runs.
48
157
  setTimeout(() => {
49
- const g1 = track.appendGroup();
158
+ const g1 = producer.appendGroup();
50
159
  g1.writeString("hello");
51
160
  g1.close();
52
- track.close();
161
+ producer.close();
53
162
  }, 10);
54
163
  expect(await track.readString()).toBe("hello");
55
164
  }, 2000);
package/track.test.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"track.test.js","sourceRoot":"","sources":["../src/track.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,IAAI,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;IACvD,MAAM,KAAK,GAAG,IA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K,CAAC,KAAK,EAAE,CAAC;IACf,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,CAAC,MAAM,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAChD,CAAC,EAAE,IAAI,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport { Group } from \"./group.ts\";\nimport { Track } from \"./track.ts\";\n\ntest(\"nextGroupOrdered skips late arrivals\", async () => {\n\tconst track = new Track(\"test\");\n\n\ttrack.writeGroup(new Group(5));\n\n\tconst first = await track.nextGroupOrdered();\n\texpect(first?.sequence).toBe(5);\n\n\t// Late arrivals with sequence <= last returned are skipped.\n\ttrack.writeGroup(new Group(3));\n\ttrack.writeGroup(new Group(4));\n\ttrack.writeGroup(new Group(7));\n\n\tconst next = await track.nextGroupOrdered();\n\texpect(next?.sequence).toBe(7);\n});\n\ntest(\"nextGroupOrdered returns buffered groups in sequence\", async () => {\n\tconst track = new Track(\"test\");\n\n\ttrack.writeGroup(new Group(3));\n\ttrack.writeGroup(new Group(5));\n\n\texpect((await track.nextGroupOrdered())?.sequence).toBe(3);\n\texpect((await track.nextGroupOrdered())?.sequence).toBe(5);\n});\n\ntest(\"recvGroup after nextGroupOrdered still returns late arrivals\", async () => {\n\tconst track = new Track(\"test\");\n\n\ttrack.writeGroup(new Group(5));\n\n\t// Ordered returns seq 5, advancing its cursor.\n\tconst ordered = await track.nextGroupOrdered();\n\texpect(ordered?.sequence).toBe(5);\n\n\t// recvGroup is independent of the ordered cursor: a late seq 3 still surfaces.\n\ttrack.writeGroup(new Group(3));\n\tconst recv = await track.recvGroup();\n\texpect(recv?.sequence).toBe(3);\n});\n\ntest(\"nextGroupOrdered returns undefined when track closes\", async () => {\n\tconst track = new Track(\"test\");\n\ttrack.close();\n\texpect(await track.nextGroupOrdered()).toBeUndefined();\n});\n\ntest(\"readFrame does not livelock when a sole group finishes before the next arrives\", async () => {\n\tconst track = new Track(\"test\");\n\n\t// A group is appended then finished empty while the track stays open. A finished group's\n\t// readable() resolves immediately, so the reader must not busy-wait on it (which would starve the\n\t// macrotask queue and never observe the next group).\n\tconst g0 = track.appendGroup();\n\tg0.close();\n\n\t// The next group arrives via a macrotask; if the reader livelocks on microtasks it never runs.\n\tsetTimeout(() => {\n\t\tconst g1 = track.appendGroup();\n\t\tg1.writeString(\"hello\");\n\t\tg1.close();\n\t\ttrack.close();\n\t}, 10);\n\n\texpect(await track.readString()).toBe(\"hello\");\n}, 2000);\n"]}
1
+ {"version":3,"file":"track.test.js","sourceRoot":"","sources":["../src/track.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAC9B,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAE9B,IAAI,CAAC,8EAA8E,EAAE,KAAK,IAAI,EAAE;IAC/F,MAAM,QAAQ,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IAE3C,6BAA6B;IAC7B,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEzC,MAAM,CAAC,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;IAC/B,MAAM,CAAC,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;IAC/B,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAExC,8DAA8D;IAC9D,CAAC,CAAC,KAAK,EAAE,CAAC;IACV,MAAM,CAAC,QAAQ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CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport { Producer as GroupProducer } from \"./group.ts\";\nimport { Timestamp } from \"./time.ts\";\nimport { Producer as TrackProducer } from \"./track.ts\";\n\nconst enc = new TextEncoder();\nconst dec = new TextDecoder();\n\ntest(\"used reflects subscriber demand and unused resolves when the last one leaves\", async () => {\n\tconst producer = new TrackProducer(\"test\");\n\n\t// No subscribers: no demand.\n\texpect(producer.used.peek()).toBe(false);\n\n\tconst a = producer.subscribe();\n\tconst b = producer.subscribe();\n\texpect(producer.used.peek()).toBe(true);\n\n\t// Closing one of two keeps demand, so unused() stays pending.\n\ta.close();\n\texpect(producer.used.peek()).toBe(true);\n\n\t// Closing the last subscriber drops demand; unused() resolves. The consumer wire awaits this\n\t// to tear an idle upstream down.\n\tb.close();\n\tawait producer.unused();\n\texpect(producer.used.peek()).toBe(false);\n});\n\ntest(\"a producer never self-closes on zero demand: a publisher keeps serving new subscribers\", async () => {\n\tconst producer = new TrackProducer(\"video\");\n\n\t// Demand comes and goes...\n\tconst a = producer.subscribe();\n\ta.close();\n\tawait producer.unused();\n\n\t// ...but the producer stays open (only the wire acts on `unused`, not the producer itself),\n\t// so a publisher writing to a track nobody is watching is unaffected.\n\texpect(producer.closed.peek()).toBeUndefined();\n\n\t// A later subscriber still works and replays the cache.\n\tproducer.writeString(\"still here\");\n\tconst b = producer.subscribe();\n\texpect(await b.readString()).toBe(\"still here\");\n\texpect(producer.used.peek()).toBe(true);\n});\n\ntest(\"unused() resolves immediately when there was never any demand\", async () => {\n\tconst producer = new TrackProducer(\"video\");\n\t// No subscriber was ever attached; unused() must not hang.\n\tawait producer.unused();\n\texpect(producer.used.peek()).toBe(false);\n});\n\ntest(\"used stays true across churn while at least one subscriber remains\", async () => {\n\tconst producer = new TrackProducer(\"video\");\n\n\tconst a = producer.subscribe();\n\t// Rapidly add and drop extra subscribers; `a` keeps demand asserted throughout.\n\tfor (let i = 0; i < 20; i++) {\n\t\tconst t = producer.subscribe();\n\t\tt.close();\n\t\texpect(producer.used.peek()).toBe(true);\n\t}\n\n\ta.close();\n\tawait producer.unused();\n\texpect(producer.used.peek()).toBe(false);\n});\n\ntest(\"appendDatagram shares the group sequence counter\", () => {\n\tconst producer = new TrackProducer(\"test\");\n\tconst ts = Timestamp.fromMillis(10);\n\n\t// Interleave groups and datagrams: they draw from one monotonic counter.\n\texpect(producer.appendGroup().sequence).toBe(0);\n\texpect(producer.appendDatagram(ts, enc.encode(\"a\"))).toBe(1);\n\texpect(producer.appendGroup().sequence).toBe(2);\n\texpect(producer.appendDatagram(ts, enc.encode(\"b\"))).toBe(3);\n});\n\ntest(\"appendDatagram delivers to a subscriber\", async () => {\n\tconst producer = new TrackProducer(\"test\");\n\tconst track = producer.subscribe();\n\tconst ts = Timestamp.fromMillis(42);\n\n\tconst seq = producer.appendDatagram(ts, enc.encode(\"hello\"));\n\tconst got = await track.recvDatagram();\n\texpect(got?.sequence).toBe(seq);\n\texpect(got?.timestamp).toBe(ts);\n\texpect(got && dec.decode(got.payload)).toBe(\"hello\");\n});\n\ntest(\"writeDatagram preserves an explicit sequence\", async () => {\n\tconst producer = new TrackProducer(\"test\");\n\tconst track = producer.subscribe();\n\n\t// A relay forwarding an upstream datagram keeps its sequence number.\n\tproducer.writeDatagram({ sequence: 100, timestamp: Timestamp.fromMillis(5), payload: enc.encode(\"x\") });\n\texpect((await track.recvDatagram())?.sequence).toBe(100);\n\n\t// The shared counter advanced past it, so the next appended group continues from 101.\n\texpect(producer.appendGroup().sequence).toBe(101);\n});\n\ntest(\"recvDatagram advances the ordered group cursor\", async () => {\n\tconst producer = new TrackProducer(\"test\");\n\tconst track = producer.subscribe();\n\n\tproducer.writeDatagram({ sequence: 5, timestamp: Timestamp.fromMillis(5), payload: enc.encode(\"x\") });\n\texpect((await track.recvDatagram())?.sequence).toBe(5);\n\n\t// Ordered group reads treat lower sequences as late once a datagram used sequence 5.\n\tproducer.writeGroup(new GroupProducer(3));\n\tproducer.writeGroup(new GroupProducer(6));\n\texpect((await track.nextGroup())?.sequence).toBe(6);\n});\n\ntest(\"appendDatagram rejects a payload over the QUIC datagram frame ceiling\", () => {\n\tconst producer = new TrackProducer(\"test\");\n\texpect(() => producer.appendDatagram(Timestamp.fromMillis(0), new Uint8Array(65536))).toThrow();\n});\n\ntest(\"a subscriber update is forwarded to the producer's update signal\", async () => {\n\tconst producer = new TrackProducer(\"test\");\n\tconst track = producer.subscribe();\n\n\t// The wire layer watches the producer's signal to emit SUBSCRIBE_UPDATE.\n\texpect(producer.subscription.peek()).toBeUndefined();\n\tconst next = producer.subscription.changed();\n\ttrack.update({ priority: 7 });\n\texpect((await next)?.priority).toBe(7);\n});\n\ntest(\"nextGroup skips late arrivals\", async () => {\n\tconst producer = new TrackProducer(\"test\");\n\tconst track = producer.subscribe();\n\n\tproducer.writeGroup(new GroupProducer(5));\n\n\tconst first = await track.nextGroup();\n\texpect(first?.sequence).toBe(5);\n\n\t// Late arrivals with sequence <= last returned are skipped.\n\tproducer.writeGroup(new GroupProducer(3));\n\tproducer.writeGroup(new GroupProducer(4));\n\tproducer.writeGroup(new GroupProducer(7));\n\n\tconst next = await track.nextGroup();\n\texpect(next?.sequence).toBe(7);\n});\n\ntest(\"nextGroup returns buffered groups in sequence\", async () => {\n\tconst producer = new TrackProducer(\"test\");\n\tconst track = producer.subscribe();\n\n\tproducer.writeGroup(new GroupProducer(3));\n\tproducer.writeGroup(new GroupProducer(5));\n\n\texpect((await track.nextGroup())?.sequence).toBe(3);\n\texpect((await track.nextGroup())?.sequence).toBe(5);\n});\n\ntest(\"recvGroup after nextGroup still returns late arrivals\", async () => {\n\tconst producer = new TrackProducer(\"test\");\n\tconst track = producer.subscribe();\n\n\tproducer.writeGroup(new GroupProducer(5));\n\n\t// Ordered returns seq 5, advancing its cursor.\n\tconst ordered = await track.nextGroup();\n\texpect(ordered?.sequence).toBe(5);\n\n\t// recvGroup is independent of the ordered cursor: a late seq 3 still surfaces.\n\tproducer.writeGroup(new GroupProducer(3));\n\tconst recv = await track.recvGroup();\n\texpect(recv?.sequence).toBe(3);\n});\n\ntest(\"nextGroup returns undefined when track closes\", async () => {\n\tconst producer = new TrackProducer(\"test\");\n\tconst track = producer.subscribe();\n\tproducer.close();\n\texpect(await track.nextGroup()).toBeUndefined();\n});\n\ntest(\"readFrame does not livelock when a sole group finishes before the next arrives\", async () => {\n\tconst producer = new TrackProducer(\"test\");\n\tconst track = producer.subscribe();\n\n\t// A group is appended then finished empty while the track stays open. A finished group's\n\t// readable() resolves immediately, so the reader must not busy-wait on it (which would starve the\n\t// macrotask queue and never observe the next group).\n\tconst g0 = producer.appendGroup();\n\tg0.close();\n\n\t// The next group arrives via a macrotask; if the reader livelocks on microtasks it never runs.\n\tsetTimeout(() => {\n\t\tconst g1 = producer.appendGroup();\n\t\tg1.writeString(\"hello\");\n\t\tg1.close();\n\t\tproducer.close();\n\t}, 10);\n\n\texpect(await track.readString()).toBe(\"hello\");\n}, 2000);\n"]}
package/util/error.d.ts CHANGED
@@ -1,3 +1,12 @@
1
1
  export declare function error(err: unknown): Error;
2
+ /**
3
+ * Format an error into a non-empty, human-readable string for logging.
4
+ *
5
+ * Safari always leaves `WebTransportError.message` blank, so a bare `err.message`
6
+ * degrades to an empty string and the reason is lost. This falls back to the error
7
+ * type name and appends the WebTransport `source` and application `streamErrorCode`
8
+ * (the code that identifies a RESET_STREAM), so the log line always says something.
9
+ */
10
+ export declare function reason(err: unknown): string;
2
11
  export declare function unreachable(value: never): never;
3
12
  //# sourceMappingURL=error.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/util/error.ts"],"names":[],"mappings":"AACA,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CAEzC;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAE/C"}
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/util/error.ts"],"names":[],"mappings":"AACA,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CAEzC;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAa3C;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAE/C"}
package/util/error.js CHANGED
@@ -3,6 +3,27 @@
3
3
  export function error(err) {
4
4
  return err instanceof Error ? err : new Error(String(err));
5
5
  }
6
+ /**
7
+ * Format an error into a non-empty, human-readable string for logging.
8
+ *
9
+ * Safari always leaves `WebTransportError.message` blank, so a bare `err.message`
10
+ * degrades to an empty string and the reason is lost. This falls back to the error
11
+ * type name and appends the WebTransport `source` and application `streamErrorCode`
12
+ * (the code that identifies a RESET_STREAM), so the log line always says something.
13
+ */
14
+ export function reason(err) {
15
+ const e = error(err);
16
+ // WebTransportError carries the failure origin and the peer's application error code,
17
+ // often the only identifying detail since WebKit leaves `message` empty.
18
+ if (typeof WebTransportError !== "undefined" && e instanceof WebTransportError) {
19
+ const parts = [`source=${e.source}`];
20
+ if (e.streamErrorCode !== null)
21
+ parts.push(`code=${e.streamErrorCode}`);
22
+ const detail = parts.join(" ");
23
+ return e.message ? `${e.message} (${detail})` : `WebTransportError: ${detail}`;
24
+ }
25
+ return e.message || e.name || "unknown error";
26
+ }
6
27
  export function unreachable(value) {
7
28
  throw new Error(`unreachable: ${value}`);
8
29
  }
package/util/error.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/util/error.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,MAAM,UAAU,KAAK,CAAC,GAAY;IACjC,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAY;IACvC,MAAM,IAAI,KAAK,CAAC,gBAAgB,KAAK,EAAE,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["// I hate javascript.\nexport function error(err: unknown): Error {\n\treturn err instanceof Error ? err : new Error(String(err));\n}\n\nexport function unreachable(value: never): never {\n\tthrow new Error(`unreachable: ${value}`);\n}\n"]}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/util/error.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,MAAM,UAAU,KAAK,CAAC,GAAY;IACjC,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAC,GAAY;IAClC,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IAErB,sFAAsF;IACtF,yEAAyE;IACzE,IAAI,OAAO,iBAAiB,KAAK,WAAW,IAAI,CAAC,YAAY,iBAAiB,EAAE,CAAC;QAChF,MAAM,KAAK,GAAG,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,CAAC,eAAe,KAAK,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;QACxE,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/B,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,CAAC,sBAAsB,MAAM,EAAE,CAAC;IAChF,CAAC;IAED,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,IAAI,eAAe,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAY;IACvC,MAAM,IAAI,KAAK,CAAC,gBAAgB,KAAK,EAAE,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["// I hate javascript.\nexport function error(err: unknown): Error {\n\treturn err instanceof Error ? err : new Error(String(err));\n}\n\n/**\n * Format an error into a non-empty, human-readable string for logging.\n *\n * Safari always leaves `WebTransportError.message` blank, so a bare `err.message`\n * degrades to an empty string and the reason is lost. This falls back to the error\n * type name and appends the WebTransport `source` and application `streamErrorCode`\n * (the code that identifies a RESET_STREAM), so the log line always says something.\n */\nexport function reason(err: unknown): string {\n\tconst e = error(err);\n\n\t// WebTransportError carries the failure origin and the peer's application error code,\n\t// often the only identifying detail since WebKit leaves `message` empty.\n\tif (typeof WebTransportError !== \"undefined\" && e instanceof WebTransportError) {\n\t\tconst parts = [`source=${e.source}`];\n\t\tif (e.streamErrorCode !== null) parts.push(`code=${e.streamErrorCode}`);\n\t\tconst detail = parts.join(\" \");\n\t\treturn e.message ? `${e.message} (${detail})` : `WebTransportError: ${detail}`;\n\t}\n\n\treturn e.message || e.name || \"unknown error\";\n}\n\nexport function unreachable(value: never): never {\n\tthrow new Error(`unreachable: ${value}`);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=error.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.test.d.ts","sourceRoot":"","sources":["../../src/util/error.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,45 @@
1
+ /* @ts-self-types="./error.test.d.ts" */
2
+ import { afterEach, beforeEach, expect, test } from "bun:test";
3
+ import { reason } from "./error.js";
4
+ test("reason: plain Error keeps its message", () => {
5
+ expect(reason(new Error("boom"))).toBe("boom");
6
+ });
7
+ test("reason: non-Error value is stringified", () => {
8
+ expect(reason("nope")).toBe("nope");
9
+ });
10
+ test("reason: empty message falls back to the type name", () => {
11
+ // Safari's WebTransportError.message is always blank; the reason must never be empty.
12
+ expect(reason(new Error(""))).toBe("Error");
13
+ });
14
+ // Minimal stand-in for the DOM WebTransportError, which the test runtime may not define.
15
+ class FakeWebTransportError extends Error {
16
+ source;
17
+ streamErrorCode;
18
+ constructor(source, streamErrorCode, message = "") {
19
+ super(message);
20
+ this.name = "WebTransportError";
21
+ this.source = source;
22
+ this.streamErrorCode = streamErrorCode;
23
+ }
24
+ }
25
+ const globals = globalThis;
26
+ let originalWebTransportError;
27
+ beforeEach(() => {
28
+ // Force `instanceof WebTransportError` in reason() to match our stand-in.
29
+ originalWebTransportError = globals.WebTransportError;
30
+ globals.WebTransportError = FakeWebTransportError;
31
+ });
32
+ afterEach(() => {
33
+ globals.WebTransportError = originalWebTransportError;
34
+ });
35
+ test("reason: WebTransportError with a blank message surfaces source and code", () => {
36
+ // The Safari case from the bug report: a RESET_STREAM with no message.
37
+ expect(reason(new FakeWebTransportError("stream", 0))).toBe("WebTransportError: source=stream code=0");
38
+ });
39
+ test("reason: WebTransportError omits a null stream error code", () => {
40
+ expect(reason(new FakeWebTransportError("session", null))).toBe("WebTransportError: source=session");
41
+ });
42
+ test("reason: WebTransportError keeps a populated message and appends details", () => {
43
+ expect(reason(new FakeWebTransportError("stream", 42, "Received RESET_STREAM."))).toBe("Received RESET_STREAM. (source=stream code=42)");
44
+ });
45
+ //# sourceMappingURL=error.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.test.js","sourceRoot":"","sources":["../../src/util/error.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IAClD,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,wCAAwC,EAAE,GAAG,EAAE;IACnD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,C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AC,mCAAmC,CAAC,CAAC;AACtG,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,yEAAyE,EAAE,GAAG,EAAE;IACpF,MAAM,CAAC,MAAM,CAAC,IAAI,qBAAqB,CAAC,QAAQ,EAAE,EAAE,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC,IAAI,CACrF,gDAAgD,CAChD,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { afterEach, beforeEach, expect, test } from \"bun:test\";\nimport { reason } from \"./error.ts\";\n\ntest(\"reason: plain Error keeps its message\", () => {\n\texpect(reason(new Error(\"boom\"))).toBe(\"boom\");\n});\n\ntest(\"reason: non-Error value is stringified\", () => {\n\texpect(reason(\"nope\")).toBe(\"nope\");\n});\n\ntest(\"reason: empty message falls back to the type name\", () => {\n\t// Safari's WebTransportError.message is always blank; the reason must never be empty.\n\texpect(reason(new Error(\"\"))).toBe(\"Error\");\n});\n\n// Minimal stand-in for the DOM WebTransportError, which the test runtime may not define.\nclass FakeWebTransportError extends Error {\n\treadonly source: string;\n\treadonly streamErrorCode: number | null;\n\n\tconstructor(source: string, streamErrorCode: number | null, message = \"\") {\n\t\tsuper(message);\n\t\tthis.name = \"WebTransportError\";\n\t\tthis.source = source;\n\t\tthis.streamErrorCode = streamErrorCode;\n\t}\n}\n\nconst globals = globalThis as { WebTransportError?: unknown };\nlet originalWebTransportError: unknown;\n\nbeforeEach(() => {\n\t// Force `instanceof WebTransportError` in reason() to match our stand-in.\n\toriginalWebTransportError = globals.WebTransportError;\n\tglobals.WebTransportError = FakeWebTransportError;\n});\n\nafterEach(() => {\n\tglobals.WebTransportError = originalWebTransportError;\n});\n\ntest(\"reason: WebTransportError with a blank message surfaces source and code\", () => {\n\t// The Safari case from the bug report: a RESET_STREAM with no message.\n\texpect(reason(new FakeWebTransportError(\"stream\", 0))).toBe(\"WebTransportError: source=stream code=0\");\n});\n\ntest(\"reason: WebTransportError omits a null stream error code\", () => {\n\texpect(reason(new FakeWebTransportError(\"session\", null))).toBe(\"WebTransportError: source=session\");\n});\n\ntest(\"reason: WebTransportError keeps a populated message and appends details\", () => {\n\texpect(reason(new FakeWebTransportError(\"stream\", 42, \"Received RESET_STREAM.\"))).toBe(\n\t\t\"Received RESET_STREAM. (source=stream code=42)\",\n\t);\n});\n"]}
package/util/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./error";
2
+ export * from "./timeout";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
package/util/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  /* @ts-self-types="./index.d.ts" */
2
2
  export * from "./error.js";
3
+ export * from "./timeout.js";
3
4
  //# sourceMappingURL=index.js.map
package/util/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC","sourcesContent":["export * from \"./error.ts\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC","sourcesContent":["export * from \"./error.ts\";\nexport * from \"./timeout.ts\";\n"]}
@@ -0,0 +1,5 @@
1
+ export declare class TimeoutError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare function withTimeout<T>(promise: Promise<T>, ms: number, message: string): Promise<T>;
5
+ //# sourceMappingURL=timeout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/util/timeout.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IACtC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAKD,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAM3F"}
@@ -0,0 +1,18 @@
1
+ /* @ts-self-types="./timeout.d.ts" */
2
+ export class TimeoutError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "TimeoutError";
6
+ }
7
+ }
8
+ // Race `promise` against a timeout. There's no cancellation; if `promise`
9
+ // settles after the timeout fires the caller is responsible for cleaning up
10
+ // any side effects (open streams, etc.) it may produce.
11
+ export function withTimeout(promise, ms, message) {
12
+ let timer;
13
+ const timeout = new Promise((_, reject) => {
14
+ timer = setTimeout(() => reject(new TimeoutError(message)), ms);
15
+ });
16
+ return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
17
+ }
18
+ //# sourceMappingURL=timeout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../src/util/timeout.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC5B,CAAC;CACD;AAED,0EAA0E;AAC1E,4EAA4E;AAC5E,wDAAwD;AACxD,MAAM,UAAU,WAAW,CAAI,OAAmB,EAAE,EAAU,EAAE,OAAe;IAC9E,IAAI,KAAoC,CAAC;IACzC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAChD,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["export class TimeoutError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"TimeoutError\";\n\t}\n}\n\n// Race `promise` against a timeout. There's no cancellation; if `promise`\n// settles after the timeout fires the caller is responsible for cleaning up\n// any side effects (open streams, etc.) it may produce.\nexport function withTimeout<T>(promise: Promise<T>, ms: number, message: string): Promise<T> {\n\tlet timer: ReturnType<typeof setTimeout>;\n\tconst timeout = new Promise<never>((_, reject) => {\n\t\ttimer = setTimeout(() => reject(new TimeoutError(message)), ms);\n\t});\n\treturn Promise.race([promise, timeout]).finally(() => clearTimeout(timer));\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=timeout.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.test.d.ts","sourceRoot":"","sources":["../../src/util/timeout.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ /* @ts-self-types="./timeout.test.d.ts" */
2
+ import { expect, test } from "bun:test";
3
+ import { TimeoutError, withTimeout } from "./timeout.js";
4
+ test("withTimeout: resolves before deadline", async () => {
5
+ const result = await withTimeout(Promise.resolve(42), 100, "should not fire");
6
+ expect(result).toBe(42);
7
+ });
8
+ test("withTimeout: rejects with TimeoutError after deadline", async () => {
9
+ const pending = new Promise(() => {
10
+ // never settles
11
+ });
12
+ await expect(withTimeout(pending, 10, "timed out")).rejects.toBeInstanceOf(TimeoutError);
13
+ });
14
+ test("withTimeout: passes through promise rejection", async () => {
15
+ const failure = Promise.reject(new Error("boom"));
16
+ await expect(withTimeout(failure, 100, "should not fire")).rejects.toThrow("boom");
17
+ });
18
+ //# sourceMappingURL=timeout.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.test.js","sourceRoot":"","sources":["../../src/util/timeout.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEzD,IAAI,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;IACxD,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAAC;IAC9E,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uDAAuD,EAAE,KAAK,IAAI,EAAE;IACxE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAS,GAAG,EAAE;QACxC,gBAAgB;IACjB,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;AAC1F,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;IAChE,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,MAAM,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AACpF,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport { TimeoutError, withTimeout } from \"./timeout.ts\";\n\ntest(\"withTimeout: resolves before deadline\", async () => {\n\tconst result = await withTimeout(Promise.resolve(42), 100, \"should not fire\");\n\texpect(result).toBe(42);\n});\n\ntest(\"withTimeout: rejects with TimeoutError after deadline\", async () => {\n\tconst pending = new Promise<number>(() => {\n\t\t// never settles\n\t});\n\tawait expect(withTimeout(pending, 10, \"timed out\")).rejects.toBeInstanceOf(TimeoutError);\n});\n\ntest(\"withTimeout: passes through promise rejection\", async () => {\n\tconst failure = Promise.reject(new Error(\"boom\"));\n\tawait expect(withTimeout(failure, 100, \"should not fire\")).rejects.toThrow(\"boom\");\n});\n"]}