@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,18 +1,24 @@
1
1
  /* @ts-self-types="./subscriber.d.ts" */
2
+ import { race, Signal } from "@moq/signals";
2
3
  import * as announce from "../announced.js";
3
4
  import * as broadcast from "../broadcast.js";
4
5
  import { BroadcastCache } from "../consume.js";
5
- import { error, ProtocolViolation, reason } from "../error.js";
6
+ import { closeError, controlTimeout, error, ProtocolViolation, reason, sessionCause } from "../error.js";
6
7
  import * as netGroup from "../group.js";
8
+ import { Cost, routesEqual, UNKNOWN_HOP } from "../hop.js";
9
+ import { hiddenBelow, hooks, scopeCaptures, scopeHead, scopeOverlaps } from "../internal.js";
7
10
  import * as Path from "../path.js";
11
+ import { TAIL_GRACE_MS, Tail } from "../tail.js";
8
12
  import { Timestamp } from "../time.js";
9
- import { withTimeout } from "../util/timeout.js";
13
+ import { TimeoutError, withTimeout } from "../util/timeout.js";
14
+ import { overrideBroadcastWire, wireOf } from "../wire.js";
10
15
  import { DuplicateTrackAlias, RetiredTrackAlias, TrackAliases } from "./aliases.js";
11
16
  import * as Cluster from "./cluster.js";
17
+ import { requestReason, toRequestCode } from "./error.js";
12
18
  import { Frame } from "./object.js";
13
- import { toWire } from "./priority.js";
14
- import { PublishError } from "./publish.js";
15
- import { PublishNamespace, PublishNamespaceDone, PublishNamespaceError, PublishNamespaceOk, } from "./publish_namespace.js";
19
+ import { fromWire, toWire } from "./priority.js";
20
+ import { PublishDone, PublishError, publishDoneClean } from "./publish.js";
21
+ import { PublishNamespaceDone, PublishNamespaceError, PublishNamespaceOk, PublishNamespaceUpdate, } from "./publish_namespace.js";
16
22
  import { RequestError, RequestOk } from "./request.js";
17
23
  import { joinFilter, Subscribe, SubscribeError, SubscribeOk, Unsubscribe } from "./subscribe.js";
18
24
  import { PublishBlocked, SubscribeNamespace, SubscribeNamespaceEntry, SubscribeNamespaceEntryDone, SubscribeNamespaceLegacy, SubscribeNamespaceOk, UnsubscribeNamespace, } from "./subscribe_namespace.js";
@@ -21,6 +27,10 @@ import { Version } from "./version.js";
21
27
  // concurrent QUIC streams (Chrome ~100); past the cap openBi() silently
22
28
  // blocks. The timeout turns that into a clear error.
23
29
  const SUBSCRIBE_OK_TIMEOUT_MS = 10_000;
30
+ /** Whether a reader with `filter` sees an announcement at `path`. */
31
+ function sees(filter, path) {
32
+ return scopeOverlaps(filter.scope, path) && (filter.hidden || !hiddenBelow(filter.prefix, path));
33
+ }
24
34
  /**
25
35
  * Handles subscribing to broadcasts using moq-transport protocol.
26
36
  * Uses the stream-per-request pattern (real bidi streams for v17, virtual for v14-v16).
@@ -29,6 +39,9 @@ const SUBSCRIBE_OK_TIMEOUT_MS = 10_000;
29
39
  */
30
40
  export class Subscriber {
31
41
  #session;
42
+ // The transport, so a request cut off by the session's close ends with the session's
43
+ // error. Optional for tests that drive a bare session.
44
+ #quic;
32
45
  // The Hop IDs this session declared; see {@link Cluster}. What the peer declared is what
33
46
  // says whether an advertisement carries a hop path, and ours is what a path looping back
34
47
  // to us contains.
@@ -53,16 +66,20 @@ export class Subscriber {
53
66
  // Counting them is what keeps the second from duplicating the announce and the first
54
67
  // to end from retracting what the other still holds.
55
68
  #announced = new Map();
56
- // Any consumers that want each new announcement.
57
- #announcedConsumers = new Set();
69
+ // Any consumers that want each new announcement, keyed by their local filter.
70
+ #announcedConsumers = new Map();
71
+ // Whether the peer understands the HIDDEN parameter (MoQ Hidden).
72
+ #hidden;
58
73
  /**
59
74
  * Creates a new Subscriber instance.
60
75
  *
61
76
  * @internal
62
77
  */
63
- constructor({ session, cluster, }) {
78
+ constructor({ session, quic, cluster, hidden = false, }) {
64
79
  this.#session = session;
80
+ this.#quic = quic;
65
81
  this.#cluster = cluster;
82
+ this.#hidden = hidden;
66
83
  }
67
84
  /**
68
85
  * Whether an advertisement is ours coming back: its hop path already ran through us, so
@@ -75,23 +92,42 @@ export class Subscriber {
75
92
  #reflected(advert) {
76
93
  return advert !== undefined && this.#cluster !== undefined && Cluster.loops(advert, this.#cluster.self);
77
94
  }
95
+ /** The route an advertisement carries; one without a path is anonymous and free. */
96
+ #route(advert) {
97
+ if (advert === undefined)
98
+ return { hops: [UNKNOWN_HOP], cost: Cost.zero };
99
+ return { hops: advert.hops, cost: { warm: advert.cost, cold: advert.cost } };
100
+ }
78
101
  /**
79
- * Gets an announced reader for the specified prefix.
102
+ * Gets an announced reader matching `scope`. Paths are relative to the session,
103
+ * not the scope.
80
104
  *
81
105
  * The peer is asked with SUBSCRIBE_NAMESPACE regardless of what it declared, and an
82
106
  * unsolicited PUBLISH_NAMESPACE lands here too, so a peer that only tells and one
83
107
  * that only answers are both discovered.
108
+ *
109
+ * Hidden routes (a `.`-prefixed segment below the scope's head) are left out unless
110
+ * `options.hidden` opts in. The opt-in rides the SUBSCRIBE_NAMESPACE when the peer
111
+ * understands it (MoQ Hidden); the rule is also applied here, since an unsolicited
112
+ * PUBLISH_NAMESPACE or a peer that never heard of it hides nothing.
84
113
  */
85
- announced(prefix = Path.empty()) {
86
- const announced = new announce.Producer(prefix);
87
- for (const active of this.#announced.keys()) {
88
- const suffix = Path.stripPrefix(prefix, active);
89
- if (suffix === null)
114
+ announced(scope = Path.Pattern.all(), options) {
115
+ // The wire speaks announce interest by prefix.
116
+ const prefix = scopeHead(scope);
117
+ const filter = { scope, prefix, hidden: options?.hidden ?? false };
118
+ const announced = new announce.Producer();
119
+ for (const [active, info] of this.#announced) {
120
+ if (!sees(filter, active))
90
121
  continue;
91
- announced.append({ path: suffix, active: true });
122
+ announced.append({
123
+ prefix: active,
124
+ captures: scopeCaptures(scope, active),
125
+ kind: "announced",
126
+ route: info.route,
127
+ });
92
128
  }
93
- this.#announcedConsumers.add(announced);
94
- void this.#runAnnounced(announced, prefix).finally(() => {
129
+ this.#announcedConsumers.set(announced, filter);
130
+ void this.#runAnnounced(announced, prefix, filter.hidden && this.#hidden).finally(() => {
95
131
  this.#announcedConsumers.delete(announced);
96
132
  announced.close();
97
133
  });
@@ -101,28 +137,48 @@ export class Subscriber {
101
137
  * Record one more advertisement for a path, telling consumers only when it is the
102
138
  * first. A second one is the same namespace said twice, not news.
103
139
  */
104
- #attachAnnounce(path) {
105
- const count = this.#announced.get(path) ?? 0;
106
- this.#announced.set(path, count + 1);
107
- if (count > 0)
140
+ #attachAnnounce(path, route) {
141
+ const existing = this.#announced.get(path);
142
+ if (existing) {
143
+ existing.count += 1;
108
144
  return;
145
+ }
146
+ this.#announced.set(path, { count: 1, route });
109
147
  console.debug(`announced: broadcast=${path} active=true`);
110
- for (const consumer of this.#announcedConsumers) {
111
- const suffix = Path.stripPrefix(consumer.prefix, path);
112
- if (suffix === null)
148
+ for (const [consumer, filter] of this.#announcedConsumers) {
149
+ if (!sees(filter, path))
113
150
  continue;
114
- consumer.append({ path: suffix, active: true });
151
+ const scope = filter.scope;
152
+ consumer.append({ prefix: path, captures: scopeCaptures(scope, path), kind: "announced", route });
153
+ }
154
+ }
155
+ /**
156
+ * Replace the stored route for a path that is already announced. A no-op when the
157
+ * hops and cost did not change; otherwise consumers hear `updated` so a forwarder
158
+ * can reprice without retracting.
159
+ */
160
+ #updateAnnounce(path, route) {
161
+ const existing = this.#announced.get(path);
162
+ if (existing === undefined || routesEqual(existing.route, route))
163
+ return;
164
+ existing.route = route;
165
+ console.debug(`announced: broadcast=${path} rerouted`);
166
+ for (const [consumer, filter] of this.#announcedConsumers) {
167
+ if (!sees(filter, path))
168
+ continue;
169
+ const scope = filter.scope;
170
+ consumer.append({ prefix: path, captures: scopeCaptures(scope, path), kind: "updated", route });
115
171
  }
116
172
  }
117
173
  /**
118
174
  * Drop one advertisement for a path, retracting it only once the last one goes.
119
175
  */
120
176
  #detachAnnounce(path) {
121
- const count = this.#announced.get(path);
122
- if (count === undefined)
177
+ const existing = this.#announced.get(path);
178
+ if (existing === undefined)
123
179
  return;
124
- if (count > 1) {
125
- this.#announced.set(path, count - 1);
180
+ if (existing.count > 1) {
181
+ existing.count -= 1;
126
182
  return;
127
183
  }
128
184
  this.#announced.delete(path);
@@ -130,19 +186,24 @@ export class Subscriber {
130
186
  // would otherwise hand the dead generation to whoever consumes the path next.
131
187
  this.#consumes.evict(path);
132
188
  console.debug(`announced: broadcast=${path} active=false`);
133
- for (const consumer of this.#announcedConsumers) {
134
- const suffix = Path.stripPrefix(consumer.prefix, path);
135
- if (suffix === null)
189
+ for (const [consumer, filter] of this.#announcedConsumers) {
190
+ if (!sees(filter, path))
136
191
  continue;
192
+ const scope = filter.scope;
137
193
  try {
138
- consumer.append({ path: suffix, active: false });
194
+ consumer.append({
195
+ prefix: path,
196
+ captures: scopeCaptures(scope, path),
197
+ kind: "retracted",
198
+ route: existing.route,
199
+ });
139
200
  }
140
201
  catch {
141
202
  // Consumer already closed, will be cleaned up
142
203
  }
143
204
  }
144
205
  }
145
- async #runAnnounced(announced, prefix) {
206
+ async #runAnnounced(announced, prefix, hidden) {
146
207
  const version = this.#session.version;
147
208
  // Suffixes live on this stream, so a repeat is recognized as an update to the
148
209
  // advertisement rather than a second one, which would leak the count.
@@ -171,11 +232,11 @@ export class Subscriber {
171
232
  version === Version.DRAFT_16 ||
172
233
  version === Version.DRAFT_17) {
173
234
  await stream.writer.u53(SubscribeNamespaceLegacy.id);
174
- await new SubscribeNamespaceLegacy({ namespace: prefix, requestId }).encode(stream.writer, version);
235
+ await new SubscribeNamespaceLegacy({ namespace: prefix, requestId, hidden }).encode(stream.writer, version);
175
236
  }
176
237
  else {
177
238
  await stream.writer.u53(SubscribeNamespace.id);
178
- await new SubscribeNamespace({ namespace: prefix, requestId }).encode(stream.writer, version);
239
+ await new SubscribeNamespace({ namespace: prefix, requestId, hidden }).encode(stream.writer, version);
179
240
  }
180
241
  console.debug(`subscribe_namespace written: requestId=${requestId}`);
181
242
  // Read response
@@ -212,10 +273,15 @@ export class Subscriber {
212
273
  this.#detachAnnounce(path);
213
274
  continue;
214
275
  }
215
- // A repeat updates the advertisement; only the first is news.
216
- if (!live.has(path)) {
276
+ // A repeat replaces the advertisement in place: HOP_PATH / ROUTE_COST
277
+ // can change without a NAMESPACE_DONE. Only the first is a new path.
278
+ const route = this.#route(entry.cluster);
279
+ if (live.has(path)) {
280
+ this.#updateAnnounce(path, route);
281
+ }
282
+ else {
217
283
  live.add(path);
218
- this.#attachAnnounce(path);
284
+ this.#attachAnnounce(path, route);
219
285
  }
220
286
  }
221
287
  else if (msgType === SubscribeNamespaceEntryDone.id) {
@@ -246,7 +312,7 @@ export class Subscriber {
246
312
  this.#session.close();
247
313
  });
248
314
  // Wait for either the read loop or the announced to close
249
- await Promise.race([readLoop, announced.closed]);
315
+ await race([readLoop, announced.closed]);
250
316
  // For v14/v15: send UnsubscribeNamespace before closing
251
317
  if (version === Version.DRAFT_14 || version === Version.DRAFT_15) {
252
318
  try {
@@ -308,7 +374,7 @@ export class Subscriber {
308
374
  const consumer = new ConsumeBroadcast();
309
375
  void (async () => {
310
376
  for (;;) {
311
- const request = await consumer.requested();
377
+ const request = await wireOf(consumer).requested();
312
378
  if (!request)
313
379
  break;
314
380
  void this.#runSubscribe(path, request);
@@ -316,28 +382,43 @@ export class Subscriber {
316
382
  })();
317
383
  return consumer;
318
384
  }
385
+ // The adapter is gone. If the transport has already closed, that close is the
386
+ // error. A still-open transport, such as a GOAWAY drain, has no peer code yet,
387
+ // so this does not wait for it.
388
+ async #closedSession() {
389
+ const quic = this.#quic;
390
+ if (!quic)
391
+ return new Error("session closed");
392
+ return Promise.race([
393
+ closeError(quic),
394
+ new Promise((resolve) => queueMicrotask(() => resolve(new Error("session closed")))),
395
+ ]);
396
+ }
319
397
  async #runSubscribe(broadcast, request) {
320
398
  const requestId = await this.#session.nextRequestId();
321
399
  if (requestId === undefined) {
322
- request.reject(new Error("session closed"));
400
+ request.reject(await this.#closedSession());
323
401
  return;
324
402
  }
325
403
  console.debug(`subscribe start: id=${requestId} broadcast=${broadcast} track=${request.name}`);
326
- // IETF negotiates group order in SUBSCRIBE_OK; this implementation only
327
- // supports descending (newest-first), so commit ordered: false. (There's no
328
- // per-frame timescale, so the rest stay at their defaults.) This
329
- // resolves the consumer's track.info() and gives us the write side that
330
- // incoming object streams are routed into.
331
- const producer = request.accept({ ordered: false });
404
+ // Keep the request pending until SUBSCRIBE_OK supplies immutable track metadata.
405
+ // Group streams already wait on the alias, so early data stays behind this response.
406
+ const producer = hooks.pendingTrackProducer(request);
407
+ const subscription = { track: producer, tail: new Tail() };
332
408
  // Open the stream and wait for SUBSCRIBE_OK under a timeout. State
333
409
  // flows back via `state` so the timeout path can clean up the stream
334
410
  // and any registration if setup eventually finishes.
335
411
  const state = {};
336
- const setup = this.#openSubscribe(state, broadcast, request, producer, requestId);
412
+ const setup = this.#openSubscribe(state, broadcast, request, subscription, requestId);
337
413
  // The publisher can be serving before it answers, so waiting only on the response
338
414
  // would miss the local side going away and leave it serving a track nobody reads.
339
415
  // Demand returning before we commit is not abandonment, matching the serving loop.
340
416
  const waitAbandoned = async () => {
417
+ // An info-only lookup attaches no subscriber yet still waits on SUBSCRIBE_OK for
418
+ // the track info, so only demand that arrived and then left is abandonment.
419
+ while (!producer.used.peek() && producer.closed.peek() === undefined) {
420
+ await Signal.race(producer.used, producer.closed);
421
+ }
341
422
  for (;;) {
342
423
  await producer.unused();
343
424
  if (producer.closed.peek() !== undefined || !producer.used.peek())
@@ -347,7 +428,7 @@ export class Subscriber {
347
428
  let stream;
348
429
  let trackAlias;
349
430
  try {
350
- const result = await Promise.race([
431
+ const result = await race([
351
432
  withTimeout(setup, SUBSCRIBE_OK_TIMEOUT_MS, `subscribe timed out after ${SUBSCRIBE_OK_TIMEOUT_MS}ms waiting for SUBSCRIBE_OK (browser stream limit reached?)`),
352
433
  waitAbandoned(),
353
434
  ]);
@@ -358,8 +439,9 @@ export class Subscriber {
358
439
  console.debug(`subscribe ok: id=${requestId} broadcast=${broadcast} track=${request.name}`);
359
440
  }
360
441
  catch (err) {
361
- const e = error(err);
362
- producer.close(e);
442
+ // A control request that timed out is not late content, so it carries its own code.
443
+ const e = err instanceof TimeoutError ? controlTimeout(err) : await sessionCause(this.#quic, err);
444
+ request.reject(e);
363
445
  console.warn(`subscribe error: id=${requestId} broadcast=${broadcast} track=${request.name} error=${reason(e)}`);
364
446
  // Runs now for whatever is already open, and again if `setup` settles late.
365
447
  // Retirement is repeated because a late SUBSCRIBE_OK can register an alias after
@@ -367,7 +449,7 @@ export class Subscriber {
367
449
  let torn = false;
368
450
  const cleanup = async (afterSetup) => {
369
451
  state.cancelled = true;
370
- if (state.registeredAlias !== undefined && this.#aliases.retire(state.registeredAlias, producer)) {
452
+ if (state.registeredAlias !== undefined && this.#aliases.retire(state.registeredAlias, subscription)) {
371
453
  this.#timescales.delete(state.registeredAlias);
372
454
  }
373
455
  if (!state.stream || torn)
@@ -402,10 +484,10 @@ export class Subscriber {
402
484
  const publisherEnded = Symbol("publisher");
403
485
  const localEnded = Symbol("local");
404
486
  const idle = Symbol("idle");
405
- // Terminal conditions settle at most once (stream close = PublishDone, track close =
406
- // local unsubscribe); race them once so the demand loop doesn't re-subscribe each pass.
407
- const done = Promise.race([
408
- stream.reader.closed.then(() => publisherEnded),
487
+ // Terminal conditions settle at most once (PublishDone, track close = local
488
+ // unsubscribe); race them once so the demand loop doesn't re-subscribe each pass.
489
+ const done = race([
490
+ this.#runPublishDone(stream, subscription).then(() => publisherEnded),
409
491
  producer.closed.then(() => localEnded),
410
492
  ]);
411
493
  // Serve until a terminal condition fires or the last local subscriber leaves. The unused
@@ -413,22 +495,26 @@ export class Subscriber {
413
495
  // down resumes on the same stream.
414
496
  let terminal = localEnded;
415
497
  for (;;) {
416
- const reason = await Promise.race([done, producer.unused().then(() => idle)]);
498
+ const reason = await race([done, producer.unused().then(() => idle)]);
417
499
  if (reason === idle && producer.closed.peek() === undefined && producer.used.peek())
418
500
  continue;
419
501
  terminal = reason;
420
502
  break;
421
503
  }
504
+ // Close before the cancellation is written, not after: awaiting the write first
505
+ // reopens the window the demand re-check above just closed, and a subscriber that
506
+ // returned during it would be closed by this line. The lite subscriber closes
507
+ // straight out of its loop for the same reason.
508
+ producer.close();
422
509
  // The publisher already ended the request, so there is nothing to cancel. Sending
423
510
  // UNSUBSCRIBE here would name a request it has already torn down.
424
511
  if (terminal !== publisherEnded)
425
512
  await this.#cancelSubscribe(stream, requestId);
426
- producer.close();
427
513
  stream.close();
428
514
  console.debug(`subscribe close: id=${requestId} broadcast=${broadcast} track=${request.name}`);
429
515
  }
430
516
  catch (err) {
431
- const e = error(err);
517
+ const e = await sessionCause(this.#quic, err);
432
518
  producer.close(e);
433
519
  stream.abort(e);
434
520
  console.warn(`subscribe error: id=${requestId} broadcast=${broadcast} track=${request.name} error=${reason(e)}`);
@@ -436,10 +522,37 @@ export class Subscriber {
436
522
  finally {
437
523
  // Only the owner tears down the alias metadata: a later subscription may have
438
524
  // reclaimed the alias and installed its own timescale.
439
- if (this.#aliases.retire(trackAlias, producer))
525
+ if (this.#aliases.retire(trackAlias, subscription))
440
526
  this.#timescales.delete(trackAlias);
441
527
  }
442
528
  }
529
+ /**
530
+ * Read the PUBLISH_DONE that ends a subscription, then wait for the data streams it counts.
531
+ *
532
+ * An error status aborts the track with it. A clean one leaves streams in flight, since
533
+ * QUIC does not order them, so wait until the Stream Count many have been read, or a
534
+ * bounded grace for the ones that never arrive (the draft says to use a timeout). The count
535
+ * is only a hint: a peer may send 0 regardless, so 0 waits out the grace. A request stream
536
+ * that ends without one ends the track the same way.
537
+ */
538
+ async #runPublishDone(stream, subscription) {
539
+ const version = this.#session.version;
540
+ let count;
541
+ if (!(await stream.reader.done())) {
542
+ const typeId = await stream.reader.u53();
543
+ if (typeId !== PublishDone.id) {
544
+ throw new ProtocolViolation(`unexpected message on a subscription: 0x${typeId.toString(16)}`);
545
+ }
546
+ const done = await PublishDone.decode(stream.reader, version);
547
+ if (!publishDoneClean(done.statusCode, version)) {
548
+ throw new Error(`publish done: status=0x${done.statusCode.toString(16)} reason=${done.reasonPhrase}`);
549
+ }
550
+ count = done.streamCount;
551
+ }
552
+ const { tail, track } = subscription;
553
+ const complete = () => count !== undefined && count > 0n && BigInt(tail.streams) >= count;
554
+ await tail.settle(complete, TAIL_GRACE_MS, track.closed);
555
+ }
443
556
  /**
444
557
  * Tell the publisher to stop serving a subscription we are walking away from.
445
558
  *
@@ -465,7 +578,7 @@ export class Subscriber {
465
578
  // `state` is populated as soon as the stream opens and again when the
466
579
  // trackAlias is registered, so the caller can clean both up on timeout
467
580
  // even before this promise settles.
468
- async #openSubscribe(state, broadcast, request, producer, requestId) {
581
+ async #openSubscribe(state, broadcast, request, subscription, requestId) {
469
582
  const version = this.#session.version;
470
583
  state.stream = await this.#session.openBi();
471
584
  // The timeout can fire while the open is still in flight, in which case cleanup ran
@@ -503,7 +616,7 @@ export class Subscriber {
503
616
  const err = version === Version.DRAFT_14
504
617
  ? await SubscribeError.decode(state.stream.reader, version)
505
618
  : await RequestError.decode(state.stream.reader, version);
506
- reasonPhrase = `code=${err.errorCode} reason=${err.reasonPhrase}`;
619
+ reasonPhrase = requestReason(err.errorCode, err.reasonPhrase, "subscribe", version);
507
620
  }
508
621
  }
509
622
  catch {
@@ -513,8 +626,11 @@ export class Subscriber {
513
626
  throw new Error(`SUBSCRIBE error: ${reasonPhrase}`);
514
627
  }
515
628
  const ok = await SubscribeOk.decode(state.stream.reader, version);
629
+ if (state.cancelled)
630
+ throw new Error("subscribe cancelled before acceptance");
631
+ request.accept({ priority: fromWire(ok.properties.priority ?? 128) });
516
632
  try {
517
- this.#aliases.set(ok.trackAlias, producer, { broadcast, name: request.name });
633
+ this.#aliases.set(ok.trackAlias, subscription, { broadcast, name: request.name });
518
634
  const timescale = ok.properties.timescale;
519
635
  if (timescale !== undefined) {
520
636
  this.#timescales.set(ok.trackAlias, timescale);
@@ -548,7 +664,7 @@ export class Subscriber {
548
664
  await stream.writer.u53(RequestError.id);
549
665
  await new RequestError({
550
666
  requestId: msg.requestId,
551
- errorCode: 400,
667
+ errorCode: toRequestCode("uninterested", "publish_namespace", version),
552
668
  reasonPhrase: "route loops back",
553
669
  }).encode(stream.writer, version);
554
670
  stream.close();
@@ -563,11 +679,14 @@ export class Subscriber {
563
679
  const legacy = version === Version.DRAFT_14 || version === Version.DRAFT_15;
564
680
  if (legacy && (this.#announced.has(path) || this.#legacyRequests.has(path))) {
565
681
  console.warn("duplicate PublishNamespace");
682
+ // No draft registers a code for a duplicate, and this refusal is a draft-14/15
683
+ // implementation limit, which is what INTERNAL_ERROR describes.
684
+ const errorCode = toRequestCode("internal", "publish_namespace", version);
566
685
  if (version === Version.DRAFT_14) {
567
686
  await stream.writer.u53(PublishNamespaceError.id);
568
687
  await new PublishNamespaceError({
569
688
  requestId: msg.requestId,
570
- errorCode: 409,
689
+ errorCode,
571
690
  reasonPhrase: "duplicate namespace",
572
691
  }).encode(stream.writer, version);
573
692
  }
@@ -575,7 +694,7 @@ export class Subscriber {
575
694
  await stream.writer.u53(RequestError.id);
576
695
  await new RequestError({
577
696
  requestId: msg.requestId,
578
- errorCode: 409,
697
+ errorCode,
579
698
  reasonPhrase: "duplicate namespace",
580
699
  }).encode(stream.writer, version);
581
700
  }
@@ -608,10 +727,12 @@ export class Subscriber {
608
727
  // Only now is the advertisement ours to announce, for the reason above: a
609
728
  // consumer reacting with a SUBSCRIBE must not interleave with that OK.
610
729
  attached = true;
611
- this.#attachAnnounce(path);
612
- // An advertisement is updated in place, by repeating PUBLISH_NAMESPACE on the
613
- // stream that already carries it, so read until the stream ends rather than
614
- // waiting on the close. Nothing else would deliver a re-parented route.
730
+ this.#attachAnnounce(path, this.#route(msg.cluster));
731
+ // An advertisement is updated in place with REQUEST_UPDATE on the stream that
732
+ // already carries it, so read until the stream ends rather than waiting on the
733
+ // close. Nothing else would deliver a re-parented route. What the peer holds
734
+ // is kept current, since an update carries only what changed.
735
+ let held = msg.cluster;
615
736
  const done = version === Version.DRAFT_16 || legacy;
616
737
  for (;;) {
617
738
  if (await stream.reader.done())
@@ -621,32 +742,60 @@ export class Subscriber {
621
742
  await PublishNamespaceDone.decode(stream.reader, version);
622
743
  break;
623
744
  }
624
- if (typeId !== PublishNamespace.id) {
745
+ // A repeated PUBLISH_NAMESPACE lands here too: a second request on the
746
+ // stream is the base draft's duplicate request ID.
747
+ if (typeId !== PublishNamespaceUpdate.id) {
625
748
  throw new ProtocolViolation(`unexpected message on publish_namespace stream: 0x${typeId.toString(16)}`);
626
749
  }
627
- const update = await PublishNamespace.decode(stream.reader, version, Cluster.negotiated(this.#cluster));
628
- // The stream is the advertisement, so an update on it must name the same
629
- // one. Applying a mismatched update would retarget this path with metadata
630
- // meant for a different request.
631
- if (update.requestId !== msg.requestId || update.trackNamespace !== path) {
632
- throw new ProtocolViolation("publish_namespace update does not match its stream");
750
+ const update = await PublishNamespaceUpdate.decode(stream.reader, version);
751
+ // The parameters exist only on a session that negotiated the extension;
752
+ // anywhere else they are the peer's violation.
753
+ if (held === undefined) {
754
+ if (update.update.hops !== undefined || update.update.cost !== undefined) {
755
+ throw new ProtocolViolation("cluster parameters on a session that negotiated none");
756
+ }
757
+ }
758
+ else {
759
+ // A different original publisher is a different advertisement, which the
760
+ // draft has withdrawn and made again: its content is not continuous with
761
+ // what is held. Refusing the update closes the stream, which is that
762
+ // withdrawal.
763
+ if (update.update.hops !== undefined && update.update.hops[0] !== held.hops[0]) {
764
+ console.warn(`publish_namespace update changes the publisher: broadcast=${path}`);
765
+ await stream.writer.u53(RequestError.id);
766
+ await new RequestError({
767
+ errorCode: toRequestCode("not_supported", "publish_namespace", version),
768
+ reasonPhrase: "a new publisher is a new advertisement",
769
+ }).encode(stream.writer, version);
770
+ stream.close();
771
+ return;
772
+ }
773
+ held = Cluster.apply(held, update.update);
633
774
  }
634
- // A path that now runs through us is unusable, so give it back. Keep
635
- // reading: this stream is the advertisement's only channel, so a later
636
- // clean path arrives here or nowhere.
637
- if (this.#reflected(update.cluster)) {
775
+ // A path that now runs through us is unusable, so give it back. The update
776
+ // itself is accepted, and reading continues: this stream is the
777
+ // advertisement's only channel, so a later clean path arrives here or
778
+ // nowhere.
779
+ if (this.#reflected(held)) {
638
780
  if (attached) {
639
781
  attached = false;
640
782
  console.debug(`publish_namespace now loops back, detaching: broadcast=${path}`);
641
783
  this.#detachAnnounce(path);
642
784
  }
643
- continue;
644
785
  }
645
- // Re-attach: a clean path replaced the reflected one we detached from.
646
- if (!attached) {
786
+ else if (!attached) {
787
+ // Re-attach: a clean path replaced the reflected one we detached from.
647
788
  attached = true;
648
- this.#attachAnnounce(path);
789
+ this.#attachAnnounce(path, this.#route(held));
790
+ }
791
+ else {
792
+ this.#updateAnnounce(path, this.#route(held));
649
793
  }
794
+ // Nothing here can fail to apply, so every update is acknowledged. A leaf
795
+ // routes nothing, so a repricing changes nothing it holds; consumers still
796
+ // hear the new route so a forwarder can reprice.
797
+ await stream.writer.u53(RequestOk.id);
798
+ await new RequestOk({}).encode(stream.writer, version);
650
799
  }
651
800
  }
652
801
  finally {
@@ -667,17 +816,17 @@ export class Subscriber {
667
816
  */
668
817
  async runPublish(msg, stream) {
669
818
  const version = this.#session.version;
670
- // NOT_SUPPORTED, from the PUBLISH error codes in draft-19 section 10.10. We decline
671
- // the method itself rather than this particular track, which is UNINTERESTED (0x4).
819
+ // We decline the method itself rather than this particular track, which would be
820
+ // UNINTERESTED.
672
821
  //
673
822
  // The alias the message carries is deliberately not recorded. Nothing will ever bind
674
823
  // it, and a rejected request has no lifetime of ours to hang the cleanup on.
675
- const NOT_SUPPORTED = 0x3;
824
+ const errorCode = toRequestCode("not_supported", "publish", version);
676
825
  if (version === Version.DRAFT_14) {
677
826
  await stream.writer.u53(PublishError.id);
678
827
  const err = new PublishError({
679
828
  requestId: msg.requestId,
680
- errorCode: NOT_SUPPORTED,
829
+ errorCode,
681
830
  reasonPhrase: "publish not supported",
682
831
  });
683
832
  await err.encode(stream.writer, version);
@@ -686,7 +835,7 @@ export class Subscriber {
686
835
  await stream.writer.u53(RequestError.id);
687
836
  const err = new RequestError({
688
837
  requestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,
689
- errorCode: NOT_SUPPORTED,
838
+ errorCode,
690
839
  reasonPhrase: "publish not supported",
691
840
  });
692
841
  await err.encode(stream.writer, version);
@@ -702,48 +851,104 @@ export class Subscriber {
702
851
  if (group.subGroupId !== 0) {
703
852
  throw new Error("subgroups are not supported");
704
853
  }
705
- // FIRST_OBJECT clear says this stream starts partway through the group, which the
706
- // draft lets a publisher do to answer a filter. Nothing above here can use it: the
707
- // objects that would arrive are not decodable without the missing head, and a group
708
- // is the unit an application resyncs on. Drop it and pick up at the next group, the
709
- // same degradation as a publisher that no longer holds the head.
710
- //
711
- // This only saves reading a stream we would throw away. The bit is the publisher's
712
- // claim, so what is enforced is the object ids themselves: `Frame.decode` holds every
713
- // object to starting at 0 and incrementing by 1, whatever the header said and on the
714
- // drafts that have no such bit to read.
715
- if (!group.flags.firstObject) {
716
- console.debug(`dropping a group with no head: alias=${group.trackAlias} group=${group.groupId}`);
717
- stream.stop(new Error("a group must start at object 0"));
854
+ let subscription;
855
+ try {
856
+ // The control message establishing this alias can arrive after the data stream.
857
+ subscription = await this.#aliases.get(group.trackAlias);
858
+ }
859
+ catch (err) {
860
+ const e = error(err);
861
+ // Ours: we cancelled the subscription and the publisher has not stopped yet.
862
+ // Anything else on this alias is the publisher sending data for a track it never
863
+ // acknowledged, which is worth seeing.
864
+ if (e instanceof RetiredTrackAlias) {
865
+ console.debug(`dropping group for a cancelled subscription: alias=${group.trackAlias}`);
866
+ }
867
+ stream.stop(e);
718
868
  return;
719
869
  }
720
- const producer = new netGroup.Producer(group.groupId);
870
+ const { track, tail } = subscription;
871
+ // Every data stream counts toward PUBLISH_DONE's Stream Count, even one dropped below.
872
+ const read = tail.open(group.groupId);
873
+ // Created on the first object rather than the header: an END_OF_TRACK at object 0
874
+ // means the group does not exist at all.
875
+ let producer;
876
+ const open = () => {
877
+ if (!producer) {
878
+ producer = new netGroup.Producer(group.groupId);
879
+ track.writeGroup(producer);
880
+ }
881
+ return producer;
882
+ };
721
883
  try {
722
- // The control message establishing this alias can arrive after the data stream.
723
- const track = await this.#aliases.get(group.trackAlias);
724
- track.writeGroup(producer);
884
+ // FIRST_OBJECT clear says this stream starts partway through the group, which the
885
+ // draft lets a publisher do to answer a filter. Nothing above here can use it: the
886
+ // objects that would arrive are not decodable without the missing head, and a group
887
+ // is the unit an application resyncs on. Drop it and pick up at the next group, the
888
+ // same degradation as a publisher that no longer holds the head.
889
+ //
890
+ // This only saves reading a stream we would throw away. The bit is the publisher's
891
+ // claim, so what is enforced is the object ids themselves: `Frame.decode` holds every
892
+ // object to starting at 0 and incrementing by 1, whatever the header said and on the
893
+ // drafts that have no such bit to read.
894
+ if (!group.flags.firstObject) {
895
+ console.debug(`dropping a group with no head: alias=${group.trackAlias} group=${group.groupId}`);
896
+ stream.stop(new Error("a group must start at object 0"));
897
+ return;
898
+ }
899
+ // The alias binds after SUBSCRIBE_OK commits the track property; an omitted
900
+ // header priority inherits it (draft-21 section 10.4).
901
+ if (!group.flags.hasPriority)
902
+ group.publisherPriority = toWire((await track.info()).priority);
725
903
  for (;;) {
726
- const done = await Promise.race([stream.done(), producer.closed, track.closed]);
904
+ // Only the group's own stream ends it: a track that closes first has already
905
+ // closed (or aborted) this group through its cache.
906
+ const done = await (producer ? race([stream.done(), producer.closed]) : stream.done());
727
907
  if (done !== false)
728
908
  break;
729
909
  const frame = await Frame.decode(stream, group.flags, this.#timescales.get(group.trackAlias), this.#session.version);
910
+ if (frame.endOfTrack) {
911
+ // No object at or past this location exists: after the group's last object
912
+ // the track ends with it, and at object 0 it ends before it.
913
+ const end = producer ? group.groupId + 1 : group.groupId;
914
+ producer?.close();
915
+ try {
916
+ track.finishAt(end);
917
+ }
918
+ catch (err) {
919
+ throw new ProtocolViolation(`invalid END_OF_TRACK: ${reason(error(err))}`);
920
+ }
921
+ return;
922
+ }
730
923
  if (frame.payload === undefined)
731
924
  break;
732
- producer.writeFrame({ payload: frame.payload, timestamp: frame.timestamp ?? Timestamp.now() });
925
+ open().writeFrame({ payload: frame.payload, timestamp: frame.timestamp ?? Timestamp.now() });
733
926
  }
734
- producer.close();
927
+ // A group with no objects still exists.
928
+ open().close();
735
929
  }
736
930
  catch (err) {
737
931
  const e = error(err);
738
- // Ours: we cancelled the subscription and the publisher has not stopped yet.
739
- // Anything else on this alias is the publisher sending data for a track it never
740
- // acknowledged, which is worth seeing.
741
- if (e instanceof RetiredTrackAlias) {
742
- console.debug(`dropping group for a cancelled subscription: alias=${group.trackAlias}`);
932
+ if (e instanceof ProtocolViolation) {
933
+ // The publisher broke the track's end, which no later group can repair.
934
+ producer?.close(e);
935
+ track.close(e);
936
+ }
937
+ else {
938
+ // A stream that fails before its first object still names a group, which the
939
+ // reader sees fail rather than silently go missing.
940
+ try {
941
+ open().close(e);
942
+ }
943
+ catch {
944
+ // The track has already closed or ended below this group.
945
+ }
743
946
  }
744
- producer.close(e);
745
947
  stream.stop(e);
746
948
  }
949
+ finally {
950
+ read();
951
+ }
747
952
  }
748
953
  }
749
954
  /**
@@ -752,16 +957,15 @@ export class Subscriber {
752
957
  * group fetch, so `track.Consumer.fetchGroup()` is rejected.
753
958
  */
754
959
  class ConsumeBroadcast extends broadcast.Consumer {
755
- // biome-ignore lint/complexity/noUselessConstructor: widens the protected base constructor to public
756
960
  constructor(state) {
757
961
  super(state);
962
+ overrideBroadcastWire(this, {
963
+ fetchGroup: () => Promise.reject(new Error("fetch group is not supported for moq-transport")),
964
+ });
758
965
  }
759
966
  // Preserve the subclass when the consume cache shares this broadcast across callers.
760
967
  clone() {
761
968
  return new ConsumeBroadcast(this.shareState());
762
969
  }
763
- fetchGroup() {
764
- return Promise.reject(new Error("fetch group is not supported for moq-transport"));
765
- }
766
970
  }
767
971
  //# sourceMappingURL=subscriber.js.map