@moq/net 0.3.5 → 0.4.1

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 (244) hide show
  1. package/announce.d.ts +7 -0
  2. package/announce.d.ts.map +1 -0
  3. package/announce.js +8 -0
  4. package/announce.js.map +1 -0
  5. package/announced.d.ts +49 -91
  6. package/announced.d.ts.map +1 -1
  7. package/announced.js +21 -156
  8. package/announced.js.map +1 -1
  9. package/bandwidth.d.ts +163 -0
  10. package/bandwidth.d.ts.map +1 -0
  11. package/bandwidth.js +304 -0
  12. package/bandwidth.js.map +1 -0
  13. package/bandwidth_api.d.ts +7 -0
  14. package/bandwidth_api.d.ts.map +1 -0
  15. package/bandwidth_api.js +8 -0
  16. package/bandwidth_api.js.map +1 -0
  17. package/broadcast.d.ts +23 -28
  18. package/broadcast.d.ts.map +1 -1
  19. package/broadcast.js +61 -40
  20. package/broadcast.js.map +1 -1
  21. package/connection/accept.d.ts +16 -1
  22. package/connection/accept.d.ts.map +1 -1
  23. package/connection/accept.js +48 -25
  24. package/connection/accept.js.map +1 -1
  25. package/connection/browser.d.ts.map +1 -1
  26. package/connection/browser.js +9 -7
  27. package/connection/browser.js.map +1 -1
  28. package/connection/connect.d.ts +30 -6
  29. package/connection/connect.d.ts.map +1 -1
  30. package/connection/connect.js +95 -46
  31. package/connection/connect.js.map +1 -1
  32. package/connection/established.d.ts +17 -21
  33. package/connection/established.d.ts.map +1 -1
  34. package/connection/established.js.map +1 -1
  35. package/connection/forward.d.ts +2 -0
  36. package/connection/forward.d.ts.map +1 -0
  37. package/connection/forward.js +166 -0
  38. package/connection/forward.js.map +1 -0
  39. package/connection/handshake.d.ts +1 -0
  40. package/connection/handshake.d.ts.map +1 -1
  41. package/connection/handshake.js +5 -2
  42. package/connection/handshake.js.map +1 -1
  43. package/connection/index.d.ts +5 -5
  44. package/connection/index.d.ts.map +1 -1
  45. package/connection/index.js +4 -5
  46. package/connection/index.js.map +1 -1
  47. package/connection/pool.d.ts +186 -0
  48. package/connection/pool.d.ts.map +1 -0
  49. package/connection/pool.js +361 -0
  50. package/connection/pool.js.map +1 -0
  51. package/connection/reload.d.ts +14 -93
  52. package/connection/reload.d.ts.map +1 -1
  53. package/connection/reload.js +217 -81
  54. package/connection/reload.js.map +1 -1
  55. package/connection/stats.d.ts +3 -26
  56. package/connection/stats.d.ts.map +1 -1
  57. package/connection/stats.js.map +1 -1
  58. package/connection/transport.d.ts +0 -7
  59. package/connection/transport.d.ts.map +1 -1
  60. package/consume.d.ts +1 -43
  61. package/consume.d.ts.map +1 -1
  62. package/consume.js +1 -1
  63. package/consume.js.map +1 -1
  64. package/error.d.ts +180 -29
  65. package/error.d.ts.map +1 -1
  66. package/error.js +331 -16
  67. package/error.js.map +1 -1
  68. package/errors.d.ts +7 -0
  69. package/errors.d.ts.map +1 -0
  70. package/errors.js +8 -0
  71. package/errors.js.map +1 -0
  72. package/group.d.ts +9 -43
  73. package/group.d.ts.map +1 -1
  74. package/group.js +283 -69
  75. package/group.js.map +1 -1
  76. package/hop.d.ts +107 -0
  77. package/hop.d.ts.map +1 -0
  78. package/hop.js +103 -0
  79. package/hop.js.map +1 -0
  80. package/ietf/adapter.d.ts +5 -1
  81. package/ietf/adapter.d.ts.map +1 -1
  82. package/ietf/adapter.js +27 -9
  83. package/ietf/adapter.js.map +1 -1
  84. package/ietf/aliases.d.ts +1 -78
  85. package/ietf/aliases.d.ts.map +1 -1
  86. package/ietf/cluster.d.ts +6 -120
  87. package/ietf/cluster.d.ts.map +1 -1
  88. package/ietf/cluster.js +81 -41
  89. package/ietf/cluster.js.map +1 -1
  90. package/ietf/connection.d.ts +6 -72
  91. package/ietf/connection.d.ts.map +1 -1
  92. package/ietf/connection.js +17 -49
  93. package/ietf/connection.js.map +1 -1
  94. package/ietf/error.d.ts +11 -0
  95. package/ietf/error.d.ts.map +1 -0
  96. package/ietf/error.js +193 -0
  97. package/ietf/error.js.map +1 -0
  98. package/ietf/filter.d.ts.map +1 -1
  99. package/ietf/filter.js +6 -1
  100. package/ietf/filter.js.map +1 -1
  101. package/ietf/goaway.d.ts.map +1 -1
  102. package/ietf/goaway.js +22 -5
  103. package/ietf/goaway.js.map +1 -1
  104. package/ietf/hidden.d.ts +2 -0
  105. package/ietf/hidden.d.ts.map +1 -0
  106. package/ietf/hidden.js +30 -0
  107. package/ietf/hidden.js.map +1 -0
  108. package/ietf/index.d.ts +1 -0
  109. package/ietf/index.d.ts.map +1 -1
  110. package/ietf/index.js +1 -0
  111. package/ietf/index.js.map +1 -1
  112. package/ietf/object.d.ts +8 -2
  113. package/ietf/object.d.ts.map +1 -1
  114. package/ietf/object.js +17 -3
  115. package/ietf/object.js.map +1 -1
  116. package/ietf/parameters.d.ts +7 -2
  117. package/ietf/parameters.d.ts.map +1 -1
  118. package/ietf/parameters.js +35 -17
  119. package/ietf/parameters.js.map +1 -1
  120. package/ietf/properties.d.ts +1 -0
  121. package/ietf/properties.d.ts.map +1 -1
  122. package/ietf/properties.js +14 -0
  123. package/ietf/properties.js.map +1 -1
  124. package/ietf/publish.d.ts +19 -2
  125. package/ietf/publish.d.ts.map +1 -1
  126. package/ietf/publish.js +40 -6
  127. package/ietf/publish.js.map +1 -1
  128. package/ietf/publish_namespace.d.ts +25 -0
  129. package/ietf/publish_namespace.d.ts.map +1 -1
  130. package/ietf/publish_namespace.js +63 -0
  131. package/ietf/publish_namespace.js.map +1 -1
  132. package/ietf/publisher.d.ts +1 -82
  133. package/ietf/publisher.d.ts.map +1 -1
  134. package/ietf/publisher.js +302 -181
  135. package/ietf/publisher.js.map +1 -1
  136. package/ietf/solicit.d.ts +1 -40
  137. package/ietf/solicit.d.ts.map +1 -1
  138. package/ietf/subscribe.d.ts +1 -5
  139. package/ietf/subscribe.d.ts.map +1 -1
  140. package/ietf/subscribe.js +11 -13
  141. package/ietf/subscribe.js.map +1 -1
  142. package/ietf/subscribe_namespace.d.ts +8 -2
  143. package/ietf/subscribe_namespace.d.ts.map +1 -1
  144. package/ietf/subscribe_namespace.js +18 -8
  145. package/ietf/subscribe_namespace.js.map +1 -1
  146. package/ietf/subscriber.d.ts +1 -65
  147. package/ietf/subscriber.d.ts.map +1 -1
  148. package/ietf/subscriber.js +325 -121
  149. package/ietf/subscriber.js.map +1 -1
  150. package/ietf/version.d.ts +12 -1
  151. package/ietf/version.d.ts.map +1 -1
  152. package/ietf/version.js +13 -0
  153. package/ietf/version.js.map +1 -1
  154. package/index.d.ts +11 -6
  155. package/index.d.ts.map +1 -1
  156. package/index.js +10 -5
  157. package/index.js.map +1 -1
  158. package/internal.d.ts +104 -1
  159. package/internal.d.ts.map +1 -1
  160. package/internal.js +76 -0
  161. package/internal.js.map +1 -1
  162. package/lite/announce.d.ts +60 -10
  163. package/lite/announce.d.ts.map +1 -1
  164. package/lite/announce.js +173 -31
  165. package/lite/announce.js.map +1 -1
  166. package/lite/connection.d.ts +9 -59
  167. package/lite/connection.d.ts.map +1 -1
  168. package/lite/connection.js +26 -32
  169. package/lite/connection.js.map +1 -1
  170. package/lite/fetch.d.ts +15 -1
  171. package/lite/fetch.d.ts.map +1 -1
  172. package/lite/fetch.js +39 -7
  173. package/lite/fetch.js.map +1 -1
  174. package/lite/goaway.d.ts.map +1 -1
  175. package/lite/goaway.js +7 -1
  176. package/lite/goaway.js.map +1 -1
  177. package/lite/group.d.ts +18 -4
  178. package/lite/group.d.ts.map +1 -1
  179. package/lite/group.js +31 -10
  180. package/lite/group.js.map +1 -1
  181. package/lite/priority.d.ts +1 -61
  182. package/lite/priority.d.ts.map +1 -1
  183. package/lite/priority.js +4 -5
  184. package/lite/priority.js.map +1 -1
  185. package/lite/publisher.d.ts +1 -69
  186. package/lite/publisher.d.ts.map +1 -1
  187. package/lite/publisher.js +593 -227
  188. package/lite/publisher.js.map +1 -1
  189. package/lite/setup.d.ts +7 -7
  190. package/lite/setup.d.ts.map +1 -1
  191. package/lite/setup.js +13 -13
  192. package/lite/setup.js.map +1 -1
  193. package/lite/subscribe.d.ts +71 -17
  194. package/lite/subscribe.d.ts.map +1 -1
  195. package/lite/subscribe.js +205 -53
  196. package/lite/subscribe.js.map +1 -1
  197. package/lite/subscriber.d.ts +15 -56
  198. package/lite/subscriber.d.ts.map +1 -1
  199. package/lite/subscriber.js +316 -188
  200. package/lite/subscriber.js.map +1 -1
  201. package/lite/track.d.ts +4 -10
  202. package/lite/track.d.ts.map +1 -1
  203. package/lite/track.js +34 -29
  204. package/lite/track.js.map +1 -1
  205. package/lite/version.d.ts +42 -6
  206. package/lite/version.d.ts.map +1 -1
  207. package/lite/version.js +126 -10
  208. package/lite/version.js.map +1 -1
  209. package/origin.d.ts +248 -29
  210. package/origin.d.ts.map +1 -1
  211. package/origin.js +1232 -37
  212. package/origin.js.map +1 -1
  213. package/package.json +8 -3
  214. package/path.d.ts +25 -7
  215. package/path.d.ts.map +1 -1
  216. package/path.js +5 -3
  217. package/path.js.map +1 -1
  218. package/stream.d.ts +2 -2
  219. package/stream.d.ts.map +1 -1
  220. package/stream.js +39 -25
  221. package/stream.js.map +1 -1
  222. package/tail.d.ts +11 -0
  223. package/tail.d.ts.map +1 -0
  224. package/tail.js +121 -0
  225. package/tail.js.map +1 -0
  226. package/time.d.ts +15 -2
  227. package/time.d.ts.map +1 -1
  228. package/time.js +28 -9
  229. package/time.js.map +1 -1
  230. package/track.d.ts +195 -84
  231. package/track.d.ts.map +1 -1
  232. package/track.js +694 -196
  233. package/track.js.map +1 -1
  234. package/wire.d.ts +69 -0
  235. package/wire.d.ts.map +1 -0
  236. package/wire.js +32 -0
  237. package/wire.js.map +1 -0
  238. package/zod.d.ts +1 -1
  239. package/zod.d.ts.map +1 -1
  240. package/zod.js.map +1 -1
  241. package/mock.d.ts +0 -66
  242. package/mock.d.ts.map +0 -1
  243. package/mock.js +0 -243
  244. package/mock.js.map +0 -1
@@ -1,11 +1,11 @@
1
1
  /* @ts-self-types="./connection.d.ts" */
2
2
  import { Signal } from "@moq/signals";
3
- import * as announce from "../announced.js";
4
3
  import { transportStats } from "../connection/stats.js";
5
4
  import { transportOf } from "../connection/transport.js";
6
- import { randomOrigin } from "../origin.js";
7
- import * as Path from "../path.js";
5
+ import { closeError, error, fromClose, StreamCode, StreamError, sessionCause } from "../error.js";
6
+ import { randomHop } from "../hop.js";
8
7
  import { Readers, Stream, Writer } from "../stream.js";
8
+ import { registerWire } from "../wire.js";
9
9
  import { AnnounceRequest } from "./announce.js";
10
10
  import { Fetch } from "./fetch.js";
11
11
  import { Goaway } from "./goaway.js";
@@ -44,9 +44,9 @@ export class Connection {
44
44
  #subscriber;
45
45
  /** The peer's PROBE estimates; see {@link Established.probe}. */
46
46
  probe;
47
- /** Random per-connection origin id. Shared by Publisher (for outbound hop
47
+ /** Random per-connection Hop ID. Shared by Publisher (for outbound hop
48
48
  * chains) and Subscriber (available for optional self-filtering on announces). */
49
- origin;
49
+ hop;
50
50
  // The peer's SETUP, recorded once its Setup stream is read (lite-05+). Streams whose
51
51
  // encoding depends on a negotiated capability (e.g. PROBE) wait on this. undefined
52
52
  // until the peer's SETUP arrives; stays undefined forever on older drafts.
@@ -73,7 +73,7 @@ export class Connection {
73
73
  *
74
74
  * @internal
75
75
  */
76
- constructor({ url, quic, version, session, discovery = true }) {
76
+ constructor({ url, quic, version, session, discovery = true, publish }) {
77
77
  this.url = url;
78
78
  this.#quic = quic;
79
79
  this.#session = session;
@@ -82,9 +82,10 @@ export class Connection {
82
82
  this.transport = transportOf(quic);
83
83
  this.discovery = discovery;
84
84
  this.probe = this.#probe;
85
- this.origin = randomOrigin();
86
- this.#publisher = new Publisher(this.#quic, this.#version, this.origin);
87
- this.#subscriber = new Subscriber(this.#quic, this.#version, this.origin, this.#probe, this.#peerSetup);
85
+ this.hop = randomHop();
86
+ this.#publisher = new Publisher(this.#quic, this.#version, this.hop, publish);
87
+ this.#subscriber = new Subscriber(this.#quic, this.#version, this.hop, this.#probe, this.#peerSetup);
88
+ registerWire(this, { consume: (path) => this.#subscriber.consume(path) });
88
89
  void this.#run();
89
90
  }
90
91
  /**
@@ -112,33 +113,24 @@ export class Connection {
112
113
  if (hasDatagrams(this.#version)) {
113
114
  tasks.push(this.#subscriber.runDatagrams());
114
115
  }
116
+ let fatal;
115
117
  try {
116
118
  await Promise.all(tasks);
117
119
  }
118
120
  catch (err) {
119
121
  console.error("fatal error running connection", err);
122
+ // A session-sourced failure is the peer's close, not the raw transport error.
123
+ fatal = await sessionCause(this.#quic, err);
120
124
  }
121
125
  finally {
126
+ // The session died under every track it was receiving, so they end with its
127
+ // error. A deliberate close() already ended them cleanly, which makes this a no-op.
128
+ this.#subscriber.close(fatal ?? (await closeError(this.#quic)));
122
129
  this.close();
123
130
  }
124
131
  }
125
- publish(path, producer) {
126
- this.#publisher.publish(path, producer);
127
- }
128
- announced(prefix = Path.empty()) {
129
- return this.#subscriber.announced(prefix);
130
- }
131
- consume(path) {
132
- return this.#subscriber.consume(path);
133
- }
134
- /**
135
- * Watches a broadcast, live only while it is announced.
136
- *
137
- * @param path - The path of the broadcast to watch
138
- * @returns A reactive handle to the broadcast
139
- */
140
- announcedBroadcast(path) {
141
- return new announce.Broadcast({ connection: this, path });
132
+ announced(scope, options) {
133
+ return this.#subscriber.announced(scope, options);
142
134
  }
143
135
  async #runSession() {
144
136
  if (!this.#session) {
@@ -159,15 +151,16 @@ export class Connection {
159
151
  // The browser uses WebTransport, which carries the request URI, so we advertise no
160
152
  // path and leave routing to the URL. The probe level reflects what this transport
161
153
  // can actually measure; we never pad, so we never advertise Increase.
162
- // Role stays Both: publish/consume are called after this point, so there is nothing
163
- // to narrow yet. The origin declares our session identity so the peer can filter
154
+ // Role stays Both: the publish origin starts empty and fills later, and consume is
155
+ // called after this point, so there is nothing to narrow yet. The origin declares
156
+ // our session identity so the peer can filter
164
157
  // reflected announcements (lite-06 removed ANNOUNCE_REQUEST's exclude_hop for it).
165
158
  async #sendSetup() {
166
159
  const writer = await Writer.open(this.#quic);
167
160
  try {
168
161
  await writer.u53(DataType.Setup);
169
162
  const probe = await probeLevel(this.#quic, this.#version);
170
- await new Setup({ probe, origin: this.origin }).encode(writer, this.#version);
163
+ await new Setup({ probe, hop: this.hop }).encode(writer, this.#version);
171
164
  writer.close();
172
165
  }
173
166
  catch (err) {
@@ -229,7 +222,7 @@ export class Connection {
229
222
  break;
230
223
  this.#runUni(stream)
231
224
  .then(() => {
232
- stream.stop(new Error("cancel"));
225
+ stream.stop(new StreamError(StreamCode.Cancel, { message: "cancel" }));
233
226
  })
234
227
  .catch((err) => {
235
228
  stream.stop(err);
@@ -239,7 +232,7 @@ export class Connection {
239
232
  async #runUni(stream) {
240
233
  const typ = await stream.u53();
241
234
  if (typ === DataType.Group) {
242
- const msg = await Group.decode(stream);
235
+ const msg = await Group.decode(stream, this.#version);
243
236
  await this.#subscriber.runGroup(msg, stream);
244
237
  }
245
238
  else if (typ === DataType.Setup) {
@@ -257,8 +250,9 @@ export class Connection {
257
250
  async stats() {
258
251
  return transportStats(this.#quic);
259
252
  }
253
+ /** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */
260
254
  get closed() {
261
- return this.#quic.closed.then(() => undefined);
255
+ return this.#quic.closed.then(fromClose, (err) => error(err));
262
256
  }
263
257
  }
264
258
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/lite/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAA0B,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAkB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAe,YAAY,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;A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,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAChD,CAAC;CACD;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAkB,EAAE,OAAgB;IACpE,MAAM,QAAQ,GACb,IAGA,CAAC,QAAQ,CAAC;IACX,IAAI,OAAO,QAAQ,KAAK,UAAU;QAAE,OAAO,UAAU,CAAC,IAAI,CAAC;IAE3D,6EAA6E;IAC7E,IAAI,KAAwE,CAAC;IAC7E,IAAI,CAAC;QACJ,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,UAAU,CAAC,IAAI,CAAC;IACxB,CAAC;IAED,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;IACjE,OAAO,KAAK,CAAC,iBAAiB,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;AAC7F,CAAC","sourcesContent":["import { type Getter, Signal } from \"@moq/signals\";\nimport * as announce from \"../announced.ts\";\nimport type * as broadcast from \"../broadcast.ts\";\nimport type { Established } from \"../connection/established.ts\";\nimport { type Probe, type Stats, transportStats } from \"../connection/stats.ts\";\nimport { type Transport, transportOf } from \"../connection/transport.ts\";\nimport { type Origin, randomOrigin } from \"../origin.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Reader, Readers, Stream, Writer } from \"../stream.ts\";\nimport { AnnounceRequest } from \"./announce.ts\";\nimport { Fetch } from \"./fetch.ts\";\nimport { Goaway } from \"./goaway.ts\";\nimport { Group } from \"./group.ts\";\nimport { Publisher } from \"./publisher.ts\";\nimport { SessionInfo } from \"./session.ts\";\nimport { ProbeLevel, type Role, Setup } from \"./setup.ts\";\nimport { DataType, StreamId } from \"./stream.ts\";\nimport { Subscribe } from \"./subscribe.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { Track as TrackMessage } from \"./track.ts\";\nimport { hasDatagrams, hasProbeRtt, hasSetupStream, type Version, versionName } from \"./version.ts\";\n\n/**\n * Constructor options for {@link Connection}.\n *\n * @internal\n */\nexport interface ConnectionProps {\n\t/** The URL of the connection. */\n\turl: URL;\n\t/** The established WebTransport session. */\n\tquic: WebTransport;\n\t/** The negotiated wire version. */\n\tversion: Version;\n\t/** The session stream, absent on drafts that have none. */\n\tsession?: Stream;\n\t/** Whether the relay supports broadcast discovery. Defaults to true. */\n\tdiscovery?: boolean;\n}\n\n/**\n * Represents a connection to a MoQ server.\n *\n * @public\n */\nexport class Connection implements Established {\n\t// The URL of the connection.\n\treadonly url: URL;\n\n\t// The version of the connection as a human-readable string.\n\treadonly version: string;\n\n\t// The wire transport this session runs over.\n\treadonly transport: Transport;\n\n\t/** Whether the relay supports broadcast discovery; see {@link Established.discovery}. */\n\treadonly discovery: boolean;\n\n\t// The version used for encoding/decoding.\n\t#version: Version;\n\n\t// The established WebTransport session.\n\t#quic: WebTransport;\n\n\t// Use to receive/send session messages.\n\t#session?: Stream;\n\n\t// Module for contributing tracks.\n\t#publisher: Publisher;\n\n\t// Module for distributing tracks.\n\t#subscriber: Subscriber;\n\n\t/** The peer's PROBE estimates; see {@link Established.probe}. */\n\treadonly probe: Getter<Probe>;\n\n\t/** Random per-connection origin id. Shared by Publisher (for outbound hop\n\t * chains) and Subscriber (available for optional self-filtering on announces). */\n\treadonly origin: Origin;\n\n\t// The peer's SETUP, recorded once its Setup stream is read (lite-05+). Streams whose\n\t// encoding depends on a negotiated capability (e.g. PROBE) wait on this. undefined\n\t// until the peer's SETUP arrives; stays undefined forever on older drafts.\n\t#peerSetup = new Signal<Setup | undefined>(undefined);\n\n\t// Mirrors the role out of #peerSetup, so the public surface exposes the peer's declared\n\t// direction without handing out the whole SETUP (whose probe level gates our own streams).\n\t#peerRole = new Signal<Role | undefined>(undefined);\n\n\t// Written by the Subscriber as PROBE messages arrive.\n\t#probe = new Signal<Probe>({});\n\n\t/**\n\t * The {@link Role} the peer advertised in its SETUP, for a server deciding whether the\n\t * peer's authorization grants the direction it intends to use.\n\t *\n\t * `undefined` until the peer's SETUP arrives, and forever on pre-lite-05 versions, which\n\t * carry no in-band role. {@link Role.Both} is the absence of the parameter, so it is what\n\t * a peer reports when it declines to declare a direction, sends a value we don't\n\t * recognize, or is a server (which never sends one).\n\t */\n\tget peerRole(): Getter<Role | undefined> {\n\t\treturn this.#peerRole;\n\t}\n\n\t/**\n\t * Creates a new Connection instance.\n\t *\n\t * @internal\n\t */\n\tconstructor({ url, quic, version, session, discovery = true }: ConnectionProps) {\n\t\tthis.url = url;\n\t\tthis.#quic = quic;\n\t\tthis.#session = session;\n\t\tthis.version = versionName(version);\n\t\tthis.#version = version;\n\t\tthis.transport = transportOf(quic);\n\t\tthis.discovery = discovery;\n\n\t\tthis.probe = this.#probe;\n\n\t\tthis.origin = randomOrigin();\n\t\tthis.#publisher = new Publisher(this.#quic, this.#version, this.origin);\n\t\tthis.#subscriber = new Subscriber(this.#quic, this.#version, this.origin, this.#probe, this.#peerSetup);\n\n\t\tvoid this.#run();\n\t}\n\n\t/**\n\t * Closes the connection.\n\t */\n\tclose() {\n\t\tthis.#publisher.close();\n\t\tthis.#subscriber.close();\n\n\t\ttry {\n\t\t\t// TODO: For whatever reason, this try/catch doesn't seem to work..?\n\t\t\tthis.#quic.close();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t}\n\n\tasync #run(): Promise<void> {\n\t\tconst tasks: Promise<void>[] = [this.#runSession(), this.#runBidis(), this.#runUnis()];\n\n\t\tif (hasSetupStream(this.#version)) {\n\t\t\ttasks.push(this.#sendSetup());\n\t\t}\n\n\t\ttasks.push(this.#subscriber.runProbe());\n\n\t\t// Route incoming QUIC datagrams into their subscriptions (lite-05+; runDatagrams\n\t\t// no-ops on a transport that doesn't carry them).\n\t\tif (hasDatagrams(this.#version)) {\n\t\t\ttasks.push(this.#subscriber.runDatagrams());\n\t\t}\n\n\t\ttry {\n\t\t\tawait Promise.all(tasks);\n\t\t} catch (err) {\n\t\t\tconsole.error(\"fatal error running connection\", err);\n\t\t} finally {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\tpublish(path: Path.Valid, producer: broadcast.Producer) {\n\t\tthis.#publisher.publish(path, producer);\n\t}\n\n\tannounced(prefix = Path.empty()): announce.Consumer {\n\t\treturn this.#subscriber.announced(prefix);\n\t}\n\n\tconsume(path: Path.Valid): broadcast.Consumer {\n\t\treturn this.#subscriber.consume(path);\n\t}\n\n\t/**\n\t * Watches a broadcast, live only while it is announced.\n\t *\n\t * @param path - The path of the broadcast to watch\n\t * @returns A reactive handle to the broadcast\n\t */\n\tannouncedBroadcast(path: Path.Valid): announce.Broadcast {\n\t\treturn new announce.Broadcast({ connection: this, path });\n\t}\n\n\tasync #runSession() {\n\t\tif (!this.#session) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst msg = await SessionInfo.decodeMaybe(this.#session.reader, this.#version);\n\t\t\t\tif (!msg) break;\n\t\t\t}\n\t\t} finally {\n\t\t\tconsole.debug(\"session stream closed\");\n\t\t}\n\t}\n\n\t// Open the unidirectional Setup Stream, send our single SETUP, and FIN (lite-05+).\n\t// The browser uses WebTransport, which carries the request URI, so we advertise no\n\t// path and leave routing to the URL. The probe level reflects what this transport\n\t// can actually measure; we never pad, so we never advertise Increase.\n\t// Role stays Both: publish/consume are called after this point, so there is nothing\n\t// to narrow yet. The origin declares our session identity so the peer can filter\n\t// reflected announcements (lite-06 removed ANNOUNCE_REQUEST's exclude_hop for it).\n\tasync #sendSetup(): Promise<void> {\n\t\tconst writer = await Writer.open(this.#quic);\n\t\ttry {\n\t\t\tawait writer.u53(DataType.Setup);\n\t\t\tconst probe = await probeLevel(this.#quic, this.#version);\n\t\t\tawait new Setup({ probe, origin: this.origin }).encode(writer, this.#version);\n\t\t\twriter.close();\n\t\t} catch (err: unknown) {\n\t\t\twriter.reset(err);\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tasync #runBidis() {\n\t\tfor (;;) {\n\t\t\tconst stream = await Stream.accept(this.#quic);\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runBidi(stream)\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.writer.reset(err);\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tstream.writer.close();\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runBidi(stream: Stream) {\n\t\tconst typ = await stream.reader.u53();\n\n\t\tif (typ === StreamId.Session) {\n\t\t\tthrow new Error(\"duplicate session stream\");\n\t\t} else if (typ === StreamId.Announce) {\n\t\t\tconst msg = await AnnounceRequest.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runAnnounce(msg, stream);\n\t\t} else if (typ === StreamId.Subscribe) {\n\t\t\tconst msg = await Subscribe.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runSubscribe(msg, stream);\n\t\t} else if (typ === StreamId.Fetch) {\n\t\t\tconst msg = await Fetch.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runFetch(msg, stream);\n\t\t} else if (typ === StreamId.Track) {\n\t\t\tconst msg = await TrackMessage.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runTrackInfo(msg, stream);\n\t\t} else if (typ === StreamId.Probe) {\n\t\t\tawait this.#publisher.runProbe(stream);\n\t\t} else if (typ === StreamId.Goaway) {\n\t\t\tconst msg = await Goaway.decode(stream.reader, this.#version);\n\t\t\tconsole.info(\"received goaway:\", msg.uri);\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\tasync #runUnis() {\n\t\tconst readers = new Readers(this.#quic);\n\n\t\tfor (;;) {\n\t\t\tconst stream = await readers.next();\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runUni(stream)\n\t\t\t\t.then(() => {\n\t\t\t\t\tstream.stop(new Error(\"cancel\"));\n\t\t\t\t})\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.stop(err);\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runUni(stream: Reader) {\n\t\tconst typ = await stream.u53();\n\t\tif (typ === DataType.Group) {\n\t\t\tconst msg = await Group.decode(stream);\n\t\t\tawait this.#subscriber.runGroup(msg, stream);\n\t\t} else if (typ === DataType.Setup) {\n\t\t\t// The peer sends exactly one SETUP, then FINs. Record it so capability-gated\n\t\t\t// streams (e.g. PROBE) can react, then drain to the FIN.\n\t\t\tconst setup = await Setup.decode(stream, this.#version);\n\t\t\tthis.#peerSetup.set(setup);\n\t\t\tthis.#peerRole.set(setup.role);\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\t/** Snapshot the transport's counters; see {@link Established.stats}. */\n\tasync stats(): Promise<Stats> {\n\t\treturn transportStats(this.#quic);\n\t}\n\n\tget closed(): Promise<void> {\n\t\treturn this.#quic.closed.then(() => undefined);\n\t}\n}\n\n/**\n * The probe level to advertise in SETUP, from what the transport can measure.\n *\n * `Report` claims we can measure and periodically report, so it is only truthful\n * when a metric this version can carry actually exists. The qmux/WebSocket fallback\n * implements no `getStats()` at all, and even a transport that has one may report\n * neither figure. Advertising `Report` and then holding the subscriber's PROBE\n * stream open with nothing to send is the state this avoids; the subscriber's own\n * gate then skips a stream it could not use.\n *\n * Mirrors `ProbeLevel::detect` in `moq-net`, including its limitation: a metric\n * that only appears after SETUP reads as unsupported here.\n *\n * @internal\n */\nexport async function probeLevel(quic: WebTransport, version: Version): Promise<ProbeLevel> {\n\tconst getStats = (\n\t\tquic as unknown as {\n\t\t\tgetStats?: () => Promise<{ estimatedSendRate: number | null; smoothedRtt?: number | null }>;\n\t\t}\n\t).getStats;\n\tif (typeof getStats !== \"function\") return ProbeLevel.None;\n\n\t// A transport that can't answer tells us nothing, which is itself an answer.\n\tlet stats: { estimatedSendRate: number | null; smoothedRtt?: number | null };\n\ttry {\n\t\tstats = await getStats.call(quic);\n\t} catch {\n\t\treturn ProbeLevel.None;\n\t}\n\n\tconst rtt = hasProbeRtt(version) ? stats.smoothedRtt : undefined;\n\treturn stats.estimatedSendRate != null || rtt != null ? ProbeLevel.Report : ProbeLevel.None;\n}\n"]}
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/lite/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAA0B,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAkB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAClG,OAAO,EAAY,SAAS,EAAE,MAAM,WAAW,CAAC;AAGhD,OAAO,EAAe,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAa,KAAK,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,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CAAC;IACX,IAAI,OAAO,QAAQ,KAAK,UAAU;QAAE,OAAO,UAAU,CAAC,IAAI,CAAC;IAE3D,6EAA6E;IAC7E,IAAI,KAAwE,CAAC;IAC7E,IAAI,CAAC;QACJ,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,UAAU,CAAC,IAAI,CAAC;IACxB,CAAC;IAED,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;IACjE,OAAO,KAAK,CAAC,iBAAiB,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;AAC7F,CAAC","sourcesContent":["import { type Getter, Signal } from \"@moq/signals\";\nimport type * as announce from \"../announced.ts\";\nimport type { Established } from \"../connection/established.ts\";\nimport { type Probe, type Stats, transportStats } from \"../connection/stats.ts\";\nimport { type Transport, transportOf } from \"../connection/transport.ts\";\nimport { closeError, error, fromClose, StreamCode, StreamError, sessionCause } from \"../error.ts\";\nimport { type Hop, randomHop } from \"../hop.ts\";\nimport type { Consumer as OriginConsumer } from \"../origin.ts\";\nimport type * as Path from \"../path.ts\";\nimport { type Reader, Readers, Stream, Writer } from \"../stream.ts\";\nimport { registerWire } from \"../wire.ts\";\nimport { AnnounceRequest } from \"./announce.ts\";\nimport { Fetch } from \"./fetch.ts\";\nimport { Goaway } from \"./goaway.ts\";\nimport { Group } from \"./group.ts\";\nimport { Publisher } from \"./publisher.ts\";\nimport { SessionInfo } from \"./session.ts\";\nimport { ProbeLevel, type Role, Setup } from \"./setup.ts\";\nimport { DataType, StreamId } from \"./stream.ts\";\nimport { Subscribe } from \"./subscribe.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { Track as TrackMessage } from \"./track.ts\";\nimport { hasDatagrams, hasProbeRtt, hasSetupStream, type Version, versionName } from \"./version.ts\";\n\n/**\n * Constructor options for {@link Connection}.\n *\n * @internal\n */\nexport interface ConnectionProps {\n\t/** The URL of the connection. */\n\turl: URL;\n\t/** The established WebTransport session. */\n\tquic: WebTransport;\n\t/** The negotiated wire version. */\n\tversion: Version;\n\t/** The session stream, absent on drafts that have none. */\n\tsession?: Stream;\n\t/** Whether the relay supports broadcast discovery. Defaults to true. */\n\tdiscovery?: boolean;\n\t/** The origin whose broadcasts are served to the peer. Omit to publish nothing. */\n\tpublish?: OriginConsumer;\n}\n\n/**\n * Represents a connection to a MoQ server.\n *\n * @public\n */\nexport class Connection implements Established {\n\t// The URL of the connection.\n\treadonly url: URL;\n\n\t// The version of the connection as a human-readable string.\n\treadonly version: string;\n\n\t// The wire transport this session runs over.\n\treadonly transport: Transport;\n\n\t/** Whether the relay supports broadcast discovery; see {@link Established.discovery}. */\n\treadonly discovery: boolean;\n\n\t// The version used for encoding/decoding.\n\t#version: Version;\n\n\t// The established WebTransport session.\n\t#quic: WebTransport;\n\n\t// Use to receive/send session messages.\n\t#session?: Stream;\n\n\t// Module for contributing tracks.\n\t#publisher: Publisher;\n\n\t// Module for distributing tracks.\n\t#subscriber: Subscriber;\n\n\t/** The peer's PROBE estimates; see {@link Established.probe}. */\n\treadonly probe: Getter<Probe>;\n\n\t/** Random per-connection Hop ID. Shared by Publisher (for outbound hop\n\t * chains) and Subscriber (available for optional self-filtering on announces). */\n\treadonly hop: Hop;\n\n\t// The peer's SETUP, recorded once its Setup stream is read (lite-05+). Streams whose\n\t// encoding depends on a negotiated capability (e.g. PROBE) wait on this. undefined\n\t// until the peer's SETUP arrives; stays undefined forever on older drafts.\n\t#peerSetup = new Signal<Setup | undefined>(undefined);\n\n\t// Mirrors the role out of #peerSetup, so the public surface exposes the peer's declared\n\t// direction without handing out the whole SETUP (whose probe level gates our own streams).\n\t#peerRole = new Signal<Role | undefined>(undefined);\n\n\t// Written by the Subscriber as PROBE messages arrive.\n\t#probe = new Signal<Probe>({});\n\n\t/**\n\t * The {@link Role} the peer advertised in its SETUP, for a server deciding whether the\n\t * peer's authorization grants the direction it intends to use.\n\t *\n\t * `undefined` until the peer's SETUP arrives, and forever on pre-lite-05 versions, which\n\t * carry no in-band role. {@link Role.Both} is the absence of the parameter, so it is what\n\t * a peer reports when it declines to declare a direction, sends a value we don't\n\t * recognize, or is a server (which never sends one).\n\t */\n\tget peerRole(): Getter<Role | undefined> {\n\t\treturn this.#peerRole;\n\t}\n\n\t/**\n\t * Creates a new Connection instance.\n\t *\n\t * @internal\n\t */\n\tconstructor({ url, quic, version, session, discovery = true, publish }: ConnectionProps) {\n\t\tthis.url = url;\n\t\tthis.#quic = quic;\n\t\tthis.#session = session;\n\t\tthis.version = versionName(version);\n\t\tthis.#version = version;\n\t\tthis.transport = transportOf(quic);\n\t\tthis.discovery = discovery;\n\n\t\tthis.probe = this.#probe;\n\n\t\tthis.hop = randomHop();\n\t\tthis.#publisher = new Publisher(this.#quic, this.#version, this.hop, publish);\n\t\tthis.#subscriber = new Subscriber(this.#quic, this.#version, this.hop, this.#probe, this.#peerSetup);\n\t\tregisterWire(this, { consume: (path) => this.#subscriber.consume(path) });\n\n\t\tvoid this.#run();\n\t}\n\n\t/**\n\t * Closes the connection.\n\t */\n\tclose() {\n\t\tthis.#publisher.close();\n\t\tthis.#subscriber.close();\n\n\t\ttry {\n\t\t\t// TODO: For whatever reason, this try/catch doesn't seem to work..?\n\t\t\tthis.#quic.close();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t}\n\n\tasync #run(): Promise<void> {\n\t\tconst tasks: Promise<void>[] = [this.#runSession(), this.#runBidis(), this.#runUnis()];\n\n\t\tif (hasSetupStream(this.#version)) {\n\t\t\ttasks.push(this.#sendSetup());\n\t\t}\n\n\t\ttasks.push(this.#subscriber.runProbe());\n\n\t\t// Route incoming QUIC datagrams into their subscriptions (lite-05+; runDatagrams\n\t\t// no-ops on a transport that doesn't carry them).\n\t\tif (hasDatagrams(this.#version)) {\n\t\t\ttasks.push(this.#subscriber.runDatagrams());\n\t\t}\n\n\t\tlet fatal: Error | undefined;\n\t\ttry {\n\t\t\tawait Promise.all(tasks);\n\t\t} catch (err) {\n\t\t\tconsole.error(\"fatal error running connection\", err);\n\t\t\t// A session-sourced failure is the peer's close, not the raw transport error.\n\t\t\tfatal = await sessionCause(this.#quic, err);\n\t\t} finally {\n\t\t\t// The session died under every track it was receiving, so they end with its\n\t\t\t// error. A deliberate close() already ended them cleanly, which makes this a no-op.\n\t\t\tthis.#subscriber.close(fatal ?? (await closeError(this.#quic)));\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\tannounced(scope?: Path.Pattern, options?: announce.Options): announce.Consumer {\n\t\treturn this.#subscriber.announced(scope, options);\n\t}\n\n\tasync #runSession() {\n\t\tif (!this.#session) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst msg = await SessionInfo.decodeMaybe(this.#session.reader, this.#version);\n\t\t\t\tif (!msg) break;\n\t\t\t}\n\t\t} finally {\n\t\t\tconsole.debug(\"session stream closed\");\n\t\t}\n\t}\n\n\t// Open the unidirectional Setup Stream, send our single SETUP, and FIN (lite-05+).\n\t// The browser uses WebTransport, which carries the request URI, so we advertise no\n\t// path and leave routing to the URL. The probe level reflects what this transport\n\t// can actually measure; we never pad, so we never advertise Increase.\n\t// Role stays Both: the publish origin starts empty and fills later, and consume is\n\t// called after this point, so there is nothing to narrow yet. The origin declares\n\t// our session identity so the peer can filter\n\t// reflected announcements (lite-06 removed ANNOUNCE_REQUEST's exclude_hop for it).\n\tasync #sendSetup(): Promise<void> {\n\t\tconst writer = await Writer.open(this.#quic);\n\t\ttry {\n\t\t\tawait writer.u53(DataType.Setup);\n\t\t\tconst probe = await probeLevel(this.#quic, this.#version);\n\t\t\tawait new Setup({ probe, hop: this.hop }).encode(writer, this.#version);\n\t\t\twriter.close();\n\t\t} catch (err: unknown) {\n\t\t\twriter.reset(err);\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tasync #runBidis() {\n\t\tfor (;;) {\n\t\t\tconst stream = await Stream.accept(this.#quic);\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runBidi(stream)\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.writer.reset(err);\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tstream.writer.close();\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runBidi(stream: Stream) {\n\t\tconst typ = await stream.reader.u53();\n\n\t\tif (typ === StreamId.Session) {\n\t\t\tthrow new Error(\"duplicate session stream\");\n\t\t} else if (typ === StreamId.Announce) {\n\t\t\tconst msg = await AnnounceRequest.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runAnnounce(msg, stream);\n\t\t} else if (typ === StreamId.Subscribe) {\n\t\t\tconst msg = await Subscribe.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runSubscribe(msg, stream);\n\t\t} else if (typ === StreamId.Fetch) {\n\t\t\tconst msg = await Fetch.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runFetch(msg, stream);\n\t\t} else if (typ === StreamId.Track) {\n\t\t\tconst msg = await TrackMessage.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runTrackInfo(msg, stream);\n\t\t} else if (typ === StreamId.Probe) {\n\t\t\tawait this.#publisher.runProbe(stream);\n\t\t} else if (typ === StreamId.Goaway) {\n\t\t\tconst msg = await Goaway.decode(stream.reader, this.#version);\n\t\t\tconsole.info(\"received goaway:\", msg.uri);\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\tasync #runUnis() {\n\t\tconst readers = new Readers(this.#quic);\n\n\t\tfor (;;) {\n\t\t\tconst stream = await readers.next();\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runUni(stream)\n\t\t\t\t.then(() => {\n\t\t\t\t\tstream.stop(new StreamError(StreamCode.Cancel, { message: \"cancel\" }));\n\t\t\t\t})\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.stop(err);\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runUni(stream: Reader) {\n\t\tconst typ = await stream.u53();\n\t\tif (typ === DataType.Group) {\n\t\t\tconst msg = await Group.decode(stream, this.#version);\n\t\t\tawait this.#subscriber.runGroup(msg, stream);\n\t\t} else if (typ === DataType.Setup) {\n\t\t\t// The peer sends exactly one SETUP, then FINs. Record it so capability-gated\n\t\t\t// streams (e.g. PROBE) can react, then drain to the FIN.\n\t\t\tconst setup = await Setup.decode(stream, this.#version);\n\t\t\tthis.#peerSetup.set(setup);\n\t\t\tthis.#peerRole.set(setup.role);\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\t/** Snapshot the transport's counters; see {@link Established.stats}. */\n\tasync stats(): Promise<Stats> {\n\t\treturn transportStats(this.#quic);\n\t}\n\n\t/** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */\n\tget closed(): Promise<Error | null> {\n\t\treturn this.#quic.closed.then(fromClose, (err: unknown) => error(err));\n\t}\n}\n\n/**\n * The probe level to advertise in SETUP, from what the transport can measure.\n *\n * `Report` claims we can measure and periodically report, so it is only truthful\n * when a metric this version can carry actually exists. The qmux/WebSocket fallback\n * implements no `getStats()` at all, and even a transport that has one may report\n * neither figure. Advertising `Report` and then holding the subscriber's PROBE\n * stream open with nothing to send is the state this avoids; the subscriber's own\n * gate then skips a stream it could not use.\n *\n * Mirrors `ProbeLevel::detect` in `moq-net`, including its limitation: a metric\n * that only appears after SETUP reads as unsupported here.\n *\n * @internal\n */\nexport async function probeLevel(quic: WebTransport, version: Version): Promise<ProbeLevel> {\n\tconst getStats = (\n\t\tquic as unknown as {\n\t\t\tgetStats?: () => Promise<{ estimatedSendRate: number | null; smoothedRtt?: number | null }>;\n\t\t}\n\t).getStats;\n\tif (typeof getStats !== \"function\") return ProbeLevel.None;\n\n\t// A transport that can't answer tells us nothing, which is itself an answer.\n\tlet stats: { estimatedSendRate: number | null; smoothedRtt?: number | null };\n\ttry {\n\t\tstats = await getStats.call(quic);\n\t} catch {\n\t\treturn ProbeLevel.None;\n\t}\n\n\tconst rtt = hasProbeRtt(version) ? stats.smoothedRtt : undefined;\n\treturn stats.estimatedSendRate != null || rtt != null ? ProbeLevel.Report : ProbeLevel.None;\n}\n"]}
package/lite/fetch.d.ts CHANGED
@@ -7,7 +7,21 @@ export declare class Fetch {
7
7
  track: string;
8
8
  priority: number;
9
9
  group: number;
10
- constructor(broadcast: Path.Valid, track: string, priority: number, group: number);
10
+ /** Index of the first frame to return; 0 is the start of the group. Lite-06+. */
11
+ startFrame: number;
12
+ /**
13
+ * Index of the last frame to return (inclusive), or undefined for through the end
14
+ * of the group. Lite-06+.
15
+ */
16
+ endFrame?: number;
17
+ constructor({ broadcast, track, priority, group, startFrame, endFrame, }: {
18
+ broadcast: Path.Valid;
19
+ track: string;
20
+ priority: number;
21
+ group: number;
22
+ startFrame?: number;
23
+ endFrame?: number;
24
+ });
11
25
  encode(w: Writer, version: Version): Promise<void>;
12
26
  static decode(r: Reader, version: Version): Promise<Fetch>;
13
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/lite/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAYvC,qBAAa,KAAK;;IACjB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IAEd,YAAY,SAAS,EAAE,IAAI,CAAC,KAAK,EAAE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AAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAG/D;CACD"}
package/lite/fetch.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* @ts-self-types="./fetch.d.ts" */
2
2
  import * as Path from "../path.js";
3
3
  import * as Message from "./message.js";
4
- import { Version } from "./version.js";
4
+ import { hasFrameBounds, Version } from "./version.js";
5
5
  function guardFetch(version) {
6
6
  switch (version) {
7
7
  case Version.DRAFT_01:
@@ -16,32 +16,64 @@ export class Fetch {
16
16
  track;
17
17
  priority;
18
18
  group;
19
- constructor(broadcast, track, priority, group) {
19
+ /** Index of the first frame to return; 0 is the start of the group. Lite-06+. */
20
+ startFrame;
21
+ /**
22
+ * Index of the last frame to return (inclusive), or undefined for through the end
23
+ * of the group. Lite-06+.
24
+ */
25
+ endFrame;
26
+ constructor({ broadcast, track, priority, group, startFrame = 0, endFrame, }) {
20
27
  this.broadcast = broadcast;
21
28
  this.track = track;
22
29
  this.priority = priority;
23
30
  this.group = group;
31
+ this.startFrame = startFrame;
32
+ this.endFrame = endFrame;
24
33
  }
25
- async #encode(w) {
34
+ async #encode(w, version) {
26
35
  await w.string(Path.encode(this.broadcast));
27
36
  await w.string(this.track);
28
37
  await w.u8(this.priority);
29
38
  await w.u53(this.group);
39
+ if (hasFrameBounds(version)) {
40
+ await w.u53(this.startFrame);
41
+ await w.u53(this.endFrame !== undefined ? this.endFrame + 1 : 0);
42
+ }
43
+ else if (this.startFrame !== 0 || this.endFrame !== undefined) {
44
+ // The peer would serve the whole group, including frames we excluded.
45
+ throw new Error("frame bounds not supported for this version");
46
+ }
30
47
  }
31
- static async #decode(r) {
48
+ static async #decode(r, version) {
32
49
  const broadcast = Path.decode(await r.string());
33
50
  const track = await r.string();
34
51
  const priority = await r.u8();
35
52
  const group = await r.u53();
36
- return new Fetch(broadcast, track, priority, group);
53
+ if (!hasFrameBounds(version)) {
54
+ return new Fetch({ broadcast, track, priority, group });
55
+ }
56
+ const startFrame = await r.u53();
57
+ const endFrame = await r.u53();
58
+ if (endFrame > 0 && endFrame - 1 < startFrame) {
59
+ throw new Error("fetch frame range ends before it starts");
60
+ }
61
+ return new Fetch({
62
+ broadcast,
63
+ track,
64
+ priority,
65
+ group,
66
+ startFrame,
67
+ endFrame: endFrame > 0 ? endFrame - 1 : undefined,
68
+ });
37
69
  }
38
70
  async encode(w, version) {
39
71
  guardFetch(version);
40
- return Message.encode(w, (w) => this.#encode(w));
72
+ return Message.encode(w, (w) => this.#encode(w, version));
41
73
  }
42
74
  static async decode(r, version) {
43
75
  guardFetch(version);
44
- return Message.decode(r, (r) => Fetch.#decode(r));
76
+ return Message.decode(r, (r) => Fetch.#decode(r, version));
45
77
  }
46
78
  }
47
79
  //# sourceMappingURL=fetch.js.map
package/lite/fetch.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/lite/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,SAAS,UAAU,CAAC,OAAgB;IACnC,QAAQ,OAAO,EAAE,CAAC;QACjB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAAC,QAAQ;YACpB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QACzD;YACC,MAAM;IACR,CAAC;AACF,CAAC;AAED,MAAM,OAAO,KAAK;IACjB,SAAS,CAAa;IACtB,KAAK,CAAS;IACd,QAAQ,CAAS;IACjB,KAAK,CAAS;IAEd,YAAY,SAAqB,EAAE,KAAa,EAAE,QAAgB,EAAE,KAAa;QAChF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,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IACnD,CAAC;CACD","sourcesContent":["import * as Path from \"../path.ts\";\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { Version } from \"./version.ts\";\n\nfunction guardFetch(version: Version) {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\t\tthrow new Error(\"fetch not supported for this version\");\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n\nexport class Fetch {\n\tbroadcast: Path.Valid;\n\ttrack: string;\n\tpriority: number;\n\tgroup: number;\n\n\tconstructor(broadcast: Path.Valid, track: string, priority: number, group: number) {\n\t\tthis.broadcast = broadcast;\n\t\tthis.track = track;\n\t\tthis.priority = priority;\n\t\tthis.group = group;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.string(Path.encode(this.broadcast));\n\t\tawait w.string(this.track);\n\t\tawait w.u8(this.priority);\n\t\tawait w.u53(this.group);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Fetch> {\n\t\tconst broadcast = Path.decode(await r.string());\n\t\tconst track = await r.string();\n\t\tconst priority = await r.u8();\n\t\tconst group = await r.u53();\n\n\t\treturn new Fetch(broadcast, track, priority, group);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tguardFetch(version);\n\t\treturn Message.encode(w, (w) => this.#encode(w));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<Fetch> {\n\t\tguardFetch(version);\n\t\treturn Message.decode(r, (r) => Fetch.#decode(r));\n\t}\n}\n"]}
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/lite/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvD,SAAS,UAAU,CAAC,OAAgB;IACnC,QAAQ,OAAO,EAAE,CAAC;QAC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;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QACvC,UAAU,CAAC,OAAO,CAAC,CAAC;QACpB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,UAAU,CAAC,OAAO,CAAC,CAAC;QACpB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;CACD","sourcesContent":["import * as Path from \"../path.ts\";\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { hasFrameBounds, Version } from \"./version.ts\";\n\nfunction guardFetch(version: Version) {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\t\tthrow new Error(\"fetch not supported for this version\");\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n\nexport class Fetch {\n\tbroadcast: Path.Valid;\n\ttrack: string;\n\tpriority: number;\n\tgroup: number;\n\n\t/** Index of the first frame to return; 0 is the start of the group. Lite-06+. */\n\tstartFrame: number;\n\n\t/**\n\t * Index of the last frame to return (inclusive), or undefined for through the end\n\t * of the group. Lite-06+.\n\t */\n\tendFrame?: number;\n\n\tconstructor({\n\t\tbroadcast,\n\t\ttrack,\n\t\tpriority,\n\t\tgroup,\n\t\tstartFrame = 0,\n\t\tendFrame,\n\t}: {\n\t\tbroadcast: Path.Valid;\n\t\ttrack: string;\n\t\tpriority: number;\n\t\tgroup: number;\n\t\tstartFrame?: number;\n\t\tendFrame?: number;\n\t}) {\n\t\tthis.broadcast = broadcast;\n\t\tthis.track = track;\n\t\tthis.priority = priority;\n\t\tthis.group = group;\n\t\tthis.startFrame = startFrame;\n\t\tthis.endFrame = endFrame;\n\t}\n\n\tasync #encode(w: Writer, version: Version) {\n\t\tawait w.string(Path.encode(this.broadcast));\n\t\tawait w.string(this.track);\n\t\tawait w.u8(this.priority);\n\t\tawait w.u53(this.group);\n\n\t\tif (hasFrameBounds(version)) {\n\t\t\tawait w.u53(this.startFrame);\n\t\t\tawait w.u53(this.endFrame !== undefined ? this.endFrame + 1 : 0);\n\t\t} else if (this.startFrame !== 0 || this.endFrame !== undefined) {\n\t\t\t// The peer would serve the whole group, including frames we excluded.\n\t\t\tthrow new Error(\"frame bounds not supported for this version\");\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader, version: Version): Promise<Fetch> {\n\t\tconst broadcast = Path.decode(await r.string());\n\t\tconst track = await r.string();\n\t\tconst priority = await r.u8();\n\t\tconst group = await r.u53();\n\n\t\tif (!hasFrameBounds(version)) {\n\t\t\treturn new Fetch({ broadcast, track, priority, group });\n\t\t}\n\n\t\tconst startFrame = await r.u53();\n\t\tconst endFrame = await r.u53();\n\t\tif (endFrame > 0 && endFrame - 1 < startFrame) {\n\t\t\tthrow new Error(\"fetch frame range ends before it starts\");\n\t\t}\n\n\t\treturn new Fetch({\n\t\t\tbroadcast,\n\t\t\ttrack,\n\t\t\tpriority,\n\t\t\tgroup,\n\t\t\tstartFrame,\n\t\t\tendFrame: endFrame > 0 ? endFrame - 1 : undefined,\n\t\t});\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tguardFetch(version);\n\t\treturn Message.encode(w, (w) => this.#encode(w, version));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<Fetch> {\n\t\tguardFetch(version);\n\t\treturn Message.decode(r, (r) => Fetch.#decode(r, version));\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"goaway.d.ts","sourceRoot":"","sources":["../../src/lite/goaway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAgBvC,qBAAa,MAAM;;IAClB,GAAG,EAAE,MAAM,CAAC;IAEZ,YAAY,GAAG,EAAE,MAAM,EAEtB;IAUK,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvD;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAGhE;CACD"}
1
+ {"version":3,"file":"goaway.d.ts","sourceRoot":"","sources":["../../src/lite/goaway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAgBvC,qBAAa,MAAM;;IAClB,GAAG,EAAE,MAAM,CAAC;IAEZ,YAAY,GAAG,EAAE,MAAM,EAEtB;IAgBK,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvD;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAGhE;CACD"}
package/lite/goaway.js CHANGED
@@ -23,7 +23,13 @@ export class Goaway {
23
23
  await w.string(this.uri);
24
24
  }
25
25
  static async #decode(r) {
26
- return new Goaway(await r.string());
26
+ const uri = await r.string();
27
+ // The URI is capped at 8,192 bytes, matching the IETF wire and the Rust
28
+ // decoder; a longer one is a protocol violation.
29
+ if (new TextEncoder().encode(uri).byteLength > 8192) {
30
+ throw new Error("GOAWAY URI exceeds 8,192 bytes");
31
+ }
32
+ return new Goaway(uri);
27
33
  }
28
34
  async encode(w, version) {
29
35
  guardGoaway(version);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","sourcesContent":["import type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { Version } from \"./version.ts\";\n\nfunction guardGoaway(version: Version) {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\t\tthrow new Error(\"goaway not supported for this version\");\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n\n/// Sent to gracefully shut down a session and optionally redirect to a new URI.\n///\n/// Lite04+ only.\nexport class Goaway {\n\turi: string;\n\n\tconstructor(uri: string) {\n\t\tthis.uri = uri;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.string(this.uri);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Goaway> {\n\t\treturn new Goaway(await r.string());\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tguardGoaway(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<Goaway> {\n\t\tguardGoaway(version);\n\t\treturn Message.decode(r, Goaway.#decode);\n\t}\n}\n"]}
1
+ {"version":3,"file":"goaway.js","sourceRoot":"","sources":["../../src/lite/goaway.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,SAAS,WAAW,CAAC,OAAgB;IACpC,QAAQ,OAAO,EAAE,CAAC;QACjB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAAC,QAAQ;YACpB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC1D;YACC,MAAM;IACR,CAAC;AACF,CAAC;AAED,gFAAgF;AAChF,GAAG;AACH,iBAAiB;AACjB,MAAM,OAAO,MAAM;IAClB,GAAG,CAAS;IAEZ,YAAY,GAAW;QACtB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS;QACtB,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAS;QAC7B,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;QAC7B,wEAAwE;QACxE,iDAAiD;QACjD,IAAI,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,UAAU,GAAG,IAAI,EAAE,CAAC;YACrD,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QACvC,WAAW,CAAC,OAAO,CAAC,CAAC;QACrB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,WAAW,CAAC,OAAO,CAAC,CAAC;QACrB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;CACD","sourcesContent":["import type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { Version } from \"./version.ts\";\n\nfunction guardGoaway(version: Version) {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\t\tthrow new Error(\"goaway not supported for this version\");\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n\n/// Sent to gracefully shut down a session and optionally redirect to a new URI.\n///\n/// Lite04+ only.\nexport class Goaway {\n\turi: string;\n\n\tconstructor(uri: string) {\n\t\tthis.uri = uri;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.string(this.uri);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Goaway> {\n\t\tconst uri = await r.string();\n\t\t// The URI is capped at 8,192 bytes, matching the IETF wire and the Rust\n\t\t// decoder; a longer one is a protocol violation.\n\t\tif (new TextEncoder().encode(uri).byteLength > 8192) {\n\t\t\tthrow new Error(\"GOAWAY URI exceeds 8,192 bytes\");\n\t\t}\n\t\treturn new Goaway(uri);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tguardGoaway(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<Goaway> {\n\t\tguardGoaway(version);\n\t\treturn Message.decode(r, Goaway.#decode);\n\t}\n}\n"]}
package/lite/group.d.ts CHANGED
@@ -1,12 +1,26 @@
1
1
  import type { Reader, Writer } from "../stream";
2
+ import { type Version } from "./version";
2
3
  export declare class Group {
3
4
  #private;
4
5
  subscribe: bigint;
5
6
  sequence: number;
6
- constructor(subscribe: bigint, sequence: number);
7
- encode(w: Writer): Promise<void>;
8
- static decode(r: Reader): Promise<Group>;
9
- static decodeMaybe(r: Reader): Promise<Group | undefined>;
7
+ /**
8
+ * The index of the first frame on this stream within the group.
9
+ *
10
+ * 0 (the common case) means the stream carries the group from its beginning. A
11
+ * higher value means the leading frames are not here, either because the
12
+ * subscription started partway into the group or because the publisher only holds
13
+ * the tail. Lite-06+; older versions always start at 0.
14
+ */
15
+ frameStart: number;
16
+ constructor({ subscribe, sequence, frameStart, }: {
17
+ subscribe: bigint;
18
+ sequence: number;
19
+ frameStart?: number;
20
+ });
21
+ encode(w: Writer, version: Version): Promise<void>;
22
+ static decode(r: Reader, version: Version): Promise<Group>;
23
+ static decodeMaybe(r: Reader, version: Version): Promise<Group | undefined>;
10
24
  }
11
25
  export declare class Frame {
12
26
  #private;
@@ -1 +1 @@
1
- {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../src/lite/group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGnD,qBAAa,KAAK;;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IAEjB,YAAY,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAG9C;IAWK,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErC;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAE7C;IAED,OAAa,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAE9D;CACD;AAED,qBAAa,KAAK;;IACjB,OAAO,EAAE,UAAU,CAAC;IAEpB,YAAY,OAAO,EAAE,UAAU,EAE9B;IAWK,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErC;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAE7C;CACD"}
1
+ {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../src/lite/group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5D,qBAAa,KAAK;;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;;OAOG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB,YAAY,EACX,SAAS,EACT,QAAQ,EACR,UAAc,GACd,EAAE;QACF,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,CAAC,EAAE,MAAM,CAAC;KACpB,EAIA;IAoBK,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvD;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAE/D;IAED,OAAa,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAEhF;CACD;AAED,qBAAa,KAAK;;IACjB,OAAO,EAAE,UAAU,CAAC;IAEpB,YAAY,OAAO,EAAE,UAAU,EAE9B;IAWK,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErC;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAE7C;CACD"}
package/lite/group.js CHANGED
@@ -1,27 +1,48 @@
1
1
  /* @ts-self-types="./group.d.ts" */
2
2
  import * as Message from "./message.js";
3
+ import { hasFrameBounds } from "./version.js";
3
4
  export class Group {
4
5
  subscribe;
5
6
  sequence;
6
- constructor(subscribe, sequence) {
7
+ /**
8
+ * The index of the first frame on this stream within the group.
9
+ *
10
+ * 0 (the common case) means the stream carries the group from its beginning. A
11
+ * higher value means the leading frames are not here, either because the
12
+ * subscription started partway into the group or because the publisher only holds
13
+ * the tail. Lite-06+; older versions always start at 0.
14
+ */
15
+ frameStart;
16
+ constructor({ subscribe, sequence, frameStart = 0, }) {
7
17
  this.subscribe = subscribe;
8
18
  this.sequence = sequence;
19
+ this.frameStart = frameStart;
9
20
  }
10
- async #encode(w) {
21
+ async #encode(w, version) {
11
22
  await w.u62(this.subscribe);
12
23
  await w.u53(this.sequence);
24
+ if (hasFrameBounds(version)) {
25
+ await w.u53(this.frameStart);
26
+ }
27
+ else if (this.frameStart !== 0) {
28
+ // The peer would number the frames from 0 and silently misalign the group.
29
+ throw new Error("frame offsets not supported for this version");
30
+ }
13
31
  }
14
- static async #decode(r) {
15
- return new Group(await r.u62(), await r.u53());
32
+ static async #decode(r, version) {
33
+ const subscribe = await r.u62();
34
+ const sequence = await r.u53();
35
+ const frameStart = hasFrameBounds(version) ? await r.u53() : 0;
36
+ return new Group({ subscribe, sequence, frameStart });
16
37
  }
17
- async encode(w) {
18
- return Message.encode(w, this.#encode.bind(this));
38
+ async encode(w, version) {
39
+ return Message.encode(w, (w) => this.#encode(w, version));
19
40
  }
20
- static async decode(r) {
21
- return Message.decode(r, Group.#decode);
41
+ static async decode(r, version) {
42
+ return Message.decode(r, (r) => Group.#decode(r, version));
22
43
  }
23
- static async decodeMaybe(r) {
24
- return Message.decodeMaybe(r, Group.#decode);
44
+ static async decodeMaybe(r, version) {
45
+ return Message.decodeMaybe(r, (r) => Group.#decode(r, version));
25
46
  }
26
47
  }
27
48
  export class Frame {
package/lite/group.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"group.js","sourceRoot":"","sources":["../../src/lite/group.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,MAAM,OAAO,KAAK;IACjB,SAAS,CAAS;IAClB,QAAQ,CAAS;IAEjB,YAAY,SAAiB,EAAE,QAAgB;QAC9C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS;QACtB,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5B,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAS;QAC7B,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,C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\";\n\nexport class Group {\n\tsubscribe: bigint;\n\tsequence: number;\n\n\tconstructor(subscribe: bigint, sequence: number) {\n\t\tthis.subscribe = subscribe;\n\t\tthis.sequence = sequence;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u62(this.subscribe);\n\t\tawait w.u53(this.sequence);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Group> {\n\t\treturn new Group(await r.u62(), await r.u53());\n\t}\n\n\tasync encode(w: Writer): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader): Promise<Group> {\n\t\treturn Message.decode(r, Group.#decode);\n\t}\n\n\tstatic async decodeMaybe(r: Reader): Promise<Group | undefined> {\n\t\treturn Message.decodeMaybe(r, Group.#decode);\n\t}\n}\n\nexport class Frame {\n\tpayload: Uint8Array;\n\n\tconstructor(payload: Uint8Array) {\n\t\tthis.payload = payload;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.write(this.payload);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Frame> {\n\t\tconst payload = await r.readAll();\n\t\treturn new Frame(payload);\n\t}\n\n\tasync encode(w: Writer): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader): Promise<Frame> {\n\t\treturn Message.decode(r, Frame.#decode);\n\t}\n}\n"]}
1
+ {"version":3,"file":"group.js","sourceRoot":"","sources":["../../src/lite/group.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,cAAc,EAAgB,MAAM,cAAc,CAAC;AAE5D,MAAM,OAAO,KAAK;IACjB,SAAS,CAAS;IAClB,QAAQ,CAAS;IAEjB;;;;;;;OAOG;IACH,UAAU,CAAS;IAEnB,YAAY,EACX,SAAS,EACT,QAAQ,EACR,UAAU,GAAG,CAAC,GAKd;QACA,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,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MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAS,EAAE,OAAgB;QACnD,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IACjE,CAAC;CACD;AAED,MAAM,OAAO,KAAK;IACjB,OAAO,CAAa;IAEpB,YAAY,OAAmB;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS;QACtB,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAS;QAC7B,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;QAClC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS;QACrB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS;QAC5B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACD","sourcesContent":["import type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { hasFrameBounds, type Version } from \"./version.ts\";\n\nexport class Group {\n\tsubscribe: bigint;\n\tsequence: number;\n\n\t/**\n\t * The index of the first frame on this stream within the group.\n\t *\n\t * 0 (the common case) means the stream carries the group from its beginning. A\n\t * higher value means the leading frames are not here, either because the\n\t * subscription started partway into the group or because the publisher only holds\n\t * the tail. Lite-06+; older versions always start at 0.\n\t */\n\tframeStart: number;\n\n\tconstructor({\n\t\tsubscribe,\n\t\tsequence,\n\t\tframeStart = 0,\n\t}: {\n\t\tsubscribe: bigint;\n\t\tsequence: number;\n\t\tframeStart?: number;\n\t}) {\n\t\tthis.subscribe = subscribe;\n\t\tthis.sequence = sequence;\n\t\tthis.frameStart = frameStart;\n\t}\n\n\tasync #encode(w: Writer, version: Version) {\n\t\tawait w.u62(this.subscribe);\n\t\tawait w.u53(this.sequence);\n\t\tif (hasFrameBounds(version)) {\n\t\t\tawait w.u53(this.frameStart);\n\t\t} else if (this.frameStart !== 0) {\n\t\t\t// The peer would number the frames from 0 and silently misalign the group.\n\t\t\tthrow new Error(\"frame offsets not supported for this version\");\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader, version: Version): Promise<Group> {\n\t\tconst subscribe = await r.u62();\n\t\tconst sequence = await r.u53();\n\t\tconst frameStart = hasFrameBounds(version) ? await r.u53() : 0;\n\t\treturn new Group({ subscribe, sequence, frameStart });\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\treturn Message.encode(w, (w) => this.#encode(w, version));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<Group> {\n\t\treturn Message.decode(r, (r) => Group.#decode(r, version));\n\t}\n\n\tstatic async decodeMaybe(r: Reader, version: Version): Promise<Group | undefined> {\n\t\treturn Message.decodeMaybe(r, (r) => Group.#decode(r, version));\n\t}\n}\n\nexport class Frame {\n\tpayload: Uint8Array;\n\n\tconstructor(payload: Uint8Array) {\n\t\tthis.payload = payload;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.write(this.payload);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Frame> {\n\t\tconst payload = await r.readAll();\n\t\treturn new Frame(payload);\n\t}\n\n\tasync encode(w: Writer): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader): Promise<Frame> {\n\t\treturn Message.decode(r, Frame.#decode);\n\t}\n}\n"]}
@@ -3,65 +3,5 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import type { Writer } from "../stream";
7
- import type * as track from "../track";
8
- /**
9
- * What to rank a group stream by.
10
- *
11
- * @internal
12
- */
13
- export interface Rank {
14
- /** The subscriber's track priority, which outweighs everything below it. */
15
- priority: number;
16
- /**
17
- * Where the group sits in the queue its own subscription wants sent, 0 being the one to
18
- * send next. Defaults to 0, which is right for a stream that is the only one of its kind.
19
- */
20
- position?: number;
21
- }
22
- /**
23
- * The transport send order for a group, where HIGHER values are transmitted first.
24
- *
25
- * A higher `priority` always wins. Below it, a group is ranked by its `position` in its own
26
- * subscription rather than by its sequence, so two tracks at the same priority interleave:
27
- * each one's next group ties with the other's, whatever their group numbering. Comparing
28
- * sequences instead would let a track that had been running longer, or that numbered its
29
- * groups from a clock, starve one that started later.
30
- *
31
- * @internal
32
- */
33
- export declare function sendOrder({ priority, position }: Rank): number;
34
- /**
35
- * Ranks one subscription's group streams against each other, and re-ranks them whenever the
36
- * set changes or the subscription is updated.
37
- *
38
- * A group's rank is its position among the groups in flight, so which group goes first is
39
- * decided here rather than by arithmetic on sequence numbers. Newest-first by default, since
40
- * that is what live playback wants; an `ordered` subscription is playing through in sequence,
41
- * so it gets the oldest group first instead.
42
- *
43
- * One listener covers the whole subscription. A listener per group would instead pile up on
44
- * it, and a track that stalls with many groups open would trip the signals leak guard.
45
- *
46
- * @internal
47
- */
48
- export declare class Priority {
49
- #private;
50
- /** Follow `track`'s subscription until {@link close}. */
51
- constructor(track: track.Subscriber);
52
- /** The send order for a group at `sequence`, whether or not it has a stream yet. */
53
- rank(sequence: number): number;
54
- /** Rank a group's stream now, and again whenever the ranking changes, until {@link remove}. */
55
- add(stream: Writer, sequence: number): void;
56
- /** Stop ranking a finished group's stream, promoting whatever was queued behind it. */
57
- remove(stream: Writer): void;
58
- /**
59
- * Stop taking new groups, and release the subscription listener once the last one leaves.
60
- *
61
- * The track can finish while several groups are still draining, and those are the ones the
62
- * subscriber is still waiting on. They keep being promoted as the groups ahead of them
63
- * finish, rather than being stranded at whatever position they held when the track ended.
64
- */
65
- close(): void;
66
- }
6
+ export {};
67
7
  //# sourceMappingURL=priority.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"priority.d.ts","sourceRoot":"","sources":["../../src/lite/priority.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAC;AAY1C;;;;GAIG;AACH,MAAM,WAAW,IAAI;IACpB,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,QAAY,EAAE,EAAE,IAAI,GAAG,MAAM,CAElE;AAQD;;;;;;;;;;;;;GAaG;AACH,qBAAa,QAAQ;;IAMpB,yDAAyD;IACzD,YAAY,KAAK,EAAE,KAAK,CAAC,UAAU,EAGlC;IAED,oFAAoF;IACpF,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAK7B;IAED,+FAA+F;IAC/F,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAMnC;IAED,uFAAuF;IACvF,MAAM,CAAC,MAAM,EAAE,MAAM,QAQpB;IAED;;;;;;OAMG;IACH,KAAK,SAGJ;CAqBD"}
1
+ {"version":3,"file":"priority.d.ts","sourceRoot":"","sources":["../../src/lite/priority.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}