@mattebox/player 0.7.0 → 0.9.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/dist/cdn/mattebox-player.min.js +3 -3
- package/dist/controls/icons.d.ts +5 -28
- package/dist/controls/icons.d.ts.map +1 -1
- package/dist/controls/icons.js +38 -29
- package/dist/controls/icons.js.map +1 -1
- package/dist/controls/markers.d.ts +39 -0
- package/dist/controls/markers.d.ts.map +1 -0
- package/dist/controls/markers.js +38 -0
- package/dist/controls/markers.js.map +1 -0
- package/dist/controls/menu.d.ts +14 -2
- package/dist/controls/menu.d.ts.map +1 -1
- package/dist/controls/menu.js +50 -4
- package/dist/controls/menu.js.map +1 -1
- package/dist/controls/native-tracks.d.ts +28 -0
- package/dist/controls/native-tracks.d.ts.map +1 -0
- package/dist/controls/native-tracks.js +30 -0
- package/dist/controls/native-tracks.js.map +1 -0
- package/dist/controls/quality-names.d.ts +15 -0
- package/dist/controls/quality-names.d.ts.map +1 -0
- package/dist/controls/quality-names.js +62 -0
- package/dist/controls/quality-names.js.map +1 -0
- package/dist/controls/track-names.d.ts +40 -0
- package/dist/controls/track-names.d.ts.map +1 -0
- package/dist/controls/track-names.js +59 -0
- package/dist/controls/track-names.js.map +1 -0
- package/dist/element.d.ts +60 -2
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +182 -23
- package/dist/element.js.map +1 -1
- package/dist/elements/audio-menu.d.ts +19 -8
- package/dist/elements/audio-menu.d.ts.map +1 -1
- package/dist/elements/audio-menu.js +60 -19
- package/dist/elements/audio-menu.js.map +1 -1
- package/dist/elements/component.d.ts.map +1 -1
- package/dist/elements/component.js +10 -0
- package/dist/elements/component.js.map +1 -1
- package/dist/elements/control-bar.d.ts +2 -0
- package/dist/elements/control-bar.d.ts.map +1 -1
- package/dist/elements/control-bar.js +23 -7
- package/dist/elements/control-bar.js.map +1 -1
- package/dist/elements/current-time.d.ts.map +1 -1
- package/dist/elements/current-time.js +1 -1
- package/dist/elements/current-time.js.map +1 -1
- package/dist/elements/drm-badge.d.ts +3 -2
- package/dist/elements/drm-badge.d.ts.map +1 -1
- package/dist/elements/drm-badge.js +11 -9
- package/dist/elements/drm-badge.js.map +1 -1
- package/dist/elements/duration.d.ts.map +1 -1
- package/dist/elements/duration.js +6 -2
- package/dist/elements/duration.js.map +1 -1
- package/dist/elements/error-screen.js +1 -1
- package/dist/elements/live-button.js +1 -1
- package/dist/elements/marker-button.d.ts +22 -0
- package/dist/elements/marker-button.d.ts.map +1 -0
- package/dist/elements/marker-button.js +95 -0
- package/dist/elements/marker-button.js.map +1 -0
- package/dist/elements/quality-menu.d.ts +4 -0
- package/dist/elements/quality-menu.d.ts.map +1 -1
- package/dist/elements/quality-menu.js +22 -8
- package/dist/elements/quality-menu.js.map +1 -1
- package/dist/elements/scan-button.js +1 -1
- package/dist/elements/seek-bar.d.ts +6 -1
- package/dist/elements/seek-bar.d.ts.map +1 -1
- package/dist/elements/seek-bar.js +37 -25
- package/dist/elements/seek-bar.js.map +1 -1
- package/dist/elements/shared.js +3 -3
- package/dist/elements/skip-button.js +2 -2
- package/dist/elements/skip-button.js.map +1 -1
- package/dist/elements/spinner.js +1 -1
- package/dist/elements/start-button.d.ts +5 -0
- package/dist/elements/start-button.d.ts.map +1 -1
- package/dist/elements/start-button.js +15 -2
- package/dist/elements/start-button.js.map +1 -1
- package/dist/elements/subtitles-menu.d.ts +7 -1
- package/dist/elements/subtitles-menu.d.ts.map +1 -1
- package/dist/elements/subtitles-menu.js +62 -20
- package/dist/elements/subtitles-menu.js.map +1 -1
- package/dist/elements/title.d.ts.map +1 -1
- package/dist/elements/title.js +3 -1
- package/dist/elements/title.js.map +1 -1
- package/dist/elements/volume-slider.js +1 -1
- package/dist/elements/volume.js +1 -1
- package/dist/entries/marker-button.d.ts +5 -0
- package/dist/entries/marker-button.d.ts.map +1 -0
- package/dist/entries/marker-button.js +9 -0
- package/dist/entries/marker-button.js.map +1 -0
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/asyncToGenerator.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/defineProperty.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/objectSpread2.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/toPrimitive.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/toPropertyKey.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/typeof.js +1 -1
- package/dist/es2015/controls/chapters.js +1 -1
- package/dist/es2015/controls/icons.js +38 -29
- package/dist/es2015/controls/markers.js +36 -0
- package/dist/es2015/controls/menu.js +52 -5
- package/dist/es2015/controls/native-tracks.js +29 -0
- package/dist/es2015/controls/quality-names.js +67 -0
- package/dist/es2015/controls/track-names.js +57 -0
- package/dist/es2015/element.js +185 -29
- package/dist/es2015/elements/audio-menu.js +66 -20
- package/dist/es2015/elements/component.js +10 -0
- package/dist/es2015/elements/control-bar.js +23 -7
- package/dist/es2015/elements/current-time.js +1 -1
- package/dist/es2015/elements/drm-badge.js +12 -9
- package/dist/es2015/elements/duration.js +6 -2
- package/dist/es2015/elements/error-screen.js +1 -1
- package/dist/es2015/elements/live-button.js +1 -1
- package/dist/es2015/elements/marker-button.js +96 -0
- package/dist/es2015/elements/quality-menu.js +23 -8
- package/dist/es2015/elements/scan-button.js +1 -1
- package/dist/es2015/elements/seek-bar.js +42 -29
- package/dist/es2015/elements/shared.js +3 -3
- package/dist/es2015/elements/skip-button.js +2 -2
- package/dist/es2015/elements/spinner.js +1 -1
- package/dist/es2015/elements/start-button.js +15 -2
- package/dist/es2015/elements/subtitles-menu.js +72 -26
- package/dist/es2015/elements/title.js +3 -1
- package/dist/es2015/elements/volume-slider.js +1 -1
- package/dist/es2015/elements/volume.js +1 -1
- package/dist/es2015/entries/marker-button.js +7 -0
- package/dist/es2015/index.js +3 -1
- package/dist/es2015/presets.js +1 -1
- package/dist/es2015/style.js +1 -1
- package/dist/es2015/tags.js +2 -1
- package/dist/host.d.ts +3 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/style.js +1 -1
- package/dist/tags.d.ts +1 -0
- package/dist/tags.d.ts.map +1 -1
- package/dist/tags.js +2 -1
- package/dist/tags.js.map +1 -1
- package/package.json +4 -5
- package/NOTICE +0 -24
package/dist/element.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
import { createMarkers } from "./controls/markers.js";
|
|
1
2
|
import { namespaces } from "./namespaces.js";
|
|
2
3
|
import { drmGuard, resolvePreset } from "./presets.js";
|
|
3
4
|
import { STYLE } from "./style.js";
|
|
4
5
|
import { errorSurface } from "./surface.js";
|
|
5
6
|
import { PLAYER } from "./tags.js";
|
|
6
|
-
import { createPlayer, inferType, matteboxHandler, nativeHandler } from "@mattebox/player-core";
|
|
7
|
+
import { createPlayer, inferType, matteboxHandler, nativeHandler, preferNativeHls } from "@mattebox/player-core";
|
|
7
8
|
//#region src/element.ts
|
|
9
|
+
/**
|
|
10
|
+
* `off` keeps HLS on the engine in Safari. Anything else lets Safari play
|
|
11
|
+
* HLS itself: FairPlay, AirPlay, Low-Latency HLS and the platform's
|
|
12
|
+
* fullscreen then work as Apple built them. Changing it reloads.
|
|
13
|
+
*/
|
|
14
|
+
const NATIVE_HLS = "native-hls";
|
|
8
15
|
/** Attributes forwarded onto the video as attributes, never as properties. */
|
|
9
16
|
const FORWARDED = [
|
|
10
17
|
"autoplay",
|
|
@@ -12,13 +19,17 @@ const FORWARDED = [
|
|
|
12
19
|
"poster",
|
|
13
20
|
"crossorigin"
|
|
14
21
|
];
|
|
22
|
+
const LICENSE_URL = "license-url";
|
|
23
|
+
const CERTIFICATE_URL = "certificate-url";
|
|
15
24
|
/** Everything else the element watches. Changing any of them reloads. */
|
|
16
25
|
const OWN = [
|
|
17
26
|
"src",
|
|
18
27
|
"type",
|
|
19
28
|
"preset",
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
LICENSE_URL,
|
|
30
|
+
CERTIFICATE_URL,
|
|
31
|
+
"thumbnails",
|
|
32
|
+
NATIVE_HLS
|
|
22
33
|
];
|
|
23
34
|
/**
|
|
24
35
|
* The chapters file URL. A session with the engine's `chapters` namespace
|
|
@@ -44,11 +55,33 @@ const CONTROLS = "controls";
|
|
|
44
55
|
* control the page placed shows. Changing it never reloads.
|
|
45
56
|
*/
|
|
46
57
|
const PLAYSINLINE = "playsinline";
|
|
58
|
+
/**
|
|
59
|
+
* The size tier the controls draw for: `compact` on a small player, such
|
|
60
|
+
* as a phone held upright, `wide` on a large one, such as a TV or
|
|
61
|
+
* fullscreen, and `regular` between. The element measures itself and sets
|
|
62
|
+
* the attribute, so a stylesheet matches `mattebox-player[layout="compact"]`.
|
|
63
|
+
* A page that writes one of the three values fixes it, and removing the
|
|
64
|
+
* attribute hands it back. The player's own box decides, not the screen:
|
|
65
|
+
* a small embed on a desktop is compact, and a phone in fullscreen is not.
|
|
66
|
+
*/
|
|
67
|
+
const LAYOUT = "layout";
|
|
68
|
+
const LAYOUTS = [
|
|
69
|
+
"compact",
|
|
70
|
+
"regular",
|
|
71
|
+
"wide"
|
|
72
|
+
];
|
|
73
|
+
/** Under either, the player is compact. */
|
|
74
|
+
const COMPACT_WIDTH = 480;
|
|
75
|
+
const COMPACT_HEIGHT = 320;
|
|
76
|
+
/** From both, the player is wide. */
|
|
77
|
+
const WIDE_WIDTH = 1280;
|
|
78
|
+
const WIDE_HEIGHT = 700;
|
|
47
79
|
/** The video's state, as attributes on the element, read on the events the video fires for it. */
|
|
48
80
|
const STATE_EVENTS = [
|
|
49
81
|
"play",
|
|
50
82
|
"pause",
|
|
51
83
|
"ended",
|
|
84
|
+
"seeked",
|
|
52
85
|
"emptied",
|
|
53
86
|
"volumechange",
|
|
54
87
|
"loadedmetadata",
|
|
@@ -58,6 +91,8 @@ const STATE_EVENTS = [
|
|
|
58
91
|
"stalled",
|
|
59
92
|
"canplay"
|
|
60
93
|
];
|
|
94
|
+
/** The stages that register a key system, which a native session's DRM offers. */
|
|
95
|
+
const KEY_SYSTEMS = ["eme-fairplay", "eme-cenc"];
|
|
61
96
|
/** Every stage the engine ships. A narrower preset is optimization. */
|
|
62
97
|
const DEFAULT_PRESET = "full";
|
|
63
98
|
/**
|
|
@@ -79,7 +114,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
79
114
|
...OWN,
|
|
80
115
|
CONTROLS,
|
|
81
116
|
CHAPTERS,
|
|
82
|
-
PLAYSINLINE
|
|
117
|
+
PLAYSINLINE,
|
|
118
|
+
LAYOUT
|
|
83
119
|
];
|
|
84
120
|
}
|
|
85
121
|
/**
|
|
@@ -94,14 +130,18 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
94
130
|
}
|
|
95
131
|
constructor(options) {
|
|
96
132
|
super();
|
|
97
|
-
this.
|
|
133
|
+
this.own = options ?? null;
|
|
98
134
|
this.focusable = false;
|
|
99
135
|
this.track = null;
|
|
100
136
|
this.given = null;
|
|
137
|
+
this.list = null;
|
|
138
|
+
this.tried = "";
|
|
101
139
|
this.core = null;
|
|
102
140
|
this.current = null;
|
|
103
141
|
this.failure = null;
|
|
104
142
|
this.reflecting = false;
|
|
143
|
+
this.sizes = null;
|
|
144
|
+
this.fixed = false;
|
|
105
145
|
this.started = false;
|
|
106
146
|
this.waiting = false;
|
|
107
147
|
this.offs = [];
|
|
@@ -117,9 +157,14 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
117
157
|
this.media.addEventListener("playing", () => {
|
|
118
158
|
this.failure = null;
|
|
119
159
|
});
|
|
160
|
+
this.marks = createMarkers(this.media, (name, detail) => this.emit(name, detail));
|
|
120
161
|
this.stage = document.createElement("div");
|
|
121
162
|
this.stage.setAttribute("part", "stage");
|
|
122
|
-
|
|
163
|
+
const slot = document.createElement("slot");
|
|
164
|
+
slot.addEventListener("slotchange", () => {
|
|
165
|
+
if (this.current === null && JSON.stringify(this.wanted()) !== this.tried) this.reload();
|
|
166
|
+
});
|
|
167
|
+
this.stage.append(slot);
|
|
123
168
|
this.surface = errorSurface(() => {
|
|
124
169
|
this.reload();
|
|
125
170
|
});
|
|
@@ -132,6 +177,23 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
132
177
|
get video() {
|
|
133
178
|
return this.media;
|
|
134
179
|
}
|
|
180
|
+
/** The ranges the page named in this source: credits to skip, parts that must not play. */
|
|
181
|
+
get markers() {
|
|
182
|
+
return this.marks;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The sources to try in order, set from script. The `src` attribute wins
|
|
186
|
+
* over them, and they win over the `<source>` children. Setting them
|
|
187
|
+
* loads, and null returns to the children.
|
|
188
|
+
*/
|
|
189
|
+
get sources() {
|
|
190
|
+
return this.list;
|
|
191
|
+
}
|
|
192
|
+
set sources(value) {
|
|
193
|
+
this.list = value;
|
|
194
|
+
if (this.marks.list.length > 0) this.marks.set([]);
|
|
195
|
+
this.reload();
|
|
196
|
+
}
|
|
135
197
|
/** The core, or null until the first source has been set up: resolving a preset is asynchronous. */
|
|
136
198
|
get player() {
|
|
137
199
|
return this.core;
|
|
@@ -153,8 +215,28 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
153
215
|
if (this.media.parentNode !== this) this.append(this.media);
|
|
154
216
|
for (const name of FORWARDED) this.forward(name);
|
|
155
217
|
this.reflect();
|
|
218
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
219
|
+
this.sizes = new ResizeObserver(() => {
|
|
220
|
+
this.measure();
|
|
221
|
+
});
|
|
222
|
+
this.sizes.observe(this);
|
|
223
|
+
}
|
|
224
|
+
this.measure();
|
|
156
225
|
this.reload();
|
|
157
226
|
}
|
|
227
|
+
/** Sets `layout` from the element's box, unless the page fixed it. */
|
|
228
|
+
measure() {
|
|
229
|
+
if (this.fixed) return;
|
|
230
|
+
const width = this.clientWidth;
|
|
231
|
+
const height = this.clientHeight;
|
|
232
|
+
if (width === 0 || height === 0) return;
|
|
233
|
+
const layout = width < COMPACT_WIDTH || height < COMPACT_HEIGHT ? "compact" : width >= WIDE_WIDTH && height >= WIDE_HEIGHT ? "wide" : "regular";
|
|
234
|
+
if (this.getAttribute(LAYOUT) === layout) return;
|
|
235
|
+
this.reflecting = true;
|
|
236
|
+
this.setAttribute(LAYOUT, layout);
|
|
237
|
+
this.reflecting = false;
|
|
238
|
+
this.emit("layoutchange", layout);
|
|
239
|
+
}
|
|
158
240
|
/** The two states the video does not hold: whether it has played once, and whether it waits for data. */
|
|
159
241
|
note(event) {
|
|
160
242
|
if (event === "playing") {
|
|
@@ -194,6 +276,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
194
276
|
return (this.getAttribute("type") ?? (src === null ? void 0 : inferType(src)))?.startsWith("audio/") === true;
|
|
195
277
|
}
|
|
196
278
|
disconnectedCallback() {
|
|
279
|
+
this.sizes?.disconnect();
|
|
280
|
+
this.sizes = null;
|
|
197
281
|
this.enqueue(() => this.teardown());
|
|
198
282
|
}
|
|
199
283
|
attributeChangedCallback(name) {
|
|
@@ -209,12 +293,21 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
209
293
|
this.chapters();
|
|
210
294
|
return;
|
|
211
295
|
}
|
|
296
|
+
if (name === LAYOUT) {
|
|
297
|
+
if (this.reflecting) return;
|
|
298
|
+
const value = this.getAttribute(LAYOUT);
|
|
299
|
+
this.fixed = value !== null && LAYOUTS.includes(value);
|
|
300
|
+
if (this.fixed) this.emit("layoutchange", value);
|
|
301
|
+
else this.measure();
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
212
304
|
if (name === PLAYSINLINE) {
|
|
213
305
|
this.media.toggleAttribute(PLAYSINLINE, this.getAttribute(PLAYSINLINE) !== "false");
|
|
214
306
|
return;
|
|
215
307
|
}
|
|
216
308
|
if (name === "preset") this.enqueue(() => this.discard());
|
|
217
309
|
if (name === "src" || name === "type") this.toggleAttribute("audio", this.audio());
|
|
310
|
+
if (name === "src" && this.marks.list.length > 0) this.marks.set([]);
|
|
218
311
|
this.reload();
|
|
219
312
|
}
|
|
220
313
|
/**
|
|
@@ -303,27 +396,58 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
303
396
|
async run() {
|
|
304
397
|
this.unmount();
|
|
305
398
|
if (!this.isConnected) return;
|
|
306
|
-
const
|
|
307
|
-
|
|
399
|
+
const sources = this.wanted();
|
|
400
|
+
this.tried = JSON.stringify(sources);
|
|
401
|
+
if (sources.length === 0) return;
|
|
308
402
|
const core = await this.ensure();
|
|
309
|
-
const type = this.getAttribute("type");
|
|
310
|
-
const source = type === null ? { url } : {
|
|
311
|
-
url,
|
|
312
|
-
type
|
|
313
|
-
};
|
|
314
403
|
this.failure = null;
|
|
315
404
|
this.surface.clear();
|
|
316
|
-
let session;
|
|
317
405
|
try {
|
|
318
|
-
|
|
406
|
+
await core.load(sources);
|
|
319
407
|
} catch {
|
|
320
408
|
return;
|
|
321
409
|
}
|
|
322
|
-
if (!this.isConnected)
|
|
323
|
-
|
|
324
|
-
|
|
410
|
+
if (!this.isConnected) await core.unload();
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* What to load, ranked as a video ranks them: the `src` attribute, then
|
|
414
|
+
* the `sources` property, then the `<source>` children in their order.
|
|
415
|
+
* A child carries its own `license-url` and `certificate-url`.
|
|
416
|
+
*/
|
|
417
|
+
wanted() {
|
|
418
|
+
const url = this.getAttribute("src");
|
|
419
|
+
if (url !== null) {
|
|
420
|
+
const type = this.getAttribute("type");
|
|
421
|
+
return [type === null ? { url } : {
|
|
422
|
+
url,
|
|
423
|
+
type
|
|
424
|
+
}];
|
|
325
425
|
}
|
|
326
|
-
|
|
426
|
+
const eme = drmGuard().without === void 0;
|
|
427
|
+
if (this.list !== null) return eme ? this.list : this.list.map(({ url, type }) => type === void 0 ? { url } : {
|
|
428
|
+
url,
|
|
429
|
+
type
|
|
430
|
+
});
|
|
431
|
+
const found = [];
|
|
432
|
+
for (const child of Array.from(this.children)) {
|
|
433
|
+
const src = child.localName === "source" ? child.getAttribute("src") : null;
|
|
434
|
+
if (src === null) continue;
|
|
435
|
+
const type = child.getAttribute("type");
|
|
436
|
+
const license = child.getAttribute(LICENSE_URL);
|
|
437
|
+
const certificate = child.getAttribute(CERTIFICATE_URL);
|
|
438
|
+
found.push({
|
|
439
|
+
url: src,
|
|
440
|
+
...type === null ? {} : { type },
|
|
441
|
+
...!eme || license === null && certificate === null ? {} : { drm: {
|
|
442
|
+
...license === null ? {} : { licenseUrl: license },
|
|
443
|
+
...certificate === null ? {} : { certificateUrl: certificate }
|
|
444
|
+
} }
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
return found;
|
|
448
|
+
}
|
|
449
|
+
/** Sets a session up. It runs for every session, the one that replaces a failed source included. */
|
|
450
|
+
adopt(session) {
|
|
327
451
|
this.given = null;
|
|
328
452
|
this.configure(session);
|
|
329
453
|
this.chapters();
|
|
@@ -333,6 +457,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
333
457
|
const core = createPlayer(this.media, { handlers: await this.chain() });
|
|
334
458
|
this.offs.push(core.on("sourcechange", (session) => {
|
|
335
459
|
this.current = session;
|
|
460
|
+
if (session !== null && this.isConnected) this.adopt(session);
|
|
336
461
|
this.emit("sourcechange", session);
|
|
337
462
|
}), core.on("error", (error) => {
|
|
338
463
|
this.report(error);
|
|
@@ -340,13 +465,25 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
340
465
|
this.core = core;
|
|
341
466
|
return core;
|
|
342
467
|
}
|
|
468
|
+
/**
|
|
469
|
+
* Read at each use, not once in the constructor. Importing the package
|
|
470
|
+
* registers the element, and the parser's elements are constructed then,
|
|
471
|
+
* before the page's own `define()` call can run.
|
|
472
|
+
*/
|
|
473
|
+
get options() {
|
|
474
|
+
return this.own ?? defaults;
|
|
475
|
+
}
|
|
343
476
|
async chain() {
|
|
344
477
|
if (this.options.handlers !== void 0) return this.options.handlers;
|
|
345
478
|
const config = this.options.config === void 0 ? {} : { config: this.options.config };
|
|
479
|
+
const native = (stages) => nativeHandler({
|
|
480
|
+
prefer: (source, env) => this.getAttribute(NATIVE_HLS) !== "off" && preferNativeHls(source, env),
|
|
481
|
+
drm: () => this.drm(stages)
|
|
482
|
+
});
|
|
346
483
|
if (this.options.stages !== void 0) return [matteboxHandler({
|
|
347
484
|
stages: this.options.stages,
|
|
348
485
|
...config
|
|
349
|
-
}),
|
|
486
|
+
}), native(() => this.options.stages ?? [])];
|
|
350
487
|
const name = this.getAttribute("preset") ?? DEFAULT_PRESET;
|
|
351
488
|
const preset = await resolvePreset(name);
|
|
352
489
|
if (preset === null) {
|
|
@@ -364,15 +501,37 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
364
501
|
preset,
|
|
365
502
|
...config,
|
|
366
503
|
...drmGuard()
|
|
367
|
-
}),
|
|
504
|
+
}), native(() => preset.stages())];
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* The DRM a native session attaches: the page's `drm` option, the
|
|
508
|
+
* key-system stages of the engine's stack, and the `license-url`
|
|
509
|
+
* attribute. None on a browser without EME, as for the engine.
|
|
510
|
+
*/
|
|
511
|
+
drm(stages) {
|
|
512
|
+
if (drmGuard().without !== void 0) return void 0;
|
|
513
|
+
const keySystems = stages().filter((stage) => KEY_SYSTEMS.includes(stage.name));
|
|
514
|
+
const license = this.getAttribute(LICENSE_URL);
|
|
515
|
+
const certificate = this.getAttribute(CERTIFICATE_URL);
|
|
516
|
+
const page = this.options.drm;
|
|
517
|
+
if (keySystems.length === 0 && license === null && page === void 0) return void 0;
|
|
518
|
+
return {
|
|
519
|
+
keySystems,
|
|
520
|
+
...page,
|
|
521
|
+
...license === null ? {} : { licenseUrl: license },
|
|
522
|
+
...certificate === null ? {} : { certificateUrl: certificate }
|
|
523
|
+
};
|
|
368
524
|
}
|
|
369
525
|
/** What the attributes ask of the session's namespaces, once there is one. */
|
|
370
526
|
configure(session) {
|
|
371
527
|
const engine = session.engine;
|
|
372
528
|
if (engine === null) return;
|
|
373
529
|
const optional = namespaces(engine);
|
|
374
|
-
const
|
|
375
|
-
|
|
530
|
+
const own = session.source.drm;
|
|
531
|
+
const license = this.getAttribute(LICENSE_URL);
|
|
532
|
+
if (license !== null && own?.licenseUrl === void 0) optional.drm?.setLicenseUrl(license);
|
|
533
|
+
const certificate = this.getAttribute(CERTIFICATE_URL);
|
|
534
|
+
if (certificate !== null && own?.certificateUrl === void 0) optional.drm?.setCertificateUrl(certificate);
|
|
376
535
|
const track = this.getAttribute("thumbnails");
|
|
377
536
|
if (track !== null && optional.thumbnails !== void 0) optional.thumbnails.load(track).catch(() => void 0);
|
|
378
537
|
}
|
package/dist/element.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","names":[],"sources":["../src/element.ts"],"sourcesContent":["/**\n * <mattebox-player>: a real <video> as a light-DOM child, so the integrator\n * can reach it, and the error surface in shadow DOM. The element never\n * forwards or wraps a media element member: play, pause, seek, volume and\n * the rest live on the video, where the browser, Picture-in-Picture and the\n * OS media session already find them.\n *\n * The controls are elements the page places inside, beside the video, and\n * the stage slots them over the picture. The element appends none of its\n * own: the composition is the page's in every mode, and `none` hides every\n * child but the video. The element reflects the video's state as\n * attributes on itself, `paused`, `playing`, `ended`, `muted`, `audio`,\n * `started` and `waiting`, for the page's stylesheet and the controls\n * alike.\n *\n * No class fields, `#private` or otherwise: the ES2015 build would lower\n * them into runtime helpers, and the emit check bans helpers. Statics are\n * getters and instance state is declared, then assigned in the constructor.\n */\n\nimport type { Handler, Player, PlayerError, Session, Source } from '@mattebox/player-core';\nimport { createPlayer, inferType, matteboxHandler, nativeHandler } from '@mattebox/player-core';\nimport type { KernelConfig, Mattebox, Stage } from 'mattebox';\nimport type { PlayerHost } from './host.js';\nimport { namespaces } from './namespaces.js';\nimport { drmGuard, resolvePreset } from './presets.js';\nimport { STYLE } from './style.js';\nimport type { ErrorSurface } from './surface.js';\nimport { errorSurface } from './surface.js';\nimport { PLAYER } from './tags.js';\n\n/** Attributes forwarded onto the video as attributes, never as properties. */\nconst FORWARDED = ['autoplay', 'muted', 'poster', 'crossorigin'];\n\n/** Everything else the element watches. Changing any of them reloads. */\nconst OWN = ['src', 'type', 'preset', 'license-url', 'thumbnails'];\n\n/**\n * The chapters file URL. A session with the engine's `chapters` namespace\n * loads it there: through the engine's transport, so request hooks apply,\n * and in every format the engine reads. Any other session gets a\n * `<track kind=\"chapters\">` on the video, hidden so its cues load and\n * nothing is drawn. The seek bar and the chapters menu read either.\n * Changing it never reloads the source.\n */\nconst CHAPTERS = 'chapters';\n\n/**\n * The one attribute whose meaning the element owns: `native` keeps the\n * browser's controls on the video, `custom` swaps them for the controls the\n * page placed inside, `none` takes the browser's off and hides every child\n * but the video. Anything else is `native`. Changing it never touches the\n * session.\n */\nconst CONTROLS = 'controls';\n\n/**\n * Inline playback, on until the page writes `playsinline=\"false\"`, the way\n * `spellcheck` and `draggable` are on until told otherwise. An iPhone takes\n * a video without `playsinline` to its own fullscreen on play, where no\n * control the page placed shows. Changing it never reloads.\n */\nconst PLAYSINLINE = 'playsinline';\n\n/** The video's state, as attributes on the element, read on the events the video fires for it. */\nconst STATE_EVENTS = [\n 'play',\n 'pause',\n 'ended',\n 'emptied',\n 'volumechange',\n 'loadedmetadata',\n 'resize',\n 'playing',\n 'waiting',\n 'stalled',\n 'canplay',\n];\n\n/** Every stage the engine ships. A narrower preset is optimization. */\nconst DEFAULT_PRESET = 'full';\n\n/**\n * What the element dispatches. `error` is also a standard DOM event name, so\n * without these overloads a listener on it is typed as `ErrorEvent` and the\n * payload needs a double cast. They are declarations only: no runtime bytes.\n */\nexport interface MatteboxPlayerEventMap {\n sourcechange: CustomEvent<Session | null>;\n error: CustomEvent<PlayerError>;\n}\n\nexport interface MatteboxPlayerElement {\n addEventListener<K extends keyof MatteboxPlayerEventMap>(\n type: K,\n listener: (this: MatteboxPlayerElement, event: MatteboxPlayerEventMap[K]) => void,\n options?: boolean | AddEventListenerOptions,\n ): void;\n addEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | AddEventListenerOptions,\n ): void;\n removeEventListener<K extends keyof MatteboxPlayerEventMap>(\n type: K,\n listener: (this: MatteboxPlayerElement, event: MatteboxPlayerEventMap[K]) => void,\n options?: boolean | EventListenerOptions,\n ): void;\n removeEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | EventListenerOptions,\n ): void;\n}\n\nexport interface MatteboxPlayerOptions {\n /** The whole chain, in order. Takes precedence over `stages` and the `preset` attribute. */\n readonly handlers?: readonly Handler[];\n /** Stages for the mattebox handler. Takes precedence over the `preset` attribute. */\n readonly stages?: readonly Stage[];\n /**\n * Kernel tuning for the engines the elements build, `traceCapacity` among\n * it. A page decision, like the stages, so not an attribute. Ignored with\n * `handlers`, which carry their own.\n */\n readonly config?: Partial<KernelConfig>;\n}\n\n/**\n * What `define()` recorded, for the elements the parser creates. It is the\n * one value shared across elements, because a page that writes only markup\n * still has to be able to say what the engine carries.\n */\nlet defaults: MatteboxPlayerOptions = {};\n\n/**\n * The interface above merges only `addEventListener` and `removeEventListener`\n * overloads, which the class inherits from HTMLElement. The rule it suppresses\n * guards against properties an interface declares and a constructor never\n * assigns, and there are none.\n */\n// biome-ignore lint/suspicious/noUnsafeDeclarationMerging: method overloads only, no properties\nexport class MatteboxPlayerElement extends HTMLElement implements PlayerHost {\n static get observedAttributes(): readonly string[] {\n return [...FORWARDED, ...OWN, CONTROLS, CHAPTERS, PLAYSINLINE];\n }\n\n /**\n * Registers the element once, and records the stages markup-only pages\n * get. The controls register through their own entries, the package's\n * root entry importing every one; a control connected before its player\n * is defined waits for the definition.\n */\n static define(options?: MatteboxPlayerOptions): void {\n if (options !== undefined) defaults = options;\n if (customElements.get(PLAYER) === undefined) {\n customElements.define(PLAYER, MatteboxPlayerElement);\n }\n }\n\n declare private readonly media: HTMLVideoElement;\n /** Wraps the slot: the picture, and the controls over it or under it. */\n declare private readonly stage: HTMLDivElement;\n /** Whether the element gave itself a tabindex for the bar, to take back with it. */\n declare private focusable: boolean;\n declare private readonly surface: ErrorSurface;\n /** The chapters track element, while the `chapters` attribute names one and the engine takes none. */\n declare private track: HTMLTrackElement | null;\n /** The chapters URL the current session's engine was given, or null. */\n declare private given: string | null;\n declare private readonly options: MatteboxPlayerOptions;\n declare private core: Player | null;\n declare private current: Session | null;\n declare private failure: PlayerError | null;\n /** Whether an attribute change is the element's own reflection, which must not write back to the video. */\n declare private reflecting: boolean;\n /** The video has played once since its source was set: `started`, which tells a first play from a pause. */\n declare private started: boolean;\n /** The video waits for data: `waiting`, set on `waiting` and `stalled`, cleared once it can play. */\n declare private waiting: boolean;\n declare private offs: Array<() => void>;\n /** Everything the element does to the player runs here, so it runs in order. */\n declare private queue: Promise<void>;\n /** Whether a run is queued and not yet started, so a burst of changes loads once. */\n declare private pending: boolean;\n\n constructor(options?: MatteboxPlayerOptions) {\n super();\n this.options = options ?? defaults;\n this.focusable = false;\n this.track = null;\n this.given = null;\n this.core = null;\n this.current = null;\n this.failure = null;\n this.reflecting = false;\n this.started = false;\n this.waiting = false;\n this.offs = [];\n this.queue = Promise.resolve();\n this.pending = false;\n\n this.media = document.createElement('video');\n // Native until the `controls` attribute says otherwise, which arrives\n // through attributeChangedCallback: a constructor must not read attributes.\n this.media.controls = true;\n // Inline is the default, and the player's own attribute has not arrived\n // yet. Set as an attribute: not every browser has the `playsInline`\n // property. The fullscreen button still reaches the iPhone's fullscreen,\n // through `webkitEnterFullscreen`.\n this.media.setAttribute(PLAYSINLINE, '');\n for (const name of STATE_EVENTS) {\n this.media.addEventListener(name, () => {\n this.note(name);\n this.reflect();\n });\n }\n // An error over a picture that then plays is wrong by definition.\n this.media.addEventListener('playing', () => {\n this.failure = null;\n });\n this.stage = document.createElement('div');\n this.stage.setAttribute('part', 'stage');\n this.stage.append(document.createElement('slot'));\n this.surface = errorSurface(() => {\n this.reload();\n });\n\n const root = this.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = STYLE;\n root.append(style, this.stage, this.surface.root);\n }\n\n /** The media element. Everything the browser already does is here. */\n get video(): HTMLVideoElement {\n return this.media;\n }\n\n /** The core, or null until the first source has been set up: resolving a preset is asynchronous. */\n get player(): Player | null {\n return this.core;\n }\n\n /** The engine feeding the video, or null for a native session and before the first load. */\n get engine(): Mattebox | null {\n return this.current?.engine ?? null;\n }\n\n /**\n * The fatal error of the current load, or null once a load starts or\n * playback resumes. The `error` event says when; this says what, for a\n * control that attaches after the event, such as an error screen parsed\n * after a source that failed while the page was still loading.\n */\n get error(): PlayerError | null {\n return this.failure;\n }\n\n connectedCallback(): void {\n if (this.media.parentNode !== this) this.append(this.media);\n for (const name of FORWARDED) this.forward(name);\n this.reflect();\n this.reload();\n }\n\n /** The two states the video does not hold: whether it has played once, and whether it waits for data. */\n private note(event: string): void {\n if (event === 'playing') {\n this.started = true;\n this.waiting = false;\n } else if (event === 'waiting' || event === 'stalled') {\n this.waiting = true;\n } else if (event === 'canplay') {\n this.waiting = false;\n } else if (event === 'emptied') {\n // A new source starts over: the title shows again before its first play.\n this.started = false;\n this.waiting = false;\n }\n }\n\n /** The video's state on the element, for `mattebox-player[paused]` and the like. */\n private reflect(): void {\n const video = this.media;\n this.reflecting = true;\n this.toggleAttribute('paused', video.paused);\n this.toggleAttribute('playing', !video.paused);\n this.toggleAttribute('ended', video.ended);\n // `muted` is also forwarded: the page's attribute sets the video, and\n // the video's state sets the attribute. Reflection never forwards, so\n // a read can only ever change the attribute, never the video.\n this.toggleAttribute('muted', video.muted);\n this.toggleAttribute('audio', this.audio());\n this.toggleAttribute('started', this.started);\n this.toggleAttribute('waiting', this.waiting);\n this.reflecting = false;\n }\n\n /**\n * Whether the source has no picture. Once the metadata is in, the video's\n * size decides: zero by zero is sound alone, and `resize` catches a stream\n * that moves to or from an audio-only rendition. Before that, the type the\n * page wrote or the URL implies is the hint, so an mp3 is `audio` from\n * the start rather than from its metadata.\n */\n private audio(): boolean {\n const video = this.media;\n if (video.readyState >= HTMLMediaElement.HAVE_METADATA) {\n return video.videoWidth === 0 && video.videoHeight === 0;\n }\n const src = this.getAttribute('src');\n const type = this.getAttribute('type') ?? (src === null ? undefined : inferType(src));\n return type?.startsWith('audio/') === true;\n }\n\n disconnectedCallback(): void {\n // A single-page app must not leave a pipeline attached to a video it\n // navigated away from. Reconnecting loads the `src` again.\n this.enqueue(() => this.teardown());\n }\n\n attributeChangedCallback(name: string): void {\n if (FORWARDED.includes(name)) {\n if (!this.reflecting) this.forward(name);\n return;\n }\n if (name === CONTROLS) {\n this.mode();\n return;\n }\n if (name === CHAPTERS) {\n this.chapters();\n return;\n }\n if (name === PLAYSINLINE) {\n // On the video it is a boolean attribute, so off is absent.\n this.media.toggleAttribute(PLAYSINLINE, this.getAttribute(PLAYSINLINE) !== 'false');\n return;\n }\n // The preset decides the chain, so it is the one attribute that rebuilds it.\n if (name === 'preset') this.enqueue(() => this.discard());\n // The source's type is the hint for `audio` until its metadata arrives.\n // Only `audio`: a full reflection here would drop a `muted` the page\n // wrote before its own callback forwards it.\n if (name === 'src' || name === 'type') this.toggleAttribute('audio', this.audio());\n this.reload();\n }\n\n /**\n * Applies the `controls` attribute: the video's own controls and the\n * tabindex. The controls themselves are elements the page placed, and\n * they attach on their own; the element appends none.\n */\n private mode(): void {\n const value = this.getAttribute(CONTROLS);\n const custom = value === 'custom';\n this.media.controls = !custom && value !== 'none';\n // Under custom controls the error screen element carries a fatal error.\n if (custom) this.surface.clear();\n if (!custom) {\n if (this.focusable) this.removeAttribute('tabindex');\n this.focusable = false;\n } else if (!this.hasAttribute('tabindex')) {\n // A bare video is not focusable, so without this a click on it would\n // leave the shortcuts nowhere to listen. A page that set its own\n // tabindex keeps it.\n this.tabIndex = 0;\n this.focusable = true;\n }\n }\n\n /** Hands the `chapters` attribute to the engine, or keeps a hidden chapters track on the video for it. */\n private chapters(): void {\n const url = this.getAttribute(CHAPTERS);\n const engine = this.current?.engine ?? null;\n const api = engine === null ? undefined : namespaces(engine).chapters;\n if (api !== undefined) {\n this.track?.remove();\n this.track = null;\n if (url === this.given) return;\n this.given = url;\n // An empty list removes the chapters the attribute loaded.\n if (url === null) api.set([]);\n else void api.load(url).catch(() => undefined);\n return;\n }\n if (url === null) {\n this.track?.remove();\n this.track = null;\n return;\n }\n const held = this.track;\n if (held !== null && held.parentNode === this.media && held.getAttribute('src') === url) return;\n // A new element each time: one removed mid-load, as the engine's attach\n // does, stays in its error state, and neither a new `src` nor a second\n // insertion starts it loading again.\n held?.remove();\n const track = document.createElement('track');\n track.kind = 'chapters';\n track.src = url;\n this.track = track;\n this.media.append(track);\n // Set after the insertion: a track element's mode exists once it is in\n // a media element, and `hidden` is what makes its cues load unseen.\n track.track.mode = 'hidden';\n }\n\n private forward(name: string): void {\n const value = this.getAttribute(name);\n if (value === null) this.media.removeAttribute(name);\n else this.media.setAttribute(name, value);\n // A video reads `muted` into its state only when it is created, and this\n // one was created before any attribute reached it. Muted autoplay and\n // the autoplay policy read the state, so the attribute alone would not do.\n if (name === 'muted') this.media.muted = value !== null;\n }\n\n private enqueue(task: () => Promise<void>): void {\n this.queue = this.queue.then(task, task).catch(() => undefined);\n }\n\n /**\n * One run per burst. The parser sets every attribute and then connects the\n * element before any queued task starts, and each of those would load on\n * its own; the flag folds them into the one run that sees the final state.\n */\n private reload(): void {\n if (this.pending) return;\n this.pending = true;\n this.enqueue(() => {\n this.pending = false;\n return this.run();\n });\n }\n\n private emit(name: string, detail: unknown): void {\n this.dispatchEvent(new CustomEvent(name, { detail, bubbles: true, composed: true }));\n }\n\n private report(error: PlayerError): void {\n if (error.fatal) {\n this.failure = error;\n // Under custom controls the error screen element is the surface, and\n // the element's own row under the video stays quiet.\n if (this.getAttribute(CONTROLS) !== 'custom') this.surface.show(error);\n }\n this.emit('error', error);\n }\n\n private async run(): Promise<void> {\n this.unmount();\n if (!this.isConnected) return;\n const url = this.getAttribute('src');\n if (url === null) return;\n\n const core = await this.ensure();\n const type = this.getAttribute('type');\n const source: Source = type === null ? { url } : { url, type };\n this.failure = null;\n this.surface.clear();\n\n let session: Session;\n try {\n session = await core.load(source);\n } catch {\n // The core already reported it on the error event, which the surface\n // and the element's own event both carry. Nothing to add here.\n return;\n }\n if (!this.isConnected) {\n await core.unload();\n return;\n }\n this.current = session;\n this.given = null;\n this.configure(session);\n // The engine's attach empties the media element to reset its resource\n // selection (`kernel/mse.ts`), and the chapters track goes with the\n // `<source>` children it means. Wanted: the track to survive attach.\n // Had to: put it back once the session is in. The surface that would\n // make it one call: an attach that removes `<source>` children alone.\n // A session with the engine's chapters takes the URL there instead.\n this.chapters();\n }\n\n private async ensure(): Promise<Player> {\n if (this.core !== null) return this.core;\n const core = createPlayer(this.media, { handlers: await this.chain() });\n this.offs.push(\n core.on('sourcechange', (session) => {\n // Before the event goes out, so a control that reads `engine` on\n // `sourcechange` sees the session the event is about.\n this.current = session;\n this.emit('sourcechange', session);\n }),\n core.on('error', (error) => {\n this.report(error);\n }),\n );\n this.core = core;\n return core;\n }\n\n private async chain(): Promise<readonly Handler[]> {\n if (this.options.handlers !== undefined) return this.options.handlers;\n const config = this.options.config === undefined ? {} : { config: this.options.config };\n if (this.options.stages !== undefined) {\n return [matteboxHandler({ stages: this.options.stages, ...config }), nativeHandler()];\n }\n const name = this.getAttribute('preset') ?? DEFAULT_PRESET;\n const preset = await resolvePreset(name);\n if (preset === null) {\n this.report({\n category: 'config',\n code: 'CONFIG_INVALID',\n fatal: true,\n recoverable: false,\n handler: null,\n context: { preset: name },\n });\n return [nativeHandler()];\n }\n return [matteboxHandler({ preset, ...config, ...drmGuard() }), nativeHandler()];\n }\n\n /** What the attributes ask of the session's namespaces, once there is one. */\n private configure(session: Session): void {\n const engine = session.engine;\n if (engine === null) return;\n\n const optional = namespaces(engine);\n\n const license = this.getAttribute('license-url');\n // After the session exists, not before: passing a license URL up front\n // means constructing eme-core, and importing a stage to configure it\n // would bundle it.\n if (license !== null && optional.drm !== undefined) optional.drm.setLicenseUrl(license);\n\n const track = this.getAttribute('thumbnails');\n if (track !== null && optional.thumbnails !== undefined) {\n // Loaded here; drawn by the seek bar's preview under `controls=\"custom\"`.\n // Native controls expose no scrub position to anchor a preview to, so\n // under `native` the track only answers `engine.thumbnails.at(time)` for\n // the app. See docs/guide/03-the-element.md.\n void optional.thumbnails.load(track).catch(() => undefined);\n }\n }\n\n private unmount(): void {\n this.current = null;\n }\n\n private async teardown(): Promise<void> {\n this.unmount();\n if (this.core !== null) await this.core.unload();\n }\n\n /** Drops the player itself, so the next run builds a chain from the new preset. */\n private async discard(): Promise<void> {\n await this.teardown();\n for (const off of this.offs) off();\n this.offs = [];\n this.core = null;\n }\n}\n"],"mappings":";;;;;;;;AAgCA,MAAM,YAAY;CAAC;CAAY;CAAS;CAAU;AAAa;;AAG/D,MAAM,MAAM;CAAC;CAAO;CAAQ;CAAU;CAAe;AAAY;;;;;;;;;AAUjE,MAAM,WAAW;;;;;;;;AASjB,MAAM,WAAW;;;;;;;AAQjB,MAAM,cAAc;;AAGpB,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,iBAAiB;;;;;;AAqDvB,IAAI,WAAkC,CAAC;;;;;;;AASvC,IAAa,wBAAb,MAAa,8BAA8B,YAAkC;CAC3E,WAAW,q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KAAK;GAC1B,CAAC;GACD,OAAO,CAAC,cAAc,CAAC;EACzB;EACA,OAAO,CAAC,gBAAgB;GAAE;GAAQ,GAAG;GAAQ,GAAG,SAAS;EAAE,CAAC,GAAG,cAAc,CAAC;CAChF;;CAGA,UAAkB,SAAwB;EACxC,MAAM,SAAS,QAAQ;EACvB,IAAI,WAAW,MAAM;EAErB,MAAM,WAAW,WAAW,MAAM;EAElC,MAAM,UAAU,KAAK,aAAa,aAAa;EAI/C,IAAI,YAAY,QAAQ,SAAS,QAAQ,KAAA,GAAW,SAAS,IAAI,cAAc,OAAO;EAEtF,MAAM,QAAQ,KAAK,aAAa,YAAY;EAC5C,IAAI,UAAU,QAAQ,SAAS,eAAe,KAAA,GAK5C,SAAc,WAAW,KAAK,KAAK,CAAC,CAAC,YAAY,KAAA,CAAS;CAE9D;CAEA,UAAwB;EACtB,KAAK,UAAU;CACjB;CAEA,MAAc,WAA0B;EACtC,KAAK,QAAQ;EACb,IAAI,KAAK,SAAS,MAAM,MAAM,KAAK,KAAK,OAAO;CACjD;;CAGA,MAAc,UAAyB;EACrC,MAAM,KAAK,SAAS;EACpB,KAAK,MAAM,OAAO,KAAK,MAAM,IAAI;EACjC,KAAK,OAAO,CAAC;EACb,KAAK,OAAO;CACd;AACF"}
|
|
1
|
+
{"version":3,"file":"element.js","names":[],"sources":["../src/element.ts"],"sourcesContent":["/**\n * <mattebox-player>: a real <video> as a light-DOM child, so the integrator\n * can reach it, and the error surface in shadow DOM. The element never\n * forwards or wraps a media element member: play, pause, seek, volume and\n * the rest live on the video, where the browser, Picture-in-Picture and the\n * OS media session already find them.\n *\n * The controls are elements the page places inside, beside the video, and\n * the stage slots them over the picture. The element appends none of its\n * own: the composition is the page's in every mode, and `none` hides every\n * child but the video. The element reflects the video's state as\n * attributes on itself, `paused`, `playing`, `ended`, `muted`, `audio`,\n * `started` and `waiting`, for the page's stylesheet and the controls\n * alike.\n *\n * No class fields, `#private` or otherwise: the ES2015 build would lower\n * them into runtime helpers, and the emit check bans helpers. Statics are\n * getters and instance state is declared, then assigned in the constructor.\n */\n\nimport type { Handler, Player, PlayerError, Session, Source } from '@mattebox/player-core';\nimport {\n createPlayer,\n inferType,\n matteboxHandler,\n nativeHandler,\n preferNativeHls,\n} from '@mattebox/player-core';\nimport type { KernelConfig, Mattebox, Stage } from 'mattebox';\nimport type { AttachEmeOptions } from 'mattebox/eme';\nimport type { Marker, Markers } from './controls/markers.js';\nimport { createMarkers } from './controls/markers.js';\nimport type { PlayerHost } from './host.js';\nimport { namespaces } from './namespaces.js';\nimport { drmGuard, resolvePreset } from './presets.js';\nimport { STYLE } from './style.js';\nimport type { ErrorSurface } from './surface.js';\nimport { errorSurface } from './surface.js';\nimport { PLAYER } from './tags.js';\n\n/**\n * `off` keeps HLS on the engine in Safari. Anything else lets Safari play\n * HLS itself: FairPlay, AirPlay, Low-Latency HLS and the platform's\n * fullscreen then work as Apple built them. Changing it reloads.\n */\nconst NATIVE_HLS = 'native-hls';\n\n/** Attributes forwarded onto the video as attributes, never as properties. */\nconst FORWARDED = ['autoplay', 'muted', 'poster', 'crossorigin'];\n\nconst LICENSE_URL = 'license-url';\nconst CERTIFICATE_URL = 'certificate-url';\n\n/** Everything else the element watches. Changing any of them reloads. */\nconst OWN = ['src', 'type', 'preset', LICENSE_URL, CERTIFICATE_URL, 'thumbnails', NATIVE_HLS];\n\n/**\n * The chapters file URL. A session with the engine's `chapters` namespace\n * loads it there: through the engine's transport, so request hooks apply,\n * and in every format the engine reads. Any other session gets a\n * `<track kind=\"chapters\">` on the video, hidden so its cues load and\n * nothing is drawn. The seek bar and the chapters menu read either.\n * Changing it never reloads the source.\n */\nconst CHAPTERS = 'chapters';\n\n/**\n * The one attribute whose meaning the element owns: `native` keeps the\n * browser's controls on the video, `custom` swaps them for the controls the\n * page placed inside, `none` takes the browser's off and hides every child\n * but the video. Anything else is `native`. Changing it never touches the\n * session.\n */\nconst CONTROLS = 'controls';\n\n/**\n * Inline playback, on until the page writes `playsinline=\"false\"`, the way\n * `spellcheck` and `draggable` are on until told otherwise. An iPhone takes\n * a video without `playsinline` to its own fullscreen on play, where no\n * control the page placed shows. Changing it never reloads.\n */\nconst PLAYSINLINE = 'playsinline';\n\n/**\n * The size tier the controls draw for: `compact` on a small player, such\n * as a phone held upright, `wide` on a large one, such as a TV or\n * fullscreen, and `regular` between. The element measures itself and sets\n * the attribute, so a stylesheet matches `mattebox-player[layout=\"compact\"]`.\n * A page that writes one of the three values fixes it, and removing the\n * attribute hands it back. The player's own box decides, not the screen:\n * a small embed on a desktop is compact, and a phone in fullscreen is not.\n */\nconst LAYOUT = 'layout';\nconst LAYOUTS = ['compact', 'regular', 'wide'];\n/** Under either, the player is compact. */\nconst COMPACT_WIDTH = 480;\nconst COMPACT_HEIGHT = 320;\n/** From both, the player is wide. */\nconst WIDE_WIDTH = 1280;\nconst WIDE_HEIGHT = 700;\n\n/** The video's state, as attributes on the element, read on the events the video fires for it. */\nconst STATE_EVENTS = [\n 'play',\n 'pause',\n 'ended',\n // A seek back from the end leaves `ended` with no play, pause or ended event.\n 'seeked',\n 'emptied',\n 'volumechange',\n 'loadedmetadata',\n 'resize',\n 'playing',\n 'waiting',\n 'stalled',\n 'canplay',\n];\n\n/** The stages that register a key system, which a native session's DRM offers. */\nconst KEY_SYSTEMS = ['eme-fairplay', 'eme-cenc'];\n\n/** Every stage the engine ships. A narrower preset is optimization. */\nconst DEFAULT_PRESET = 'full';\n\n/**\n * What the element dispatches. `error` is also a standard DOM event name, so\n * without these overloads a listener on it is typed as `ErrorEvent` and the\n * payload needs a double cast. They are declarations only: no runtime bytes.\n */\nexport interface MatteboxPlayerEventMap {\n sourcechange: CustomEvent<Session | null>;\n /** The size tier changed: `compact`, `regular` or `wide`. */\n layoutchange: CustomEvent<string>;\n error: CustomEvent<PlayerError>;\n /** The markers changed: set by the page, or cleared by a new source. */\n markerschange: CustomEvent<readonly Marker[]>;\n /** Playback reached a blocked range and moved past it. */\n blocked: CustomEvent<Marker>;\n}\n\nexport interface MatteboxPlayerElement {\n addEventListener<K extends keyof MatteboxPlayerEventMap>(\n type: K,\n listener: (this: MatteboxPlayerElement, event: MatteboxPlayerEventMap[K]) => void,\n options?: boolean | AddEventListenerOptions,\n ): void;\n addEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | AddEventListenerOptions,\n ): void;\n removeEventListener<K extends keyof MatteboxPlayerEventMap>(\n type: K,\n listener: (this: MatteboxPlayerElement, event: MatteboxPlayerEventMap[K]) => void,\n options?: boolean | EventListenerOptions,\n ): void;\n removeEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | EventListenerOptions,\n ): void;\n}\n\nexport interface MatteboxPlayerOptions {\n /** The whole chain, in order. Takes precedence over `stages` and the `preset` attribute. */\n readonly handlers?: readonly Handler[];\n /** Stages for the mattebox handler. Takes precedence over the `preset` attribute. */\n readonly stages?: readonly Stage[];\n /**\n * Kernel tuning for the engines the elements build, `traceCapacity` among\n * it. A page decision, like the stages, so not an attribute. Ignored with\n * `handlers`, which carry their own.\n */\n readonly config?: Partial<KernelConfig>;\n /**\n * DRM for a native session, as `attachEme` from `mattebox/eme` takes it:\n * `keySystems`, `licenseUrl`, `licenseUrls`, `requestHook`. Without\n * `keySystems` the session offers the key-system stages of the engine's\n * stack. The `license-url` attribute overrides `licenseUrl`, and\n * `certificate-url` gives the FairPlay certificate. Ignored\n * with `handlers`, which carry their own.\n */\n readonly drm?: AttachEmeOptions;\n}\n\n/**\n * What `define()` recorded, for the elements the parser creates. It is the\n * one value shared across elements, because a page that writes only markup\n * still has to be able to say what the engine carries.\n */\nlet defaults: MatteboxPlayerOptions = {};\n\n/**\n * The interface above merges only `addEventListener` and `removeEventListener`\n * overloads, which the class inherits from HTMLElement. The rule it suppresses\n * guards against properties an interface declares and a constructor never\n * assigns, and there are none.\n */\n// biome-ignore lint/suspicious/noUnsafeDeclarationMerging: method overloads only, no properties\nexport class MatteboxPlayerElement extends HTMLElement implements PlayerHost {\n static get observedAttributes(): readonly string[] {\n return [...FORWARDED, ...OWN, CONTROLS, CHAPTERS, PLAYSINLINE, LAYOUT];\n }\n\n /**\n * Registers the element once, and records the stages markup-only pages\n * get. The controls register through their own entries, the package's\n * root entry importing every one; a control connected before its player\n * is defined waits for the definition.\n */\n static define(options?: MatteboxPlayerOptions): void {\n if (options !== undefined) defaults = options;\n if (customElements.get(PLAYER) === undefined) {\n customElements.define(PLAYER, MatteboxPlayerElement);\n }\n }\n\n declare private readonly media: HTMLVideoElement;\n /** Wraps the slot: the picture, and the controls over it or under it. */\n declare private readonly stage: HTMLDivElement;\n /** Whether the element gave itself a tabindex for the bar, to take back with it. */\n declare private focusable: boolean;\n declare private readonly surface: ErrorSurface;\n declare private readonly marks: Markers;\n /** The chapters track element, while the `chapters` attribute names one and the engine takes none. */\n declare private track: HTMLTrackElement | null;\n /** The chapters URL the current session's engine was given, or null. */\n declare private given: string | null;\n /** The sources the page set from script, or null. */\n declare private list: readonly Source[] | null;\n /** The sources of the last run, as text: what tells a new `<source>` child from the ones already tried. */\n declare private tried: string;\n /** The options this element was constructed with, or null for the ones `define()` recorded. */\n declare private readonly own: MatteboxPlayerOptions | null;\n declare private core: Player | null;\n declare private current: Session | null;\n declare private failure: PlayerError | null;\n /** Whether an attribute change is the element's own reflection, which must not write back to the video. */\n declare private reflecting: boolean;\n /** Watches the element's box for `layout`, while connected. */\n declare private sizes: ResizeObserver | null;\n /** Whether the page wrote `layout`, so the element leaves it alone. */\n declare private fixed: boolean;\n /** The video has played once since its source was set: `started`, which tells a first play from a pause. */\n declare private started: boolean;\n /** The video waits for data: `waiting`, set on `waiting` and `stalled`, cleared once it can play. */\n declare private waiting: boolean;\n declare private offs: Array<() => void>;\n /** Everything the element does to the player runs here, so it runs in order. */\n declare private queue: Promise<void>;\n /** Whether a run is queued and not yet started, so a burst of changes loads once. */\n declare private pending: boolean;\n\n constructor(options?: MatteboxPlayerOptions) {\n super();\n this.own = options ?? null;\n this.focusable = false;\n this.track = null;\n this.given = null;\n this.list = null;\n this.tried = '';\n this.core = null;\n this.current = null;\n this.failure = null;\n this.reflecting = false;\n this.sizes = null;\n this.fixed = false;\n this.started = false;\n this.waiting = false;\n this.offs = [];\n this.queue = Promise.resolve();\n this.pending = false;\n\n this.media = document.createElement('video');\n // Native until the `controls` attribute says otherwise, which arrives\n // through attributeChangedCallback: a constructor must not read attributes.\n this.media.controls = true;\n // Inline is the default, and the player's own attribute has not arrived\n // yet. Set as an attribute: not every browser has the `playsInline`\n // property. The fullscreen button still reaches the iPhone's fullscreen,\n // through `webkitEnterFullscreen`.\n this.media.setAttribute(PLAYSINLINE, '');\n for (const name of STATE_EVENTS) {\n this.media.addEventListener(name, () => {\n this.note(name);\n this.reflect();\n });\n }\n // An error over a picture that then plays is wrong by definition.\n this.media.addEventListener('playing', () => {\n this.failure = null;\n });\n this.marks = createMarkers(this.media, (name, detail) => this.emit(name, detail));\n this.stage = document.createElement('div');\n this.stage.setAttribute('part', 'stage');\n const slot = document.createElement('slot');\n // The parser connects the element before its children exist, so the\n // first run finds no `<source>`. A video starts its selection when a\n // `<source>` arrives and nothing is loaded, and so does this.\n slot.addEventListener('slotchange', () => {\n if (this.current === null && JSON.stringify(this.wanted()) !== this.tried) this.reload();\n });\n this.stage.append(slot);\n this.surface = errorSurface(() => {\n this.reload();\n });\n\n const root = this.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = STYLE;\n root.append(style, this.stage, this.surface.root);\n }\n\n /** The media element. Everything the browser already does is here. */\n get video(): HTMLVideoElement {\n return this.media;\n }\n\n /** The ranges the page named in this source: credits to skip, parts that must not play. */\n get markers(): Markers {\n return this.marks;\n }\n\n /**\n * The sources to try in order, set from script. The `src` attribute wins\n * over them, and they win over the `<source>` children. Setting them\n * loads, and null returns to the children.\n */\n get sources(): readonly Source[] | null {\n return this.list;\n }\n\n set sources(value: readonly Source[] | null) {\n this.list = value;\n // Markers belong to a source, as for `src`.\n if (this.marks.list.length > 0) this.marks.set([]);\n this.reload();\n }\n\n /** The core, or null until the first source has been set up: resolving a preset is asynchronous. */\n get player(): Player | null {\n return this.core;\n }\n\n /** The engine feeding the video, or null for a native session and before the first load. */\n get engine(): Mattebox | null {\n return this.current?.engine ?? null;\n }\n\n /**\n * The fatal error of the current load, or null once a load starts or\n * playback resumes. The `error` event says when; this says what, for a\n * control that attaches after the event, such as an error screen parsed\n * after a source that failed while the page was still loading.\n */\n get error(): PlayerError | null {\n return this.failure;\n }\n\n connectedCallback(): void {\n if (this.media.parentNode !== this) this.append(this.media);\n for (const name of FORWARDED) this.forward(name);\n this.reflect();\n if (typeof ResizeObserver !== 'undefined') {\n this.sizes = new ResizeObserver(() => {\n this.measure();\n });\n this.sizes.observe(this);\n }\n this.measure();\n this.reload();\n }\n\n /** Sets `layout` from the element's box, unless the page fixed it. */\n private measure(): void {\n if (this.fixed) return;\n const width = this.clientWidth;\n const height = this.clientHeight;\n // Not laid out yet: no tier until there is a box to judge.\n if (width === 0 || height === 0) return;\n const layout =\n width < COMPACT_WIDTH || height < COMPACT_HEIGHT\n ? 'compact'\n : width >= WIDE_WIDTH && height >= WIDE_HEIGHT\n ? 'wide'\n : 'regular';\n if (this.getAttribute(LAYOUT) === layout) return;\n this.reflecting = true;\n this.setAttribute(LAYOUT, layout);\n this.reflecting = false;\n this.emit('layoutchange', layout);\n }\n\n /** The two states the video does not hold: whether it has played once, and whether it waits for data. */\n private note(event: string): void {\n if (event === 'playing') {\n this.started = true;\n this.waiting = false;\n } else if (event === 'waiting' || event === 'stalled') {\n this.waiting = true;\n } else if (event === 'canplay') {\n this.waiting = false;\n } else if (event === 'emptied') {\n // A new source starts over: the title shows again before its first play.\n this.started = false;\n this.waiting = false;\n }\n }\n\n /** The video's state on the element, for `mattebox-player[paused]` and the like. */\n private reflect(): void {\n const video = this.media;\n this.reflecting = true;\n this.toggleAttribute('paused', video.paused);\n this.toggleAttribute('playing', !video.paused);\n this.toggleAttribute('ended', video.ended);\n // `muted` is also forwarded: the page's attribute sets the video, and\n // the video's state sets the attribute. Reflection never forwards, so\n // a read can only ever change the attribute, never the video.\n this.toggleAttribute('muted', video.muted);\n this.toggleAttribute('audio', this.audio());\n this.toggleAttribute('started', this.started);\n this.toggleAttribute('waiting', this.waiting);\n this.reflecting = false;\n }\n\n /**\n * Whether the source has no picture. Once the metadata is in, the video's\n * size decides: zero by zero is sound alone, and `resize` catches a stream\n * that moves to or from an audio-only rendition. Before that, the type the\n * page wrote or the URL implies is the hint, so an mp3 is `audio` from\n * the start rather than from its metadata.\n */\n private audio(): boolean {\n const video = this.media;\n if (video.readyState >= HTMLMediaElement.HAVE_METADATA) {\n return video.videoWidth === 0 && video.videoHeight === 0;\n }\n const src = this.getAttribute('src');\n const type = this.getAttribute('type') ?? (src === null ? undefined : inferType(src));\n return type?.startsWith('audio/') === true;\n }\n\n disconnectedCallback(): void {\n this.sizes?.disconnect();\n this.sizes = null;\n // A single-page app must not leave a pipeline attached to a video it\n // navigated away from. Reconnecting loads the `src` again.\n this.enqueue(() => this.teardown());\n }\n\n attributeChangedCallback(name: string): void {\n if (FORWARDED.includes(name)) {\n if (!this.reflecting) this.forward(name);\n return;\n }\n if (name === CONTROLS) {\n this.mode();\n return;\n }\n if (name === CHAPTERS) {\n this.chapters();\n return;\n }\n if (name === LAYOUT) {\n // The element's own write is not the page's.\n if (this.reflecting) return;\n const value = this.getAttribute(LAYOUT);\n this.fixed = value !== null && LAYOUTS.includes(value);\n if (this.fixed) this.emit('layoutchange', value);\n else this.measure();\n return;\n }\n if (name === PLAYSINLINE) {\n // On the video it is a boolean attribute, so off is absent.\n this.media.toggleAttribute(PLAYSINLINE, this.getAttribute(PLAYSINLINE) !== 'false');\n return;\n }\n // The preset decides the chain, so it is the one attribute that rebuilds it.\n if (name === 'preset') this.enqueue(() => this.discard());\n // The source's type is the hint for `audio` until its metadata arrives.\n // Only `audio`: a full reflection here would drop a `muted` the page\n // wrote before its own callback forwards it.\n if (name === 'src' || name === 'type') this.toggleAttribute('audio', this.audio());\n // Markers belong to a source. Cleared here, not on `emptied`, which\n // arrives later and would clear the ones the page sets right after.\n if (name === 'src' && this.marks.list.length > 0) this.marks.set([]);\n this.reload();\n }\n\n /**\n * Applies the `controls` attribute: the video's own controls and the\n * tabindex. The controls themselves are elements the page placed, and\n * they attach on their own; the element appends none.\n */\n private mode(): void {\n const value = this.getAttribute(CONTROLS);\n const custom = value === 'custom';\n this.media.controls = !custom && value !== 'none';\n // Under custom controls the error screen element carries a fatal error.\n if (custom) this.surface.clear();\n if (!custom) {\n if (this.focusable) this.removeAttribute('tabindex');\n this.focusable = false;\n } else if (!this.hasAttribute('tabindex')) {\n // A bare video is not focusable, so without this a click on it would\n // leave the shortcuts nowhere to listen. A page that set its own\n // tabindex keeps it.\n this.tabIndex = 0;\n this.focusable = true;\n }\n }\n\n /** Hands the `chapters` attribute to the engine, or keeps a hidden chapters track on the video for it. */\n private chapters(): void {\n const url = this.getAttribute(CHAPTERS);\n const engine = this.current?.engine ?? null;\n const api = engine === null ? undefined : namespaces(engine).chapters;\n if (api !== undefined) {\n this.track?.remove();\n this.track = null;\n if (url === this.given) return;\n this.given = url;\n // An empty list removes the chapters the attribute loaded.\n if (url === null) api.set([]);\n else void api.load(url).catch(() => undefined);\n return;\n }\n if (url === null) {\n this.track?.remove();\n this.track = null;\n return;\n }\n const held = this.track;\n if (held !== null && held.parentNode === this.media && held.getAttribute('src') === url) return;\n // A new element each time: one removed mid-load, as the engine's attach\n // does, stays in its error state, and neither a new `src` nor a second\n // insertion starts it loading again.\n held?.remove();\n const track = document.createElement('track');\n track.kind = 'chapters';\n track.src = url;\n this.track = track;\n this.media.append(track);\n // Set after the insertion: a track element's mode exists once it is in\n // a media element, and `hidden` is what makes its cues load unseen.\n track.track.mode = 'hidden';\n }\n\n private forward(name: string): void {\n const value = this.getAttribute(name);\n if (value === null) this.media.removeAttribute(name);\n else this.media.setAttribute(name, value);\n // A video reads `muted` into its state only when it is created, and this\n // one was created before any attribute reached it. Muted autoplay and\n // the autoplay policy read the state, so the attribute alone would not do.\n if (name === 'muted') this.media.muted = value !== null;\n }\n\n private enqueue(task: () => Promise<void>): void {\n this.queue = this.queue.then(task, task).catch(() => undefined);\n }\n\n /**\n * One run per burst. The parser sets every attribute and then connects the\n * element before any queued task starts, and each of those would load on\n * its own; the flag folds them into the one run that sees the final state.\n */\n private reload(): void {\n if (this.pending) return;\n this.pending = true;\n this.enqueue(() => {\n this.pending = false;\n return this.run();\n });\n }\n\n private emit(name: string, detail: unknown): void {\n this.dispatchEvent(new CustomEvent(name, { detail, bubbles: true, composed: true }));\n }\n\n private report(error: PlayerError): void {\n if (error.fatal) {\n this.failure = error;\n // Under custom controls the error screen element is the surface, and\n // the element's own row under the video stays quiet.\n if (this.getAttribute(CONTROLS) !== 'custom') this.surface.show(error);\n }\n this.emit('error', error);\n }\n\n private async run(): Promise<void> {\n this.unmount();\n if (!this.isConnected) return;\n const sources = this.wanted();\n this.tried = JSON.stringify(sources);\n if (sources.length === 0) return;\n\n const core = await this.ensure();\n this.failure = null;\n this.surface.clear();\n\n try {\n await core.load(sources);\n } catch {\n // The core already reported it on the error event, which the surface\n // and the element's own event both carry. Nothing to add here.\n return;\n }\n if (!this.isConnected) await core.unload();\n }\n\n /**\n * What to load, ranked as a video ranks them: the `src` attribute, then\n * the `sources` property, then the `<source>` children in their order.\n * A child carries its own `license-url` and `certificate-url`.\n */\n private wanted(): readonly Source[] {\n const url = this.getAttribute('src');\n if (url !== null) {\n const type = this.getAttribute('type');\n return [type === null ? { url } : { url, type }];\n }\n // A browser without EME gets no DRM stage, and a source must not bring DRM back.\n const eme = drmGuard().without === undefined;\n if (this.list !== null) {\n return eme\n ? this.list\n : this.list.map(({ url, type }) => (type === undefined ? { url } : { url, type }));\n }\n const found: Source[] = [];\n for (const child of Array.from(this.children)) {\n const src = child.localName === 'source' ? child.getAttribute('src') : null;\n if (src === null) continue;\n const type = child.getAttribute('type');\n const license = child.getAttribute(LICENSE_URL);\n const certificate = child.getAttribute(CERTIFICATE_URL);\n found.push({\n url: src,\n ...(type === null ? {} : { type }),\n ...(!eme || (license === null && certificate === null)\n ? {}\n : {\n drm: {\n ...(license === null ? {} : { licenseUrl: license }),\n ...(certificate === null ? {} : { certificateUrl: certificate }),\n },\n }),\n });\n }\n return found;\n }\n\n /** Sets a session up. It runs for every session, the one that replaces a failed source included. */\n private adopt(session: Session): void {\n this.given = null;\n this.configure(session);\n // The engine's attach empties the media element to reset its resource\n // selection (`kernel/mse.ts`), and the chapters track goes with the\n // `<source>` children it means. Wanted: the track to survive attach.\n // Had to: put it back once the session is in. The surface that would\n // make it one call: an attach that removes `<source>` children alone.\n // A session with the engine's chapters takes the URL there instead.\n this.chapters();\n }\n\n private async ensure(): Promise<Player> {\n if (this.core !== null) return this.core;\n const core = createPlayer(this.media, { handlers: await this.chain() });\n this.offs.push(\n core.on('sourcechange', (session) => {\n // Before the event goes out, so a control that reads `engine` on\n // `sourcechange` sees the session the event is about.\n this.current = session;\n if (session !== null && this.isConnected) this.adopt(session);\n this.emit('sourcechange', session);\n }),\n core.on('error', (error) => {\n this.report(error);\n }),\n );\n this.core = core;\n return core;\n }\n\n /**\n * Read at each use, not once in the constructor. Importing the package\n * registers the element, and the parser's elements are constructed then,\n * before the page's own `define()` call can run.\n */\n private get options(): MatteboxPlayerOptions {\n return this.own ?? defaults;\n }\n\n private async chain(): Promise<readonly Handler[]> {\n if (this.options.handlers !== undefined) return this.options.handlers;\n const config = this.options.config === undefined ? {} : { config: this.options.config };\n // The stack is read at load time: a preset builds its stages only when asked.\n const native = (stages: () => readonly Stage[]): Handler =>\n nativeHandler({\n // Read on every load, so the attribute applies without a new chain.\n prefer: (source, env) =>\n this.getAttribute(NATIVE_HLS) !== 'off' && preferNativeHls(source, env),\n drm: () => this.drm(stages),\n });\n if (this.options.stages !== undefined) {\n return [\n matteboxHandler({ stages: this.options.stages, ...config }),\n native(() => this.options.stages ?? []),\n ];\n }\n const name = this.getAttribute('preset') ?? DEFAULT_PRESET;\n const preset = await resolvePreset(name);\n if (preset === null) {\n this.report({\n category: 'config',\n code: 'CONFIG_INVALID',\n fatal: true,\n recoverable: false,\n handler: null,\n context: { preset: name },\n });\n return [nativeHandler()];\n }\n return [matteboxHandler({ preset, ...config, ...drmGuard() }), native(() => preset.stages())];\n }\n\n /**\n * The DRM a native session attaches: the page's `drm` option, the\n * key-system stages of the engine's stack, and the `license-url`\n * attribute. None on a browser without EME, as for the engine.\n */\n private drm(stages: () => readonly Stage[]): AttachEmeOptions | undefined {\n if (drmGuard().without !== undefined) return undefined;\n const keySystems = stages().filter((stage) => KEY_SYSTEMS.includes(stage.name));\n const license = this.getAttribute(LICENSE_URL);\n const certificate = this.getAttribute(CERTIFICATE_URL);\n const page = this.options.drm;\n if (keySystems.length === 0 && license === null && page === undefined) return undefined;\n return {\n keySystems,\n ...page,\n ...(license === null ? {} : { licenseUrl: license }),\n ...(certificate === null ? {} : { certificateUrl: certificate }),\n };\n }\n\n /** What the attributes ask of the session's namespaces, once there is one. */\n private configure(session: Session): void {\n const engine = session.engine;\n if (engine === null) return;\n\n const optional = namespaces(engine);\n\n // The attributes are the default. A source's own URL is already on the\n // engine: the handler set it from `source.drm` before the load.\n const own = session.source.drm;\n const license = this.getAttribute(LICENSE_URL);\n // After the session exists, not before: passing a license URL up front\n // means constructing eme-core, and importing a stage to configure it\n // would bundle it.\n if (license !== null && own?.licenseUrl === undefined) optional.drm?.setLicenseUrl(license);\n const certificate = this.getAttribute(CERTIFICATE_URL);\n if (certificate !== null && own?.certificateUrl === undefined) {\n optional.drm?.setCertificateUrl(certificate);\n }\n\n const track = this.getAttribute('thumbnails');\n if (track !== null && optional.thumbnails !== undefined) {\n // Loaded here; drawn by the seek bar's preview under `controls=\"custom\"`.\n // Native controls expose no scrub position to anchor a preview to, so\n // under `native` the track only answers `engine.thumbnails.at(time)` for\n // the app. See docs/guide/03-the-element.md.\n void optional.thumbnails.load(track).catch(() => undefined);\n }\n }\n\n private unmount(): void {\n this.current = null;\n }\n\n private async teardown(): Promise<void> {\n this.unmount();\n if (this.core !== null) await this.core.unload();\n }\n\n /** Drops the player itself, so the next run builds a chain from the new preset. */\n private async discard(): Promise<void> {\n await this.teardown();\n for (const off of this.offs) off();\n this.offs = [];\n this.core = null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA6CA,MAAM,aAAa;;AAGnB,MAAM,YAAY;CAAC;CAAY;CAAS;CAAU;AAAa;AAE/D,MAAM,cAAc;AACpB,MAAM,kBAAkB;;AAGxB,MAAM,MAAM;CAAC;CAAO;CAAQ;CAAU;CAAa;CAAiB;CAAc;AAAU;;;;;;;;;AAU5F,MAAM,WAAW;;;;;;;;AASjB,MAAM,WAAW;;;;;;;AAQjB,MAAM,cAAc;;;;;;;;;;AAWpB,MAAM,SAAS;AACf,MAAM,UAAU;CAAC;CAAW;CAAW;AAAM;;AAE7C,MAAM,gBAAgB;AACtB,MAAM,iBAAiB;;AAEvB,MAAM,aAAa;AACnB,MAAM,cAAc;;AAGpB,MAAM,eAAe;CACnB;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,cAAc,CAAC,gBAAgB,UAAU;;AAG/C,MAAM,iBAAiB;;;;;;AAoEvB,IAAI,WAAkC,CAAC;;;;;;;AASvC,IAAa,wBAAb,MAAa,8BAA8B,YAAkC;CAC3E,WAAW,qBAAwC;EACjD,OAAO;GAAC,GAAG;GAAW,GAAG;GAAK;GAAU;GAAU;GAAa;EAAM;CACvE;;;;;;;CAQA,OAAO,OAAO,SAAuC;EACnD,IAAI,YAAY,KAAA,GAAW,WAAW;EACtC,IAAI,eAAe,IAAA,iBAAU,MAAM,KAAA,GACjC,eAAe,OAAO,QAAQ,qBAAqB;CAEvD;CAsCA,YAAY,SAAiC;EAC3C,MAAM;EACN,KAAK,MAAM,WAAW;EACtB,KAAK,YAAY;EACjB,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,OAAO;EACZ,KAAK,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
1
|
/**
|
|
2
|
-
* <mbx-audio-menu>: the audio track over `engine.tracks
|
|
3
|
-
*
|
|
4
|
-
* from `label`.
|
|
5
|
-
*
|
|
2
|
+
* <mbx-audio-menu>: the audio track over `engine.tracks`, or over the
|
|
3
|
+
* video's `audioTracks` for a native session. Hidden unless there is a
|
|
4
|
+
* choice to make. The name comes from `label`. An engine track reads as
|
|
5
|
+
* its name in the manifest, else its language's name, else its language
|
|
6
|
+
* code, else "Track" (`label-track`) and its place. A native track reads
|
|
7
|
+
* the same from its label and language. A badge marks an
|
|
8
|
+
* audio description track (`label-ad`, "AD") and the original language
|
|
9
|
+
* (`label-original`, "Original"), from the engine's standard
|
|
10
|
+
* characteristics (guide chapter 06), or from the native track's `kind`.
|
|
6
11
|
*/
|
|
7
12
|
import type { ContentType, Mattebox, Track } from 'mattebox';
|
|
13
|
+
import type { TrackEntry } from '../controls/track-names.js';
|
|
8
14
|
import type { PlayerHost } from '../host.js';
|
|
9
15
|
import { MenuElement } from './menu-element.js';
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The tracks of one content type that the engine can play and `listed`
|
|
18
|
+
* keeps, as entries with their badges, and the active one's id when it
|
|
19
|
+
* is listed. A track the browser cannot decode, or that no stage plays,
|
|
20
|
+
* stays out (guide chapter 06).
|
|
21
|
+
*/
|
|
22
|
+
export declare function trackItems(engine: Mattebox, contentType: ContentType, badges?: (track: Track) => readonly string[], listed?: (track: Track) => boolean): [TrackEntry[], string | null];
|
|
14
23
|
/** Subscribes `tick` to the track events, and answers the unsubscribe. */
|
|
15
24
|
export declare function onTracks(engine: Mattebox, tick: () => void): () => void;
|
|
16
25
|
export declare class MbxAudioMenu extends MenuElement {
|
|
@@ -19,6 +28,8 @@ export declare class MbxAudioMenu extends MenuElement {
|
|
|
19
28
|
constructor();
|
|
20
29
|
protected name(): string;
|
|
21
30
|
protected attach(player: PlayerHost): void;
|
|
31
|
+
/** The native session's audio tracks as entries, and the enabled one's. */
|
|
32
|
+
private native;
|
|
22
33
|
protected render(): void;
|
|
23
34
|
}
|
|
24
35
|
//# sourceMappingURL=audio-menu.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio-menu.d.ts","sourceRoot":"","sources":["../../src/elements/audio-menu.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"audio-menu.d.ts","sourceRoot":"","sources":["../../src/elements/audio-menu.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAK7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAU,MAAM,mBAAmB,CAAC;AAWxD;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,QAAQ,EAChB,WAAW,EAAE,WAAW,EACxB,MAAM,GAAE,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,MAAM,EAAa,EACtD,MAAM,GAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAoB,GAC7C,CAAC,UAAU,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC,CAiB/B;AAOD,0EAA0E;AAC1E,wBAAgB,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAKvE;AAED,qBAAa,YAAa,SAAQ,WAAW;IAC3C,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,QAAgB,MAAM,CAAkB;;cAQrB,IAAI,IAAI,MAAM;cAId,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAanD,2EAA2E;IAC3E,OAAO,CAAC,MAAM;cAgBK,MAAM,IAAI,IAAI;CAwClC"}
|