@moq/net 0.4.0 → 0.4.2

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 (204) hide show
  1. package/announced.d.ts +14 -0
  2. package/announced.d.ts.map +1 -1
  3. package/announced.js.map +1 -1
  4. package/broadcast.d.ts +27 -10
  5. package/broadcast.d.ts.map +1 -1
  6. package/broadcast.js +47 -21
  7. package/broadcast.js.map +1 -1
  8. package/connection/accept.js +14 -4
  9. package/connection/accept.js.map +1 -1
  10. package/connection/connect.d.ts.map +1 -1
  11. package/connection/connect.js +14 -4
  12. package/connection/connect.js.map +1 -1
  13. package/connection/established.d.ts +2 -1
  14. package/connection/established.d.ts.map +1 -1
  15. package/connection/established.js.map +1 -1
  16. package/connection/forward.js +61 -47
  17. package/connection/forward.js.map +1 -1
  18. package/connection/goaway.d.ts +34 -0
  19. package/connection/goaway.d.ts.map +1 -0
  20. package/connection/goaway.js +176 -0
  21. package/connection/goaway.js.map +1 -0
  22. package/connection/handshake.d.ts +5 -2
  23. package/connection/handshake.d.ts.map +1 -1
  24. package/connection/handshake.js +45 -10
  25. package/connection/handshake.js.map +1 -1
  26. package/connection/pool.d.ts +24 -11
  27. package/connection/pool.d.ts.map +1 -1
  28. package/connection/pool.js +50 -18
  29. package/connection/pool.js.map +1 -1
  30. package/connection/reload.d.ts.map +1 -1
  31. package/connection/reload.js +189 -35
  32. package/connection/reload.js.map +1 -1
  33. package/error.d.ts +11 -0
  34. package/error.d.ts.map +1 -1
  35. package/error.js +35 -0
  36. package/error.js.map +1 -1
  37. package/errors.d.ts +1 -1
  38. package/errors.d.ts.map +1 -1
  39. package/errors.js +1 -1
  40. package/errors.js.map +1 -1
  41. package/group.d.ts.map +1 -1
  42. package/group.js +5 -4
  43. package/group.js.map +1 -1
  44. package/hop.d.ts +8 -0
  45. package/hop.d.ts.map +1 -1
  46. package/hop.js +16 -0
  47. package/hop.js.map +1 -1
  48. package/ietf/adapter.d.ts +9 -1
  49. package/ietf/adapter.d.ts.map +1 -1
  50. package/ietf/adapter.js +46 -17
  51. package/ietf/adapter.js.map +1 -1
  52. package/ietf/cluster.d.ts +3 -3
  53. package/ietf/cluster.js +3 -3
  54. package/ietf/cluster.js.map +1 -1
  55. package/ietf/connection.d.ts +1 -1
  56. package/ietf/connection.d.ts.map +1 -1
  57. package/ietf/connection.js +118 -41
  58. package/ietf/connection.js.map +1 -1
  59. package/ietf/error.js +27 -2
  60. package/ietf/error.js.map +1 -1
  61. package/ietf/fetch.d.ts +7 -20
  62. package/ietf/fetch.d.ts.map +1 -1
  63. package/ietf/fetch.js +52 -22
  64. package/ietf/fetch.js.map +1 -1
  65. package/ietf/filter.d.ts +2 -0
  66. package/ietf/filter.d.ts.map +1 -1
  67. package/ietf/filter.js +4 -0
  68. package/ietf/filter.js.map +1 -1
  69. package/ietf/goaway.d.ts +9 -1
  70. package/ietf/goaway.d.ts.map +1 -1
  71. package/ietf/goaway.js +20 -0
  72. package/ietf/goaway.js.map +1 -1
  73. package/ietf/hidden.d.ts +2 -0
  74. package/ietf/hidden.d.ts.map +1 -0
  75. package/ietf/hidden.js +30 -0
  76. package/ietf/hidden.js.map +1 -0
  77. package/ietf/index.d.ts +2 -1
  78. package/ietf/index.d.ts.map +1 -1
  79. package/ietf/index.js +2 -1
  80. package/ietf/index.js.map +1 -1
  81. package/ietf/object.d.ts +15 -8
  82. package/ietf/object.d.ts.map +1 -1
  83. package/ietf/object.js +54 -36
  84. package/ietf/object.js.map +1 -1
  85. package/ietf/parameters.d.ts +12 -0
  86. package/ietf/parameters.d.ts.map +1 -1
  87. package/ietf/parameters.js +82 -12
  88. package/ietf/parameters.js.map +1 -1
  89. package/ietf/properties.d.ts +1 -0
  90. package/ietf/properties.d.ts.map +1 -1
  91. package/ietf/properties.js +14 -0
  92. package/ietf/properties.js.map +1 -1
  93. package/ietf/publish.d.ts +19 -2
  94. package/ietf/publish.d.ts.map +1 -1
  95. package/ietf/publish.js +40 -6
  96. package/ietf/publish.js.map +1 -1
  97. package/ietf/publish_namespace.d.ts +2 -2
  98. package/ietf/publish_namespace.js +2 -2
  99. package/ietf/publish_namespace.js.map +1 -1
  100. package/ietf/publisher.js +383 -214
  101. package/ietf/publisher.js.map +1 -1
  102. package/ietf/subscribe.d.ts +7 -1
  103. package/ietf/subscribe.d.ts.map +1 -1
  104. package/ietf/subscribe.js +25 -18
  105. package/ietf/subscribe.js.map +1 -1
  106. package/ietf/subscribe_namespace.d.ts +8 -2
  107. package/ietf/subscribe_namespace.d.ts.map +1 -1
  108. package/ietf/subscribe_namespace.js +20 -11
  109. package/ietf/subscribe_namespace.js.map +1 -1
  110. package/ietf/subscriber.js +226 -88
  111. package/ietf/subscriber.js.map +1 -1
  112. package/ietf/token.d.ts +2 -0
  113. package/ietf/token.d.ts.map +1 -0
  114. package/ietf/token.js +99 -0
  115. package/ietf/token.js.map +1 -0
  116. package/ietf/track.d.ts +4 -0
  117. package/ietf/track.d.ts.map +1 -1
  118. package/ietf/track.js +6 -20
  119. package/ietf/track.js.map +1 -1
  120. package/index.d.ts +1 -1
  121. package/index.d.ts.map +1 -1
  122. package/index.js.map +1 -1
  123. package/internal.d.ts +19 -3
  124. package/internal.d.ts.map +1 -1
  125. package/internal.js +43 -0
  126. package/internal.js.map +1 -1
  127. package/lite/announce.d.ts +46 -2
  128. package/lite/announce.d.ts.map +1 -1
  129. package/lite/announce.js +133 -15
  130. package/lite/announce.js.map +1 -1
  131. package/lite/connection.d.ts +1 -1
  132. package/lite/connection.d.ts.map +1 -1
  133. package/lite/connection.js +30 -9
  134. package/lite/connection.js.map +1 -1
  135. package/lite/datagram.d.ts +3 -2
  136. package/lite/datagram.d.ts.map +1 -1
  137. package/lite/datagram.js +7 -8
  138. package/lite/datagram.js.map +1 -1
  139. package/lite/group.d.ts +12 -8
  140. package/lite/group.d.ts.map +1 -1
  141. package/lite/group.js +37 -16
  142. package/lite/group.js.map +1 -1
  143. package/lite/message.d.ts +2 -2
  144. package/lite/message.d.ts.map +1 -1
  145. package/lite/message.js +14 -5
  146. package/lite/message.js.map +1 -1
  147. package/lite/publisher.js +174 -133
  148. package/lite/publisher.js.map +1 -1
  149. package/lite/setup.d.ts +1 -1
  150. package/lite/setup.d.ts.map +1 -1
  151. package/lite/setup.js +22 -19
  152. package/lite/setup.js.map +1 -1
  153. package/lite/subscribe.d.ts +10 -4
  154. package/lite/subscribe.d.ts.map +1 -1
  155. package/lite/subscribe.js +20 -10
  156. package/lite/subscribe.js.map +1 -1
  157. package/lite/subscriber.d.ts +10 -2
  158. package/lite/subscriber.d.ts.map +1 -1
  159. package/lite/subscriber.js +333 -188
  160. package/lite/subscriber.js.map +1 -1
  161. package/lite/version.d.ts +11 -0
  162. package/lite/version.d.ts.map +1 -1
  163. package/lite/version.js +56 -0
  164. package/lite/version.js.map +1 -1
  165. package/origin.d.ts +46 -19
  166. package/origin.d.ts.map +1 -1
  167. package/origin.js +529 -189
  168. package/origin.js.map +1 -1
  169. package/package.json +8 -4
  170. package/stream.d.ts +79 -14
  171. package/stream.d.ts.map +1 -1
  172. package/stream.js +375 -133
  173. package/stream.js.map +1 -1
  174. package/tail.d.ts +18 -0
  175. package/tail.d.ts.map +1 -0
  176. package/tail.js +167 -0
  177. package/tail.js.map +1 -0
  178. package/track.d.ts +46 -7
  179. package/track.d.ts.map +1 -1
  180. package/track.js +263 -101
  181. package/track.js.map +1 -1
  182. package/util/abort.d.ts +2 -0
  183. package/util/abort.d.ts.map +1 -0
  184. package/util/abort.js +20 -0
  185. package/util/abort.js.map +1 -0
  186. package/util/u64.d.ts +39 -0
  187. package/util/u64.d.ts.map +1 -0
  188. package/util/u64.js +83 -0
  189. package/util/u64.js.map +1 -0
  190. package/util/varint.d.ts +29 -0
  191. package/util/varint.d.ts.map +1 -0
  192. package/util/varint.js +198 -0
  193. package/util/varint.js.map +1 -0
  194. package/varint.d.ts +10 -6
  195. package/varint.d.ts.map +1 -1
  196. package/varint.js +40 -237
  197. package/varint.js.map +1 -1
  198. package/wire.d.ts +19 -3
  199. package/wire.d.ts.map +1 -1
  200. package/wire.js.map +1 -1
  201. package/ietf/control.d.ts +0 -135
  202. package/ietf/control.d.ts.map +0 -1
  203. package/ietf/control.js +0 -242
  204. package/ietf/control.js.map +0 -1
package/announced.d.ts CHANGED
@@ -35,6 +35,20 @@ export interface Update {
35
35
  /** Hops and cost of the route; on a retraction, its last advertised values. */
36
36
  route: Route;
37
37
  }
38
+ /**
39
+ * Options for an announcement stream.
40
+ *
41
+ * @public
42
+ */
43
+ export interface Options {
44
+ /**
45
+ * Also report hidden routes: those with a path segment starting with `.` below the
46
+ * scope's literal head. Hidden routes are left out by default, so a platform can add
47
+ * `.`-named broadcasts (stats, internal routes) without them turning up in apps that
48
+ * list everything. Subscribing to a hidden path by name works either way.
49
+ */
50
+ hidden?: boolean;
51
+ }
38
52
  /** Whether a route covers the path after an update of this {@link Kind}. */
39
53
  export declare function isActive(kind: Kind): boolean;
40
54
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"announced.d.ts","sourceRoot":"","sources":["../src/announced.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,KAAK,UAAU,EAAgB,MAAM,cAAc,CAAC;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAC;AAEvC;;;;GAIG;AACH,MAAM,MAAM,IAAI,GAAG,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,MAAM;IACtB;;OAEG;IACH,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC;IACnB,gFAAgF;IAChF,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC;IACrC,iEAAiE;IACjE,IAAI,EAAE,IAAI,CAAC;IACX,+EAA+E;IAC/E,KAAK,EAAE,KAAK,CAAC;CACb;AAED,4EAA4E;AAC5E,wBAAgB,QAA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C,iEAAiE;IACjE,IAAI,EAAE,IAAI,CAAC;IACX,+EAA+E;IAC/E,KAAK,EAAE,KAAK,CAAC;CACb;AAED;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACvB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,4EAA4E;AAC5E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE5C;AAiBD;;;;GAIG;AACH,qBAAa,QAAQ;;IAGpB;;;OAGG;IACH,IAAI,MAAM,IAAI,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,CAErC;IAED,kDAAkD;IAClD,OAAO,IAAI,QAAQ,CAElB;IAED,2CAA2C;IAC3C,MAAM,CAAC,MAAM,EAAE,MAAM,QAKpB;IAED,qCAAqC;IACrC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,QAElB;CACD;AAMD;;;;;;;GAOG;AACH,qBAAa,QAAQ;;IAGpB,OAAO,eAEN;IAED,mEAAmE;IACnE,IAAI,MAAM,IAAI,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,CAErC;IAMD,iEAAiE;IAC1D,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAMvE;IAED,qCAAqC;IAC/B,IAAI,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAWxC;IAED,qCAAqC;IACrC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,QAElB;CACD"}
package/announced.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"announced.js","sourceRoot":"","sources":["../src/announced.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAmB,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAmC7D,4EAA4E;AAC5E,MAAM,UAAU,QAAQ,CAAC,IAAU;IAClC,OAAO,IAAI,KAAK,WAAW,CAAC;AAC7B,CAAC;AAED,6EAA6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paths are available under a scope.\n *\n * @module\n */\nimport { type GetPromise, Once, Signal } from \"@moq/signals\";\nimport type { Route } from \"./hop.js\";\nimport type * as Path from \"./path.js\";\n\n/**\n * What an {@link Update} reports about its prefix.\n *\n * @public\n */\nexport type Kind = \"announced\" | \"updated\" | \"retracted\";\n\n/**\n * A route announcement, update, or retraction.\n *\n * An announcement is always a prefix, never a broadcast: a route claims that\n * {@link prefix} and every path beneath it can be served. By convention a publisher\n * announces each broadcast's exact path, so enumerating routes enumerates broadcasts;\n * resolve one with the origin's `request(path)`. Narrow with a {@link Path.Pattern}\n * locally to follow a subset.\n *\n * @public\n */\nexport interface Update {\n\t/**\n\t * The prefix the route covers, relative to the origin (for a session, its URL path).\n\t */\n\tprefix: Path.Valid;\n\t/** What the filter's wildcards stood for, when this prefix pins all of them. */\n\tcaptures: Path.Pattern[] | undefined;\n\t/** Whether the prefix was announced, re-priced, or retracted. */\n\tkind: Kind;\n\t/** Hops and cost of the route; on a retraction, its last advertised values. */\n\troute: Route;\n}\n\n/** Whether a route covers the path after an update of this {@link Kind}. */\nexport function isActive(kind: Kind): boolean {\n\treturn kind !== \"retracted\";\n}\n\n/** Reactive backing state shared by announcement producers and consumers. */\nclass AnnounceState {\n\tqueue = new Signal<Update[]>([]);\n\tclosed = new Once<Error | null>();\n}\n\n// Once.set throws on a second settle, and both ends of a stream can close independently.\nfunction closeState(state: AnnounceState, abort?: Error) {\n\tif (state.closed.peek() !== undefined) return;\n\tstate.closed.set(abort ?? null);\n\tstate.queue.mutate((queue) => {\n\t\tqueue.length = 0;\n\t});\n}\n\n/**\n * The write side of an announcement stream.\n *\n * @public\n */\nexport class Producer {\n\t#state = new AnnounceState();\n\n\t/**\n\t * Settles once the stream 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/** A read handle for this announcement stream. */\n\tconsume(): Consumer {\n\t\treturn makeConsumer(this.#state);\n\t}\n\n\t/** Writes an announcement to the queue. */\n\tappend(update: Update) {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"announcements are closed\");\n\t\tthis.#state.queue.mutate((queue) => {\n\t\t\tqueue.push(update);\n\t\t});\n\t}\n\n\t/** Closes the writer. Idempotent. */\n\tclose(abort?: Error) {\n\t\tcloseState(this.#state, abort);\n\t}\n}\n\n// Constructs a Consumer from within this module without exposing a public constructor\n// that would leak the unexported AnnounceState. Assigned in the class's static block.\nlet makeConsumer: (state: AnnounceState) => Consumer;\n\n/**\n * The read side of an announcement stream.\n *\n * Created internally: obtain one from {@link Producer.consume} or the connection's\n * `announced(scope)`.\n *\n * @public\n */\nexport class Consumer {\n\t#state: AnnounceState;\n\n\tprivate constructor(state: AnnounceState) {\n\t\tthis.#state = state;\n\t}\n\n\t/** Settles once the stream closes; see {@link Producer.closed}. */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\tstatic {\n\t\tmakeConsumer = (state) => new Consumer(state);\n\t}\n\n\t/** The announcements as they arrive, until the stream closes. */\n\tasync *[Symbol.asyncIterator](): AsyncGenerator<Update, void, undefined> {\n\t\tfor (;;) {\n\t\t\tconst update = await this.next();\n\t\t\tif (!update) return;\n\t\t\tyield update;\n\t\t}\n\t}\n\n\t/** Returns the next announcement. */\n\tasync next(): Promise<Update | undefined> {\n\t\tfor (;;) {\n\t\t\tconst announce = this.#state.queue.peek().shift();\n\t\t\tif (announce) return announce;\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.queue, this.#state.closed);\n\t\t}\n\t}\n\n\t/** Closes the reader. Idempotent. */\n\tclose(abort?: Error) {\n\t\tcloseState(this.#state, abort);\n\t}\n}\n"]}
1
+ {"version":3,"file":"announced.js","sourceRoot":"","sources":["../src/announced.ts"],"names":[],"m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AAC,MAAM,CAAC,CAAC;QAC1D,CAAC;IACF,CAAC;IAED,qCAAqC;IACrC,KAAK,CAAC,KAAa;QAClB,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC;CACD","sourcesContent":["/**\n * Broadcast announcement streams: which broadcast paths are available under a scope.\n *\n * @module\n */\nimport { type GetPromise, Once, Signal } from \"@moq/signals\";\nimport type { Route } from \"./hop.js\";\nimport type * as Path from \"./path.js\";\n\n/**\n * What an {@link Update} reports about its prefix.\n *\n * @public\n */\nexport type Kind = \"announced\" | \"updated\" | \"retracted\";\n\n/**\n * A route announcement, update, or retraction.\n *\n * An announcement is always a prefix, never a broadcast: a route claims that\n * {@link prefix} and every path beneath it can be served. By convention a publisher\n * announces each broadcast's exact path, so enumerating routes enumerates broadcasts;\n * resolve one with the origin's `request(path)`. Narrow with a {@link Path.Pattern}\n * locally to follow a subset.\n *\n * @public\n */\nexport interface Update {\n\t/**\n\t * The prefix the route covers, relative to the origin (for a session, its URL path).\n\t */\n\tprefix: Path.Valid;\n\t/** What the filter's wildcards stood for, when this prefix pins all of them. */\n\tcaptures: Path.Pattern[] | undefined;\n\t/** Whether the prefix was announced, re-priced, or retracted. */\n\tkind: Kind;\n\t/** Hops and cost of the route; on a retraction, its last advertised values. */\n\troute: Route;\n}\n\n/**\n * Options for an announcement stream.\n *\n * @public\n */\nexport interface Options {\n\t/**\n\t * Also report hidden routes: those with a path segment starting with `.` below the\n\t * scope's literal head. Hidden routes are left out by default, so a platform can add\n\t * `.`-named broadcasts (stats, internal routes) without them turning up in apps that\n\t * list everything. Subscribing to a hidden path by name works either way.\n\t */\n\thidden?: boolean;\n}\n\n/** Whether a route covers the path after an update of this {@link Kind}. */\nexport function isActive(kind: Kind): boolean {\n\treturn kind !== \"retracted\";\n}\n\n/** Reactive backing state shared by announcement producers and consumers. */\nclass AnnounceState {\n\tqueue = new Signal<Update[]>([]);\n\tclosed = new Once<Error | null>();\n}\n\n// Once.set throws on a second settle, and both ends of a stream can close independently.\nfunction closeState(state: AnnounceState, abort?: Error) {\n\tif (state.closed.peek() !== undefined) return;\n\tstate.closed.set(abort ?? null);\n\tstate.queue.mutate((queue) => {\n\t\tqueue.length = 0;\n\t});\n}\n\n/**\n * The write side of an announcement stream.\n *\n * @public\n */\nexport class Producer {\n\t#state = new AnnounceState();\n\n\t/**\n\t * Settles once the stream 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/** A read handle for this announcement stream. */\n\tconsume(): Consumer {\n\t\treturn makeConsumer(this.#state);\n\t}\n\n\t/** Writes an announcement to the queue. */\n\tappend(update: Update) {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"announcements are closed\");\n\t\tthis.#state.queue.mutate((queue) => {\n\t\t\tqueue.push(update);\n\t\t});\n\t}\n\n\t/** Closes the writer. Idempotent. */\n\tclose(abort?: Error) {\n\t\tcloseState(this.#state, abort);\n\t}\n}\n\n// Constructs a Consumer from within this module without exposing a public constructor\n// that would leak the unexported AnnounceState. Assigned in the class's static block.\nlet makeConsumer: (state: AnnounceState) => Consumer;\n\n/**\n * The read side of an announcement stream.\n *\n * Created internally: obtain one from {@link Producer.consume} or the connection's\n * `announced(scope)`.\n *\n * @public\n */\nexport class Consumer {\n\t#state: AnnounceState;\n\n\tprivate constructor(state: AnnounceState) {\n\t\tthis.#state = state;\n\t}\n\n\t/** Settles once the stream closes; see {@link Producer.closed}. */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\tstatic {\n\t\tmakeConsumer = (state) => new Consumer(state);\n\t}\n\n\t/** The announcements as they arrive, until the stream closes. */\n\tasync *[Symbol.asyncIterator](): AsyncGenerator<Update, void, undefined> {\n\t\tfor (;;) {\n\t\t\tconst update = await this.next();\n\t\t\tif (!update) return;\n\t\t\tyield update;\n\t\t}\n\t}\n\n\t/** Returns the next announcement. */\n\tasync next(): Promise<Update | undefined> {\n\t\tfor (;;) {\n\t\t\tconst announce = this.#state.queue.peek().shift();\n\t\t\tif (announce) return announce;\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.queue, this.#state.closed);\n\t\t}\n\t}\n\n\t/** Closes the reader. Idempotent. */\n\tclose(abort?: Error) {\n\t\tcloseState(this.#state, abort);\n\t}\n}\n"]}
package/broadcast.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { type GetPromise } from "@moq/signals";
7
7
  import { Route } from "./hop";
8
+ import * as Path from "./path";
8
9
  import * as track from "./track";
9
10
  /**
10
11
  * The write side of a broadcast.
@@ -19,7 +20,7 @@ export declare class Producer {
19
20
  * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.
20
21
  */
21
22
  get closed(): GetPromise<Error | null>;
22
- /** A read handle for this broadcast. */
23
+ /** A read handle for this broadcast, named by the path the origin created it at. */
23
24
  consume(): Consumer;
24
25
  /** Insert a track that is served directly, without an on-demand request round-trip. */
25
26
  insertTrack(track: track.Producer): void;
@@ -32,8 +33,8 @@ export declare class Producer {
32
33
  /**
33
34
  * Advertise this broadcast's exact path, or re-price a standing advertisement in place.
34
35
  *
35
- * Call it once the tracks a subscriber needs first (a catalog) exist. The broadcast is
36
- * discoverable on the local origin from creation; announcing advertises it to peers. Retracts on
36
+ * Call it once the tracks a subscriber needs first (a catalog) exist. Until then the
37
+ * broadcast exists for nobody, on its own origin or at a peer. Retracts on
37
38
  * {@link unannounce} or {@link close}. Throws if this producer was not created through an
38
39
  * origin, or if the broadcast is already closed.
39
40
  */
@@ -41,9 +42,14 @@ export declare class Producer {
41
42
  hops?: Route["hops"];
42
43
  cost?: Route["cost"] | bigint;
43
44
  }): void;
44
- /** Retract the advertisement of this broadcast's path, if any. */
45
+ /**
46
+ * Retract the advertisement of this broadcast's path, if any, from local consumers and
47
+ * peers alike. {@link announce} brings it back.
48
+ */
45
49
  unannounce(): void;
46
- /** Close the broadcast, optionally with an error to abort waiters. Idempotent. */
50
+ /** End the broadcast for good: retract it, serve no new tracks, and refuse a later {@link announce}. Idempotent. */
51
+ close(): void;
52
+ /** @deprecated A broadcast end carries no cause; call `close()` without one. */
47
53
  close(abort?: Error): void;
48
54
  }
49
55
  /**
@@ -56,7 +62,16 @@ export declare class Producer {
56
62
  */
57
63
  export declare class Consumer {
58
64
  #private;
59
- protected constructor(state?: never);
65
+ protected constructor(shared?: never);
66
+ /**
67
+ * The path this handle names the broadcast by, which relative references in its catalog
68
+ * (hang's `broadcast` field) resolve against.
69
+ *
70
+ * An origin stamps each handle it hands out with the path it was requested at, relative to
71
+ * that origin handle's scope root, and a broadcast it created with the path it was created at.
72
+ * Empty for a standalone broadcast, which is then its own root: any `..` reference escapes.
73
+ */
74
+ get path(): Path.Valid;
60
75
  /**
61
76
  * Settles once the broadcast closes: `null` on a clean close, or the abort {@link Error}.
62
77
  * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.
@@ -68,8 +83,8 @@ export declare class Consumer {
68
83
  /**
69
84
  * Return another handle to the same broadcast, reference-counted with this one.
70
85
  *
71
- * Both handles read the same tracks and share one {@link closed} state; the broadcast
72
- * closes only once *every* handle has {@link close}d. Used by the connection's per-path
86
+ * Both handles read the same tracks, carry the same {@link path}, and share one {@link closed}
87
+ * state; the broadcast closes only once *every* handle has {@link close}d. Used by the connection's per-path
73
88
  * consume cache to share one subscription across callers. Subclasses that resolve info over
74
89
  * the wire override this to preserve their type (see the wire layer's consumed broadcast).
75
90
  */
@@ -78,9 +93,11 @@ export declare class Consumer {
78
93
  /** Get a lazy handle for a track on this broadcast. Repeat subscriptions dedupe onto one upstream subscription. */
79
94
  track(name: string): track.Consumer;
80
95
  /**
81
- * Release this handle. The broadcast is closed (optionally with an error to abort waiters)
82
- * once this was the last live handle; while other {@link clone}s remain open it stays live.
96
+ * Release this handle. The broadcast is closed once this was the last live handle;
97
+ * while other {@link clone}s remain open it stays live.
83
98
  */
99
+ close(): void;
100
+ /** @deprecated A broadcast end carries no cause; call `close()` without one. */
84
101
  close(abort?: Error): void;
85
102
  }
86
103
  //# sourceMappingURL=broadcast.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"broadcast.d.ts","sourceRoot":"","sources":["../src/broadcast.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,KAAK,UAAU,EAAgB,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AA8IpC;;;;GAIG;AACH,qBAAa,QAAQ;;IAIpB,cAEC;IASD;;;OAGG;IACH,IAAI,MAAM,IAAI,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,CAErC;IAED,wCAAwC;IACxC,OAAO,IAAI,QAAQ,CAElB;IAeD,uFAAuF;IACvF,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,GAAG,IAAI,CAiBvC;IAED,6EAA6E;IAC7E,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAM,GAAG,KAAK,CAAC,QAAQ,CAIxE;IAED,kDAAkD;IAClD,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE9B;IAED,wDAAwD;IACxD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,QAAQ,CAElC;IAWD;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,GAAE,KAAK,GAAG;QAAE,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAAC,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA;KAAkB,GAAG,IAAI,CAMrG;IAED,kEAAkE;IAClE,UAAU,IAA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I,CAE9B;IAED,wDAAwD;IACxD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,QAAQ,CAElC;IAWD;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,GAAE,KAAK,GAAG;QAAE,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAAC,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA;KAAkB,GAAG,IAAI,CAMrG;IAED;;;OAGG;IACH,UAAU,IAAI,IAAI,CAEjB;IAED,oHAAoH;IACpH,KAAK,IAAI,IAAI,CAAC;IACd,gFAAgF;IAChF,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;CAM3B;AAYD;;;;;;;GAOG;AACH,qBAAa,QAAQ;;IAOpB,SAAS,aAAa,MAAM,CAAC,EAAE,KAAK,EAAE;IAqBtC;;;;;;;OAOG;IACH,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,CAErB;IAED;;;;;;OAMG;IACH,IAAI,MAAM,IAAI,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,CAErC;IAED;;;;;;;OAOG;IACH,KAAK,IAAI,QAAQ,CAEhB;IAID,SAAS,CAAC,UAAU,IAAI,KAAK,CAE5B;IAED,mHAAmH;IACnH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,QAAQ,CAElC;IAeD;;;OAGG;IACH,KAAK,IAAI,IAAI,CAAC;IACd,gFAAgF;IAChF,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;CAO3B"}
package/broadcast.js CHANGED
@@ -5,11 +5,15 @@
5
5
  * @module
6
6
  */
7
7
  import { Once, Signal } from "@moq/signals";
8
+ import { NotFound } from "./error.js";
8
9
  import { Route } from "./hop.js";
9
10
  import { hooks } from "./internal.js";
11
+ import * as Path from "./path.js";
10
12
  import * as track from "./track.js";
13
+ import { untilAborted } from "./util/abort.js";
11
14
  import { registerWire, trackOf } from "./wire.js";
12
15
  let attachAnnouncer;
16
+ let stampProducer;
13
17
  /** Reactive backing state shared by broadcast producers and consumers. */
14
18
  class BroadcastState {
15
19
  requested = new Signal([]);
@@ -98,13 +102,14 @@ async function resolveTrackInfo(state, name) {
98
102
  // requested sequence. The default for a produced broadcast; the consuming wire layer
99
103
  // overrides it to fetch over the network (or to reject when the transport has no FETCH).
100
104
  async function fetchGroup(state, name, sequence, options = {}) {
105
+ options.signal?.throwIfAborted();
101
106
  const subscriber = subscribe(state, name, { priority: options.priority });
102
107
  hooks.exemptFetch(subscriber);
103
108
  try {
104
109
  for (;;) {
105
- const group = await subscriber.recvGroup();
110
+ const group = await untilAborted(subscriber.recvGroup(), options.signal);
106
111
  if (!group)
107
- throw new Error(`group not found: ${sequence}`);
112
+ throw new NotFound(`group ${sequence}`);
108
113
  if (group.sequence === sequence) {
109
114
  // Close the subscription when the returned group finishes, not now: an
110
115
  // in-progress group must keep receiving frames for its lifetime (mirrors
@@ -114,7 +119,7 @@ async function fetchGroup(state, name, sequence, options = {}) {
114
119
  }
115
120
  group.close();
116
121
  if (group.sequence > sequence)
117
- throw new Error(`group not found: ${sequence}`);
122
+ throw new NotFound(`group ${sequence}`);
118
123
  }
119
124
  }
120
125
  catch (err) {
@@ -130,6 +135,7 @@ async function fetchGroup(state, name, sequence, options = {}) {
130
135
  export class Producer {
131
136
  #state = new BroadcastState();
132
137
  #announcer;
138
+ #path = Path.empty();
133
139
  constructor() {
134
140
  registerWire(this, this.#wire(false));
135
141
  }
@@ -138,6 +144,9 @@ export class Producer {
138
144
  producer.#announcer = announcer;
139
145
  };
140
146
  hooks.attachAnnouncer = attachAnnouncer;
147
+ stampProducer = (producer, path) => {
148
+ producer.#path = path;
149
+ };
141
150
  }
142
151
  /**
143
152
  * Settles once the broadcast closes: `null` on a clean close, or the abort {@link Error}.
@@ -146,9 +155,9 @@ export class Producer {
146
155
  get closed() {
147
156
  return this.#state.closed;
148
157
  }
149
- /** A read handle for this broadcast. */
158
+ /** A read handle for this broadcast, named by the path the origin created it at. */
150
159
  consume() {
151
- return makeConsumer(this.#state);
160
+ return makeConsumer({ state: this.#state, path: this.#path });
152
161
  }
153
162
  async #requested() {
154
163
  for (;;) {
@@ -204,8 +213,8 @@ export class Producer {
204
213
  /**
205
214
  * Advertise this broadcast's exact path, or re-price a standing advertisement in place.
206
215
  *
207
- * Call it once the tracks a subscriber needs first (a catalog) exist. The broadcast is
208
- * discoverable on the local origin from creation; announcing advertises it to peers. Retracts on
216
+ * Call it once the tracks a subscriber needs first (a catalog) exist. Until then the
217
+ * broadcast exists for nobody, on its own origin or at a peer. Retracts on
209
218
  * {@link unannounce} or {@link close}. Throws if this producer was not created through an
210
219
  * origin, or if the broadcast is already closed.
211
220
  */
@@ -217,11 +226,13 @@ export class Producer {
217
226
  throw new Error("broadcast is not attached to an origin");
218
227
  this.#announcer.announce(Route.normalize(route));
219
228
  }
220
- /** Retract the advertisement of this broadcast's path, if any. */
229
+ /**
230
+ * Retract the advertisement of this broadcast's path, if any, from local consumers and
231
+ * peers alike. {@link announce} brings it back.
232
+ */
221
233
  unannounce() {
222
234
  this.#announcer?.unannounce();
223
235
  }
224
- /** Close the broadcast, optionally with an error to abort waiters. Idempotent. */
225
236
  close(abort) {
226
237
  this.#announcer?.unannounce();
227
238
  this.#announcer = undefined;
@@ -241,10 +252,12 @@ let makeConsumer;
241
252
  */
242
253
  export class Consumer {
243
254
  #state;
255
+ #path;
244
256
  // Guards against a double close() on this handle over-decrementing the consumer count.
245
257
  #closed = false;
246
- constructor(state) {
247
- this.#state = state ?? new BroadcastState();
258
+ constructor(shared) {
259
+ this.#state = shared?.state ?? new BroadcastState();
260
+ this.#path = shared?.path ?? Path.empty();
248
261
  this.#state.consumers++;
249
262
  registerWire(this, {
250
263
  subscribe: (name, options) => subscribe(this.#state, name, options, true),
@@ -254,7 +267,24 @@ export class Consumer {
254
267
  });
255
268
  }
256
269
  static {
257
- makeConsumer = (state) => new Consumer(state);
270
+ makeConsumer = (shared) => new Consumer(shared);
271
+ hooks.stampPath = (target, path) => {
272
+ if (target instanceof Consumer)
273
+ target.#path = path;
274
+ else
275
+ stampProducer(target, path);
276
+ };
277
+ }
278
+ /**
279
+ * The path this handle names the broadcast by, which relative references in its catalog
280
+ * (hang's `broadcast` field) resolve against.
281
+ *
282
+ * An origin stamps each handle it hands out with the path it was requested at, relative to
283
+ * that origin handle's scope root, and a broadcast it created with the path it was created at.
284
+ * Empty for a standalone broadcast, which is then its own root: any `..` reference escapes.
285
+ */
286
+ get path() {
287
+ return this.#path;
258
288
  }
259
289
  /**
260
290
  * Settles once the broadcast closes: `null` on a clean close, or the abort {@link Error}.
@@ -269,18 +299,18 @@ export class Consumer {
269
299
  /**
270
300
  * Return another handle to the same broadcast, reference-counted with this one.
271
301
  *
272
- * Both handles read the same tracks and share one {@link closed} state; the broadcast
273
- * closes only once *every* handle has {@link close}d. Used by the connection's per-path
302
+ * Both handles read the same tracks, carry the same {@link path}, and share one {@link closed}
303
+ * state; the broadcast closes only once *every* handle has {@link close}d. Used by the connection's per-path
274
304
  * consume cache to share one subscription across callers. Subclasses that resolve info over
275
305
  * the wire override this to preserve their type (see the wire layer's consumed broadcast).
276
306
  */
277
307
  clone() {
278
308
  return new Consumer(this.shareState());
279
309
  }
280
- // Hand this consumer's backing state to a clone. Opaque (`never`) so the state type stays
281
- // unexported; a subclass passes it straight back into its own `super(...)`.
310
+ // Hand this consumer's backing state and path to a clone. Opaque (`never`) so the state type
311
+ // stays unexported; a subclass passes it straight back into its own `super(...)`.
282
312
  shareState() {
283
- return this.#state;
313
+ return { state: this.#state, path: this.#path };
284
314
  }
285
315
  /** Get a lazy handle for a track on this broadcast. Repeat subscriptions dedupe onto one upstream subscription. */
286
316
  track(name) {
@@ -299,10 +329,6 @@ export class Consumer {
299
329
  await Signal.race(this.#state.requested, this.#state.closed);
300
330
  }
301
331
  }
302
- /**
303
- * Release this handle. The broadcast is closed (optionally with an error to abort waiters)
304
- * once this was the last live handle; while other {@link clone}s remain open it stays live.
305
- */
306
332
  close(abort) {
307
333
  if (this.#closed)
308
334
  return;
package/broadcast.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../src/broadcast.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAmB,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,KAAK,EAAsB,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,OAAO,EAA0B,MAAM,WAAW,CAAC;AAU1E,IAAI,eAAmE,CAAC;AAExE,0EAA0E;AAC1E,MAAM,cAAc;IACnB,SAAS,GAAG,IAAI,MAAM,CAAkB,EAAE,CAAC,CAAC;IAC5C,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;IACnC,MAAM,GAAG,IAAI,IAAI,EAAgB,CAAC;IAClC,MAAM,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC3C,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC7C,uFAAuF;IACvF,0FAA0F;IAC1F,SAAS,GAAG,CAAC,CAAC;CACd;AAED,SAAS,cAAc,CAAC,KAAqB;IAC5C,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IACzC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;IAClD,OAAO,SAAS,CAAC,GAAG,EAAE,CAAC;AACxB,CAAC;AAED,+EAA+E;AAC/E,8EAA8E;AAC9E,6DAA6D;AAC7D,EAAE;AACF,sFAAsF;AACtF,+CAA+C;AAC/C,SAAS,UAAU,CAAC,KAAqB,EAAE,KAAa;IACv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AAC;IAED,0FAA0F;IAC1F,4EAA4E;IAClE,UAAU;QACnB,OAAO,IAAI,CAAC,MAAe,CAAC;IAC7B,CAAC;IAED,mHAAmH;IACnH,KAAK,CAAC,IAAY;QACjB,OAAO,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,UAAU;QACf,SAAS,CAAC;YACT,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC5C,IAAI,OAAO;gBAAE,OAAO,OAAO,CAAC;YAE5B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACzC,IAAI,MAAM,YAAY,KAAK;gBAAE,MAAM,MAAM,CAAC;YAC1C,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,SAAS,CAAC;YAE3C,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC9D,CAAC;IACF,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAa;QAClB,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO;QACzB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC;YAAE,OAAO;QACxC,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC;CACD","sourcesContent":["/**\n * Broadcast role handles: a named collection of tracks produced by a publisher.\n *\n * @module\n */\nimport { type GetPromise, Once, Signal } from \"@moq/signals\";\nimport type { Consumer as GroupConsumer } from \"./group.ts\";\nimport { Route } from \"./hop.ts\";\nimport { hooks, type TrackSequence } from \"./internal.ts\";\nimport * as track from \"./track.ts\";\nimport { registerWire, trackOf, type Broadcast as Wire } from \"./wire.ts\";\n\n/** The origin callback a created broadcast uses to advertise its exact path. @internal */\nexport interface Announcer {\n\t/** Advertise or re-price this broadcast's path. */\n\tannounce(route: Route): void;\n\t/** Retract the advertisement, leaving the broadcast reachable by exact path. */\n\tunannounce(): void;\n}\n\nlet attachAnnouncer: (producer: Producer, announcer: Announcer) => void;\n\n/** Reactive backing state shared by broadcast producers and consumers. */\nclass BroadcastState {\n\trequested = new Signal<track.Request[]>([]);\n\tpending = new Set<track.Request>();\n\tclosed = new Once<Error | null>();\n\ttracks = new Map<string, track.Producer>();\n\tsequences = new Map<string, TrackSequence>();\n\t// Live consumer handles sharing this state (see {@link Consumer.clone}). The broadcast\n\t// closes once the last one closes, so a shared consumer can be handed to several callers.\n\tconsumers = 0;\n}\n\nfunction dequeueRequest(state: BroadcastState): track.Request | undefined {\n\tconst requested = state.requested.peek();\n\trequested.sort((a, b) => a.priority - b.priority);\n\treturn requested.pop();\n}\n\n// Close the broadcast and reject any requests still pending in the queue, so a\n// subscriber blocked on the track's info() or group reads is unblocked rather\n// than left waiting on a producer that will never be served.\n//\n// Once.set throws on a second settle, and the producer and each consumer handle close\n// independently, so this has to be idempotent.\nfunction closeState(state: BroadcastState, abort?: Error) {\n\tif (state.closed.peek() !== undefined) return;\n\tstate.closed.set(abort ?? null);\n\tfor (const request of state.pending) request.reject(abort);\n\tstate.requested.mutate((requests) => {\n\t\trequests.length = 0;\n\t});\n}\n\n// `register` is set on the subscribing (consumer) side: the fresh producer is cached in\n// `state.tracks` so repeat subscriptions to the same track fan out from one upstream subscription\n// instead of opening a new one, mirroring the Rust `broadcast::Consumer::track` weak-dedup. The\n// consumer wire watches the producer's demand ({@link track.Producer.used}) and tears the upstream\n// down once its last subscriber leaves, closing the producer, which evicts the cache entry below.\n// The publishing side leaves `register` false: `state.tracks` there holds only the tracks the app\n// inserted, and a dynamic serve stays one request per peer subscription.\nfunction subscribe(\n\tstate: BroadcastState,\n\tname: string,\n\toptions: track.Subscription = {},\n\tregister = false,\n): track.Subscriber {\n\tif (state.closed.peek() !== undefined) {\n\t\tthrow new Error(`broadcast is closed: ${state.closed.peek()}`);\n\t}\n\n\tconst existing = state.tracks.get(name);\n\tif (existing) {\n\t\tif (existing.closed.peek() === undefined) return existing.subscribe(options);\n\t\tstate.tracks.delete(name);\n\t}\n\n\tconst producer = new track.Producer(name);\n\tconst subscriber = producer.subscribe(options);\n\n\tif (register) {\n\t\tstate.tracks.set(name, producer);\n\t\t// Drop the cache entry once the upstream closes (the wire tears it down when its last\n\t\t// subscriber leaves), so a later subscribe re-opens it.\n\t\tvoid producer.closed.then(() => {\n\t\t\tif (state.tracks.get(name) === producer) state.tracks.delete(name);\n\t\t});\n\t}\n\n\tstate.requested.mutate((requested) => {\n\t\trequested.push(hooks.makeRequest({ name, producer, sequences: state.sequences, pending: state.pending }));\n\t});\n\n\treturn subscriber;\n}\n\nasync function resolveTrackInfo(state: BroadcastState, name: string): Promise<track.Info> {\n\tconst existing = state.tracks.get(name);\n\tif (existing && existing.closed.peek() === undefined) {\n\t\treturn existing.info();\n\t}\n\n\tif (state.closed.peek() !== undefined) {\n\t\treturn Promise.reject(new Error(`broadcast is closed: ${state.closed.peek()}`));\n\t}\n\n\tconst producer = new track.Producer(name);\n\tstate.requested.mutate((requested) => {\n\t\trequested.push(hooks.makeRequest({ name, producer, sequences: state.sequences, pending: state.pending }));\n\t});\n\n\ttry {\n\t\treturn await producer.info();\n\t} finally {\n\t\tproducer.close();\n\t}\n}\n\n// Serve a group from the local retained window by subscribing and scanning to the\n// requested sequence. The default for a produced broadcast; the consuming wire layer\n// overrides it to fetch over the network (or to reject when the transport has no FETCH).\nasync function fetchGroup(\n\tstate: BroadcastState,\n\tname: string,\n\tsequence: number,\n\toptions: track.FetchGroupOptions = {},\n): Promise<GroupConsumer> {\n\tconst subscriber = subscribe(state, name, { priority: options.priority });\n\thooks.exemptFetch(subscriber);\n\ttry {\n\t\tfor (;;) {\n\t\t\tconst group = await subscriber.recvGroup();\n\t\t\tif (!group) throw new Error(`group not found: ${sequence}`);\n\t\t\tif (group.sequence === sequence) {\n\t\t\t\t// Close the subscription when the returned group finishes, not now: an\n\t\t\t\t// in-progress group must keep receiving frames for its lifetime (mirrors\n\t\t\t\t// Rust poll_fetch). Also fires if the caller closes the group early.\n\t\t\t\tvoid group.closed.then(() => subscriber.close());\n\t\t\t\treturn group;\n\t\t\t}\n\n\t\t\tgroup.close();\n\t\t\tif (group.sequence > sequence) throw new Error(`group not found: ${sequence}`);\n\t\t}\n\t} catch (err) {\n\t\tsubscriber.close();\n\t\tthrow err;\n\t}\n}\n\n/**\n * The write side of a broadcast.\n *\n * @public\n */\nexport class Producer {\n\t#state = new BroadcastState();\n\t#announcer?: Announcer;\n\n\tconstructor() {\n\t\tregisterWire(this, this.#wire(false));\n\t}\n\n\tstatic {\n\t\tattachAnnouncer = (producer, announcer) => {\n\t\t\tproducer.#announcer = announcer;\n\t\t};\n\t\thooks.attachAnnouncer = attachAnnouncer;\n\t}\n\n\t/**\n\t * Settles once the broadcast 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/** A read handle for this broadcast. */\n\tconsume(): Consumer {\n\t\treturn makeConsumer(this.#state);\n\t}\n\n\tasync #requested(): Promise<track.Request | undefined> {\n\t\tfor (;;) {\n\t\t\tconst request = dequeueRequest(this.#state);\n\t\t\tif (request) return request;\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.requested, this.#state.closed);\n\t\t}\n\t}\n\n\t/** Insert a track that is served directly, without an on-demand request round-trip. */\n\tinsertTrack(track: track.Producer): void {\n\t\tif (this.#state.closed.peek() !== undefined) {\n\t\t\tthrow new Error(`broadcast is closed: ${this.#state.closed.peek()}`);\n\t\t}\n\n\t\tconst existing = this.#state.tracks.get(track.name);\n\t\tif (existing && existing.closed.peek() === undefined) {\n\t\t\tthrow new Error(`duplicate track: ${track.name}`);\n\t\t}\n\n\t\tthis.#state.tracks.set(track.name, track);\n\n\t\tvoid track.closed.then(() => {\n\t\t\tif (this.#state.tracks.get(track.name) === track) {\n\t\t\t\tthis.#state.tracks.delete(track.name);\n\t\t\t}\n\t\t});\n\t}\n\n\t/** Create a track, insert it into the broadcast, and return its producer. */\n\tcreateTrack(name: string, info: Partial<track.Info> = {}): track.Producer {\n\t\tconst producer = new track.Producer(name).accept(info);\n\t\tthis.insertTrack(producer);\n\t\treturn producer;\n\t}\n\n\t/** Remove a statically inserted track by name. */\n\tremoveTrack(name: string): void {\n\t\tthis.#state.tracks.delete(name);\n\t}\n\n\t/** A lazy read handle for a track on this broadcast. */\n\ttrack(name: string): track.Consumer {\n\t\treturn trackOf(name, this);\n\t}\n\n\t#wire(register: boolean): Wire {\n\t\treturn {\n\t\t\tsubscribe: (name, options) => subscribe(this.#state, name, options, register),\n\t\t\tresolveTrackInfo: (name) => resolveTrackInfo(this.#state, name),\n\t\t\tfetchGroup: (name, sequence, options) => fetchGroup(this.#state, name, sequence, options),\n\t\t\trequested: () => this.#requested(),\n\t\t};\n\t}\n\n\t/**\n\t * Advertise this broadcast's exact path, or re-price a standing advertisement in place.\n\t *\n\t * Call it once the tracks a subscriber needs first (a catalog) exist. The broadcast is\n\t * discoverable on the local origin from creation; announcing advertises it to peers. Retracts on\n\t * {@link unannounce} or {@link close}. Throws if this producer was not created through an\n\t * origin, or if the broadcast is already closed.\n\t */\n\tannounce(route: Route | { hops?: Route[\"hops\"]; cost?: Route[\"cost\"] | bigint } = Route.default): void {\n\t\tif (this.#state.closed.peek() !== undefined) {\n\t\t\tthrow new Error(`broadcast is closed: ${this.#state.closed.peek()}`);\n\t\t}\n\t\tif (!this.#announcer) throw new Error(\"broadcast is not attached to an origin\");\n\t\tthis.#announcer.announce(Route.normalize(route));\n\t}\n\n\t/** Retract the advertisement of this broadcast's path, if any. */\n\tunannounce(): void {\n\t\tthis.#announcer?.unannounce();\n\t}\n\n\t/** Close the broadcast, optionally with an error to abort waiters. Idempotent. */\n\tclose(abort?: Error) {\n\t\tthis.#announcer?.unannounce();\n\t\tthis.#announcer = undefined;\n\t\tcloseState(this.#state, abort);\n\t}\n}\n\n// Constructs a Consumer from within this module without exposing a public constructor\n// that would leak the unexported BroadcastState. Assigned in the class's static block.\nlet makeConsumer: (state: BroadcastState) => Consumer;\n\n/**\n * The read side of a broadcast.\n *\n * Created internally: obtain one from {@link Producer.consume} or an origin request.\n * The wire layers subclass it to resolve tracks over the network.\n *\n * @public\n */\nexport class Consumer {\n\t#state: BroadcastState;\n\n\t// Guards against a double close() on this handle over-decrementing the consumer count.\n\t#closed = false;\n\n\tprotected constructor(state?: never);\n\tprotected constructor(state?: BroadcastState) {\n\t\tthis.#state = state ?? new BroadcastState();\n\t\tthis.#state.consumers++;\n\t\tregisterWire(this, {\n\t\t\tsubscribe: (name, options) => subscribe(this.#state, name, options, true),\n\t\t\tresolveTrackInfo: (name) => resolveTrackInfo(this.#state, name),\n\t\t\tfetchGroup: (name, sequence, options) => fetchGroup(this.#state, name, sequence, options),\n\t\t\trequested: () => this.#requested(),\n\t\t});\n\t}\n\n\tstatic {\n\t\tmakeConsumer = (state) => new Consumer(state as never);\n\t}\n\n\t/**\n\t * Settles once the broadcast 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\t * Shared by every {@link clone}: it settles once the last handle closes. The subscribing\n\t * wire layer peeks it to evict a closed entry from its per-path consume cache.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/**\n\t * Return another handle to the same broadcast, reference-counted with this one.\n\t *\n\t * Both handles read the same tracks and share one {@link closed} state; the broadcast\n\t * closes only once *every* handle has {@link close}d. Used by the connection's per-path\n\t * consume cache to share one subscription across callers. Subclasses that resolve info over\n\t * the wire override this to preserve their type (see the wire layer's consumed broadcast).\n\t */\n\tclone(): Consumer {\n\t\treturn new Consumer(this.shareState());\n\t}\n\n\t// Hand this consumer's backing state to a clone. Opaque (`never`) so the state type stays\n\t// unexported; a subclass passes it straight back into its own `super(...)`.\n\tprotected shareState(): never {\n\t\treturn this.#state as never;\n\t}\n\n\t/** Get a lazy handle for a track on this broadcast. Repeat subscriptions dedupe onto one upstream subscription. */\n\ttrack(name: string): track.Consumer {\n\t\treturn trackOf(name, this);\n\t}\n\n\tasync #requested(): Promise<track.Request | undefined> {\n\t\tfor (;;) {\n\t\t\tconst request = dequeueRequest(this.#state);\n\t\t\tif (request) return request;\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.requested, this.#state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * Release this handle. The broadcast is closed (optionally with an error to abort waiters)\n\t * once this was the last live handle; while other {@link clone}s remain open it stays live.\n\t */\n\tclose(abort?: Error) {\n\t\tif (this.#closed) return;\n\t\tthis.#closed = true;\n\t\tif (--this.#state.consumers > 0) return;\n\t\tcloseState(this.#state, abort);\n\t}\n}\n"]}
1
+ {"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../src/broadcast.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAmB,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,KAAK,EAAsB,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,OAAO,EAA0B,MAAM,WAAW,CAAC;A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AC,CAAC;IAChC,CAAC;CACD","sourcesContent":["/**\n * Broadcast role handles: a named collection of tracks produced by a publisher.\n *\n * @module\n */\nimport { type GetPromise, Once, Signal } from \"@moq/signals\";\nimport { NotFound } from \"./error.ts\";\nimport type { Consumer as GroupConsumer } from \"./group.ts\";\nimport { Route } from \"./hop.ts\";\nimport { hooks, type TrackSequence } from \"./internal.ts\";\nimport * as Path from \"./path.ts\";\nimport * as track from \"./track.ts\";\nimport { untilAborted } from \"./util/abort.ts\";\nimport { registerWire, trackOf, type Broadcast as Wire } from \"./wire.ts\";\n\n/** The origin callback a created broadcast uses to advertise its exact path. @internal */\nexport interface Announcer {\n\t/** Advertise or re-price this broadcast's path. */\n\tannounce(route: Route): void;\n\t/** Retract the advertisement from local consumers and peers alike. */\n\tunannounce(): void;\n}\n\nlet attachAnnouncer: (producer: Producer, announcer: Announcer) => void;\nlet stampProducer: (producer: Producer, path: Path.Valid) => void;\n\n/** Reactive backing state shared by broadcast producers and consumers. */\nclass BroadcastState {\n\trequested = new Signal<track.Request[]>([]);\n\tpending = new Set<track.Request>();\n\tclosed = new Once<Error | null>();\n\ttracks = new Map<string, track.Producer>();\n\tsequences = new Map<string, TrackSequence>();\n\t// Live consumer handles sharing this state (see {@link Consumer.clone}). The broadcast\n\t// closes once the last one closes, so a shared consumer can be handed to several callers.\n\tconsumers = 0;\n}\n\nfunction dequeueRequest(state: BroadcastState): track.Request | undefined {\n\tconst requested = state.requested.peek();\n\trequested.sort((a, b) => a.priority - b.priority);\n\treturn requested.pop();\n}\n\n// Close the broadcast and reject any requests still pending in the queue, so a\n// subscriber blocked on the track's info() or group reads is unblocked rather\n// than left waiting on a producer that will never be served.\n//\n// Once.set throws on a second settle, and the producer and each consumer handle close\n// independently, so this has to be idempotent.\nfunction closeState(state: BroadcastState, abort?: Error) {\n\tif (state.closed.peek() !== undefined) return;\n\tstate.closed.set(abort ?? null);\n\tfor (const request of state.pending) request.reject(abort);\n\tstate.requested.mutate((requests) => {\n\t\trequests.length = 0;\n\t});\n}\n\n// `register` is set on the subscribing (consumer) side: the fresh producer is cached in\n// `state.tracks` so repeat subscriptions to the same track fan out from one upstream subscription\n// instead of opening a new one, mirroring the Rust `broadcast::Consumer::track` weak-dedup. The\n// consumer wire watches the producer's demand ({@link track.Producer.used}) and tears the upstream\n// down once its last subscriber leaves, closing the producer, which evicts the cache entry below.\n// The publishing side leaves `register` false: `state.tracks` there holds only the tracks the app\n// inserted, and a dynamic serve stays one request per peer subscription.\nfunction subscribe(\n\tstate: BroadcastState,\n\tname: string,\n\toptions: track.Subscription = {},\n\tregister = false,\n): track.Subscriber {\n\tif (state.closed.peek() !== undefined) {\n\t\tthrow new Error(`broadcast is closed: ${state.closed.peek()}`);\n\t}\n\n\tconst existing = state.tracks.get(name);\n\tif (existing) {\n\t\tif (existing.closed.peek() === undefined) return existing.subscribe(options);\n\t\tstate.tracks.delete(name);\n\t}\n\n\tconst producer = new track.Producer(name);\n\tconst subscriber = producer.subscribe(options);\n\n\tif (register) {\n\t\tstate.tracks.set(name, producer);\n\t\t// Drop the cache entry once the upstream closes (the wire tears it down when its last\n\t\t// subscriber leaves), so a later subscribe re-opens it.\n\t\tvoid producer.closed.then(() => {\n\t\t\tif (state.tracks.get(name) === producer) state.tracks.delete(name);\n\t\t});\n\t}\n\n\tstate.requested.mutate((requested) => {\n\t\trequested.push(hooks.makeRequest({ name, producer, sequences: state.sequences, pending: state.pending }));\n\t});\n\n\treturn subscriber;\n}\n\nasync function resolveTrackInfo(state: BroadcastState, name: string): Promise<track.Info> {\n\tconst existing = state.tracks.get(name);\n\tif (existing && existing.closed.peek() === undefined) {\n\t\treturn existing.info();\n\t}\n\n\tif (state.closed.peek() !== undefined) {\n\t\treturn Promise.reject(new Error(`broadcast is closed: ${state.closed.peek()}`));\n\t}\n\n\tconst producer = new track.Producer(name);\n\tstate.requested.mutate((requested) => {\n\t\trequested.push(hooks.makeRequest({ name, producer, sequences: state.sequences, pending: state.pending }));\n\t});\n\n\ttry {\n\t\treturn await producer.info();\n\t} finally {\n\t\tproducer.close();\n\t}\n}\n\n// Serve a group from the local retained window by subscribing and scanning to the\n// requested sequence. The default for a produced broadcast; the consuming wire layer\n// overrides it to fetch over the network (or to reject when the transport has no FETCH).\nasync function fetchGroup(\n\tstate: BroadcastState,\n\tname: string,\n\tsequence: number,\n\toptions: track.FetchGroupOptions = {},\n): Promise<GroupConsumer> {\n\toptions.signal?.throwIfAborted();\n\tconst subscriber = subscribe(state, name, { priority: options.priority });\n\thooks.exemptFetch(subscriber);\n\ttry {\n\t\tfor (;;) {\n\t\t\tconst group = await untilAborted(subscriber.recvGroup(), options.signal);\n\t\t\tif (!group) throw new NotFound(`group ${sequence}`);\n\t\t\tif (group.sequence === sequence) {\n\t\t\t\t// Close the subscription when the returned group finishes, not now: an\n\t\t\t\t// in-progress group must keep receiving frames for its lifetime (mirrors\n\t\t\t\t// Rust poll_fetch). Also fires if the caller closes the group early.\n\t\t\t\tvoid group.closed.then(() => subscriber.close());\n\t\t\t\treturn group;\n\t\t\t}\n\n\t\t\tgroup.close();\n\t\t\tif (group.sequence > sequence) throw new NotFound(`group ${sequence}`);\n\t\t}\n\t} catch (err) {\n\t\tsubscriber.close();\n\t\tthrow err;\n\t}\n}\n\n/**\n * The write side of a broadcast.\n *\n * @public\n */\nexport class Producer {\n\t#state = new BroadcastState();\n\t#announcer?: Announcer;\n\t#path = Path.empty();\n\n\tconstructor() {\n\t\tregisterWire(this, this.#wire(false));\n\t}\n\n\tstatic {\n\t\tattachAnnouncer = (producer, announcer) => {\n\t\t\tproducer.#announcer = announcer;\n\t\t};\n\t\thooks.attachAnnouncer = attachAnnouncer;\n\t\tstampProducer = (producer, path) => {\n\t\t\tproducer.#path = path;\n\t\t};\n\t}\n\n\t/**\n\t * Settles once the broadcast 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/** A read handle for this broadcast, named by the path the origin created it at. */\n\tconsume(): Consumer {\n\t\treturn makeConsumer({ state: this.#state, path: this.#path });\n\t}\n\n\tasync #requested(): Promise<track.Request | undefined> {\n\t\tfor (;;) {\n\t\t\tconst request = dequeueRequest(this.#state);\n\t\t\tif (request) return request;\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.requested, this.#state.closed);\n\t\t}\n\t}\n\n\t/** Insert a track that is served directly, without an on-demand request round-trip. */\n\tinsertTrack(track: track.Producer): void {\n\t\tif (this.#state.closed.peek() !== undefined) {\n\t\t\tthrow new Error(`broadcast is closed: ${this.#state.closed.peek()}`);\n\t\t}\n\n\t\tconst existing = this.#state.tracks.get(track.name);\n\t\tif (existing && existing.closed.peek() === undefined) {\n\t\t\tthrow new Error(`duplicate track: ${track.name}`);\n\t\t}\n\n\t\tthis.#state.tracks.set(track.name, track);\n\n\t\tvoid track.closed.then(() => {\n\t\t\tif (this.#state.tracks.get(track.name) === track) {\n\t\t\t\tthis.#state.tracks.delete(track.name);\n\t\t\t}\n\t\t});\n\t}\n\n\t/** Create a track, insert it into the broadcast, and return its producer. */\n\tcreateTrack(name: string, info: Partial<track.Info> = {}): track.Producer {\n\t\tconst producer = new track.Producer(name).accept(info);\n\t\tthis.insertTrack(producer);\n\t\treturn producer;\n\t}\n\n\t/** Remove a statically inserted track by name. */\n\tremoveTrack(name: string): void {\n\t\tthis.#state.tracks.delete(name);\n\t}\n\n\t/** A lazy read handle for a track on this broadcast. */\n\ttrack(name: string): track.Consumer {\n\t\treturn trackOf(name, this);\n\t}\n\n\t#wire(register: boolean): Wire {\n\t\treturn {\n\t\t\tsubscribe: (name, options) => subscribe(this.#state, name, options, register),\n\t\t\tresolveTrackInfo: (name) => resolveTrackInfo(this.#state, name),\n\t\t\tfetchGroup: (name, sequence, options) => fetchGroup(this.#state, name, sequence, options),\n\t\t\trequested: () => this.#requested(),\n\t\t};\n\t}\n\n\t/**\n\t * Advertise this broadcast's exact path, or re-price a standing advertisement in place.\n\t *\n\t * Call it once the tracks a subscriber needs first (a catalog) exist. Until then the\n\t * broadcast exists for nobody, on its own origin or at a peer. Retracts on\n\t * {@link unannounce} or {@link close}. Throws if this producer was not created through an\n\t * origin, or if the broadcast is already closed.\n\t */\n\tannounce(route: Route | { hops?: Route[\"hops\"]; cost?: Route[\"cost\"] | bigint } = Route.default): void {\n\t\tif (this.#state.closed.peek() !== undefined) {\n\t\t\tthrow new Error(`broadcast is closed: ${this.#state.closed.peek()}`);\n\t\t}\n\t\tif (!this.#announcer) throw new Error(\"broadcast is not attached to an origin\");\n\t\tthis.#announcer.announce(Route.normalize(route));\n\t}\n\n\t/**\n\t * Retract the advertisement of this broadcast's path, if any, from local consumers and\n\t * peers alike. {@link announce} brings it back.\n\t */\n\tunannounce(): void {\n\t\tthis.#announcer?.unannounce();\n\t}\n\n\t/** End the broadcast for good: retract it, serve no new tracks, and refuse a later {@link announce}. Idempotent. */\n\tclose(): void;\n\t/** @deprecated A broadcast end carries no cause; call `close()` without one. */\n\tclose(abort?: Error): void;\n\tclose(abort?: Error) {\n\t\tthis.#announcer?.unannounce();\n\t\tthis.#announcer = undefined;\n\t\tcloseState(this.#state, abort);\n\t}\n}\n\n// What a new consumer handle inherits: the shared broadcast plus the path naming it.\ninterface Shared {\n\tstate: BroadcastState;\n\tpath: Path.Valid;\n}\n\n// Constructs a Consumer from within this module without exposing a public constructor\n// that would leak the unexported BroadcastState. Assigned in the class's static block.\nlet makeConsumer: (shared: Shared) => Consumer;\n\n/**\n * The read side of a broadcast.\n *\n * Created internally: obtain one from {@link Producer.consume} or an origin request.\n * The wire layers subclass it to resolve tracks over the network.\n *\n * @public\n */\nexport class Consumer {\n\t#state: BroadcastState;\n\t#path: Path.Valid;\n\n\t// Guards against a double close() on this handle over-decrementing the consumer count.\n\t#closed = false;\n\n\tprotected constructor(shared?: never);\n\tprotected constructor(shared?: Shared) {\n\t\tthis.#state = shared?.state ?? new BroadcastState();\n\t\tthis.#path = shared?.path ?? Path.empty();\n\t\tthis.#state.consumers++;\n\t\tregisterWire(this, {\n\t\t\tsubscribe: (name, options) => subscribe(this.#state, name, options, true),\n\t\t\tresolveTrackInfo: (name) => resolveTrackInfo(this.#state, name),\n\t\t\tfetchGroup: (name, sequence, options) => fetchGroup(this.#state, name, sequence, options),\n\t\t\trequested: () => this.#requested(),\n\t\t});\n\t}\n\n\tstatic {\n\t\tmakeConsumer = (shared) => new Consumer(shared as never);\n\t\thooks.stampPath = (target, path) => {\n\t\t\tif (target instanceof Consumer) target.#path = path;\n\t\t\telse stampProducer(target, path);\n\t\t};\n\t}\n\n\t/**\n\t * The path this handle names the broadcast by, which relative references in its catalog\n\t * (hang's `broadcast` field) resolve against.\n\t *\n\t * An origin stamps each handle it hands out with the path it was requested at, relative to\n\t * that origin handle's scope root, and a broadcast it created with the path it was created at.\n\t * Empty for a standalone broadcast, which is then its own root: any `..` reference escapes.\n\t */\n\tget path(): Path.Valid {\n\t\treturn this.#path;\n\t}\n\n\t/**\n\t * Settles once the broadcast 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\t * Shared by every {@link clone}: it settles once the last handle closes. The subscribing\n\t * wire layer peeks it to evict a closed entry from its per-path consume cache.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/**\n\t * Return another handle to the same broadcast, reference-counted with this one.\n\t *\n\t * Both handles read the same tracks, carry the same {@link path}, and share one {@link closed}\n\t * state; the broadcast closes only once *every* handle has {@link close}d. Used by the connection's per-path\n\t * consume cache to share one subscription across callers. Subclasses that resolve info over\n\t * the wire override this to preserve their type (see the wire layer's consumed broadcast).\n\t */\n\tclone(): Consumer {\n\t\treturn new Consumer(this.shareState());\n\t}\n\n\t// Hand this consumer's backing state and path to a clone. Opaque (`never`) so the state type\n\t// stays unexported; a subclass passes it straight back into its own `super(...)`.\n\tprotected shareState(): never {\n\t\treturn { state: this.#state, path: this.#path } satisfies Shared as never;\n\t}\n\n\t/** Get a lazy handle for a track on this broadcast. Repeat subscriptions dedupe onto one upstream subscription. */\n\ttrack(name: string): track.Consumer {\n\t\treturn trackOf(name, this);\n\t}\n\n\tasync #requested(): Promise<track.Request | undefined> {\n\t\tfor (;;) {\n\t\t\tconst request = dequeueRequest(this.#state);\n\t\t\tif (request) return request;\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.requested, this.#state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * Release this handle. The broadcast is closed once this was the last live handle;\n\t * while other {@link clone}s remain open it stays live.\n\t */\n\tclose(): void;\n\t/** @deprecated A broadcast end carries no cause; call `close()` without one. */\n\tclose(abort?: Error): void;\n\tclose(abort?: Error) {\n\t\tif (this.#closed) return;\n\t\tthis.#closed = true;\n\t\tif (--this.#state.consumers > 0) return;\n\t\tcloseState(this.#state, abort);\n\t}\n}\n"]}
@@ -19,7 +19,8 @@ export async function accept({ transport, url, ...props }) {
19
19
  return connection;
20
20
  }
21
21
  async function acceptInner(transport, url, props) {
22
- // @ts-expect-error - TODO: add protocol to WebTransport
22
+ // The DOM lib has no `protocol` property yet. It is "" when none was negotiated, and
23
+ // undefined in a browser that predates subprotocols (Firefox before 155).
23
24
  const protocol = transport.protocol;
24
25
  const wiring = {
25
26
  discovery: props.discovery ?? true,
@@ -49,6 +50,9 @@ async function acceptInner(transport, url, props) {
49
50
  else if (protocol === Ietf.ALPN.DRAFT_15) {
50
51
  return acceptSetup(transport, url, Ietf.Version.DRAFT_15, wiring);
51
52
  }
53
+ else if (protocol === Lite.ALPN_07_WIP) {
54
+ return new Lite.Connection({ url, quic: transport, version: Lite.Version.DRAFT_07, ...wiring });
55
+ }
52
56
  else if (protocol === Lite.ALPN_06) {
53
57
  return new Lite.Connection({ url, quic: transport, version: Lite.Version.DRAFT_06, ...wiring });
54
58
  }
@@ -73,14 +77,16 @@ async function acceptInner(transport, url, props) {
73
77
  * a pair of uni streams using stream type 0x2F00.
74
78
  */
75
79
  async function acceptAlpn(transport, url, version, wiring) {
76
- const { control, solicit, cluster } = await exchangeSetup(transport, version, "moq-lite-js");
80
+ const { control, early, solicit, hidden, cluster } = await exchangeSetup(transport, version, "moq-lite-js");
77
81
  return new Ietf.Connection({
78
82
  ...wiring,
79
83
  client: false,
80
84
  url,
81
85
  quic: transport,
82
86
  control,
87
+ early,
83
88
  solicit,
89
+ hidden,
84
90
  cluster,
85
91
  // v17+ uses NativeSession which manages its own request IDs; maxRequestId is unused.
86
92
  maxRequestId: 0n,
@@ -93,7 +99,7 @@ async function acceptAlpn(transport, url, version, wiring) {
93
99
  */
94
100
  async function acceptSetup(transport, url, version, wiring) {
95
101
  // Accept bidi, read ClientSetup, write ServerSetup
96
- const stream = await Stream.accept(transport);
102
+ const stream = await Stream.accept(transport, version);
97
103
  if (!stream)
98
104
  throw new Error("no incoming bidi stream for SETUP");
99
105
  const clientCompat = await stream.reader.u53();
@@ -107,6 +113,7 @@ async function acceptSetup(transport, url, version, wiring) {
107
113
  params.setVarint(Ietf.SetupOption.MaxRequestId, 42069n);
108
114
  params.setBytes(Ietf.SetupOption.Implementation, encoder.encode("moq-lite-js"));
109
115
  Ietf.solicitIntoSetup(params);
116
+ Ietf.hiddenIntoSetup(params);
110
117
  const server = new Ietf.ServerSetup({ version, parameters: params });
111
118
  await server.encode(stream.writer, version);
112
119
  const maxRequestId = 42069n;
@@ -119,11 +126,12 @@ async function acceptSetup(transport, url, version, wiring) {
119
126
  maxRequestId,
120
127
  version,
121
128
  solicit: Ietf.solicitFromSetup(client.parameters),
129
+ hidden: Ietf.hiddenFromSetup(client.parameters),
122
130
  });
123
131
  }
124
132
  async function acceptNegotiated(transport, url, wiring, version) {
125
133
  const setupVersion = Ietf.Version.DRAFT_14;
126
- const stream = await Stream.accept(transport);
134
+ const stream = await Stream.accept(transport, setupVersion);
127
135
  if (!stream)
128
136
  throw new Error("no incoming bidi stream for SETUP");
129
137
  const clientCompat = await stream.reader.u53();
@@ -150,6 +158,7 @@ async function acceptNegotiated(transport, url, wiring, version) {
150
158
  params.setVarint(Ietf.SetupOption.MaxRequestId, 42069n);
151
159
  params.setBytes(Ietf.SetupOption.Implementation, encoder.encode("moq-lite-js"));
152
160
  Ietf.solicitIntoSetup(params);
161
+ Ietf.hiddenIntoSetup(params);
153
162
  const server = new Ietf.ServerSetup({ version: selectedVersion, parameters: params });
154
163
  await server.encode(stream.writer, setupVersion);
155
164
  if (Object.values(Lite.Version).includes(selectedVersion)) {
@@ -172,6 +181,7 @@ async function acceptNegotiated(transport, url, wiring, version) {
172
181
  maxRequestId,
173
182
  version: selectedVersion,
174
183
  solicit: Ietf.solicitFromSetup(client.parameters),
184
+ hidden: Ietf.hiddenFromSetup(client.parameters),
175
185
  });
176
186
  }
177
187
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"accept.js","sourceRoot":"","sources":["../../src/connection/accept.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAqC/C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,KAAK,EAAe;IACrE,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,SAAS,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5D,IAAI,KAAK,CAAC,OAAO;QAAE,gBAAgB,CAAC,UAAU,EAAE,KAAK,C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,EAAE,CAAC;QAClF,MAAM,YAAY,GAAG,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;QACtF,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC;YAC1B,GAAG,MAAM;YACT,MAAM,EAAE,KAAK;YACb,GAAG;YACH,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,MAAM;YACf,YAAY;YACZ,OAAO,EAAE,eAAmC;YAC5C,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC;SACjD,CAAC,CAAC;IACJ,CAAC;SAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,wBAAwB,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACzE,CAAC;AACF,CAAC","sourcesContent":["import * as Ietf from \"../ietf/index.ts\";\nimport * as Lite from \"../lite/index.ts\";\nimport type { Consumer as OriginConsumer, Producer as OriginProducer } from \"../origin.ts\";\nimport { Stream } from \"../stream.ts\";\nimport type { Established } from \"./established.ts\";\nimport { forwardAnnounced } from \"./forward.ts\";\nimport { exchangeSetup } from \"./handshake.ts\";\n\n/** Options for {@link accept}. */\nexport interface AcceptProps {\n\t/** The accepted transport. */\n\ttransport: WebTransport;\n\t/** The request URL associated with the transport. */\n\turl: URL;\n\n\t/** Version to select during SETUP negotiation (for non-ALPN paths). */\n\tversion?: number;\n\n\t/**\n\t * Whether this server supports broadcast discovery; see {@link Established.discovery}.\n\t * Defaults to true.\n\t */\n\tdiscovery?: boolean;\n\n\t/**\n\t * The origin whose broadcasts the session announces and serves to the peer. Omit to\n\t * publish nothing. Borrowed, not owned: closing the session leaves its broadcasts alone.\n\t */\n\tpublish?: OriginConsumer;\n\n\t/**\n\t * The origin the session feeds with the peer's announced broadcasts. Omit to discover\n\t * nothing. The entries retract when the session dies; see the `consume` connect option.\n\t */\n\tconsume?: OriginProducer;\n}\n\n/** The per-session wiring shared by every negotiated protocol path. */\ntype SessionProps = {\n\tdiscovery: boolean;\n\tpublish?: OriginConsumer;\n};\n\n/**\n * Server-side handshake: accepts a transport and performs the server half of the SETUP exchange.\n *\n * @param transport - The WebTransport session to accept\n * @param url - The URL of the connection\n * @param props - Optional configuration\n * @returns A promise that resolves to a Connection instance\n */\nexport async function accept({ transport, url, ...props }: AcceptProps): Promise<Established> {\n\tconst connection = await acceptInner(transport, url, props);\n\tif (props.consume) forwardAnnounced(connection, props.consume);\n\treturn connection;\n}\n\nasync function acceptInner(\n\ttransport: WebTransport,\n\turl: URL,\n\tprops: Omit<AcceptProps, \"transport\" | \"url\">,\n): Promise<Established> {\n\t// @ts-expect-error - TODO: add protocol to WebTransport\n\tconst protocol: string | undefined = transport.protocol;\n\n\tconst wiring: SessionProps = {\n\t\tdiscovery: props.discovery ?? true,\n\t\tpublish: props.publish,\n\t};\n\n\tif (protocol === Ietf.ALPN.DRAFT_22) {\n\t\treturn acceptAlpn(transport, url, Ietf.Version.DRAFT_22, wiring);\n\t}\n\tif (protocol === Ietf.ALPN.DRAFT_21) {\n\t\treturn acceptAlpn(transport, url, Ietf.Version.DRAFT_21, wiring);\n\t}\n\tif (protocol === Ietf.ALPN.DRAFT_20) {\n\t\treturn acceptAlpn(transport, url, Ietf.Version.DRAFT_20, wiring);\n\t}\n\tif (protocol === Ietf.ALPN.DRAFT_19) {\n\t\treturn acceptAlpn(transport, url, Ietf.Version.DRAFT_19, wiring);\n\t} else if (protocol === Ietf.ALPN.DRAFT_18) {\n\t\treturn acceptAlpn(transport, url, Ietf.Version.DRAFT_18, wiring);\n\t} else if (protocol === Ietf.ALPN.DRAFT_17) {\n\t\treturn acceptAlpn(transport, url, Ietf.Version.DRAFT_17, wiring);\n\t} else if (protocol === Ietf.ALPN.DRAFT_16) {\n\t\treturn acceptSetup(transport, url, Ietf.Version.DRAFT_16, wiring);\n\t} else if (protocol === Ietf.ALPN.DRAFT_15) {\n\t\treturn acceptSetup(transport, url, Ietf.Version.DRAFT_15, wiring);\n\t} else if (protocol === Lite.ALPN_06) {\n\t\treturn new Lite.Connection({ url, quic: transport, version: Lite.Version.DRAFT_06, ...wiring });\n\t} else if (protocol === Lite.ALPN_05) {\n\t\treturn new Lite.Connection({ url, quic: transport, version: Lite.Version.DRAFT_05, ...wiring });\n\t} else if (protocol === Lite.ALPN_04) {\n\t\treturn new Lite.Connection({ url, quic: transport, version: Lite.Version.DRAFT_04, ...wiring });\n\t} else if (protocol === Lite.ALPN_03) {\n\t\treturn new Lite.Connection({ url, quic: transport, version: Lite.Version.DRAFT_03, ...wiring });\n\t} else if (protocol === Lite.ALPN || protocol === \"\" || protocol === undefined) {\n\t\treturn acceptNegotiated(transport, url, wiring, props.version);\n\t} else {\n\t\tthrow new Error(`unsupported WebTransport protocol: ${protocol}`);\n\t}\n}\n\n/**\n * Draft-17+ accept: ALPN already pinned the version. SETUP is exchanged over\n * a pair of uni streams using stream type 0x2F00.\n */\nasync function acceptAlpn(\n\ttransport: WebTransport,\n\turl: URL,\n\tversion: Ietf.IetfVersion,\n\twiring: SessionProps,\n): Promise<Established> {\n\tconst { control, solicit, cluster } = await exchangeSetup(transport, version, \"moq-lite-js\");\n\n\treturn new Ietf.Connection({\n\t\t...wiring,\n\t\tclient: false,\n\t\turl,\n\t\tquic: transport,\n\t\tcontrol,\n\t\tsolicit,\n\t\tcluster,\n\t\t// v17+ uses NativeSession which manages its own request IDs; maxRequestId is unused.\n\t\tmaxRequestId: 0n,\n\t\tversion,\n\t});\n}\n\n/**\n * Legacy accept (draft-15/16): ALPN pinned the version, but the SETUP message\n * is still exchanged over a bidi stream wrapped in the moq-lite compat envelope.\n */\nasync function acceptSetup(\n\ttransport: WebTransport,\n\turl: URL,\n\tversion: Ietf.IetfVersion,\n\twiring: SessionProps,\n): Promise<Established> {\n\t// Accept bidi, read ClientSetup, write ServerSetup\n\tconst stream = await Stream.accept(transport);\n\tif (!stream) throw new Error(\"no incoming bidi stream for SETUP\");\n\n\tconst clientCompat = await stream.reader.u53();\n\tif (clientCompat !== Lite.StreamId.ClientCompat) {\n\t\tthrow new Error(`unexpected client message type: 0x${clientCompat.toString(16)}`);\n\t}\n\n\tconst client = await Ietf.ClientSetup.decode(stream.reader, version);\n\n\tawait stream.writer.u53(Lite.StreamId.ServerCompat);\n\n\tconst encoder = new TextEncoder();\n\tconst params = new Ietf.SetupOptions();\n\tparams.setVarint(Ietf.SetupOption.MaxRequestId, 42069n);\n\tparams.setBytes(Ietf.SetupOption.Implementation, encoder.encode(\"moq-lite-js\"));\n\tIetf.solicitIntoSetup(params);\n\n\tconst server = new Ietf.ServerSetup({ version, parameters: params });\n\tawait server.encode(stream.writer, version);\n\n\tconst maxRequestId = 42069n;\n\n\treturn new Ietf.Connection({\n\t\t...wiring,\n\t\tclient: false,\n\t\turl,\n\t\tquic: transport,\n\t\tcontrol: stream,\n\t\tmaxRequestId,\n\t\tversion,\n\t\tsolicit: Ietf.solicitFromSetup(client.parameters),\n\t});\n}\n\nasync function acceptNegotiated(\n\ttransport: WebTransport,\n\turl: URL,\n\twiring: SessionProps,\n\tversion?: number,\n): Promise<Established> {\n\tconst setupVersion = Ietf.Version.DRAFT_14;\n\n\tconst stream = await Stream.accept(transport);\n\tif (!stream) throw new Error(\"no incoming bidi stream for SETUP\");\n\n\tconst clientCompat = await stream.reader.u53();\n\tif (clientCompat !== Lite.StreamId.ClientCompat) {\n\t\tthrow new Error(`unexpected client message type: 0x${clientCompat.toString(16)}`);\n\t}\n\n\tconst client = await Ietf.ClientSetup.decode(stream.reader, setupVersion);\n\n\t// Pick the requested version, or first matching version from client's list\n\tconst allVersions = [...Object.values(Lite.Version), ...Object.values(Ietf.Version)] as number[];\n\tlet selectedVersion: number;\n\tif (version !== undefined) {\n\t\tselectedVersion = version;\n\t} else {\n\t\tconst match = client.versions.find((v) => allVersions.includes(v));\n\t\tif (match === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`no common version found; client offered: ${client.versions.map((v) => v.toString(16)).join(\", \")}`,\n\t\t\t);\n\t\t}\n\t\tselectedVersion = match;\n\t}\n\n\tawait stream.writer.u53(Lite.StreamId.ServerCompat);\n\n\tconst encoder = new TextEncoder();\n\tconst params = new Ietf.SetupOptions();\n\tparams.setVarint(Ietf.SetupOption.MaxRequestId, 42069n);\n\tparams.setBytes(Ietf.SetupOption.Implementation, encoder.encode(\"moq-lite-js\"));\n\tIetf.solicitIntoSetup(params);\n\n\tconst server = new Ietf.ServerSetup({ version: selectedVersion, parameters: params });\n\tawait server.encode(stream.writer, setupVersion);\n\n\tif (Object.values(Lite.Version).includes(selectedVersion as Lite.Version)) {\n\t\treturn new Lite.Connection({\n\t\t\turl,\n\t\t\tquic: transport,\n\t\t\tversion: selectedVersion as Lite.Version,\n\t\t\tsession: stream,\n\t\t\t...wiring,\n\t\t});\n\t} else if (Object.values(Ietf.Version).includes(selectedVersion as Ietf.Version)) {\n\t\tconst maxRequestId = client.parameters.getVarint(Ietf.SetupOption.MaxRequestId) ?? 0n;\n\t\treturn new Ietf.Connection({\n\t\t\t...wiring,\n\t\t\tclient: false,\n\t\t\turl,\n\t\t\tquic: transport,\n\t\t\tcontrol: stream,\n\t\t\tmaxRequestId,\n\t\t\tversion: selectedVersion as Ietf.IetfVersion,\n\t\t\tsolicit: Ietf.solicitFromSetup(client.parameters),\n\t\t});\n\t} else {\n\t\tthrow new Error(`unsupported version: ${selectedVersion.toString(16)}`);\n\t}\n}\n"]}
1
+ {"version":3,"file":"accept.js","sourceRoot":"","sources":["../../src/connection/accept.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAqC/C;;;;;;;GAOG;AACH,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AC,wBAAwB,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACzE,CAAC;AACF,CAAC","sourcesContent":["import * as Ietf from \"../ietf/index.ts\";\nimport * as Lite from \"../lite/index.ts\";\nimport type { Consumer as OriginConsumer, Producer as OriginProducer } from \"../origin.ts\";\nimport { Stream } from \"../stream.ts\";\nimport type { Established } from \"./established.ts\";\nimport { forwardAnnounced } from \"./forward.ts\";\nimport { exchangeSetup } from \"./handshake.ts\";\n\n/** Options for {@link accept}. */\nexport interface AcceptProps {\n\t/** The accepted transport. */\n\ttransport: WebTransport;\n\t/** The request URL associated with the transport. */\n\turl: URL;\n\n\t/** Version to select during SETUP negotiation (for non-ALPN paths). */\n\tversion?: number;\n\n\t/**\n\t * Whether this server supports broadcast discovery; see {@link Established.discovery}.\n\t * Defaults to true.\n\t */\n\tdiscovery?: boolean;\n\n\t/**\n\t * The origin whose broadcasts the session announces and serves to the peer. Omit to\n\t * publish nothing. Borrowed, not owned: closing the session leaves its broadcasts alone.\n\t */\n\tpublish?: OriginConsumer;\n\n\t/**\n\t * The origin the session feeds with the peer's announced broadcasts. Omit to discover\n\t * nothing. The entries retract when the session dies; see the `consume` connect option.\n\t */\n\tconsume?: OriginProducer;\n}\n\n/** The per-session wiring shared by every negotiated protocol path. */\ntype SessionProps = {\n\tdiscovery: boolean;\n\tpublish?: OriginConsumer;\n};\n\n/**\n * Server-side handshake: accepts a transport and performs the server half of the SETUP exchange.\n *\n * @param transport - The WebTransport session to accept\n * @param url - The URL of the connection\n * @param props - Optional configuration\n * @returns A promise that resolves to a Connection instance\n */\nexport async function accept({ transport, url, ...props }: AcceptProps): Promise<Established> {\n\tconst connection = await acceptInner(transport, url, props);\n\tif (props.consume) forwardAnnounced(connection, props.consume);\n\treturn connection;\n}\n\nasync function acceptInner(\n\ttransport: WebTransport,\n\turl: URL,\n\tprops: Omit<AcceptProps, \"transport\" | \"url\">,\n): Promise<Established> {\n\t// The DOM lib has no `protocol` property yet. It is \"\" when none was negotiated, and\n\t// undefined in a browser that predates subprotocols (Firefox before 155).\n\tconst protocol = (transport as { protocol?: string }).protocol;\n\n\tconst wiring: SessionProps = {\n\t\tdiscovery: props.discovery ?? true,\n\t\tpublish: props.publish,\n\t};\n\n\tif (protocol === Ietf.ALPN.DRAFT_22) {\n\t\treturn acceptAlpn(transport, url, Ietf.Version.DRAFT_22, wiring);\n\t}\n\tif (protocol === Ietf.ALPN.DRAFT_21) {\n\t\treturn acceptAlpn(transport, url, Ietf.Version.DRAFT_21, wiring);\n\t}\n\tif (protocol === Ietf.ALPN.DRAFT_20) {\n\t\treturn acceptAlpn(transport, url, Ietf.Version.DRAFT_20, wiring);\n\t}\n\tif (protocol === Ietf.ALPN.DRAFT_19) {\n\t\treturn acceptAlpn(transport, url, Ietf.Version.DRAFT_19, wiring);\n\t} else if (protocol === Ietf.ALPN.DRAFT_18) {\n\t\treturn acceptAlpn(transport, url, Ietf.Version.DRAFT_18, wiring);\n\t} else if (protocol === Ietf.ALPN.DRAFT_17) {\n\t\treturn acceptAlpn(transport, url, Ietf.Version.DRAFT_17, wiring);\n\t} else if (protocol === Ietf.ALPN.DRAFT_16) {\n\t\treturn acceptSetup(transport, url, Ietf.Version.DRAFT_16, wiring);\n\t} else if (protocol === Ietf.ALPN.DRAFT_15) {\n\t\treturn acceptSetup(transport, url, Ietf.Version.DRAFT_15, wiring);\n\t} else if (protocol === Lite.ALPN_07_WIP) {\n\t\treturn new Lite.Connection({ url, quic: transport, version: Lite.Version.DRAFT_07, ...wiring });\n\t} else if (protocol === Lite.ALPN_06) {\n\t\treturn new Lite.Connection({ url, quic: transport, version: Lite.Version.DRAFT_06, ...wiring });\n\t} else if (protocol === Lite.ALPN_05) {\n\t\treturn new Lite.Connection({ url, quic: transport, version: Lite.Version.DRAFT_05, ...wiring });\n\t} else if (protocol === Lite.ALPN_04) {\n\t\treturn new Lite.Connection({ url, quic: transport, version: Lite.Version.DRAFT_04, ...wiring });\n\t} else if (protocol === Lite.ALPN_03) {\n\t\treturn new Lite.Connection({ url, quic: transport, version: Lite.Version.DRAFT_03, ...wiring });\n\t} else if (protocol === Lite.ALPN || protocol === \"\" || protocol === undefined) {\n\t\treturn acceptNegotiated(transport, url, wiring, props.version);\n\t} else {\n\t\tthrow new Error(`unsupported WebTransport protocol: ${protocol}`);\n\t}\n}\n\n/**\n * Draft-17+ accept: ALPN already pinned the version. SETUP is exchanged over\n * a pair of uni streams using stream type 0x2F00.\n */\nasync function acceptAlpn(\n\ttransport: WebTransport,\n\turl: URL,\n\tversion: Ietf.IetfVersion,\n\twiring: SessionProps,\n): Promise<Established> {\n\tconst { control, early, solicit, hidden, cluster } = await exchangeSetup(transport, version, \"moq-lite-js\");\n\n\treturn new Ietf.Connection({\n\t\t...wiring,\n\t\tclient: false,\n\t\turl,\n\t\tquic: transport,\n\t\tcontrol,\n\t\tearly,\n\t\tsolicit,\n\t\thidden,\n\t\tcluster,\n\t\t// v17+ uses NativeSession which manages its own request IDs; maxRequestId is unused.\n\t\tmaxRequestId: 0n,\n\t\tversion,\n\t});\n}\n\n/**\n * Legacy accept (draft-15/16): ALPN pinned the version, but the SETUP message\n * is still exchanged over a bidi stream wrapped in the moq-lite compat envelope.\n */\nasync function acceptSetup(\n\ttransport: WebTransport,\n\turl: URL,\n\tversion: Ietf.IetfVersion,\n\twiring: SessionProps,\n): Promise<Established> {\n\t// Accept bidi, read ClientSetup, write ServerSetup\n\tconst stream = await Stream.accept(transport, version);\n\tif (!stream) throw new Error(\"no incoming bidi stream for SETUP\");\n\n\tconst clientCompat = await stream.reader.u53();\n\tif (clientCompat !== Lite.StreamId.ClientCompat) {\n\t\tthrow new Error(`unexpected client message type: 0x${clientCompat.toString(16)}`);\n\t}\n\n\tconst client = await Ietf.ClientSetup.decode(stream.reader, version);\n\n\tawait stream.writer.u53(Lite.StreamId.ServerCompat);\n\n\tconst encoder = new TextEncoder();\n\tconst params = new Ietf.SetupOptions();\n\tparams.setVarint(Ietf.SetupOption.MaxRequestId, 42069n);\n\tparams.setBytes(Ietf.SetupOption.Implementation, encoder.encode(\"moq-lite-js\"));\n\tIetf.solicitIntoSetup(params);\n\tIetf.hiddenIntoSetup(params);\n\n\tconst server = new Ietf.ServerSetup({ version, parameters: params });\n\tawait server.encode(stream.writer, version);\n\n\tconst maxRequestId = 42069n;\n\n\treturn new Ietf.Connection({\n\t\t...wiring,\n\t\tclient: false,\n\t\turl,\n\t\tquic: transport,\n\t\tcontrol: stream,\n\t\tmaxRequestId,\n\t\tversion,\n\t\tsolicit: Ietf.solicitFromSetup(client.parameters),\n\t\thidden: Ietf.hiddenFromSetup(client.parameters),\n\t});\n}\n\nasync function acceptNegotiated(\n\ttransport: WebTransport,\n\turl: URL,\n\twiring: SessionProps,\n\tversion?: number,\n): Promise<Established> {\n\tconst setupVersion = Ietf.Version.DRAFT_14;\n\n\tconst stream = await Stream.accept(transport, setupVersion);\n\tif (!stream) throw new Error(\"no incoming bidi stream for SETUP\");\n\n\tconst clientCompat = await stream.reader.u53();\n\tif (clientCompat !== Lite.StreamId.ClientCompat) {\n\t\tthrow new Error(`unexpected client message type: 0x${clientCompat.toString(16)}`);\n\t}\n\n\tconst client = await Ietf.ClientSetup.decode(stream.reader, setupVersion);\n\n\t// Pick the requested version, or first matching version from client's list\n\tconst allVersions = [...Object.values(Lite.Version), ...Object.values(Ietf.Version)] as number[];\n\tlet selectedVersion: number;\n\tif (version !== undefined) {\n\t\tselectedVersion = version;\n\t} else {\n\t\tconst match = client.versions.find((v) => allVersions.includes(v));\n\t\tif (match === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`no common version found; client offered: ${client.versions.map((v) => v.toString(16)).join(\", \")}`,\n\t\t\t);\n\t\t}\n\t\tselectedVersion = match;\n\t}\n\n\tawait stream.writer.u53(Lite.StreamId.ServerCompat);\n\n\tconst encoder = new TextEncoder();\n\tconst params = new Ietf.SetupOptions();\n\tparams.setVarint(Ietf.SetupOption.MaxRequestId, 42069n);\n\tparams.setBytes(Ietf.SetupOption.Implementation, encoder.encode(\"moq-lite-js\"));\n\tIetf.solicitIntoSetup(params);\n\tIetf.hiddenIntoSetup(params);\n\n\tconst server = new Ietf.ServerSetup({ version: selectedVersion, parameters: params });\n\tawait server.encode(stream.writer, setupVersion);\n\n\tif (Object.values(Lite.Version).includes(selectedVersion as Lite.Version)) {\n\t\treturn new Lite.Connection({\n\t\t\turl,\n\t\t\tquic: transport,\n\t\t\tversion: selectedVersion as Lite.Version,\n\t\t\tsession: stream,\n\t\t\t...wiring,\n\t\t});\n\t} else if (Object.values(Ietf.Version).includes(selectedVersion as Ietf.Version)) {\n\t\tconst maxRequestId = client.parameters.getVarint(Ietf.SetupOption.MaxRequestId) ?? 0n;\n\t\treturn new Ietf.Connection({\n\t\t\t...wiring,\n\t\t\tclient: false,\n\t\t\turl,\n\t\t\tquic: transport,\n\t\t\tcontrol: stream,\n\t\t\tmaxRequestId,\n\t\t\tversion: selectedVersion as Ietf.IetfVersion,\n\t\t\tsolicit: Ietf.solicitFromSetup(client.parameters),\n\t\t\thidden: Ietf.hiddenFromSetup(client.parameters),\n\t\t});\n\t} else {\n\t\tthrow new Error(`unsupported version: ${selectedVersion.toString(16)}`);\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/connection/connect.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,IAAI,cAAc,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,cAAc,CAAC;AAE3F,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAInC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAWpD,yGAAyG;AACzG,MAAM,WAAW,cAAc;IAC9B,yDAAyD;IACzD,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,mGAAmG;IACnG,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV;;;OAGG;IACH,KAAK,CAAC,EAAE,IAAI,CAAC,K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