moqtail 0.16.0 → 0.17.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.
package/README.md CHANGED
@@ -15,7 +15,7 @@ npm install moqtail
15
15
  | `moqtail/player` | `MOQtailPlayer`, elements, plugins |
16
16
  | `moqtail/player/component` | The `<moqtail-video>` web component |
17
17
 
18
- It runs in Chrome and Safari 26.4+ (WebTransport). It follows MOQT draft-22 and the MSF and CMSF editor's drafts. The player plays CMAF; LOC, captions and language switching aren't played yet. [DeepWiki](https://deepwiki.com/moqtail/moqtail) has the full list and the details this page leaves out.
18
+ It runs in Chrome and Safari 26.4+ (WebTransport). It follows MOQT draft-22 and the MSF and CMSF editor's drafts. The player plays CMAF and LOCMAF; LOC, captions and language switching aren't played yet. [DeepWiki](https://deepwiki.com/moqtail/moqtail) has the full list and the details this page leaves out.
19
19
 
20
20
  ## How It Fits Together
21
21
 
@@ -154,7 +154,7 @@ Attached with `player.on()`:
154
154
 
155
155
  The player is a chain of elements joined by pads. Each element definition says what it is (`source`, `transform` or `sink`), the pads it creates (`out` capabilities) and the pads it accepts (`in` capabilities). A source definition also has a `probe` that says whether it handles a track.
156
156
 
157
- For every track, the top-level one from the URL and every one the catalog lists, the candidates are, in order: the definitions passed to `registerElement()`, then the active plugins' elements (by plugin `priority`, then list order), then the built-in ones (catalog, CMAF, media timeline, SAP timeline). Among the candidates whose probe accepts the track, the lowest `priority` wins (default 100), then the earlier one. So yours wins a tie with a plugin's, and both win a tie with a built-in one.
157
+ For every track, the top-level one from the URL and every one the catalog lists, the candidates are, in order: the definitions passed to `registerElement()`, then the active plugins' elements (by plugin `priority`, then list order), then the built-in ones (catalog, CMAF, LOCMAF, media timeline, SAP timeline). Among the candidates whose probe accepts the track, the lowest `priority` wins (default 100), then the earlier one. So yours wins a tie with a plugin's, and both win a tie with a built-in one.
158
158
 
159
159
  A source the probe picks can be your own:
160
160
 
@@ -191,7 +191,7 @@ A plugin bundles features with the SETUP parameters they need, so a protocol ext
191
191
  - `buffer-controller`: only the first active one is used. The player attaches it while a negotiated stream is `live` and detaches it otherwise.
192
192
  - `abr-controller`: only the first active one is used. The player attaches it like the buffer controller, except while a media source provides `ABR` (switches itself, as `ssts()` sources do) or a rendition is picked manually (one of several selected).
193
193
 
194
- `ssts()` (sender-side track switching), `liveBuffer()` and `abr()` are built in. `liveBuffer()` and `abr()` have priority `Infinity`, so any other buffer or ABR controller wins over them. For now `abr()` keeps the current quality.
194
+ `ssts()` (sender-side track switching), `liveBuffer()` and `abr()` are built in. `liveBuffer()` and `abr()` have priority `Infinity`, so any other buffer or ABR controller wins over them. `abr()` steps the video rendition up and down on live streams with a small neural network, and FETCHes already-received objects to probe for room before stepping up; `abr({ onDecision })` logs each decision. [How it works](src/player/plugins/abr/README.md).
195
195
 
196
196
  ```ts
197
197
  import { MOQtailPlayer, definePlugin, liveBuffer, ssts } from 'moqtail/player'
@@ -1274,10 +1274,6 @@ declare class MOQtailClient extends Emitter<ClientEvents> {
1274
1274
  * use subscribeToTrackDatagrams() instead
1275
1275
  */
1276
1276
  readonly receivedDatagramObjects: ReadableStream<MoqtObject>;
1277
- /**
1278
- * Generates a safe, sequential local request ID for tracking pushed/incoming tracks.
1279
- */
1280
- allocatePseudoRequestId(): bigint;
1281
1277
  /**
1282
1278
  * Gets the current server setup configuration.
1283
1279
  *
@@ -808,83 +808,6 @@ var RecvStream = class RecvStream {
808
808
  await this.#reader.cancel(streamResetReason(code)).catch(() => {});
809
809
  }
810
810
  };
811
- // src/client/track/content_source.ts
812
- var StaticTrackSource = class {
813
- cache;
814
- constructor(cache) {
815
- this.cache = cache;
816
- }
817
- async getRange(start, end) {
818
- return this.cache.getRange(start, end);
819
- }
820
- };
821
- var LiveTrackSource = class {
822
- stream;
823
- #listeners = /* @__PURE__ */ new Set();
824
- /** Each listener's queue tail, so done waits for the objects still being delivered. */
825
- #queues = /* @__PURE__ */ new Map();
826
- #doneListeners = /* @__PURE__ */ new Set();
827
- #largestLocation;
828
- #ingestActive = false;
829
- #reader;
830
- constructor(stream) {
831
- this.stream = stream;
832
- this.#startIngest();
833
- }
834
- get largestLocation() {
835
- return this.#largestLocation;
836
- }
837
- async #startIngest() {
838
- if (this.#ingestActive) return;
839
- this.#ingestActive = true;
840
- try {
841
- this.#reader = this.stream.getReader();
842
- while (this.#ingestActive) {
843
- const { value, done } = await this.#reader.read();
844
- if (done) break;
845
- this.#largestLocation = value.location;
846
- for (const listener of this.#listeners) listener(value);
847
- }
848
- } catch (error) {
849
- require_emitter.logger.error("track/content_source", "Error during live object ingestion:", error);
850
- } finally {
851
- this.#ingestActive = false;
852
- this.#reader?.releaseLock();
853
- const drained = Promise.all([...this.#queues.values()].map((tail) => tail()));
854
- for (const doneListener of this.#doneListeners) drained.then(() => doneListener());
855
- }
856
- }
857
- onNewObject(listener) {
858
- let queue = Promise.resolve();
859
- const queuedListener = (obj) => {
860
- queue = queue.then(() => listener(obj)).catch((err) => {
861
- require_emitter.logger.error("track/content_source", "Error in subscriber listener:", err);
862
- });
863
- };
864
- this.#listeners.add(queuedListener);
865
- this.#queues.set(queuedListener, () => queue);
866
- return () => {
867
- this.#queues.delete(queuedListener);
868
- return this.#listeners.delete(queuedListener);
869
- };
870
- }
871
- onDone(listener) {
872
- this.#doneListeners.add(listener);
873
- return () => this.#doneListeners.delete(listener);
874
- }
875
- stop() {
876
- this.#ingestActive = false;
877
- this.#reader?.cancel();
878
- }
879
- };
880
- var HybridTrackSource = class {
881
- past;
882
- live;
883
- constructor(cache, stream) {
884
- this.past = new StaticTrackSource(cache);
885
- this.live = new LiveTrackSource(stream);
886
- }
887
- };
888
811
  // src/client/request/publish_namespace.ts
889
812
  /**
890
813
  * Copyright 2026 The MOQtail Authors
@@ -1447,21 +1370,7 @@ var TrackStatusRequest = class {
1447
1370
  */
1448
1371
  const handlerPublish = async (client, msg, stream) => {
1449
1372
  require_emitter.logger.log("handler/publish", "track: %s alias: %d", msg.fullTrackName.toString(), msg.trackAlias);
1450
- let streamController;
1451
- const objects = new ReadableStream({ start(c) {
1452
- streamController = c;
1453
- } });
1454
- const localPseudoRequestId = client.allocatePseudoRequestId();
1455
- client.requestIdMap.addMapping(localPseudoRequestId, msg.fullTrackName);
1456
- client.subscriptionAliasMap.set(localPseudoRequestId, msg.trackAlias);
1457
- client.aliasFullTrackNameMap.set(msg.trackAlias, msg.fullTrackName);
1458
- const receiver = {
1459
- requestId: localPseudoRequestId,
1460
- streamsAccepted: 0,
1461
- largestLocation: void 0,
1462
- controller: streamController
1463
- };
1464
- client.subscriptions.set(msg.trackAlias, receiver);
1373
+ const objects = client.acceptPushedTrack(msg);
1465
1374
  client.emit("peerpublish", msg, objects);
1466
1375
  await stream.send(new require_model.RequestOk());
1467
1376
  };
@@ -2604,8 +2513,10 @@ const handlerRequestError = async (client, msg, _stream, requestId) => {
2604
2513
  */
2605
2514
  const handlerPublishDone = async (client, msg, _stream, openingRequestId) => {
2606
2515
  client.emit("peerpublishdone", msg, openingRequestId);
2607
- const request = client.requests.get(openingRequestId);
2608
- if (request instanceof SubscribeRequest) {
2516
+ const alias = client.subscriptionAliasMap.get(openingRequestId);
2517
+ const found = client.requests.get(openingRequestId);
2518
+ const request = found instanceof SubscribeRequest ? found : found === void 0 && alias !== void 0 ? client.subscriptions.get(alias) : void 0;
2519
+ if (request) {
2609
2520
  request.expectedStreams = msg.streamCount;
2610
2521
  request.publishDone = msg;
2611
2522
  client.completeSubscription(request);
@@ -3256,12 +3167,6 @@ var MOQtailClient = class extends require_emitter.Emitter {
3256
3167
  return id;
3257
3168
  }
3258
3169
  /**
3259
- * Generates a safe, sequential local request ID for tracking pushed/incoming tracks.
3260
- */
3261
- allocatePseudoRequestId() {
3262
- return this.#nextClientRequestId;
3263
- }
3264
- /**
3265
3170
  * Gets the current server setup configuration.
3266
3171
  *
3267
3172
  * @returns The {@link Setup} instance the server sent back during handshake.
@@ -4339,20 +4244,28 @@ var MOQtailClient = class extends require_emitter.Emitter {
4339
4244
  */
4340
4245
  acceptPushedTrack(msg) {
4341
4246
  this.#ensureActive();
4342
- let streamController;
4343
- const stream = new ReadableStream({ start(c) {
4344
- streamController = c;
4345
- } });
4346
4247
  this.requestIdMap.addMapping(msg.requestId, msg.fullTrackName);
4248
+ const objects = new ObjectStream();
4347
4249
  const receiver = {
4348
4250
  requestId: msg.requestId,
4349
4251
  fullTrackName: msg.fullTrackName,
4350
- streamsAccepted: 0,
4252
+ streamsAccepted: 0n,
4253
+ expectedStreams: void 0,
4254
+ publishDone: void 0,
4351
4255
  largestLocation: void 0,
4352
- controller: streamController
4256
+ finish() {},
4257
+ manager: {
4258
+ objects,
4259
+ requests: [],
4260
+ drop() {},
4261
+ deliver(_request, obj) {
4262
+ objects.enqueue(obj);
4263
+ return true;
4264
+ }
4265
+ }
4353
4266
  };
4354
4267
  this.#claimTrackAlias(msg.trackAlias, receiver);
4355
- return stream;
4268
+ return objects.readable;
4356
4269
  }
4357
4270
  /**
4358
4271
  * Declare (publish) a track namespace to the peer so subscribers using matching prefixes (via {@link MOQtailClient.subscribeNamespace})
@@ -4993,18 +4906,6 @@ Object.defineProperty(exports, "FetchRequest", {
4993
4906
  return FetchRequest;
4994
4907
  }
4995
4908
  });
4996
- Object.defineProperty(exports, "HybridTrackSource", {
4997
- enumerable: true,
4998
- get: function() {
4999
- return HybridTrackSource;
5000
- }
5001
- });
5002
- Object.defineProperty(exports, "LiveTrackSource", {
5003
- enumerable: true,
5004
- get: function() {
5005
- return LiveTrackSource;
5006
- }
5007
- });
5008
4909
  Object.defineProperty(exports, "MOQtailClient", {
5009
4910
  enumerable: true,
5010
4911
  get: function() {
@@ -5065,12 +4966,6 @@ Object.defineProperty(exports, "SendStream", {
5065
4966
  return SendStream;
5066
4967
  }
5067
4968
  });
5068
- Object.defineProperty(exports, "StaticTrackSource", {
5069
- enumerable: true,
5070
- get: function() {
5071
- return StaticTrackSource;
5072
- }
5073
- });
5074
4969
  Object.defineProperty(exports, "SubscribeNamespaceRequest", {
5075
4970
  enumerable: true,
5076
4971
  get: function() {
@@ -1,4 +1,4 @@
1
- import { A as RequestError, B as GoAway, D as StreamResetCode, En as FetchObject, F as RequestUpdate, H as FetchOk, Hn as ObjectStatus, I as SubscribeOk, In as FetchHeader, Jn as Location, Kn as Tuple, L as Publish, Ln as Datagram, Lt as LocationFilter, M as SubscribeTracks, N as SubscribeNamespace, On as ControlMessageType, P as TrackStatus, Pn as SwitchMode, R as PublishDone, Sn as FullTrackName, Tn as EndOfRangeKind, X as TrackProperty, _n as Header, at as Setup, bn as MoqtObject, ct as PublishNamespace, it as Fetch, j as RequestOk, jn as PublishDoneStatusCode, k as ControlMessage, kn as GroupOrder, lt as MessageParameter, pn as PublishSkipped, r as SetupOptions, vn as RequestIdMap, xn as SubgroupObject, yn as SubgroupHeader, z as Subscribe } from "./index-CNn9BgO6.mjs";
1
+ import { A as RequestError, B as GoAway, D as StreamResetCode, En as FetchObject, F as RequestUpdate, H as FetchOk, Hn as ObjectStatus, I as SubscribeOk, In as FetchHeader, Jn as Location, Kn as Tuple, L as Publish, Ln as Datagram, Lt as LocationFilter, M as SubscribeTracks, N as SubscribeNamespace, On as ControlMessageType, P as TrackStatus, Pn as SwitchMode, R as PublishDone, Sn as FullTrackName, Tn as EndOfRangeKind, X as TrackProperty, _n as Header, at as Setup, bn as MoqtObject, ct as PublishNamespace, it as Fetch, j as RequestOk, jn as PublishDoneStatusCode, k as ControlMessage, kn as GroupOrder, lt as MessageParameter, pn as PublishSkipped, r as SetupOptions, vn as RequestIdMap, xn as SubgroupObject, yn as SubgroupHeader, z as Subscribe } from "./index-BaZgHZ8D.mjs";
2
2
  import { o as Emitter, t as LogLevel } from "./logger-B8IYkljn.mjs";
3
3
  /** `in` for a stream the peer opened, `out` for one this client opened. */
4
4
  type DataDirection = 'in' | 'out';
@@ -1274,10 +1274,6 @@ declare class MOQtailClient extends Emitter<ClientEvents> {
1274
1274
  * use subscribeToTrackDatagrams() instead
1275
1275
  */
1276
1276
  readonly receivedDatagramObjects: ReadableStream<MoqtObject>;
1277
- /**
1278
- * Generates a safe, sequential local request ID for tracking pushed/incoming tracks.
1279
- */
1280
- allocatePseudoRequestId(): bigint;
1281
1277
  /**
1282
1278
  * Gets the current server setup configuration.
1283
1279
  *
@@ -808,83 +808,6 @@ var RecvStream = class RecvStream {
808
808
  await this.#reader.cancel(streamResetReason(code)).catch(() => {});
809
809
  }
810
810
  };
811
- // src/client/track/content_source.ts
812
- var StaticTrackSource = class {
813
- cache;
814
- constructor(cache) {
815
- this.cache = cache;
816
- }
817
- async getRange(start, end) {
818
- return this.cache.getRange(start, end);
819
- }
820
- };
821
- var LiveTrackSource = class {
822
- stream;
823
- #listeners = /* @__PURE__ */ new Set();
824
- /** Each listener's queue tail, so done waits for the objects still being delivered. */
825
- #queues = /* @__PURE__ */ new Map();
826
- #doneListeners = /* @__PURE__ */ new Set();
827
- #largestLocation;
828
- #ingestActive = false;
829
- #reader;
830
- constructor(stream) {
831
- this.stream = stream;
832
- this.#startIngest();
833
- }
834
- get largestLocation() {
835
- return this.#largestLocation;
836
- }
837
- async #startIngest() {
838
- if (this.#ingestActive) return;
839
- this.#ingestActive = true;
840
- try {
841
- this.#reader = this.stream.getReader();
842
- while (this.#ingestActive) {
843
- const { value, done } = await this.#reader.read();
844
- if (done) break;
845
- this.#largestLocation = value.location;
846
- for (const listener of this.#listeners) listener(value);
847
- }
848
- } catch (error) {
849
- logger.error("track/content_source", "Error during live object ingestion:", error);
850
- } finally {
851
- this.#ingestActive = false;
852
- this.#reader?.releaseLock();
853
- const drained = Promise.all([...this.#queues.values()].map((tail) => tail()));
854
- for (const doneListener of this.#doneListeners) drained.then(() => doneListener());
855
- }
856
- }
857
- onNewObject(listener) {
858
- let queue = Promise.resolve();
859
- const queuedListener = (obj) => {
860
- queue = queue.then(() => listener(obj)).catch((err) => {
861
- logger.error("track/content_source", "Error in subscriber listener:", err);
862
- });
863
- };
864
- this.#listeners.add(queuedListener);
865
- this.#queues.set(queuedListener, () => queue);
866
- return () => {
867
- this.#queues.delete(queuedListener);
868
- return this.#listeners.delete(queuedListener);
869
- };
870
- }
871
- onDone(listener) {
872
- this.#doneListeners.add(listener);
873
- return () => this.#doneListeners.delete(listener);
874
- }
875
- stop() {
876
- this.#ingestActive = false;
877
- this.#reader?.cancel();
878
- }
879
- };
880
- var HybridTrackSource = class {
881
- past;
882
- live;
883
- constructor(cache, stream) {
884
- this.past = new StaticTrackSource(cache);
885
- this.live = new LiveTrackSource(stream);
886
- }
887
- };
888
811
  // src/client/request/publish_namespace.ts
889
812
  /**
890
813
  * Copyright 2026 The MOQtail Authors
@@ -1447,21 +1370,7 @@ var TrackStatusRequest = class {
1447
1370
  */
1448
1371
  const handlerPublish = async (client, msg, stream) => {
1449
1372
  logger.log("handler/publish", "track: %s alias: %d", msg.fullTrackName.toString(), msg.trackAlias);
1450
- let streamController;
1451
- const objects = new ReadableStream({ start(c) {
1452
- streamController = c;
1453
- } });
1454
- const localPseudoRequestId = client.allocatePseudoRequestId();
1455
- client.requestIdMap.addMapping(localPseudoRequestId, msg.fullTrackName);
1456
- client.subscriptionAliasMap.set(localPseudoRequestId, msg.trackAlias);
1457
- client.aliasFullTrackNameMap.set(msg.trackAlias, msg.fullTrackName);
1458
- const receiver = {
1459
- requestId: localPseudoRequestId,
1460
- streamsAccepted: 0,
1461
- largestLocation: void 0,
1462
- controller: streamController
1463
- };
1464
- client.subscriptions.set(msg.trackAlias, receiver);
1373
+ const objects = client.acceptPushedTrack(msg);
1465
1374
  client.emit("peerpublish", msg, objects);
1466
1375
  await stream.send(new RequestOk());
1467
1376
  };
@@ -2604,8 +2513,10 @@ const handlerRequestError = async (client, msg, _stream, requestId) => {
2604
2513
  */
2605
2514
  const handlerPublishDone = async (client, msg, _stream, openingRequestId) => {
2606
2515
  client.emit("peerpublishdone", msg, openingRequestId);
2607
- const request = client.requests.get(openingRequestId);
2608
- if (request instanceof SubscribeRequest) {
2516
+ const alias = client.subscriptionAliasMap.get(openingRequestId);
2517
+ const found = client.requests.get(openingRequestId);
2518
+ const request = found instanceof SubscribeRequest ? found : found === void 0 && alias !== void 0 ? client.subscriptions.get(alias) : void 0;
2519
+ if (request) {
2609
2520
  request.expectedStreams = msg.streamCount;
2610
2521
  request.publishDone = msg;
2611
2522
  client.completeSubscription(request);
@@ -3256,12 +3167,6 @@ var MOQtailClient = class extends Emitter {
3256
3167
  return id;
3257
3168
  }
3258
3169
  /**
3259
- * Generates a safe, sequential local request ID for tracking pushed/incoming tracks.
3260
- */
3261
- allocatePseudoRequestId() {
3262
- return this.#nextClientRequestId;
3263
- }
3264
- /**
3265
3170
  * Gets the current server setup configuration.
3266
3171
  *
3267
3172
  * @returns The {@link Setup} instance the server sent back during handshake.
@@ -4339,20 +4244,28 @@ var MOQtailClient = class extends Emitter {
4339
4244
  */
4340
4245
  acceptPushedTrack(msg) {
4341
4246
  this.#ensureActive();
4342
- let streamController;
4343
- const stream = new ReadableStream({ start(c) {
4344
- streamController = c;
4345
- } });
4346
4247
  this.requestIdMap.addMapping(msg.requestId, msg.fullTrackName);
4248
+ const objects = new ObjectStream();
4347
4249
  const receiver = {
4348
4250
  requestId: msg.requestId,
4349
4251
  fullTrackName: msg.fullTrackName,
4350
- streamsAccepted: 0,
4252
+ streamsAccepted: 0n,
4253
+ expectedStreams: void 0,
4254
+ publishDone: void 0,
4351
4255
  largestLocation: void 0,
4352
- controller: streamController
4256
+ finish() {},
4257
+ manager: {
4258
+ objects,
4259
+ requests: [],
4260
+ drop() {},
4261
+ deliver(_request, obj) {
4262
+ objects.enqueue(obj);
4263
+ return true;
4264
+ }
4265
+ }
4353
4266
  };
4354
4267
  this.#claimTrackAlias(msg.trackAlias, receiver);
4355
- return stream;
4268
+ return objects.readable;
4356
4269
  }
4357
4270
  /**
4358
4271
  * Declare (publish) a track namespace to the peer so subscribers using matching prefixes (via {@link MOQtailClient.subscribeNamespace})
@@ -4933,4 +4846,4 @@ var MOQtailClient = class extends Emitter {
4933
4846
  }
4934
4847
  }
4935
4848
  };
4936
- export { SendStream as C, ControlSendStream as D, ControlRecvStream as E, ControlStream as O, RecvStream as S, RequestStream as T, ObjectStream as _, SubscribeNamespaceRequest as a, LiveTrackSource as b, TrackStatusRequest as c, Subscription as d, DEFAULT_FILL_OPEN_TIMEOUT_MS as f, FetchRequest as g, DEFAULT_TRACK_ALIAS_RESOLUTION_TIMEOUT_MS as h, PublishPublication as i, errorMessage as k, PublishRequest as l, DEFAULT_SWITCH_DRAIN_TIMEOUT_MS as m, ObjectOrderer as n, SubscribePublication as o, DEFAULT_MAX_FILTER_RANGES as p, SendDatagramStream as r, FetchPublication as s, MOQtailClient as t, SubscribeRequest as u, PublishNamespaceRequest as v, DataStreamReporter as w, StaticTrackSource as x, HybridTrackSource as y };
4849
+ export { ControlRecvStream as C, errorMessage as E, RequestStream as S, ControlStream as T, ObjectStream as _, SubscribeNamespaceRequest as a, SendStream as b, TrackStatusRequest as c, Subscription as d, DEFAULT_FILL_OPEN_TIMEOUT_MS as f, FetchRequest as g, DEFAULT_TRACK_ALIAS_RESOLUTION_TIMEOUT_MS as h, PublishPublication as i, PublishRequest as l, DEFAULT_SWITCH_DRAIN_TIMEOUT_MS as m, ObjectOrderer as n, SubscribePublication as o, DEFAULT_MAX_FILTER_RANGES as p, SendDatagramStream as r, FetchPublication as s, MOQtailClient as t, SubscribeRequest as u, PublishNamespaceRequest as v, ControlSendStream as w, DataStreamReporter as x, RecvStream as y };
package/dist/client.cjs CHANGED
@@ -1,6 +1,84 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_client = require("./client-DQ5aGbLR.cjs");
2
+ const require_client = require("./client-FnSNJocV.cjs");
3
+ const require_emitter = require("./emitter-qNJYD3yQ.cjs");
3
4
  const require_model = require("./model.cjs");
5
+ // src/client/track/content_source.ts
6
+ var StaticTrackSource = class {
7
+ cache;
8
+ constructor(cache) {
9
+ this.cache = cache;
10
+ }
11
+ async getRange(start, end) {
12
+ return this.cache.getRange(start, end);
13
+ }
14
+ };
15
+ var LiveTrackSource = class {
16
+ stream;
17
+ #listeners = /* @__PURE__ */ new Set();
18
+ /** Each listener's queue tail, so done waits for the objects still being delivered. */
19
+ #queues = /* @__PURE__ */ new Map();
20
+ #doneListeners = /* @__PURE__ */ new Set();
21
+ #largestLocation;
22
+ #ingestActive = false;
23
+ #reader;
24
+ constructor(stream) {
25
+ this.stream = stream;
26
+ this.#startIngest();
27
+ }
28
+ get largestLocation() {
29
+ return this.#largestLocation;
30
+ }
31
+ async #startIngest() {
32
+ if (this.#ingestActive) return;
33
+ this.#ingestActive = true;
34
+ try {
35
+ this.#reader = this.stream.getReader();
36
+ while (this.#ingestActive) {
37
+ const { value, done } = await this.#reader.read();
38
+ if (done) break;
39
+ this.#largestLocation = value.location;
40
+ for (const listener of this.#listeners) listener(value);
41
+ }
42
+ } catch (error) {
43
+ require_emitter.logger.error("track/content_source", "Error during live object ingestion:", error);
44
+ } finally {
45
+ this.#ingestActive = false;
46
+ this.#reader?.releaseLock();
47
+ const drained = Promise.all([...this.#queues.values()].map((tail) => tail()));
48
+ for (const doneListener of this.#doneListeners) drained.then(() => doneListener());
49
+ }
50
+ }
51
+ onNewObject(listener) {
52
+ let queue = Promise.resolve();
53
+ const queuedListener = (obj) => {
54
+ queue = queue.then(() => listener(obj)).catch((err) => {
55
+ require_emitter.logger.error("track/content_source", "Error in subscriber listener:", err);
56
+ });
57
+ };
58
+ this.#listeners.add(queuedListener);
59
+ this.#queues.set(queuedListener, () => queue);
60
+ return () => {
61
+ this.#queues.delete(queuedListener);
62
+ return this.#listeners.delete(queuedListener);
63
+ };
64
+ }
65
+ onDone(listener) {
66
+ this.#doneListeners.add(listener);
67
+ return () => this.#doneListeners.delete(listener);
68
+ }
69
+ stop() {
70
+ this.#ingestActive = false;
71
+ this.#reader?.cancel();
72
+ }
73
+ };
74
+ var HybridTrackSource = class {
75
+ past;
76
+ live;
77
+ constructor(cache, stream) {
78
+ this.past = new StaticTrackSource(cache);
79
+ this.live = new LiveTrackSource(stream);
80
+ }
81
+ };
4
82
  // src/client/track/object_cache.ts
5
83
  /**
6
84
  * Copyright 2025 The MOQtail Authors
@@ -125,8 +203,8 @@ exports.DEFAULT_TRACK_ALIAS_RESOLUTION_TIMEOUT_MS = require_client.DEFAULT_TRACK
125
203
  exports.DataStreamReporter = require_client.DataStreamReporter;
126
204
  exports.FetchPublication = require_client.FetchPublication;
127
205
  exports.FetchRequest = require_client.FetchRequest;
128
- exports.HybridTrackSource = require_client.HybridTrackSource;
129
- exports.LiveTrackSource = require_client.LiveTrackSource;
206
+ exports.HybridTrackSource = HybridTrackSource;
207
+ exports.LiveTrackSource = LiveTrackSource;
130
208
  exports.MOQtailClient = require_client.MOQtailClient;
131
209
  exports.MemoryObjectCache = MemoryObjectCache;
132
210
  exports.ObjectOrderer = require_client.ObjectOrderer;
@@ -139,7 +217,7 @@ exports.RequestStream = require_client.RequestStream;
139
217
  exports.RingBufferObjectCache = RingBufferObjectCache;
140
218
  exports.SendDatagramStream = require_client.SendDatagramStream;
141
219
  exports.SendStream = require_client.SendStream;
142
- exports.StaticTrackSource = require_client.StaticTrackSource;
220
+ exports.StaticTrackSource = StaticTrackSource;
143
221
  exports.SubscribeNamespaceRequest = require_client.SubscribeNamespaceRequest;
144
222
  exports.SubscribePublication = require_client.SubscribePublication;
145
223
  exports.SubscribeRequest = require_client.SubscribeRequest;
package/dist/client.d.cts CHANGED
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { $ as DataStreamReporter, A as MOQtailRequest, B as Subscription, C as DEFAULT_SWITCH_DRAIN_TIMEOUT_MS, D as FetchOptions, E as EndOfRangeHandler, F as SwitchOptions, G as WindowSuspension, H as PublishRequest, I as TrackAliasHolder, J as DataEvent, K as ObjectStream, L as TrackStatusRequest, M as SubscribeOptions, N as SubscribeResult, O as FetchResult, P as SubscribeUpdateOptions, Q as DataStreamEndEvent, R as SubscribeNamespaceRequest, S as DEFAULT_MAX_FILTER_RANGES, T as EarlyDiscardPolicyConfig, U as FetchRequest, V as PublishNamespaceRequest, W as ObjectOrderer, X as DataHeaderEvent, Y as DataEventBase, Z as DataObjectEvent, _ as ControlRecvStream, a as SubscribePublication, b as ClientEvents, c as HybridTrackSource, d as PastObjectSource, et as FullTrackNameOf, f as StaticTrackSource, g as RingBufferObjectCache, h as ObjectCache, i as FetchPublication, j as ObjectOrdering, k as MOQtailClientOptions, l as LiveObjectSource, m as MemoryObjectCache, n as SendDatagramStream, o as RequestStream, p as TrackSource, q as DataDirection, r as PublishPublication, s as Track, t as MOQtailClient, u as LiveTrackSource, v as ControlSendStream, w as DEFAULT_TRACK_ALIAS_RESOLUTION_TIMEOUT_MS, x as DEFAULT_FILL_OPEN_TIMEOUT_MS, y as ControlStream, z as SubscribeRequest } from "./client-DUzLw_Y8.cjs";
16
+ import { $ as DataStreamReporter, A as MOQtailRequest, B as Subscription, C as DEFAULT_SWITCH_DRAIN_TIMEOUT_MS, D as FetchOptions, E as EndOfRangeHandler, F as SwitchOptions, G as WindowSuspension, H as PublishRequest, I as TrackAliasHolder, J as DataEvent, K as ObjectStream, L as TrackStatusRequest, M as SubscribeOptions, N as SubscribeResult, O as FetchResult, P as SubscribeUpdateOptions, Q as DataStreamEndEvent, R as SubscribeNamespaceRequest, S as DEFAULT_MAX_FILTER_RANGES, T as EarlyDiscardPolicyConfig, U as FetchRequest, V as PublishNamespaceRequest, W as ObjectOrderer, X as DataHeaderEvent, Y as DataEventBase, Z as DataObjectEvent, _ as ControlRecvStream, a as SubscribePublication, b as ClientEvents, c as HybridTrackSource, d as PastObjectSource, et as FullTrackNameOf, f as StaticTrackSource, g as RingBufferObjectCache, h as ObjectCache, i as FetchPublication, j as ObjectOrdering, k as MOQtailClientOptions, l as LiveObjectSource, m as MemoryObjectCache, n as SendDatagramStream, o as RequestStream, p as TrackSource, q as DataDirection, r as PublishPublication, s as Track, t as MOQtailClient, u as LiveTrackSource, v as ControlSendStream, w as DEFAULT_TRACK_ALIAS_RESOLUTION_TIMEOUT_MS, x as DEFAULT_FILL_OPEN_TIMEOUT_MS, y as ControlStream, z as SubscribeRequest } from "./client-CjdF7_cL.cjs";
17
17
  import { FetchObject, GroupOrder, Header, StreamResetCode, SubgroupObject } from "./model.cjs";
18
18
  import { o as Emitter } from "./logger-B8IYkljn.cjs";
19
19
  export declare class SendStream {
package/dist/client.d.mts CHANGED
@@ -13,8 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { $ as DataStreamReporter, A as MOQtailRequest, B as Subscription, C as DEFAULT_SWITCH_DRAIN_TIMEOUT_MS, D as FetchOptions, E as EndOfRangeHandler, F as SwitchOptions, G as WindowSuspension, H as PublishRequest, I as TrackAliasHolder, J as DataEvent, K as ObjectStream, L as TrackStatusRequest, M as SubscribeOptions, N as SubscribeResult, O as FetchResult, P as SubscribeUpdateOptions, Q as DataStreamEndEvent, R as SubscribeNamespaceRequest, S as DEFAULT_MAX_FILTER_RANGES, T as EarlyDiscardPolicyConfig, U as FetchRequest, V as PublishNamespaceRequest, W as ObjectOrderer, X as DataHeaderEvent, Y as DataEventBase, Z as DataObjectEvent, _ as ControlRecvStream, a as SubscribePublication, b as ClientEvents, c as HybridTrackSource, d as PastObjectSource, et as FullTrackNameOf, f as StaticTrackSource, g as RingBufferObjectCache, h as ObjectCache, i as FetchPublication, j as ObjectOrdering, k as MOQtailClientOptions, l as LiveObjectSource, m as MemoryObjectCache, n as SendDatagramStream, o as RequestStream, p as TrackSource, q as DataDirection, r as PublishPublication, s as Track, t as MOQtailClient, u as LiveTrackSource, v as ControlSendStream, w as DEFAULT_TRACK_ALIAS_RESOLUTION_TIMEOUT_MS, x as DEFAULT_FILL_OPEN_TIMEOUT_MS, y as ControlStream, z as SubscribeRequest } from "./client-epHqMdHm.mjs";
17
- import { D as StreamResetCode, En as FetchObject, _n as Header, kn as GroupOrder, xn as SubgroupObject } from "./index-CNn9BgO6.mjs";
16
+ import { $ as DataStreamReporter, A as MOQtailRequest, B as Subscription, C as DEFAULT_SWITCH_DRAIN_TIMEOUT_MS, D as FetchOptions, E as EndOfRangeHandler, F as SwitchOptions, G as WindowSuspension, H as PublishRequest, I as TrackAliasHolder, J as DataEvent, K as ObjectStream, L as TrackStatusRequest, M as SubscribeOptions, N as SubscribeResult, O as FetchResult, P as SubscribeUpdateOptions, Q as DataStreamEndEvent, R as SubscribeNamespaceRequest, S as DEFAULT_MAX_FILTER_RANGES, T as EarlyDiscardPolicyConfig, U as FetchRequest, V as PublishNamespaceRequest, W as ObjectOrderer, X as DataHeaderEvent, Y as DataEventBase, Z as DataObjectEvent, _ as ControlRecvStream, a as SubscribePublication, b as ClientEvents, c as HybridTrackSource, d as PastObjectSource, et as FullTrackNameOf, f as StaticTrackSource, g as RingBufferObjectCache, h as ObjectCache, i as FetchPublication, j as ObjectOrdering, k as MOQtailClientOptions, l as LiveObjectSource, m as MemoryObjectCache, n as SendDatagramStream, o as RequestStream, p as TrackSource, q as DataDirection, r as PublishPublication, s as Track, t as MOQtailClient, u as LiveTrackSource, v as ControlSendStream, w as DEFAULT_TRACK_ALIAS_RESOLUTION_TIMEOUT_MS, x as DEFAULT_FILL_OPEN_TIMEOUT_MS, y as ControlStream, z as SubscribeRequest } from "./client-I8mDg-Ls.mjs";
17
+ import { D as StreamResetCode, En as FetchObject, _n as Header, kn as GroupOrder, xn as SubgroupObject } from "./index-BaZgHZ8D.mjs";
18
18
  import { o as Emitter } from "./logger-B8IYkljn.mjs";
19
19
  export declare class SendStream {
20
20
  #private;
package/dist/client.mjs CHANGED
@@ -1,5 +1,83 @@
1
- import { C as SendStream, D as ControlSendStream, E as ControlRecvStream, O as ControlStream, S as RecvStream, T as RequestStream, _ as ObjectStream, a as SubscribeNamespaceRequest, b as LiveTrackSource, c as TrackStatusRequest, d as Subscription, f as DEFAULT_FILL_OPEN_TIMEOUT_MS, g as FetchRequest, h as DEFAULT_TRACK_ALIAS_RESOLUTION_TIMEOUT_MS, i as PublishPublication, l as PublishRequest, m as DEFAULT_SWITCH_DRAIN_TIMEOUT_MS, n as ObjectOrderer, o as SubscribePublication, p as DEFAULT_MAX_FILTER_RANGES, r as SendDatagramStream, s as FetchPublication, t as MOQtailClient, u as SubscribeRequest, v as PublishNamespaceRequest, w as DataStreamReporter, x as StaticTrackSource, y as HybridTrackSource } from "./client-DVi4Nh1J.mjs";
1
+ import { C as ControlRecvStream, S as RequestStream, T as ControlStream, _ as ObjectStream, a as SubscribeNamespaceRequest, b as SendStream, c as TrackStatusRequest, d as Subscription, f as DEFAULT_FILL_OPEN_TIMEOUT_MS, g as FetchRequest, h as DEFAULT_TRACK_ALIAS_RESOLUTION_TIMEOUT_MS, i as PublishPublication, l as PublishRequest, m as DEFAULT_SWITCH_DRAIN_TIMEOUT_MS, n as ObjectOrderer, o as SubscribePublication, p as DEFAULT_MAX_FILTER_RANGES, r as SendDatagramStream, s as FetchPublication, t as MOQtailClient, u as SubscribeRequest, v as PublishNamespaceRequest, w as ControlSendStream, x as DataStreamReporter, y as RecvStream } from "./client-MXn-lkAA.mjs";
2
+ import { i as logger } from "./emitter-UbeRcbuf.mjs";
2
3
  import { Location } from "./model.mjs";
4
+ // src/client/track/content_source.ts
5
+ var StaticTrackSource = class {
6
+ cache;
7
+ constructor(cache) {
8
+ this.cache = cache;
9
+ }
10
+ async getRange(start, end) {
11
+ return this.cache.getRange(start, end);
12
+ }
13
+ };
14
+ var LiveTrackSource = class {
15
+ stream;
16
+ #listeners = /* @__PURE__ */ new Set();
17
+ /** Each listener's queue tail, so done waits for the objects still being delivered. */
18
+ #queues = /* @__PURE__ */ new Map();
19
+ #doneListeners = /* @__PURE__ */ new Set();
20
+ #largestLocation;
21
+ #ingestActive = false;
22
+ #reader;
23
+ constructor(stream) {
24
+ this.stream = stream;
25
+ this.#startIngest();
26
+ }
27
+ get largestLocation() {
28
+ return this.#largestLocation;
29
+ }
30
+ async #startIngest() {
31
+ if (this.#ingestActive) return;
32
+ this.#ingestActive = true;
33
+ try {
34
+ this.#reader = this.stream.getReader();
35
+ while (this.#ingestActive) {
36
+ const { value, done } = await this.#reader.read();
37
+ if (done) break;
38
+ this.#largestLocation = value.location;
39
+ for (const listener of this.#listeners) listener(value);
40
+ }
41
+ } catch (error) {
42
+ logger.error("track/content_source", "Error during live object ingestion:", error);
43
+ } finally {
44
+ this.#ingestActive = false;
45
+ this.#reader?.releaseLock();
46
+ const drained = Promise.all([...this.#queues.values()].map((tail) => tail()));
47
+ for (const doneListener of this.#doneListeners) drained.then(() => doneListener());
48
+ }
49
+ }
50
+ onNewObject(listener) {
51
+ let queue = Promise.resolve();
52
+ const queuedListener = (obj) => {
53
+ queue = queue.then(() => listener(obj)).catch((err) => {
54
+ logger.error("track/content_source", "Error in subscriber listener:", err);
55
+ });
56
+ };
57
+ this.#listeners.add(queuedListener);
58
+ this.#queues.set(queuedListener, () => queue);
59
+ return () => {
60
+ this.#queues.delete(queuedListener);
61
+ return this.#listeners.delete(queuedListener);
62
+ };
63
+ }
64
+ onDone(listener) {
65
+ this.#doneListeners.add(listener);
66
+ return () => this.#doneListeners.delete(listener);
67
+ }
68
+ stop() {
69
+ this.#ingestActive = false;
70
+ this.#reader?.cancel();
71
+ }
72
+ };
73
+ var HybridTrackSource = class {
74
+ past;
75
+ live;
76
+ constructor(cache, stream) {
77
+ this.past = new StaticTrackSource(cache);
78
+ this.live = new LiveTrackSource(stream);
79
+ }
80
+ };
3
81
  // src/client/track/object_cache.ts
4
82
  /**
5
83
  * Copyright 2025 The MOQtail Authors
@@ -2710,6 +2710,11 @@ declare class UnknownObjectProperty {
2710
2710
  type ObjectProperty = ImmutablePropertiesObjectProperty | PriorGroupIdGapProperty | PriorObjectIdGapProperty | UnknownObjectProperty;
2711
2711
  declare namespace ObjectProperty {
2712
2712
  function fromKeyValuePair(pair: KeyValuePair): ObjectProperty;
2713
+ /**
2714
+ * Reads an Object's length-delimited property block as raw pairs, checked like
2715
+ * `fromKeyValuePair`. Throws ProtocolViolationError if it is malformed.
2716
+ */
2717
+ function deserializeRaw(buf: BaseByteBuffer): KeyValuePair[];
2713
2718
  function toKeyValuePair(ext: ObjectProperty): KeyValuePair;
2714
2719
  function deserializeAll(buf: BaseByteBuffer): ObjectProperty[];
2715
2720
  function serializeInto(exts: ObjectProperty[], payload: ByteBuffer): void;