moqtail 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1665 @@
1
+ import { w as ControlMessage, U as SubscribeOk, Q as SubscribeError, S as Subscribe, V as SubscribeUpdate, q as PublishDoneStatusCode, x as Fetch, b as PublishNamespaceOk, a as PublishNamespaceError, P as PublishNamespace, A as FetchOk, z as FetchError, J as SubscribeNamespaceOk, I as SubscribeNamespaceError, H as SubscribeNamespace, a5 as SetupParameters, G as GroupOrder, F as FilterType, a7 as VersionSpecificParameters, h as FetchType, a2 as RequestIdMap, Z as PublishNamespaceDone, B as GoAway, a1 as SubgroupHeader, a0 as FetchHeader, E as ServerSetup, c as PublishNamespaceCancel, $ as UnsubscribeNamespace, a3 as Header } from '../version_parameter-CgEPNuUt.js';
2
+ import { n as MoqtObject, L as Location, m as FullTrackName, f as ObjectForwardingPreference, K as KeyValuePair, D as DatagramObject, h as DatagramStatus, c as Tuple, o as SubgroupObject, j as FetchObject } from '../byte_buffer-BOK6VPTF.js';
3
+
4
+ /**
5
+ * Copyright 2025 The MOQtail Authors
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ declare class ControlStream {
21
+ #private;
22
+ readonly stream: ReadableStream<ControlMessage>;
23
+ onMessageSent?: (msg: ControlMessage) => void;
24
+ onMessageReceived?: (msg: ControlMessage) => void;
25
+ private constructor();
26
+ static new(bidirectionalStream: WebTransportBidirectionalStream, partialMessageTimeoutMs?: number, onMessageSent?: (msg: ControlMessage) => void, onMessageReceived?: (msg: ControlMessage) => void): ControlStream;
27
+ send(message: ControlMessage): Promise<void>;
28
+ close(): Promise<void>;
29
+ }
30
+
31
+ /**
32
+ * Copyright 2025 The MOQtail Authors
33
+ *
34
+ * Licensed under the Apache License, Version 2.0 (the "License");
35
+ * you may not use this file except in compliance with the License.
36
+ * You may obtain a copy of the License at
37
+ *
38
+ * http://www.apache.org/licenses/LICENSE-2.0
39
+ *
40
+ * Unless required by applicable law or agreed to in writing, software
41
+ * distributed under the License is distributed on an "AS IS" BASIS,
42
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43
+ * See the License for the specific language governing permissions and
44
+ * limitations under the License.
45
+ */
46
+
47
+ /**
48
+ * In‑memory index of {@link MoqtObject} instances keyed by their {@link Location} (group/subgroup/object),
49
+ * providing ordered insertion and range queries.
50
+ *
51
+ * Implementations MUST keep objects sorted ascending by (groupId, objectId) so binary searches can
52
+ * locate insertion points / range bounds efficiently. Subgroup ordinality is currently ignored for ordering
53
+ * (adjust if protocol semantics require finer granularity later).
54
+ *
55
+ * @example Typical usage
56
+ * ```ts
57
+ * const cache: ObjectCache = new MemoryObjectCache()
58
+ * cache.add(obj)
59
+ * const window = cache.getRange(startLoc, endLoc)
60
+ * const exact = cache.getByLocation(loc)
61
+ * ```
62
+ *
63
+ * Concurrency: Implementations here are not thread‑safe; callers avoid concurrent mutation from workers.
64
+ */
65
+ interface ObjectCache {
66
+ /** Insert a new {@link MoqtObject}, preserving sorted order (duplicates allowed or replaced impl‑defined). */
67
+ add(obj: MoqtObject): void;
68
+ /** Return a shallow copy array of objects whose Location is \>= start and \< end (end exclusive). */
69
+ getRange(start?: Location, end?: Location): MoqtObject[];
70
+ /** Return the object whose Location exactly matches (group & object) or undefined if absent. */
71
+ getByLocation(location: Location): MoqtObject | undefined;
72
+ /** Current number of cached objects. */
73
+ size(): number;
74
+ /** Remove all cached objects. */
75
+ clear(): void;
76
+ }
77
+ declare class MemoryObjectCache implements ObjectCache {
78
+ private objects;
79
+ add(obj: MoqtObject): void;
80
+ getRange(start?: Location, end?: Location): MoqtObject[];
81
+ getByLocation(location: Location): MoqtObject | undefined;
82
+ size(): number;
83
+ clear(): void;
84
+ private _findInsertIndex;
85
+ private _findIndex;
86
+ }
87
+ declare class RingBufferObjectCache implements ObjectCache {
88
+ private buffer;
89
+ private maxSize;
90
+ constructor(maxSize?: number);
91
+ add(obj: MoqtObject): void;
92
+ getRange(start?: Location, end?: Location): MoqtObject[];
93
+ getByLocation(location: Location): MoqtObject | undefined;
94
+ size(): number;
95
+ clear(): void;
96
+ private _findInsertIndex;
97
+ private _findIndex;
98
+ }
99
+
100
+ /**
101
+ * Copyright 2025 The MOQtail Authors
102
+ *
103
+ * Licensed under the Apache License, Version 2.0 (the "License");
104
+ * you may not use this file except in compliance with the License.
105
+ * You may obtain a copy of the License at
106
+ *
107
+ * http://www.apache.org/licenses/LICENSE-2.0
108
+ *
109
+ * Unless required by applicable law or agreed to in writing, software
110
+ * distributed under the License is distributed on an "AS IS" BASIS,
111
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
112
+ * See the License for the specific language governing permissions and
113
+ * limitations under the License.
114
+ */
115
+
116
+ /**
117
+ * Source of already-produced (historical) objects for a track.
118
+ * Backed by an {@link ObjectCache} allowing range retrieval using protocol {@link Location}s.
119
+ * Implementations MUST return objects in ascending location order and MAY return an empty array
120
+ * if the requested window is outside the cached range.
121
+ */
122
+ interface PastObjectSource {
123
+ /** Underlying cache from which objects are served */
124
+ readonly cache: ObjectCache;
125
+ /**
126
+ * Fetch a (closed) range of objects. `start`/`end` are inclusive when provided.
127
+ * Omitted bounds mean: from earliest cached (when `start` undefined) or up to latest cached (when `end` undefined).
128
+ */
129
+ getRange(start?: Location, end?: Location): Promise<MoqtObject[]>;
130
+ }
131
+ /**
132
+ * Push-oriented live object feed. Wraps a {@link https://developer.mozilla.org/docs/Web/API/ReadableStream | ReadableStream} plus lightweight event subscription helpers.
133
+ * Implementations advance {@link LiveObjectSource.largestLocation | largestLocation} monotonically as objects arrive.
134
+ */
135
+ interface LiveObjectSource {
136
+ /** Continuous stream yielding objects as they are produced */
137
+ readonly stream: ReadableStream<MoqtObject>;
138
+ /** Highest (latest) location observed so far; undefined until first object */
139
+ readonly largestLocation: Location | undefined;
140
+ /** Register a listener invoked (async) for each new object. Returns an unsubscribe function. */
141
+ onNewObject(listener: (obj: MoqtObject) => void): () => void;
142
+ /** Register a listener invoked when the live stream ends (normal or error). Returns an unsubscribe function. */
143
+ onDone(listener: () => void): () => void;
144
+ /** Stop ingestion and release underlying reader (idempotent). */
145
+ stop(): void;
146
+ }
147
+ /**
148
+ * Aggregates optional historical (`past`) and (`live`) sources for a single track.
149
+ * Either facet may be omitted:
150
+ * - VOD / static content: supply only {@link TrackSource.past | past}
151
+ * - Pure live: supply only {@link TrackSource.live | live}
152
+ * - Hybrid (catch-up + live tail): supply both.
153
+ *
154
+ * Priority handling note: publisher priority is defined on the Track metadata (see `Track.publisherPriority`).
155
+ * The library rounds non-integer values and clamps priority into [0,255] there; this interface simply
156
+ * expresses what content is available, independent of priority semantics.
157
+ */
158
+ interface TrackSource {
159
+ /** Historical object access (optional) */
160
+ readonly past?: PastObjectSource;
161
+ /** Live object feed (optional) */
162
+ readonly live?: LiveObjectSource;
163
+ }
164
+ declare class StaticTrackSource implements PastObjectSource {
165
+ readonly cache: ObjectCache;
166
+ constructor(cache: ObjectCache);
167
+ getRange(start?: Location, end?: Location): Promise<MoqtObject[]>;
168
+ }
169
+ declare class LiveTrackSource implements LiveObjectSource {
170
+ #private;
171
+ readonly stream: ReadableStream<MoqtObject>;
172
+ constructor(stream: ReadableStream<MoqtObject>);
173
+ get largestLocation(): Location | undefined;
174
+ onNewObject(listener: (obj: MoqtObject) => void): () => void;
175
+ onDone(listener: () => void): () => void;
176
+ stop(): void;
177
+ }
178
+ declare class HybridTrackSource implements TrackSource {
179
+ readonly past: PastObjectSource;
180
+ readonly live: LiveObjectSource;
181
+ constructor(cache: ObjectCache, stream: ReadableStream<MoqtObject>);
182
+ }
183
+
184
+ /**
185
+ * Copyright 2025 The MOQtail Authors
186
+ *
187
+ * Licensed under the Apache License, Version 2.0 (the "License");
188
+ * you may not use this file except in compliance with the License.
189
+ * You may obtain a copy of the License at
190
+ *
191
+ * http://www.apache.org/licenses/LICENSE-2.0
192
+ *
193
+ * Unless required by applicable law or agreed to in writing, software
194
+ * distributed under the License is distributed on an "AS IS" BASIS,
195
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
196
+ * See the License for the specific language governing permissions and
197
+ * limitations under the License.
198
+ */
199
+
200
+ /**
201
+ * Describes a media/data track known to the client (either published locally or subscribed to).
202
+ *
203
+ *
204
+ * @example Live only track
205
+ * ```ts
206
+ * const liveStream: ReadableStream<MoqtObject> = buildCameraStream()
207
+ * const track: Track = {
208
+ * fullTrackName,
209
+ * forwardingPreference: ObjectForwardingPreference.Latest,
210
+ * trackSource: { live: liveStream },
211
+ * publisherPriority: 0
212
+ * }
213
+ * client.addOrUpdateTrack(track)
214
+ * ```
215
+ *
216
+ * @example Past only track (pre‑recorded cache)
217
+ * ```ts
218
+ * const cache = new MemoryObjectCache()
219
+ * recording.forEach(obj => cache.add(obj))
220
+ * const track: Track = {
221
+ * fullTrackName,
222
+ * forwardingPreference: ObjectForwardingPreference.All,
223
+ * trackSource: { past: cache },
224
+ * publisherPriority: 64
225
+ * }
226
+ * client.addOrUpdateTrack(track)
227
+ * ```
228
+ *
229
+ * @example Hybrid (cache + live)
230
+ * ```ts
231
+ * const cache = new MemoryObjectCache()
232
+ * const liveStream = buildLiveReadableStream()
233
+ * const track: Track = {
234
+ * fullTrackName,
235
+ * forwardingPreference: ObjectForwardingPreference.Latest,
236
+ * trackSource: { past: cache, live: liveStream },
237
+ * publisherPriority: 8
238
+ * }
239
+ * client.addOrUpdateTrack(track)
240
+ * ```
241
+ */
242
+ type Track = {
243
+ /**
244
+ * Globally unique identifier for the track.
245
+ */
246
+ fullTrackName: FullTrackName;
247
+ /**
248
+ * Hint controlling which objects SHOULD be forwarded / prioritized.
249
+ */
250
+ forwardingPreference: ObjectForwardingPreference;
251
+ /**
252
+ * Accessors for live and/or past objects belonging to this track.
253
+ */
254
+ trackSource: TrackSource;
255
+ /**
256
+ * 0 (highest) .. 255 (lowest) priority advertised with objects.
257
+ * Values are rounded to nearest integer then clamped between 0 and 255.
258
+ */
259
+ publisherPriority: number;
260
+ /**
261
+ * Optional compact numeric alias assigned during protocol negotiation.
262
+ */
263
+ trackAlias?: bigint;
264
+ };
265
+
266
+ /**
267
+ * Copyright 2025 The MOQtail Authors
268
+ *
269
+ * Licensed under the Apache License, Version 2.0 (the "License");
270
+ * you may not use this file except in compliance with the License.
271
+ * You may obtain a copy of the License at
272
+ *
273
+ * http://www.apache.org/licenses/LICENSE-2.0
274
+ *
275
+ * Unless required by applicable law or agreed to in writing, software
276
+ * distributed under the License is distributed on an "AS IS" BASIS,
277
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
278
+ * See the License for the specific language governing permissions and
279
+ * limitations under the License.
280
+ */
281
+
282
+ declare class SubscribeRequest implements PromiseLike<SubscribeOk | SubscribeError> {
283
+ #private;
284
+ requestId: bigint;
285
+ fullTrackName: FullTrackName;
286
+ isCanceled: boolean;
287
+ startLocation: Location | undefined;
288
+ endGroup: bigint | undefined;
289
+ priority: number;
290
+ forward: boolean;
291
+ subscribeParameters: KeyValuePair[];
292
+ largestLocation: Location | undefined;
293
+ streamsAccepted: bigint;
294
+ expectedStreams: bigint | undefined;
295
+ readonly controller: ReadableStreamDefaultController<MoqtObject>;
296
+ readonly stream: ReadableStream<MoqtObject>;
297
+ constructor(msg: Subscribe);
298
+ update(msg: SubscribeUpdate): void;
299
+ switch(newTrackName: FullTrackName, newParameters: KeyValuePair[]): void;
300
+ unsubscribe(): void;
301
+ resolve(value: SubscribeOk | SubscribeError | PromiseLike<SubscribeOk | SubscribeError>): void;
302
+ reject(reason?: any): void;
303
+ then<TResult1 = SubscribeOk | SubscribeError, TResult2 = never>(onfulfilled?: ((value: SubscribeOk | SubscribeError) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
304
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<SubscribeOk | SubscribeError | TResult>;
305
+ finally(onfinally?: (() => void) | undefined | null): Promise<SubscribeOk | SubscribeError>;
306
+ }
307
+
308
+ /**
309
+ * Copyright 2025 The MOQtail Authors
310
+ *
311
+ * Licensed under the Apache License, Version 2.0 (the "License");
312
+ * you may not use this file except in compliance with the License.
313
+ * You may obtain a copy of the License at
314
+ *
315
+ * http://www.apache.org/licenses/LICENSE-2.0
316
+ *
317
+ * Unless required by applicable law or agreed to in writing, software
318
+ * distributed under the License is distributed on an "AS IS" BASIS,
319
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
320
+ * See the License for the specific language governing permissions and
321
+ * limitations under the License.
322
+ */
323
+
324
+ /**
325
+ * @public
326
+ * Manages the publication of MOQT objects to a subscriber for a specific track.
327
+ * Handles live object streaming, subscription lifecycle, and stream management.
328
+ */
329
+ declare class SubscribePublication {
330
+ #private;
331
+ private readonly client;
332
+ readonly track: Track;
333
+ private readonly subscribeMsg;
334
+ /**
335
+ * The latest location that was published to the subscriber.
336
+ */
337
+ latestLocation: Location | undefined;
338
+ /**
339
+ * Creates a new SubscribePublication instance.
340
+ * @param client - The MOQT client managing the subscription.
341
+ * @param track - The track being published.
342
+ * @param subscribeMsg - The subscribe message containing subscription details.
343
+ * @param largestLocation - The largest location seen so far, used for determining start location.
344
+ */
345
+ constructor(client: MOQtailClient, track: Track, subscribeMsg: Subscribe, largestLocation?: Location);
346
+ /**
347
+ * Cancels the publication and cleans up resources.
348
+ * Removes the publication from the client's publication map.
349
+ */
350
+ cancel(): void;
351
+ /**
352
+ * Marks the publication as done and sends a PublishDone message to the client.
353
+ * @param statusCode - The status code indicating why the publication ended.
354
+ * @throws :{@link InternalError} If sending the message fails.
355
+ */
356
+ done(statusCode: PublishDoneStatusCode): Promise<void>;
357
+ /**
358
+ * Updates the subscription parameters and locations based on a SubscribeUpdate message.
359
+ * @param msg - The update message containing new subscription details.
360
+ */
361
+ update(msg: SubscribeUpdate): void;
362
+ /**
363
+ * Publishes MOQT objects to the subscriber as they become available.
364
+ * Handles stream creation, object writing, and stream closure based on subscription parameters.
365
+ * @throws :{@link InternalError} If the track does not support live content.
366
+ */
367
+ publish(): Promise<void>;
368
+ }
369
+
370
+ /**
371
+ * Copyright 2025 The MOQtail Authors
372
+ *
373
+ * Licensed under the Apache License, Version 2.0 (the "License");
374
+ * you may not use this file except in compliance with the License.
375
+ * You may obtain a copy of the License at
376
+ *
377
+ * http://www.apache.org/licenses/LICENSE-2.0
378
+ *
379
+ * Unless required by applicable law or agreed to in writing, software
380
+ * distributed under the License is distributed on an "AS IS" BASIS,
381
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
382
+ * See the License for the specific language governing permissions and
383
+ * limitations under the License.
384
+ */
385
+
386
+ declare class FetchPublication {
387
+ #private;
388
+ constructor(client: MOQtailClient, track: Track, fetchRequest: Fetch);
389
+ cancel(): void;
390
+ publish(): Promise<void>;
391
+ }
392
+
393
+ /**
394
+ * Copyright 2025 The MOQtail Authors
395
+ *
396
+ * Licensed under the Apache License, Version 2.0 (the "License");
397
+ * you may not use this file except in compliance with the License.
398
+ * You may obtain a copy of the License at
399
+ *
400
+ * http://www.apache.org/licenses/LICENSE-2.0
401
+ *
402
+ * Unless required by applicable law or agreed to in writing, software
403
+ * distributed under the License is distributed on an "AS IS" BASIS,
404
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
405
+ * See the License for the specific language governing permissions and
406
+ * limitations under the License.
407
+ */
408
+
409
+ declare class PublishNamespaceRequest implements PromiseLike<PublishNamespaceOk | PublishNamespaceError> {
410
+ readonly requestId: bigint;
411
+ readonly message: PublishNamespace;
412
+ private _resolve;
413
+ private _reject;
414
+ private promise;
415
+ constructor(requestId: bigint, message: PublishNamespace);
416
+ resolve(value: PublishNamespaceOk | PublishNamespaceError | PromiseLike<PublishNamespaceOk | PublishNamespaceError>): void;
417
+ reject(reason?: any): void;
418
+ then<TResult1 = PublishNamespaceOk | PublishNamespaceError, TResult2 = never>(onfulfilled?: ((value: PublishNamespaceOk | PublishNamespaceError) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
419
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<PublishNamespaceOk | PublishNamespaceError | TResult>;
420
+ finally(onfinally?: (() => void) | undefined | null): Promise<PublishNamespaceOk | PublishNamespaceError>;
421
+ }
422
+
423
+ /**
424
+ * Copyright 2025 The MOQtail Authors
425
+ *
426
+ * Licensed under the Apache License, Version 2.0 (the "License");
427
+ * you may not use this file except in compliance with the License.
428
+ * You may obtain a copy of the License at
429
+ *
430
+ * http://www.apache.org/licenses/LICENSE-2.0
431
+ *
432
+ * Unless required by applicable law or agreed to in writing, software
433
+ * distributed under the License is distributed on an "AS IS" BASIS,
434
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
435
+ * See the License for the specific language governing permissions and
436
+ * limitations under the License.
437
+ */
438
+
439
+ declare class FetchRequest implements PromiseLike<FetchOk | FetchError> {
440
+ readonly requestId: bigint;
441
+ readonly message: Fetch;
442
+ private _resolve;
443
+ private _reject;
444
+ private promise;
445
+ controller?: ReadableStreamDefaultController<MoqtObject>;
446
+ stream: ReadableStream<MoqtObject>;
447
+ isActive: boolean;
448
+ isResolved: boolean;
449
+ constructor(message: Fetch);
450
+ resolve(value: FetchOk | FetchError | PromiseLike<FetchOk | FetchError>): void;
451
+ reject(reason?: any): void;
452
+ then<TResult1 = FetchOk | FetchError, TResult2 = never>(onfulfilled?: ((value: FetchOk | FetchError) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
453
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<FetchOk | FetchError | TResult>;
454
+ finally(onfinally?: (() => void) | undefined | null): Promise<FetchOk | FetchError>;
455
+ }
456
+
457
+ /**
458
+ * Copyright 2025 The MOQtail Authors
459
+ *
460
+ * Licensed under the Apache License, Version 2.0 (the "License");
461
+ * you may not use this file except in compliance with the License.
462
+ * You may obtain a copy of the License at
463
+ *
464
+ * http://www.apache.org/licenses/LICENSE-2.0
465
+ *
466
+ * Unless required by applicable law or agreed to in writing, software
467
+ * distributed under the License is distributed on an "AS IS" BASIS,
468
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
469
+ * See the License for the specific language governing permissions and
470
+ * limitations under the License.
471
+ */
472
+
473
+ declare class SubscribeNamespaceRequest implements PromiseLike<SubscribeNamespaceOk | SubscribeNamespaceError> {
474
+ readonly requestId: bigint;
475
+ readonly message: SubscribeNamespace;
476
+ private _resolve;
477
+ private _reject;
478
+ private promise;
479
+ constructor(requestId: bigint, message: SubscribeNamespace);
480
+ resolve(value: SubscribeNamespaceOk | SubscribeNamespaceError | PromiseLike<SubscribeNamespaceOk | SubscribeNamespaceError>): void;
481
+ reject(reason?: any): void;
482
+ then<TResult1 = SubscribeNamespaceOk | SubscribeNamespaceError, TResult2 = never>(onfulfilled?: ((value: SubscribeNamespaceOk | SubscribeNamespaceError) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
483
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<SubscribeNamespaceOk | SubscribeNamespaceError | TResult>;
484
+ finally(onfinally?: (() => void) | undefined | null): Promise<SubscribeNamespaceOk | SubscribeNamespaceError>;
485
+ }
486
+
487
+ /**
488
+ * Copyright 2025 The MOQtail Authors
489
+ *
490
+ * Licensed under the Apache License, Version 2.0 (the "License");
491
+ * you may not use this file except in compliance with the License.
492
+ * You may obtain a copy of the License at
493
+ *
494
+ * http://www.apache.org/licenses/LICENSE-2.0
495
+ *
496
+ * Unless required by applicable law or agreed to in writing, software
497
+ * distributed under the License is distributed on an "AS IS" BASIS,
498
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
499
+ * See the License for the specific language governing permissions and
500
+ * limitations under the License.
501
+ */
502
+
503
+ /**
504
+ * Discriminated union of every in‑flight MOQ‑tail control request tracked by the {@link MOQtailClient}.
505
+ *
506
+ * Each concrete request type encapsulates the original control message plus coordination primitives
507
+ * (e.g. a {@link https://developer.mozilla.org/docs/Web/API/Promise | Promise} facade / stream controller) that resolve when a terminal protocol response
508
+ * (OK / ERROR / CANCEL) is received.
509
+ *
510
+ * Used internally in maps like `MOQtailClient.requests` to look up state by request id without needing
511
+ * multiple heterogeneous collections.
512
+ *
513
+ * Variants:
514
+ * - {@link PublishNamespaceRequest} – pending PUBLISH_NAMESPACE / PUBLISH_NAMESPACE_OK / PUBLISH_NAMESPACE_ERROR.
515
+ * - {@link SubscribeNamespaceRequest} – pending SUBSCRIBE_NAMESPACE sequence.
516
+ * - {@link FetchRequest} – pending FETCH handshake producing a data stream.
517
+ * - {@link SubscribeRequest} – pending SUBSCRIBE producing subgroup object streams.
518
+
519
+ *
520
+ * @example Looking up a request by id
521
+ * ```ts
522
+ * function isActive(requests: Map<bigint, MOQtailRequest>, id: bigint) {
523
+ * const req = requests.get(id)
524
+ * if (!req) return false
525
+ * // Narrow by instanceof, e.g. FetchRequest
526
+ * if (req instanceof FetchRequest) {
527
+ * console.log('Fetch still pending for', req.message.requestId)
528
+ * }
529
+ * return true
530
+ * }
531
+ * ```
532
+ */
533
+ type MOQtailRequest = PublishNamespaceRequest | SubscribeNamespaceRequest | FetchRequest | SubscribeRequest;
534
+ /**
535
+ * Options for {@link MOQtailClient.new} controlling connection target, protocol negotiation, timeouts,
536
+ * and lifecycle callbacks.
537
+ *
538
+ * @example Minimal
539
+ * ```ts
540
+ * const opts: MOQtailClientOptions = {
541
+ * url: 'https://relay.example.com/moq',
542
+ * supportedVersions: [0xff00000b]
543
+ * }
544
+ * const client = await MOQtailClient.new(opts)
545
+ * ```
546
+ * @example With callbacks & timeouts
547
+ * ```ts
548
+ * const client = await MOQtailClient.new({
549
+ * url: relayUrl,
550
+ * supportedVersions: [0xff00000b],
551
+ * dataStreamTimeoutMs: 5000,
552
+ * controlStreamTimeoutMs: 1500,
553
+ * callbacks: {
554
+ * onMessageSent: m => logOutbound(m),
555
+ * onMessageReceived: m => logInbound(m),
556
+ * onSessionTerminated: r => console.warn('terminated', r)
557
+ * }
558
+ * })
559
+ * ```
560
+ */
561
+ type MOQtailClientOptions = {
562
+ /** Relay / server endpoint for the underlying {@link https://developer.mozilla.org/docs/Web/API/WebTransport | WebTransport} session (can be absolute {@link https://developer.mozilla.org/en-US/docs/Web/API/URL | URL} or string).*/
563
+ url: string | URL;
564
+ /** Ordered preference list of MOQT protocol version numbers (e.g. `0xff00000b`). */
565
+ supportedVersions: number[];
566
+ /** {@link SetupParameters} customizations; if omitted a default instance is built.*/
567
+ setupParameters?: SetupParameters;
568
+ /** Passed directly to the browser's {@link https://developer.mozilla.org/docs/Web/API/WebTransport | WebTransport} constructor for {@link https://developer.mozilla.org/docs/Web/API/WebTransportOptions | WebTransportOptions}. */
569
+ transportOptions?: WebTransportOptions;
570
+ /** Per *data* uni-stream idle timeout in milliseconds. */
571
+ dataStreamTimeoutMs?: number;
572
+ /** Control stream read timeout in milliseconds. */
573
+ controlStreamTimeoutMs?: number;
574
+ /** If true, enables datagram support for the session. */
575
+ enableDatagrams: boolean;
576
+ /** callbacks for observability and logging purposes: */
577
+ callbacks?: {
578
+ /** Called after a control message is successfully written to the {@link ControlStream}. */
579
+ onMessageSent?: (msg: ControlMessage) => void;
580
+ /** Called for each incoming control message before protocol handling. */
581
+ onMessageReceived?: (msg: ControlMessage) => void;
582
+ /** Fired once when the session ends (normal or error). Receives the reason passed to {@link MOQtailClient.disconnect | disconnect}. */
583
+ onSessionTerminated?: (reason?: unknown) => void;
584
+ /** Invoked for each decoded datagram object/status arriving. */
585
+ onDatagramReceived?: (data: DatagramObject | DatagramStatus) => void;
586
+ /** Invoked after enqueuing each outbound datagram object/status. */
587
+ onDatagramSent?: (data: DatagramObject | DatagramStatus) => void;
588
+ };
589
+ };
590
+ /**
591
+ * Parameters for {@link MOQtailClient.subscribe | subscribing} to a track's live objects.
592
+ *
593
+ * @example Latest object
594
+ * ```ts
595
+ * await client.subscribe({
596
+ * fullTrackName,
597
+ * priority: 0,
598
+ * groupOrder: GroupOrder.Original,
599
+ * forward: true,
600
+ * filterType: FilterType.LatestObject
601
+ * })
602
+ * ```
603
+ * @example Absolute range
604
+ * ```ts
605
+ * await client.subscribe({
606
+ * fullTrackName,
607
+ * priority: 32,
608
+ * groupOrder: GroupOrder.Original,
609
+ * forward: true,
610
+ * filterType: FilterType.AbsoluteRange,
611
+ * startLocation: { group: 100n, subgroup: 0n, object: 0n },
612
+ * endGroup: 120n
613
+ * })
614
+ * ```
615
+ */
616
+ type SubscribeOptions = {
617
+ /** Fully qualified track identifier ({@link FullTrackName}). */
618
+ fullTrackName: FullTrackName;
619
+ /** Subscriber priority (0 = highest, 255 = lowest). Values outside range are clamped. Fractional values are rounded. */
620
+ priority: number;
621
+ /** Desired {@link GroupOrder} (e.g. {@link GroupOrder.Original}) specifying delivery ordering semantics. */
622
+ groupOrder: GroupOrder;
623
+ /** If true, deliver objects forward (ascending); if false, reverse/backward semantics (implementation dependent). */
624
+ forward: boolean;
625
+ /** {@link FilterType} variant controlling starting subset (e.g. {@link FilterType.LatestObject}). */
626
+ filterType: FilterType;
627
+ /** Optional extension {@link VersionSpecificParameters} appended to the SUBSCRIBE control message. */
628
+ parameters?: VersionSpecificParameters;
629
+ /** Required for {@link FilterType.AbsoluteStart} / {@link FilterType.AbsoluteRange}; earliest {@link Location} to include. */
630
+ startLocation?: Location;
631
+ /** Required for {@link FilterType.AbsoluteRange}; exclusive upper group boundary (coerced to bigint if number provided). */
632
+ endGroup?: bigint | number;
633
+ };
634
+ /**
635
+ * Narrowing update constraints applied to an existing SUBSCRIBE via {@link MOQtailClient.subscribeUpdate}.
636
+ *
637
+ * Rules: start can only move forward (increase) and endGroup can only move backward (decrease) narrowing the window.
638
+ *
639
+ * @example Narrowing a live window
640
+ * ```ts
641
+ * await client.subscribeUpdate({
642
+ * requestId,
643
+ * startLocation: { group: 200n, subgroup: 0n, object: 0n },
644
+ * endGroup: 210n,
645
+ * priority: 16,
646
+ * forward: true
647
+ * })
648
+ * ```
649
+ */
650
+ type SubscribeUpdateOptions = {
651
+ /** The original SUBSCRIBE request id (bigint) being updated. */
652
+ subscriptionRequestId: bigint;
653
+ /** New narrowed {@link Location} start. */
654
+ startLocation: Location;
655
+ /** New narrowed end group (inclusive / protocol defined) must be \> start group. */
656
+ endGroup: bigint;
657
+ /** Updated subscriber priority (same constraints as initial subscribe). 0 is highest, 255 is lowest. */
658
+ priority: number;
659
+ /** Updated direction flag. */
660
+ forward: boolean;
661
+ /** Optional additional {@link VersionSpecificParameters}; existing parameters persist if omitted. */
662
+ parameters?: VersionSpecificParameters;
663
+ };
664
+ /**
665
+ * Parameters for {@link MOQtailClient.switch | switching} an existing SUBSCRIBE to a new track.
666
+ *
667
+ * @example Switching subscription to a new track
668
+ * ```ts
669
+ * await client.switch({
670
+ * fullTrackName: newFullTrackName,
671
+ * subscriptionRequestId
672
+ * })
673
+ * ```
674
+ */
675
+ type SwitchOptions = {
676
+ /** Fully qualified track identifier to switch to ({@link FullTrackName}). */
677
+ fullTrackName: FullTrackName;
678
+ /** The original SUBSCRIBE request id (bigint) being updated. */
679
+ subscriptionRequestId: bigint;
680
+ /** Optional additional {@link VersionSpecificParameters}; existing parameters persist if omitted. */
681
+ parameters?: VersionSpecificParameters;
682
+ };
683
+ /**
684
+ * Options for {@link MOQtailClient.fetch | performing a FETCH} operation for historical or relative object ranges.
685
+ *
686
+ * @example Standalone fetch
687
+ * ```ts
688
+ * const { requestId, stream } = await client.fetch({
689
+ * priority: 64,
690
+ * groupOrder: GroupOrder.Original,
691
+ * typeAndProps: {
692
+ * type: FetchType.StandAlone,
693
+ * props: { fullTrackName, startLocation, endLocation }
694
+ * }
695
+ * })
696
+ * ```
697
+ * @example Relative fetch joining a subscription
698
+ * ```ts
699
+ * const { requestId: subId } = await client.subscribe({
700
+ * fullTrackName,
701
+ * priority: 0,
702
+ * groupOrder: GroupOrder.Original,
703
+ * forward: true,
704
+ * filterType: FilterType.LatestObject
705
+ * })
706
+ * const fetchRes = await client.fetch({
707
+ * priority: 32,
708
+ * groupOrder: GroupOrder.Original,
709
+ * typeAndProps: {
710
+ * type: FetchType.Relative,
711
+ * props: { joiningRequestId: subId, joiningStart: 0n }
712
+ * }
713
+ * })
714
+ * ```
715
+ */
716
+ type FetchOptions = {
717
+ /** Request priority (0 = highest, 255 = lowest). Rounded & clamped. */
718
+ priority: number;
719
+ /** {@link GroupOrder} governing sequencing. */
720
+ groupOrder: GroupOrder;
721
+ /**
722
+ * Discriminated union selecting the {@link FetchType} mode and its specific properties:
723
+ * - StandAlone: full explicit range on a {@link FullTrackName} with start/end {@link Location}s.
724
+ * - Relative / Absolute: join an existing {@link SubscribeRequest} (identified by `joiningRequestId`) with starting position `joiningStart`.
725
+ */
726
+ typeAndProps: {
727
+ /** Standalone historical/segment fetch for a specific {@link FullTrackName}. */
728
+ type: FetchType.StandAlone;
729
+ /** Properties for standalone fetch: explicit track and range. */
730
+ props: {
731
+ fullTrackName: FullTrackName;
732
+ startLocation: Location;
733
+ endLocation: Location;
734
+ };
735
+ } | {
736
+ /** Fetch a range relative to an existing {@link SubscribeRequest} identified by `joiningRequestId`. */
737
+ type: FetchType.Relative;
738
+ /** Properties for relative fetch: subscription id and starting position. */
739
+ props: {
740
+ joiningRequestId: bigint;
741
+ joiningStart: bigint;
742
+ };
743
+ } | {
744
+ /** Fetch an absolute group/object range relative to a {@link SubscribeRequest}. */
745
+ type: FetchType.Absolute;
746
+ /** Properties for absolute fetch: subscription id and starting position. */
747
+ props: {
748
+ joiningRequestId: bigint;
749
+ joiningStart: bigint;
750
+ };
751
+ };
752
+ /** Optional {@link VersionSpecificParameters} block. */
753
+ parameters?: VersionSpecificParameters;
754
+ };
755
+
756
+ /**
757
+ * Copyright 2025 The MOQtail Authors
758
+ *
759
+ * Licensed under the Apache License, Version 2.0 (the "License");
760
+ * you may not use this file except in compliance with the License.
761
+ * You may obtain a copy of the License at
762
+ *
763
+ * http://www.apache.org/licenses/LICENSE-2.0
764
+ *
765
+ * Unless required by applicable law or agreed to in writing, software
766
+ * distributed under the License is distributed on an "AS IS" BASIS,
767
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
768
+ * See the License for the specific language governing permissions and
769
+ * limitations under the License.
770
+ */
771
+
772
+ /**
773
+ * Sends MoqtObjects as WebTransport datagrams.
774
+ * Parallel to SendStream but for datagram-based delivery.
775
+ *
776
+ * @example
777
+ * ```ts
778
+ * const sender = new SendDatagramStream(client.webTransport.datagrams.writable, trackAlias);
779
+ * await sender.write(moqtObject);
780
+ * ```
781
+ */
782
+ declare class SendDatagramStream {
783
+ #private;
784
+ readonly onDataSent?: (data: DatagramObject | DatagramStatus) => void;
785
+ constructor(writer: WritableStreamDefaultWriter<Uint8Array>, trackAlias: bigint, onDataSent?: (data: DatagramObject | DatagramStatus) => void);
786
+ /**
787
+ * Create a new datagram sender for a specific track.
788
+ *
789
+ * @param writeStream - WebTransport datagram writable stream
790
+ * @param trackAlias - Track alias for this datagram stream
791
+ * @param onDataSent - Optional callback fired when datagram is sent
792
+ * @returns SendDatagramStream instance
793
+ */
794
+ static new(writeStream: WritableStream<Uint8Array>, trackAlias: bigint, onDataSent?: (data: DatagramObject | DatagramStatus) => void): Promise<SendDatagramStream>;
795
+ /**
796
+ * Create a datagram sender using an existing shared writer.
797
+ * Use this when multiple senders need to share a single writer.
798
+ *
799
+ * @param writer - Existing WritableStreamDefaultWriter
800
+ * @param trackAlias - Track alias for this datagram stream
801
+ * @param onDataSent - Optional callback fired when datagram is sent
802
+ * @returns SendDatagramStream instance
803
+ */
804
+ static fromWriter(writer: WritableStreamDefaultWriter<Uint8Array>, trackAlias: bigint, onDataSent?: (data: DatagramObject | DatagramStatus) => void): SendDatagramStream;
805
+ /**
806
+ * Write a MoqtObject as a datagram.
807
+ * Converts to DatagramObject or DatagramStatus automatically.
808
+ *
809
+ * @param object - MoqtObject to send (must have Datagram forwarding preference)
810
+ * @throws ProtocolViolationError if object is not datagram-compatible
811
+ */
812
+ write(object: MoqtObject): Promise<void>;
813
+ /**
814
+ * Close the datagram writer.
815
+ */
816
+ close(): Promise<void>;
817
+ /**
818
+ * Release the writer lock without closing.
819
+ */
820
+ releaseLock(): void;
821
+ }
822
+ /**
823
+ * Receives and parses WebTransport datagrams as MoqtObjects.
824
+ * Parallel to RecvStream but for datagram-based delivery.
825
+ *
826
+ * Automatically handles:
827
+ * - DatagramObject parsing (objects with payloads)
828
+ * - DatagramStatus parsing (status-only objects)
829
+ * - Track alias to full track name resolution
830
+ *
831
+ * @example
832
+ * ```ts
833
+ * const receiver = new RecvDatagramStream(
834
+ * client.webTransport.datagrams.readable,
835
+ * (trackAlias) => client.requestIdMap.getNameByTrackAlias(trackAlias)
836
+ * );
837
+ *
838
+ * for await (const object of receiver.stream) {
839
+ * console.log('Received:', object);
840
+ * }
841
+ * ```
842
+ */
843
+ declare class RecvDatagramStream {
844
+ #private;
845
+ readonly stream: ReadableStream<MoqtObject>;
846
+ readonly onDataReceived?: (data: DatagramObject | DatagramStatus) => void;
847
+ private constructor();
848
+ /**
849
+ * Create a new datagram receiver.
850
+ *
851
+ * @param readStream - WebTransport datagram readable stream
852
+ * @param trackAliasResolver - Function to resolve track alias to full track name
853
+ * @param onDataReceived - Optional callback fired when datagram is received
854
+ * @returns RecvDatagramStream instance
855
+ */
856
+ static new(readStream: ReadableStream<Uint8Array>, trackAliasResolver: (trackAlias: bigint) => FullTrackName, onDataReceived?: (data: DatagramObject | DatagramStatus) => void): Promise<RecvDatagramStream>;
857
+ /**
858
+ * Cancel the datagram reader.
859
+ */
860
+ cancel(): Promise<void>;
861
+ /**
862
+ * Release the reader lock without canceling.
863
+ */
864
+ releaseLock(): void;
865
+ }
866
+
867
+ /**
868
+ * Copyright 2025 The MOQtail Authors
869
+ *
870
+ * Licensed under the Apache License, Version 2.0 (the "License");
871
+ * you may not use this file except in compliance with the License.
872
+ * You may obtain a copy of the License at
873
+ *
874
+ * http://www.apache.org/licenses/LICENSE-2.0
875
+ *
876
+ * Unless required by applicable law or agreed to in writing, software
877
+ * distributed under the License is distributed on an "AS IS" BASIS,
878
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
879
+ * See the License for the specific language governing permissions and
880
+ * limitations under the License.
881
+ */
882
+
883
+ /**
884
+ * @public
885
+ * Represents a Media Over QUIC Transport (MOQT) client session.
886
+ *
887
+ * Use {@link MOQtailClient.new} to establish a connection and perform MOQT operations such as subscribing to tracks,
888
+ * fetching historical data, announcing tracks for publication, and managing session lifecycle.
889
+ *
890
+ * Once initialized, the client provides high-level methods for MOQT requests and publishing. If a protocol violation
891
+ * occurs, the client will terminate and must be re-initialized.
892
+ *
893
+ * ## Usage
894
+ *
895
+ * ### Connect and Subscribe to a Track
896
+ * ```ts
897
+ * const client = await MOQtailClient.new({ url, supportedVersions: [0xff00000b] });
898
+ * const result = await client.subscribe({
899
+ * fullTrackName,
900
+ * filterType: FilterType.LatestObject,
901
+ * forward: true,
902
+ * groupOrder: GroupOrder.Original,
903
+ * priority: 0
904
+ * });
905
+ * if (!(result instanceof SubscribeError)) {
906
+ * for await (const object of result.stream) {
907
+ * // Consume MOQT objects
908
+ * }
909
+ * }
910
+ * ```
911
+ *
912
+ * ### Publish a namespace for Publishing
913
+ * ```ts
914
+ * const client = await MOQtailClient.new({ url, supportedVersions: [0xff00000b] });
915
+ * const publishNamespaceResult = await client.publishNamespace(["camera", "main"]);
916
+ * if (!(publishNamespaceResult instanceof PublishNamespaceError)) {
917
+ * // Ready to publish objects under this namespace
918
+ * }
919
+ * ```
920
+ *
921
+ * ### Graceful Shutdown
922
+ * ```ts
923
+ * await client.disconnect();
924
+ * ```
925
+ */
926
+ declare class MOQtailClient {
927
+ #private;
928
+ /**
929
+ * Namespace prefixes (tuples) the peer has requested announce notifications for via SUBSCRIBE_NAMESPACE.
930
+ * Used to decide which locally issued ANNOUNCE messages should be forwarded (future optimization: prefix trie).
931
+ */
932
+ readonly peerSubscribeNamespace: Set<Tuple>;
933
+ /**
934
+ * Namespace prefixes this client has subscribed to (issued SUBSCRIBE_NAMESPACE). Enables automatic filtering
935
+ * of incoming PUBLISH_NAMESPACE / PUBLISH_NAMESPACE_DONE. Maintained locally; no dedupe of overlapping / shadowing prefixes yet.
936
+ */
937
+ readonly subscribedAnnounces: Set<Tuple>;
938
+ /**
939
+ * Track namespaces this client has successfully announced (received ANNOUNCE_OK). Source of truth for
940
+ * deciding what to PUBLISH_NAMESPACE_DONE on teardown or targeted withdrawal.(future optimization: prefix trie).
941
+ */
942
+ readonly announcedNamespaces: Set<Tuple>;
943
+ /**
944
+ * Locally registered track definitions keyed by full track name string. Populated via addOrUpdateTrack.
945
+ * Does not imply the track has been announced or has active publications.
946
+ */
947
+ readonly trackSources: Map<string, Track>;
948
+ /**
949
+ * All in‑flight request objects keyed by requestId (SUBSCRIBE, FETCH, ANNOUNCE, etc). Facilitates lookup
950
+ * when responses / data arrive. Entries are removed on completion or error.
951
+ */
952
+ readonly requests: Map<bigint, MOQtailRequest>;
953
+ /**
954
+ * Active publications (SUBSCRIBE or FETCH) keyed by requestId to manage object stream controllers and lifecycle.
955
+ * Subset / specialization view of `requests`.
956
+ */
957
+ readonly publications: Map<bigint, SubscribePublication | FetchPublication>;
958
+ /**
959
+ * Active SUBSCRIBE request wrappers keyed by track alias for rapid alias -\> subscription resolution during
960
+ * incoming unidirectional data handling.
961
+ */
962
+ readonly subscriptions: Map<bigint, SubscribeRequest>;
963
+ /**
964
+ * Bidirectional track alias \<-\> subscription requestId mapping
965
+ */
966
+ readonly subscriptionAliasMap: Map<bigint, bigint>;
967
+ /**
968
+ * Bidirectional requestId \<-\> full track name mapping to reconstruct metadata for incoming objects.
969
+ */
970
+ readonly requestIdMap: RequestIdMap;
971
+ /**
972
+ * Maps track aliases to full track names for quick resolution during data handling.
973
+ */
974
+ readonly aliasFullTrackNameMap: Map<bigint, FullTrackName>;
975
+ /**
976
+ * Pending state updates keyed by requestId and applied once a new track alias is seen.
977
+ * Used to avoid premature state updates.
978
+ */
979
+ readonly pendingStateUpdates: Map<bigint, (newTrackAlias: bigint) => boolean>;
980
+ /** Underlying WebTransport session (set after successful construction in MOQtailClient.new). */
981
+ webTransport: WebTransport;
982
+ /** Outgoing / incoming control message bidirectional stream wrapper. */
983
+ controlStream: ControlStream;
984
+ /** Timeout (ms) applied to reading incoming data streams; undefined =\> no explicit timeout. */
985
+ dataStreamTimeoutMs?: number;
986
+ /** Timeout (ms) for control stream read operations; undefined =\> no explicit timeout. */
987
+ controlStreamTimeoutMs?: number;
988
+ /** Optional highest request id allowed (enforced externally / via configuration). */
989
+ maxRequestId?: bigint;
990
+ /**
991
+ * TODO: onNamespaceAnnounced may be a better name
992
+ * Fired when an PUBLISH_NAMESPACE control message is processed for a track namespace.
993
+ * Use to update UI or trigger discovery logic.
994
+ * Discovery event.
995
+ */
996
+ onNamespacePublished?: (msg: PublishNamespace) => void;
997
+ /**
998
+ * Fired when an PUBLISH_NAMESPACE_DONE control message is processed for a namespace.
999
+ * Use to remove tracks from UI or stop discovery.
1000
+ * Discovery event.
1001
+ */
1002
+ onNamespaceDone?: (msg: PublishNamespaceDone) => void;
1003
+ /**
1004
+ * Fired on GOAWAY reception signaling graceful session wind-down.
1005
+ * Use to prepare for disconnect or cleanup.
1006
+ * Lifecycle handler.
1007
+ */
1008
+ onGoaway?: (msg: GoAway) => void;
1009
+ /**
1010
+ * Fired if the underlying WebTransport session fails (ready → closed prematurely).
1011
+ * Use to log or alert on transport errors.
1012
+ * Lifecycle/error handler.
1013
+ */
1014
+ onWebTransportFail?: () => void;
1015
+ /**
1016
+ * Fired exactly once when the client transitions to terminated (disconnect).
1017
+ * Use to clean up resources or notify user.
1018
+ * Lifecycle handler.
1019
+ */
1020
+ onSessionTerminated?: (reason?: unknown) => void;
1021
+ /**
1022
+ * Invoked after each outbound control message is sent.
1023
+ * Use for logging or analytics.
1024
+ * Informational event.
1025
+ */
1026
+ onMessageSent?: (msg: ControlMessage) => void;
1027
+ /**
1028
+ * Invoked upon receiving each inbound control message before handling.
1029
+ * Use for logging or debugging.
1030
+ * Informational event.
1031
+ */
1032
+ onMessageReceived?: (msg: ControlMessage) => void;
1033
+ /**
1034
+ * Invoked for each decoded data object/header arriving on a uni stream (fetch or subgroup).
1035
+ * Use to process or display incoming media/data.
1036
+ * Informational event.
1037
+ */
1038
+ onDataReceived?: (data: SubgroupObject | SubgroupHeader | FetchObject | FetchHeader) => void;
1039
+ /**
1040
+ * Invoked after enqueuing each outbound data object/header.
1041
+ * Reserved for future use.
1042
+ * Informational event.
1043
+ */
1044
+ onDataSent?: (data: SubgroupObject | SubgroupHeader | FetchObject | FetchHeader) => void;
1045
+ /**
1046
+ * General-purpose error callback for surfaced exceptions not thrown to caller synchronously.
1047
+ * Use to log or display errors.
1048
+ * Error handler.
1049
+ */
1050
+ onError?: (er: unknown) => void;
1051
+ /** Invoked for each decoded datagram object/status arriving. */
1052
+ onDatagramReceived?: (data: DatagramObject | DatagramStatus) => void;
1053
+ /** Invoked after enqueuing each outbound datagram object/status. */
1054
+ onDatagramSent?: (data: DatagramObject | DatagramStatus) => void;
1055
+ /**
1056
+ * Stream of all received MoqtObjects from datagrams across all tracks
1057
+ * Consumer should filter by fullTrackName as needed
1058
+ *
1059
+ * WARNING: Only one reader should be active. For multiple subscribers,
1060
+ * use subscribeToTrackDatagrams() instead
1061
+ */
1062
+ readonly receivedDatagramObjects: ReadableStream<MoqtObject>;
1063
+ /**
1064
+ * Gets the current server setup configuration.
1065
+ *
1066
+ * @returns The {@link ServerSetup} instance associated with this client.
1067
+ */
1068
+ get serverSetup(): ServerSetup;
1069
+ /**
1070
+ * Returns true if datagram support is currently active
1071
+ */
1072
+ get isDatagramsEnabled(): boolean;
1073
+ private constructor();
1074
+ /**
1075
+ * Establishes a new {@link MOQtailClient} session over WebTransport and performs the MOQT setup handshake.
1076
+ *
1077
+ * @param args - {@link MOQtailClientOptions}
1078
+ *
1079
+ * @returns Promise resolving to a ready {@link MOQtailClient} instance.
1080
+ *
1081
+ * @throws :{@link ProtocolViolationError} If the server sends an unexpected or invalid message during setup.
1082
+ *
1083
+ * @example Minimal connection
1084
+ * ```ts
1085
+ * const client = await MOQtailClient.new({
1086
+ * url: 'https://relay.example.com/transport',
1087
+ * supportedVersions: [0xff00000b]
1088
+ * });
1089
+ * ```
1090
+ *
1091
+ * @example With callbacks and options
1092
+ * ```ts
1093
+ * const client = await MOQtailClient.new({
1094
+ * url,
1095
+ * supportedVersions: [0xff00000b],
1096
+ * setupParameters: new SetupParameters().addMaxRequestId(1000),
1097
+ * transportOptions: { congestionControl: 'default' },
1098
+ * dataStreamTimeoutMs: 5000,
1099
+ * controlStreamTimeoutMs: 2000,
1100
+ * enableDatagrams: true,
1101
+ * callbacks: {
1102
+ * onMessageSent: msg => console.log('Sent:', msg),
1103
+ * onMessageReceived: msg => console.log('Received:', msg),
1104
+ * onSessionTerminated: reason => console.warn('Session ended:', reason),
1105
+ * onDatagramReceived: data => console.log('Datagram:', data),
1106
+ * }
1107
+ * });
1108
+ * ```
1109
+ */
1110
+ static new(args: MOQtailClientOptions): Promise<MOQtailClient>;
1111
+ /**
1112
+ * Start receiving datagrams from the WebTransport connection.
1113
+ * Must be called before datagrams can be received (unless enableDatagrams: true was set in options).
1114
+ *
1115
+ * @throws MOQtailError if client is destroyed or datagrams already started
1116
+ */
1117
+ startDatagrams(): Promise<void>;
1118
+ /**
1119
+ * Stop receiving datagrams and release resources.
1120
+ * Idempotent - safe to call multiple times.
1121
+ */
1122
+ stopDatagrams(): Promise<void>;
1123
+ /**
1124
+ * Subscribe to receive datagrams for a specific track.
1125
+ * Multiple tracks can have separate handlers that run concurrently.
1126
+ *
1127
+ * @param trackAlias - Track alias to subscribe to
1128
+ * @param handler - Function called for each received MoqtObject on this track
1129
+ * @returns Unsubscribe function to remove the handler
1130
+ *
1131
+ * @example
1132
+ * ```ts
1133
+ * const unsubscribe = client.subscribeToTrackDatagrams(trackAlias, (obj) => {
1134
+ * console.log('Received datagram:', obj.payload);
1135
+ * });
1136
+ * // Later: unsubscribe();
1137
+ * ```
1138
+ */
1139
+ subscribeToTrackDatagrams(trackAlias: bigint, handler: (obj: MoqtObject) => void): () => void;
1140
+ /**
1141
+ * Unsubscribe from datagram delivery for a specific track.
1142
+ *
1143
+ * @param trackAlias - Track alias to unsubscribe from
1144
+ */
1145
+ unsubscribeFromTrackDatagrams(trackAlias: bigint): void;
1146
+ /**
1147
+ * Create a datagram sender for a specific track.
1148
+ *
1149
+ * @param trackAlias - Track alias for outgoing datagrams
1150
+ * @returns SendDatagramStream for writing MoqtObjects as datagrams
1151
+ * @throws MOQtailError if datagram writer not initialized (call startDatagrams() first)
1152
+ *
1153
+ * @example
1154
+ * ```ts
1155
+ * const sender = client.createDatagramSender(trackAlias);
1156
+ * await sender.write(moqtObject);
1157
+ * ```
1158
+ */
1159
+ createDatagramSender(trackAlias: bigint): SendDatagramStream;
1160
+ /**
1161
+ * Send a single MoqtObject as a datagram.
1162
+ * Convenience method for one-off datagram sends.
1163
+ *
1164
+ * @param trackAlias - Track alias for this object
1165
+ * @param object - MoqtObject to send
1166
+ * @throws MOQtailError if datagram writer not initialized
1167
+ *
1168
+ * @example
1169
+ * ```ts
1170
+ * await client.sendDatagram(trackAlias, moqtObject);
1171
+ * ```
1172
+ */
1173
+ sendDatagram(trackAlias: bigint, object: MoqtObject): Promise<void>;
1174
+ /**
1175
+ * Gracefully terminates this {@link MOQtailClient} session and releases underlying {@link https://developer.mozilla.org/docs/Web/API/WebTransport | WebTransport} resources.
1176
+ *
1177
+ * @param reason - Optional application-level reason (string or error) recorded and wrapped in an {@link InternalError}
1178
+ * passed to the {@link MOQtailClient.onSessionTerminated | onSessionTerminated} callback.
1179
+ *
1180
+ * @returns Promise that resolves once shutdown logic completes. Subsequent calls are safe no-ops.
1181
+ *
1182
+ * @example Basic usage
1183
+ * ```ts
1184
+ * await client.disconnect();
1185
+ * ```
1186
+ *
1187
+ * @example With reason
1188
+ * ```ts
1189
+ * await client.disconnect('user logout');
1190
+ * ```
1191
+ *
1192
+ * @example Idempotent double call
1193
+ * ```ts
1194
+ * await client.disconnect();
1195
+ * await client.disconnect(); // no error
1196
+ * ```
1197
+ *
1198
+ * @example Page unload safety
1199
+ * ```ts
1200
+ * window.addEventListener('beforeunload', () => {
1201
+ * client.disconnect('page unload');
1202
+ * });
1203
+ * ```
1204
+ */
1205
+ disconnect(reason?: unknown): Promise<void>;
1206
+ /**
1207
+ * Registers or updates a {@link Track} definition for local publishing or serving.
1208
+ *
1209
+ * A {@link Track} describes a logical media/data stream, identified by a unique name and namespace.
1210
+ * - If `trackSource.live` is present, the track can be served to subscribers in real-time.
1211
+ * - If `trackSource.past` is present, the track can be fetched for historical data.
1212
+ * - If both are present, the track supports both live and historical access.
1213
+ *
1214
+ * @param track - The {@link Track} instance to add or update. See {@link TrackSource} for live/past source options.
1215
+ * @returns void
1216
+ * @throws : {@link MOQtailError} If the client has been destroyed.
1217
+ *
1218
+ * @example Create a live video track from getUserMedia
1219
+ * ```ts
1220
+ * const stream = await navigator.mediaDevices.getUserMedia({ video: true });
1221
+ * const videoTrack = stream.getVideoTracks()[0];
1222
+ *
1223
+ * // Convert video frames to MoqtObject instances using your chosen scheme (e.g. WARP, CMAF, etc.)
1224
+ * // This part is application-specific and not provided by MOQtail:
1225
+ * const liveReadableStream: ReadableStream<MoqtObject> = ...
1226
+ *
1227
+ * // Register the track for live subscription
1228
+ * client.addOrUpdateTrack({
1229
+ * fullTrackName: { namespace: ["camera"], name: "main" },
1230
+ * forwardingPreference: ObjectForwardingPreference.Latest,
1231
+ * trackSource: { live: liveReadableStream },
1232
+ * publisherPriority: 0 // highest priority
1233
+ * });
1234
+ *
1235
+ * // For a hybrid track (live + past):
1236
+ * import { MemoryObjectCache } from './track/object_cache';
1237
+ * const cache = new MemoryObjectCache(); // Caches are not yet fully supported
1238
+ * client.addOrUpdateTrack({
1239
+ * fullTrackName: { namespace: ["camera"], name: "main" },
1240
+ * forwardingPreference: ObjectForwardingPreference.Latest,
1241
+ * trackSource: { live: liveReadableStream, past: cache },
1242
+ * publisherPriority: 8
1243
+ * });
1244
+ * ```
1245
+ */
1246
+ addOrUpdateTrack(track: Track): void;
1247
+ /**
1248
+ * Removes a previously registered {@link Track} from this client's local catalog.
1249
+ *
1250
+ * This deletes the in-memory entry inserted via {@link MOQtailClient.addOrUpdateTrack}, so future lookups by its {@link Track.fullTrackName} will fail.
1251
+ * Does **not** automatically:
1252
+ * - Send an {@link PublishNamespaceDone} (call {@link MOQtailClient.publishNamespaceDone} separately if you want to inform peers)
1253
+ * - Cancel active subscriptions or fetches (they continue until normal completion)
1254
+ * - Affect already-sent objects.
1255
+ *
1256
+ * If the track was not present, the call is a silent no-op (idempotent removal).
1257
+ *
1258
+ * @param track - The exact {@link Track} instance (its canonical name is used as the key).
1259
+ * @throws : {@link MOQtailError} If the client has been destroyed.
1260
+ *
1261
+ * @example
1262
+ * ```ts
1263
+ * // Register a track
1264
+ * client.addOrUpdateTrack(track);
1265
+ *
1266
+ * // Later, when no longer publishing:
1267
+ * client.removeTrack(track);
1268
+ *
1269
+ * // Optionally, inform peers that the namespace is no longer available:
1270
+ * await client.publishNamespaceDone(track.fullTrackName.namespace);
1271
+ * ```
1272
+ */
1273
+ removeTrack(track: Track): void;
1274
+ /**
1275
+ * Subscribes to a track and returns a stream of {@link MoqtObject}s matching the requested window and relay forwarding mode.
1276
+ *
1277
+ * - `forward: true` tells the relay to forward objects to this subscriber as they arrive.
1278
+ * - `forward: false` means the relay subscribes upstream but buffers objects locally, not forwarding them to you.
1279
+ * - `filterType: AbsoluteStart` lets you specify a start position in the future; the stream waits for that object. If the start location is \< the latest object
1280
+ * observed at the publisher then it behaves as `filterType: LatestObject`
1281
+ * - `filterType: AbsoluteRange` lets you specify a start and end group, both of should be in the future; the stream waits for those objects. If the start location is \< the latest object
1282
+ * observed at the publisher then it behaves as `filterType: LatestObject`.
1283
+ *
1284
+ * The method returns either a {@link SubscribeError} (on refusal) or an object with the subscription `requestId` and a `ReadableStream` of {@link MoqtObject}s.
1285
+ * Use the `requestId` for {@link MOQtailClient.unsubscribe} or {@link MOQtailClient.subscribeUpdate}. Use the `stream` to decode and display objects.
1286
+ *
1287
+ * @param args - {@link SubscribeOptions} describing the subscription window and relay forwarding behavior.
1288
+ * @returns Either a {@link SubscribeError} or `{ requestId, stream }` for consuming objects.
1289
+ * @throws : {@link MOQtailError} If the client is destroyed.
1290
+ * @throws : {@link ProtocolViolationError} If required fields are missing or inconsistent.
1291
+ * @throws : {@link InternalError} On transport/protocol failure (disconnect is triggered before rethrow).
1292
+ *
1293
+ * @example Subscribe to the latest object and receive future objects as they arrive
1294
+ * ```ts
1295
+ * const result = await client.subscribe({
1296
+ * fullTrackName,
1297
+ * filterType: FilterType.LatestObject,
1298
+ * forward: true,
1299
+ * groupOrder: GroupOrder.Original,
1300
+ * priority: 32
1301
+ * });
1302
+ * if (!(result instanceof SubscribeError)) {
1303
+ * for await (const obj of result.stream) {
1304
+ * // decode and display obj
1305
+ * }
1306
+ * }
1307
+ * ```
1308
+ *
1309
+ * @example Subscribe to a future range (waits for those objects to arrive)
1310
+ * ```ts
1311
+ * const result = await client.subscribe({
1312
+ * fullTrackName,
1313
+ * filterType: FilterType.AbsoluteRange,
1314
+ * startLocation: futureStart,
1315
+ * endGroup: futureEnd,
1316
+ * forward: true,
1317
+ * groupOrder: GroupOrder.Original,
1318
+ * priority: 128
1319
+ * });
1320
+ * ```
1321
+ */
1322
+ subscribe(args: SubscribeOptions): Promise<SubscribeError | {
1323
+ requestId: bigint;
1324
+ stream: ReadableStream<MoqtObject>;
1325
+ }>;
1326
+ /**
1327
+ * Stops an active subscription identified by its original SUBSCRIBE `requestId`.
1328
+ *
1329
+ * Sends an {@link Unsubscribe} control frame if the subscription is still active. If the id is unknown or already
1330
+ * cleaned up, the call is a silent no-op (hence multiple calls are idempotent).
1331
+ *
1332
+ * Use this when you no longer want incoming objects for a track (e.g. user navigated away, switching quality).
1333
+ * Canceling the consumer stream reader does **not** auto-unsubscribe; call this explicitly for prompt cleanup.
1334
+ *
1335
+ * @param requestId - The id returned from {@link MOQtailClient.subscribe}.
1336
+ * @returns Promise that resolves when the unsubscribe control frame is sent.
1337
+ * @throws :{@link MOQtailError} If the client is destroyed.
1338
+ * @throws :{@link InternalError} Wrapped lower-level failure while attempting to send (session will be disconnected first).
1339
+ *
1340
+ * @remarks
1341
+ * - Only targets SUBSCRIBE requests, not fetches. Passing a fetch request id is ignored (no-op).
1342
+ * - Safe to call multiple times; extra calls have no effect.
1343
+ *
1344
+ * @example Subscribe and later unsubscribe
1345
+ * ```ts
1346
+ * const sub = await client.subscribe({ fullTrackName, filterType: FilterType.LatestObject, forward: true, groupOrder: GroupOrder.Original, priority: 0 });
1347
+ * if (!(sub instanceof SubscribeError)) {
1348
+ * // ...consume objects...
1349
+ * await client.unsubscribe(sub.requestId);
1350
+ * }
1351
+ * ```
1352
+ *
1353
+ * @example Idempotent usage
1354
+ * ```ts
1355
+ * await client.unsubscribe(123n);
1356
+ * await client.unsubscribe(123n); // no error
1357
+ * ```
1358
+ */
1359
+ unsubscribe(requestId: bigint | number): Promise<void>;
1360
+ /**
1361
+ * Narrows or updates an active subscription window and/or relay forwarding behavior.
1362
+ *
1363
+ * Use this to:
1364
+ * - Move the start of the subscription forward (trim history or future window).
1365
+ * - Move the end group earlier (shorten the window).
1366
+ * - Change relay forwarding (`forward: false` stops forwarding new objects, `true` resumes).
1367
+ * - Adjust subscriber priority.
1368
+ *
1369
+ * Only narrowing is allowed: you cannot move the start earlier or the end group later than the original subscription.
1370
+ * Forwarding and priority can be changed at any time.
1371
+ *
1372
+ * @param args - {@link SubscribeUpdateOptions} referencing the original subscription `requestId` and new bounds.
1373
+ * @returns Promise that resolves when the update control frame is sent.
1374
+ * @throws :{@link MOQtailError} If the client is destroyed.
1375
+ * @throws :{@link ProtocolViolationError} If the update would widen the window (earlier start, later end group, or invalid ordering).
1376
+ * @throws :{@link InternalError} On transport/control failure (disconnect is triggered before rethrow).
1377
+ *
1378
+ * @remarks
1379
+ * - Only applies to active SUBSCRIBE requests; ignored if the request is not a subscription.
1380
+ * - Omitting a parameter (e.g. `priority`) leaves the previous value unchanged.
1381
+ * - Setting `forward: false` stops relay forwarding new objects after the current window drains.
1382
+ * - Safe to call multiple times; extra calls with unchanged bounds have no effect.
1383
+ *
1384
+ * @example Trim start forward
1385
+ * ```ts
1386
+ * await client.subscribeUpdate({ requestId, startLocation: laterLoc, endGroup, forward: true, priority });
1387
+ * ```
1388
+ *
1389
+ * @example Convert tailing subscription into bounded slice
1390
+ * ```ts
1391
+ * await client.subscribeUpdate({ requestId, startLocation: origStart, endGroup: cutoffGroup, forward: false, priority });
1392
+ * ```
1393
+ *
1394
+ * @example Lower priority only
1395
+ * ```ts
1396
+ * await client.subscribeUpdate({ requestId, startLocation: currentStart, endGroup: currentEnd, forward: true, priority: 200 });
1397
+ * ```
1398
+ */
1399
+ subscribeUpdate(args: SubscribeUpdateOptions): Promise<void>;
1400
+ /**
1401
+ * Switches an active subscription to a different track while retaining the same subscription parameters.
1402
+ *
1403
+ * Use this to change the subscribed track without tearing down and re-establishing a new subscription.
1404
+ *
1405
+ * @param args - {@link SwitchOptions} referencing the original subscription `requestId` and new track name.
1406
+ * @returns Promise that resolves when the switch control frame is sent.
1407
+ * @throws :{@link MOQtailError} If the client is destroyed.
1408
+ * @throws :{@link InternalError} On transport/control failure (disconnect is triggered before rethrow).
1409
+ *
1410
+ * @remarks
1411
+ * - Only applies to active SUBSCRIBE requests; ignored if the request is not a subscription.
1412
+ * - All other subscription parameters (window, forwarding, priority) remain unchanged.
1413
+ *
1414
+ * @example Switch to a different track
1415
+ * ```ts
1416
+ * await client.switch({ subscriptionRequestId, fullTrackName: newTrackName });
1417
+ * ```
1418
+ */
1419
+ switch(args: SwitchOptions): Promise<SubscribeError | {
1420
+ requestId: bigint;
1421
+ stream: ReadableStream<MoqtObject>;
1422
+ }>;
1423
+ /**
1424
+ * One-shot retrieval of a bounded object span, optionally anchored to an existing subscription, returning a stream of {@link MoqtObject}s.
1425
+ *
1426
+ * Choose a fetch type via `typeAndProps.type`:
1427
+ * - StandAlone: Historical slice of a specific {@link FullTrackName} independent of active subscriptions.
1428
+ * - Relative: Range relative to the JOINING subscription's current (largest) location; use when you want "N groups back" from live.
1429
+ * - Absolute: Absolute group/object offsets tied to an existing subscription (stable anchor) even if that subscription keeps forwarding.
1430
+ *
1431
+ * Field highlights (in {@link FetchOptions}):
1432
+ * - priority: 0 (highest) .. 255 (lowest); out-of-range rejected; non-integers rounded by caller expectation.
1433
+ * - groupOrder: {@link GroupOrder.Original} to preserve publisher order; or reorder ascending/descending if supported by server.
1434
+ * - typeAndProps: Discriminated union carrying parameters specific to each fetch mode (see examples).
1435
+ * - parameters: Optional version-specific extension block.
1436
+ *
1437
+ * Returns either a {@link FetchError} (refusal / invalid request at protocol level) or `{ requestId, stream }` whose `stream`
1438
+ * ends naturally after the bounded range completes (no explicit cancel needed for normal completion).
1439
+ *
1440
+ * Use cases:
1441
+ * - Grab a historical window for scrubbing UI while a separate live subscription tails.
1442
+ * - Late joiner fetching a short back-buffer then discarding the stream.
1443
+ * - Analytics batch job pulling a fixed slice without subscribing long-term.
1444
+ *
1445
+ * @throws MOQtailError If client is destroyed.
1446
+ * @throws ProtocolViolationError Priority out of [0-255] or missing/invalid joining subscription id for Relative/Absolute.
1447
+ * @throws InternalError Transport/control failure (the client disconnects first) then rethrows original error.
1448
+ *
1449
+ * @remarks
1450
+ * - Relative / Absolute require an existing active SUBSCRIBE `joiningRequestId`; if not found a {@link ProtocolViolationError} is thrown.
1451
+ * - Result stream is finite; reader close occurs automatically when last object delivered.
1452
+ * - Use {@link MOQtailClient.fetchCancel} only for early termination (not yet fully implemented: see TODO in code).
1453
+ *
1454
+ * @example Standalone window
1455
+ * ```ts
1456
+ * const r = await client.fetch({
1457
+ * priority: 64,
1458
+ * groupOrder: GroupOrder.Original,
1459
+ * typeAndProps: {
1460
+ * type: FetchType.StandAlone,
1461
+ * props: { fullTrackName, startLocation, endLocation }
1462
+ * }
1463
+ * })
1464
+ * if (!(r instanceof FetchError)) {
1465
+ * for await (const obj of r.stream as any) {
1466
+ * // consume objects then stream ends automatically
1467
+ * }
1468
+ * }
1469
+ * ```
1470
+ *
1471
+ * @example Relative to live subscription (e.g. last 5 groups)
1472
+ * ```ts
1473
+ * const sub = await client.subscribe({ fullTrackName, filterType: FilterType.LatestObject, forward: true, groupOrder: GroupOrder.Original, priority: 0 })
1474
+ * if (!(sub instanceof SubscribeError)) {
1475
+ * const slice = await client.fetch({
1476
+ * priority: 32,
1477
+ * groupOrder: GroupOrder.Original,
1478
+ * typeAndProps: { type: FetchType.Relative, props: { joiningRequestId: sub.requestId, joiningStart: 0n } }
1479
+ * })
1480
+ * }
1481
+ * ```
1482
+ */
1483
+ fetch(args: FetchOptions): Promise<FetchError | {
1484
+ requestId: bigint;
1485
+ stream: ReadableStream<MoqtObject>;
1486
+ }>;
1487
+ /**
1488
+ * Request early termination of an in‑flight FETCH identified by its `requestId`.
1489
+ *
1490
+ * Use when the consumer no longer needs the remaining objects (user scrubbed away, UI panel closed, replaced by a new fetch).
1491
+ * Sends a {@link FetchCancel} control frame if the id currently maps to an active fetch; otherwise silent no-op (idempotent).
1492
+ *
1493
+ * Parameter semantics:
1494
+ * - requestId: bigint returned from {@link MOQtailClient.fetch}. Numbers auto-converted to bigint.
1495
+ *
1496
+ * Current behavior / limitations:
1497
+ * - Data stream closure after cancel is TODO (objects may still arrive briefly).
1498
+ * - Unknown / already finished request: ignored without error.
1499
+ * - Only targets FETCH requests (not subscriptions).
1500
+ *
1501
+ * @throws MOQtailError If client is destroyed.
1502
+ * @throws InternalError Failure while sending the cancel (client disconnects first).
1503
+ *
1504
+ * @remarks
1505
+ * Follow-up improvement planned: actively close associated readable stream controller immediately upon acknowledgment.
1506
+ *
1507
+ * @example Cancel shortly after starting
1508
+ * ```ts
1509
+ * const r = await client.fetch({ priority: 32, groupOrder: GroupOrder.Original, typeAndProps: { type: FetchType.StandAlone, props: { fullTrackName, startLocation, endLocation } } })
1510
+ * if (!(r instanceof FetchError)) {
1511
+ * // user navigated away
1512
+ * await client.fetchCancel(r.requestId)
1513
+ * }
1514
+ * ```
1515
+ *
1516
+ * @example Idempotent double cancel
1517
+ * ```ts
1518
+ * await client.fetchCancel(456n)
1519
+ * await client.fetchCancel(456n) // no error
1520
+ * ```
1521
+ */
1522
+ fetchCancel(requestId: bigint | number): Promise<void>;
1523
+ /**
1524
+ * Declare (publish) a track namespace to the peer so subscribers using matching prefixes (via {@link MOQtailClient.subscribeNamespace})
1525
+ * can discover and begin subscribing/fetching its tracks.
1526
+ *
1527
+ * Typical flow (publisher side):
1528
+ * 1. Prepare / register one or more {@link Track} objects locally (see {@link MOQtailClient.addOrUpdateTrack}).
1529
+ * 2. Call `publishNamespace(namespace)` once per namespace prefix to expose those tracks.
1530
+ * 3. Later, call {@link MOQtailClient.publishNamespaceDone} when no longer publishing under that namespace.
1531
+ *
1532
+ * Parameter semantics:
1533
+ * - trackNamespace: Tuple representing the namespace prefix (e.g. ["camera","main"]). All tracks whose full names start with this tuple are considered within the announce scope.
1534
+ * - parameters: Optional {@link VersionSpecificParameters}; omitted =\> default instance.
1535
+ *
1536
+ * Returns: {@link PublishNamespaceOk} on success (namespace added to `announcedNamespaces`) or {@link PublishNamespaceError} explaining refusal.
1537
+ *
1538
+ * Use cases:
1539
+ * - Make a camera or sensor namespace available before any objects are pushed.
1540
+ * - Dynamically expose a newly created room / session namespace.
1541
+ * - Re-announce after reconnect to repopulate discovery state.
1542
+ *
1543
+ * @throws MOQtailError If client is destroyed.
1544
+ * @throws InternalError Transport/control failure while sending or awaiting response (client disconnects first).
1545
+ *
1546
+ * @remarks
1547
+ * - Duplicate announce detection is TODO (currently a second call will still send another PUBLISH_NAMESPACE; receiver behavior may vary).
1548
+ * - Successful announces are tracked in `announcedNamespaces`; manual removal occurs via {@link MOQtailClient.publishNamespaceDone}.
1549
+ * - Discovery subscribers (those who issued {@link MOQtailClient.subscribeNamespace}) will receive the resulting {@link PublishNamespace} message.
1550
+ *
1551
+ * @example Minimal announce
1552
+ * ```ts
1553
+ * const res = await client.publishNamespace(["camera","main"])
1554
+ * if (res instanceof PublishNamespaceOk) {
1555
+ * // ready to publish objects under tracks with this namespace prefix
1556
+ * }
1557
+ * ```
1558
+ *
1559
+ * @example PublishNamespace with parameters block
1560
+ * ```ts
1561
+ * const params = new VersionSpecificParameters().setSomeExtensionFlag(true)
1562
+ * const resp = await client.publishNamespace(["room","1234"], params)
1563
+ * ```
1564
+ */
1565
+ publishNamespace(trackNamespace: Tuple, parameters?: VersionSpecificParameters): Promise<PublishNamespaceError | PublishNamespaceOk>;
1566
+ /**
1567
+ * Withdraw a previously announced namespace so new subscribers no longer discover its tracks.
1568
+ *
1569
+ * Use when shutting down publishing for a logical scope (camera offline, room closed, session ended).
1570
+ * Removes the namespace from `announcedNamespaces` locally and sends an {@link PublishNamespaceDone} control frame.
1571
+ *
1572
+ * Parameter semantics:
1573
+ * - trackNamespace: Exact tuple used during {@link MOQtailClient.publishNamespace}. Must match to be removed from internal set.
1574
+ *
1575
+ * Behavior:
1576
+ * - Does not delete locally registered {@link Track} objects (they remain in `trackSources`).
1577
+ * - Does not forcibly end active subscriptions that were already established; peers simply stop discovering it for new ones.
1578
+ * - Silent if the namespace was not currently recorded (idempotent style).
1579
+ *
1580
+ * @throws MOQtailError If client is destroyed before sending.
1581
+ * @throws (rethrows original error) Any lower-level failure while sending results in a disconnect (unwrapped TODO: future wrap with InternalError for consistency).
1582
+ *
1583
+ * @remarks
1584
+ * Peers that issued {@link MOQtailClient.subscribeNamespace} for a matching prefix should receive the resulting {@link PublishNamespaceDone}.
1585
+ * Consider calling this before {@link MOQtailClient.disconnect} to give consumers prompt notice.
1586
+ *
1587
+ * @example Basic usage
1588
+ * ```ts
1589
+ * await client.publishNamespaceDone(["camera","main"])
1590
+ * ```
1591
+ *
1592
+ * @example Idempotent
1593
+ * ```ts
1594
+ * await client.publishNamespaceDone(["camera","main"]) // first time
1595
+ * await client.publishNamespaceDone(["camera","main"]) // no error, already removed
1596
+ * ```
1597
+ */
1598
+ publishNamespaceDone(trackNamespace: Tuple): Promise<void>;
1599
+ /**
1600
+ * Send an {@link PublishNamespaceCancel} to abort a previously issued ANNOUNCE before (or after) the peer fully processes it.
1601
+ *
1602
+ * Use when an announce was sent prematurely (e.g. validation failed locally, namespace no longer needed) and you want
1603
+ * to retract it without waiting for normal announce lifecycle or before publishing any objects.
1604
+ *
1605
+ * Parameter semantics:
1606
+ * - msg: Pre-constructed {@link PublishNamespaceCancel} referencing the original announce request id / namespace (builder provided elsewhere).
1607
+ *
1608
+ * Behavior:
1609
+ * - Simply forwards the control frame; does not modify `announcedNamespaces` (call {@link MOQtailClient.publishNamespaceDone} for local bookkeeping removal).
1610
+ * - Safe to send even if the announce already succeeded; peer may ignore duplicates per spec guidance.
1611
+ *
1612
+ * @throws MOQtailError If client is destroyed.
1613
+ * @throws InternalError Wrapped transport/control send failure (client disconnects first) then rethrows.
1614
+ *
1615
+ * @remarks
1616
+ * Use in tandem with internal tracking if you want to prevent subsequent object publication until a new announce is issued.
1617
+ *
1618
+ * @example Cancel immediately after a mistaken announce
1619
+ * ```ts
1620
+ * const publishNamespaceResp = await client.publishNamespace(["camera","temp"]) // wrong namespace
1621
+ * // Assume you kept the original announce requestId (e.g. from PublishNamespaceRequest)
1622
+ * const cancelMsg = new PublishNamespaceCancel(publishNamespaceResp.requestId as bigint)
1623
+ * await client.publishNamespaceCancel(cancelMsg)
1624
+ * ```
1625
+ */
1626
+ publishNamespaceCancel(msg: PublishNamespaceCancel): Promise<void>;
1627
+ subscribeNamespace(msg: SubscribeNamespace): Promise<void>;
1628
+ unsubscribeNamespace(msg: UnsubscribeNamespace): Promise<void>;
1629
+ }
1630
+
1631
+ /**
1632
+ * Copyright 2025 The MOQtail Authors
1633
+ *
1634
+ * Licensed under the Apache License, Version 2.0 (the "License");
1635
+ * you may not use this file except in compliance with the License.
1636
+ * You may obtain a copy of the License at
1637
+ *
1638
+ * http://www.apache.org/licenses/LICENSE-2.0
1639
+ *
1640
+ * Unless required by applicable law or agreed to in writing, software
1641
+ * distributed under the License is distributed on an "AS IS" BASIS,
1642
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1643
+ * See the License for the specific language governing permissions and
1644
+ * limitations under the License.
1645
+ */
1646
+
1647
+ declare class SendStream {
1648
+ #private;
1649
+ readonly header: Header;
1650
+ readonly onDataSent?: (data: SubgroupObject | SubgroupHeader | FetchObject | FetchHeader) => void;
1651
+ private constructor();
1652
+ static new(writeStream: WritableStream<Uint8Array>, header: Header, onDataSent?: (data: SubgroupObject | SubgroupHeader | FetchObject | FetchHeader) => void): Promise<SendStream>;
1653
+ write(object: FetchObject | SubgroupObject): Promise<void>;
1654
+ close(): Promise<void>;
1655
+ }
1656
+ declare class RecvStream {
1657
+ #private;
1658
+ readonly header: Header;
1659
+ readonly stream: ReadableStream<FetchObject | SubgroupObject>;
1660
+ readonly onDataReceived?: (data: SubgroupObject | SubgroupHeader | FetchObject | FetchHeader) => void;
1661
+ private constructor();
1662
+ static new(readStream: ReadableStream<Uint8Array>, partialDataTimeout?: number, onDataReceived?: (data: SubgroupObject | SubgroupHeader | FetchObject | FetchHeader) => void): Promise<RecvStream>;
1663
+ }
1664
+
1665
+ export { ControlStream, type FetchOptions, FetchPublication, FetchRequest, HybridTrackSource, type LiveObjectSource, LiveTrackSource, MOQtailClient, type MOQtailClientOptions, type MOQtailRequest, MemoryObjectCache, type ObjectCache, type PastObjectSource, PublishNamespaceRequest, RecvDatagramStream, RecvStream, RingBufferObjectCache, SendDatagramStream, SendStream, StaticTrackSource, SubscribeNamespaceRequest, type SubscribeOptions, SubscribePublication, SubscribeRequest, type SubscribeUpdateOptions, type SwitchOptions, type Track, type TrackSource };