moqtail 0.14.0 → 0.16.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.
Files changed (44) hide show
  1. package/README.md +153 -473
  2. package/dist/{client-Z7egUKTO.cjs → client-DQ5aGbLR.cjs} +1100 -1099
  3. package/dist/client-DUzLw_Y8.d.cts +1932 -0
  4. package/dist/{client-BW1agDFV.mjs → client-DVi4Nh1J.mjs} +942 -947
  5. package/dist/client-epHqMdHm.d.mts +1932 -0
  6. package/dist/client.cjs +121 -4
  7. package/dist/client.d.cts +23 -1933
  8. package/dist/client.d.mts +23 -1933
  9. package/dist/client.mjs +117 -2
  10. package/dist/emitter-UbeRcbuf.mjs +109 -0
  11. package/dist/{logger-c2NoQqtx.cjs → emitter-qNJYD3yQ.cjs} +61 -2
  12. package/dist/index-B-BMK-b6.d.mts +2090 -0
  13. package/dist/index-BtemTtwe.d.cts +2090 -0
  14. package/dist/{index-DBbxKcc1.d.cts → index-CNn9BgO6.d.mts} +168 -337
  15. package/dist/index.cjs +39 -34
  16. package/dist/index.d.cts +20 -4
  17. package/dist/index.d.mts +20 -4
  18. package/dist/index.mjs +5 -4
  19. package/dist/logger-B8IYkljn.d.cts +64 -0
  20. package/dist/logger-B8IYkljn.d.mts +64 -0
  21. package/dist/model.cjs +208 -359
  22. package/dist/model.d.cts +2896 -2
  23. package/dist/model.d.mts +17 -2
  24. package/dist/model.mjs +207 -359
  25. package/dist/player/component.cjs +317 -0
  26. package/dist/player/component.d.cts +50 -0
  27. package/dist/player/component.d.mts +50 -0
  28. package/dist/player/component.mjs +315 -0
  29. package/dist/player-CJayEzwt.cjs +6750 -0
  30. package/dist/player-DcctWhyM.mjs +6599 -0
  31. package/dist/player.cjs +27 -0
  32. package/dist/player.d.cts +17 -0
  33. package/dist/player.d.mts +17 -0
  34. package/dist/player.mjs +1 -0
  35. package/dist/rolldown-runtime-CmQyd0Gu.cjs +27 -0
  36. package/dist/util.cjs +9 -10
  37. package/dist/util.d.cts +20 -13
  38. package/dist/util.d.mts +20 -13
  39. package/dist/util.mjs +4 -6
  40. package/package.json +45 -5
  41. package/dist/index-DBbxKcc1.d.mts +0 -3051
  42. package/dist/logger-ByDB8lYF.mjs +0 -56
  43. package/dist/logger-dEoueCj7.d.cts +0 -35
  44. package/dist/logger-dEoueCj7.d.mts +0 -35
@@ -0,0 +1,317 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_emitter = require("../emitter-qNJYD3yQ.cjs");
3
+ const require_player = require("../player-CJayEzwt.cjs");
4
+ require("../util.cjs");
5
+ let custom_media_element = require("custom-media-element");
6
+ let media_tracks = require("media-tracks");
7
+ // src/player/component/renditions.ts
8
+ /** Keeps a host's tracks and renditions in step with one player. `dispose()` removes them. */
9
+ var Renditions = class {
10
+ #host;
11
+ #player;
12
+ #listed = /* @__PURE__ */ new Map();
13
+ #abort = new AbortController();
14
+ constructor(host, player) {
15
+ this.#host = host;
16
+ this.#player = player;
17
+ for (const list of [host.videoRenditions, host.audioRenditions]) list.addEventListener("change", () => this.#apply(), { signal: this.#abort.signal });
18
+ player.on("catalog", this.sync);
19
+ player.on("renditionchange", this.sync);
20
+ player.on("streamtypechange", this.sync);
21
+ player.on("selectionchange", this.sync);
22
+ }
23
+ /** Adds, updates, and removes tracks and renditions from the player's media sources. */
24
+ sync = () => {
25
+ if (this.#abort.signal.aborted) return;
26
+ const sources = this.#player.mediaSources;
27
+ for (const [source, listed] of this.#listed) if (!sources.includes(source)) this.#remove(source, listed);
28
+ for (const source of sources) {
29
+ const role = roleOf(source);
30
+ if (role !== "video" && role !== "audio") continue;
31
+ const listed = this.#listed.get(source) ?? this.#add(source, role);
32
+ this.#update(source, listed);
33
+ }
34
+ };
35
+ dispose() {
36
+ this.#abort.abort();
37
+ this.#player.off("catalog", this.sync);
38
+ this.#player.off("renditionchange", this.sync);
39
+ this.#player.off("streamtypechange", this.sync);
40
+ this.#player.off("selectionchange", this.sync);
41
+ for (const [source, listed] of this.#listed) this.#remove(source, listed);
42
+ }
43
+ #add(source, role) {
44
+ let listed;
45
+ if (role === "video") {
46
+ const track = this.#host.addVideoTrack("main");
47
+ track.selected = ![...this.#listed.values()].some((l) => l.role === "video");
48
+ listed = {
49
+ role,
50
+ track,
51
+ renditions: /* @__PURE__ */ new Map()
52
+ };
53
+ } else {
54
+ const track = this.#host.addAudioTrack("main");
55
+ track.enabled = true;
56
+ listed = {
57
+ role,
58
+ track,
59
+ renditions: /* @__PURE__ */ new Map()
60
+ };
61
+ }
62
+ this.#listed.set(source, listed);
63
+ return listed;
64
+ }
65
+ #remove(source, listed) {
66
+ this.#listed.delete(source);
67
+ if (listed.role === "video") this.#host.removeVideoTrack(listed.track);
68
+ else this.#host.removeAudioTrack(listed.track);
69
+ }
70
+ #update(source, listed) {
71
+ const renditions = source.getRenditions();
72
+ const ids = new Set(renditions.map((r) => r.id));
73
+ const shown = shownId(this.#player.isAbrAvailable(source), renditions);
74
+ let activeChanged = false;
75
+ for (const [id, rendition] of listed.renditions) {
76
+ if (ids.has(id)) continue;
77
+ listed.renditions.delete(id);
78
+ listed.track.removeRendition(rendition);
79
+ }
80
+ for (const r of renditions) {
81
+ let rendition = listed.renditions.get(r.id);
82
+ if (!rendition) {
83
+ rendition = listed.track.addRendition(r.src);
84
+ listed.renditions.set(r.id, rendition);
85
+ }
86
+ if (rendition.active !== r.active) activeChanged = true;
87
+ Object.assign(rendition, {
88
+ id: r.id,
89
+ src: r.src,
90
+ codec: r.codec,
91
+ bitrate: r.bitrate,
92
+ active: r.active
93
+ });
94
+ if (listed.role === "video") Object.assign(rendition, {
95
+ width: r.width,
96
+ height: r.height,
97
+ frameRate: r.frameRate
98
+ });
99
+ rendition.selected = r.id === shown;
100
+ }
101
+ if (!activeChanged) return;
102
+ (listed.role === "video" ? this.#host.videoRenditions : this.#host.audioRenditions).dispatchEvent(new Event("activechange"));
103
+ }
104
+ /** Hands each source the renditions now selected (all of them for none), when they differ from its own. */
105
+ #apply() {
106
+ for (const [source, listed] of this.#listed) {
107
+ let ids = [...listed.renditions].filter(([, r]) => r.selected).map(([id]) => id);
108
+ const renditions = source.getRenditions();
109
+ const abr = this.#player.isAbrAvailable(source);
110
+ if (ids.length === 0 && !abr) {
111
+ this.#update(source, listed);
112
+ continue;
113
+ }
114
+ const current = renditions.filter((r) => r.selected);
115
+ const active = renditions.find((r) => r.active);
116
+ if (ids.length === 0) ids = [...listed.renditions.keys()];
117
+ else if (!abr && ids.length === 1 && active && ids[0] === active.id && current.includes(active)) continue;
118
+ if (ids.length === current.length && current.every((r) => ids.includes(r.id))) continue;
119
+ source.selectRenditions(ids).catch((error) => require_emitter.logger.warn("MOQtailVideo", "selectRenditions failed", error));
120
+ }
121
+ }
122
+ };
123
+ /** The rendition to show selected: a single pick, else none under ABR (automatic), else the active one. */
124
+ function shownId(abr, renditions) {
125
+ const selected = renditions.filter((r) => r.selected);
126
+ if (selected.length === 1) return selected[0].id;
127
+ return abr ? void 0 : renditions.find((r) => r.active)?.id;
128
+ }
129
+ function roleOf(source) {
130
+ return source.pads.find((p) => p.direction === "src")?.capabilities.find((c) => c.code === 1)?.value;
131
+ }
132
+ // src/player/component/element.ts
133
+ /**
134
+ * Copyright 2026 The MOQtail Authors
135
+ *
136
+ * Licensed under the Apache License, Version 2.0 (the "License");
137
+ * you may not use this file except in compliance with the License.
138
+ * You may obtain a copy of the License at
139
+ *
140
+ * http://www.apache.org/licenses/LICENSE-2.0
141
+ *
142
+ * Unless required by applicable law or agreed to in writing, software
143
+ * distributed under the License is distributed on an "AS IS" BASIS,
144
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
145
+ * See the License for the specific language governing permissions and
146
+ * limitations under the License.
147
+ */
148
+ /**
149
+ * `<moqtail-video>`: a `<video>` in a shadow root, played by a `MOQtailPlayer` built from
150
+ * `src` and `config`. HTMLMediaElement forwarding comes from custom-media-element, tracks and
151
+ * renditions from media-tracks. Without `HTMLElement`, as in a server, the class still loads.
152
+ */
153
+ const MEDIA_ERROR_CODES = {
154
+ aborted: 1,
155
+ network: 2,
156
+ media: 3,
157
+ source: 4
158
+ };
159
+ /** @public A `<video>`-backed element implementing HTMLMediaElement and the media-ui-extensions IDL. */
160
+ var MOQtailVideoElement = class extends (0, media_tracks.MediaTracksMixin)(custom_media_element.CustomVideoElement) {
161
+ static getTemplateHTML = (attrs) => {
162
+ const { src: _, ...rest } = attrs;
163
+ return custom_media_element.CustomVideoElement.getTemplateHTML(rest);
164
+ };
165
+ #config;
166
+ #player;
167
+ #renditions;
168
+ /** The previous player's teardown; the next one waits for it, since both drive the same video. */
169
+ #destroyed = Promise.resolve();
170
+ #streamType = "unknown";
171
+ #error = null;
172
+ constructor() {
173
+ super();
174
+ if (Object.hasOwn(this, "config")) {
175
+ const value = this.config;
176
+ Reflect.deleteProperty(this, "config");
177
+ this.config = value;
178
+ }
179
+ }
180
+ /**
181
+ * Player options, read on each load. Without plugins, `liveBuffer()` and `abr()` are the ones; a
182
+ * list is taken as written, so one without them plays without a buffer or ABR controller.
183
+ * Changing it doesn't restart playback.
184
+ */
185
+ get config() {
186
+ return this.#config;
187
+ }
188
+ set config(value) {
189
+ this.#config = value;
190
+ }
191
+ get player() {
192
+ return this.#player;
193
+ }
194
+ get streamType() {
195
+ return this.#streamType;
196
+ }
197
+ /** Proposal 0007: where the live edge starts, in seconds; `NaN` on demand. */
198
+ get liveEdgeStart() {
199
+ return this.#player?.mediaSink?.liveEdgeStart ?? NaN;
200
+ }
201
+ /**
202
+ * Proposal 0007: `Infinity` while live, since earlier groups stay seekable through FETCH; `NaN`
203
+ * otherwise. Players such as Video.js treat a media as live only when it has this and `liveEdgeStart`.
204
+ */
205
+ get targetLiveWindow() {
206
+ return this.#streamType === "live" ? Infinity : NaN;
207
+ }
208
+ get error() {
209
+ return this.#error;
210
+ }
211
+ /** The inner video's `error` is left out: the sink recovers from those, and fatal ones arrive through the player. */
212
+ handleEvent(event) {
213
+ if (event.type !== "error") super.handleEvent(event);
214
+ }
215
+ attributeChangedCallback(name, oldValue, newValue) {
216
+ if (name !== "src") super.attributeChangedCallback(name, oldValue, newValue);
217
+ else if (oldValue !== newValue) this.load();
218
+ }
219
+ /** Destroys the player, then builds a new one from `src` and `config`, as `preload` and `autoplay` ask. */
220
+ load() {
221
+ this.#unload();
222
+ const src = this.getAttribute("src");
223
+ if (!src) return;
224
+ let player;
225
+ try {
226
+ player = new require_player.MOQtailPlayer(this.#playerOptions()).source(src, { switchFrom: this.hasAttribute("switch-from") }).sink(this.nativeEl);
227
+ } catch (error) {
228
+ queueMicrotask(() => this.#fail(asPlayerError(error)));
229
+ return;
230
+ }
231
+ this.#player = player;
232
+ this.#renditions = new Renditions(this, player);
233
+ player.on("error", (error) => this.#fail(error));
234
+ player.on("streamtypechange", (type) => this.#setStreamType(type));
235
+ if (this.autoplay) this.play().catch(() => {});
236
+ else if (this.getAttribute("preload") !== "none") this.#init(player).catch(() => {});
237
+ }
238
+ async play() {
239
+ const player = this.#player;
240
+ if (!player) return super.play();
241
+ await this.#init(player);
242
+ await player.play();
243
+ }
244
+ /** `config`, with `liveBuffer()` and `abr()` as the plugins when it lists none. */
245
+ #playerOptions() {
246
+ const config = this.#config ?? {};
247
+ if (config.plugins && config.plugins.length > 0) return config;
248
+ return {
249
+ ...config,
250
+ plugins: [require_player.liveBuffer(), require_player.abr()]
251
+ };
252
+ }
253
+ async #init(player) {
254
+ await this.#destroyed;
255
+ await player.init();
256
+ this.#renditions?.sync();
257
+ }
258
+ #unload() {
259
+ const player = this.#player;
260
+ this.#renditions?.dispose();
261
+ this.#renditions = void 0;
262
+ this.#player = void 0;
263
+ this.#error = null;
264
+ this.#setStreamType("unknown");
265
+ if (player) this.#destroyed = player.destroy().catch(() => {});
266
+ }
267
+ #setStreamType(type) {
268
+ if (type === this.#streamType) return;
269
+ this.#streamType = type;
270
+ this.dispatchEvent(new Event("streamtypechange"));
271
+ }
272
+ #fail(error) {
273
+ this.#error = mediaError(error);
274
+ this.dispatchEvent(new Event("error"));
275
+ }
276
+ };
277
+ function asPlayerError(error) {
278
+ if (error instanceof require_player.PlayerError) return error;
279
+ return new require_player.PlayerError("UNSUPPORTED_SOURCE", "The player could not be created", {
280
+ element: "component",
281
+ cause: error
282
+ });
283
+ }
284
+ /** `MediaError` can't be constructed, so this has its shape. */
285
+ function mediaError(error) {
286
+ return {
287
+ code: MEDIA_ERROR_CODES[error.category],
288
+ message: error.message,
289
+ MEDIA_ERR_ABORTED: 1,
290
+ MEDIA_ERR_NETWORK: 2,
291
+ MEDIA_ERR_DECODE: 3,
292
+ MEDIA_ERR_SRC_NOT_SUPPORTED: 4
293
+ };
294
+ }
295
+ // src/player/component/index.ts
296
+ /**
297
+ * Copyright 2026 The MOQtail Authors
298
+ *
299
+ * Licensed under the Apache License, Version 2.0 (the "License");
300
+ * you may not use this file except in compliance with the License.
301
+ * You may obtain a copy of the License at
302
+ *
303
+ * http://www.apache.org/licenses/LICENSE-2.0
304
+ *
305
+ * Unless required by applicable law or agreed to in writing, software
306
+ * distributed under the License is distributed on an "AS IS" BASIS,
307
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
308
+ * See the License for the specific language governing permissions and
309
+ * limitations under the License.
310
+ */
311
+ /** @public Registers `MOQtailVideoElement` as `name`. A no-op when it's taken or there's no `customElements`. */
312
+ function defineMOQtailVideo(name = "moqtail-video") {
313
+ if (typeof customElements === "undefined" || customElements.get(name)) return;
314
+ customElements.define(name, MOQtailVideoElement);
315
+ }
316
+ exports.MOQtailVideoElement = MOQtailVideoElement;
317
+ exports.defineMOQtailVideo = defineMOQtailVideo;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Copyright 2026 The MOQtail Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { d as MOQtailPlayerOptions, p as StreamType, u as MOQtailPlayer } from "../index-BtemTtwe.cjs";
17
+ import { CustomVideoElement } from "custom-media-element";
18
+ declare const MOQtailVideoElement_base: import("media-tracks").WithMediaTracks<CustomVideoElement>;
19
+ /** @public A `<video>`-backed element implementing HTMLMediaElement and the media-ui-extensions IDL. */
20
+ export declare class MOQtailVideoElement extends MOQtailVideoElement_base {
21
+ #private;
22
+ static getTemplateHTML: (attrs: Record<string, string>) => string;
23
+ constructor();
24
+ /**
25
+ * Player options, read on each load. Without plugins, `liveBuffer()` and `abr()` are the ones; a
26
+ * list is taken as written, so one without them plays without a buffer or ABR controller.
27
+ * Changing it doesn't restart playback.
28
+ */
29
+ get config(): MOQtailPlayerOptions | undefined;
30
+ set config(value: MOQtailPlayerOptions | undefined);
31
+ get player(): MOQtailPlayer | undefined;
32
+ get streamType(): StreamType;
33
+ /** Proposal 0007: where the live edge starts, in seconds; `NaN` on demand. */
34
+ get liveEdgeStart(): number;
35
+ /**
36
+ * Proposal 0007: `Infinity` while live, since earlier groups stay seekable through FETCH; `NaN`
37
+ * otherwise. Players such as Video.js treat a media as live only when it has this and `liveEdgeStart`.
38
+ */
39
+ get targetLiveWindow(): number;
40
+ get error(): MediaError | null;
41
+ /** The inner video's `error` is left out: the sink recovers from those, and fatal ones arrive through the player. */
42
+ handleEvent(event: Event): void;
43
+ attributeChangedCallback(name: string, oldValue?: string | null, newValue?: string | null): void;
44
+ /** Destroys the player, then builds a new one from `src` and `config`, as `preload` and `autoplay` ask. */
45
+ load(): void;
46
+ play(): Promise<void>;
47
+ }
48
+ /** @public Registers `MOQtailVideoElement` as `name`. A no-op when it's taken or there's no `customElements`. */
49
+ export declare function defineMOQtailVideo(name?: string): void;
50
+ export {};
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Copyright 2026 The MOQtail Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { d as MOQtailPlayerOptions, p as StreamType, u as MOQtailPlayer } from "../index-B-BMK-b6.mjs";
17
+ import { CustomVideoElement } from "custom-media-element";
18
+ declare const MOQtailVideoElement_base: import("media-tracks").WithMediaTracks<CustomVideoElement>;
19
+ /** @public A `<video>`-backed element implementing HTMLMediaElement and the media-ui-extensions IDL. */
20
+ export declare class MOQtailVideoElement extends MOQtailVideoElement_base {
21
+ #private;
22
+ static getTemplateHTML: (attrs: Record<string, string>) => string;
23
+ constructor();
24
+ /**
25
+ * Player options, read on each load. Without plugins, `liveBuffer()` and `abr()` are the ones; a
26
+ * list is taken as written, so one without them plays without a buffer or ABR controller.
27
+ * Changing it doesn't restart playback.
28
+ */
29
+ get config(): MOQtailPlayerOptions | undefined;
30
+ set config(value: MOQtailPlayerOptions | undefined);
31
+ get player(): MOQtailPlayer | undefined;
32
+ get streamType(): StreamType;
33
+ /** Proposal 0007: where the live edge starts, in seconds; `NaN` on demand. */
34
+ get liveEdgeStart(): number;
35
+ /**
36
+ * Proposal 0007: `Infinity` while live, since earlier groups stay seekable through FETCH; `NaN`
37
+ * otherwise. Players such as Video.js treat a media as live only when it has this and `liveEdgeStart`.
38
+ */
39
+ get targetLiveWindow(): number;
40
+ get error(): MediaError | null;
41
+ /** The inner video's `error` is left out: the sink recovers from those, and fatal ones arrive through the player. */
42
+ handleEvent(event: Event): void;
43
+ attributeChangedCallback(name: string, oldValue?: string | null, newValue?: string | null): void;
44
+ /** Destroys the player, then builds a new one from `src` and `config`, as `preload` and `autoplay` ask. */
45
+ load(): void;
46
+ play(): Promise<void>;
47
+ }
48
+ /** @public Registers `MOQtailVideoElement` as `name`. A no-op when it's taken or there's no `customElements`. */
49
+ export declare function defineMOQtailVideo(name?: string): void;
50
+ export {};