@videojs/spf 10.0.0-beta.26 → 10.0.0-beta.28
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/default/core/signals/when.js +38 -0
- package/dist/default/core/signals/when.js.map +1 -0
- package/dist/default/core/tasks/delayed-reschedule.js +31 -0
- package/dist/default/core/tasks/delayed-reschedule.js.map +1 -0
- package/dist/default/core/tasks/task.js +133 -3
- package/dist/default/core/tasks/task.js.map +1 -1
- package/dist/default/hls-audio.js +3 -0
- package/dist/default/hls-background-video.js +3 -0
- package/dist/default/hls-video.js +4 -0
- package/dist/default/hls.js +6 -5
- package/dist/default/media/dom/capabilities.js +2 -0
- package/dist/default/media/dom/capabilities.js.map +1 -1
- package/dist/default/media/errors.js +62 -0
- package/dist/default/media/errors.js.map +1 -0
- package/dist/default/media/hls/parse-media-playlist.js +167 -16
- package/dist/default/media/hls/parse-media-playlist.js.map +1 -1
- package/dist/default/media/hls/parse-multivariant.js +14 -3
- package/dist/default/media/hls/parse-multivariant.js.map +1 -1
- package/dist/default/media/hls/reload-policy.js +71 -0
- package/dist/default/media/hls/reload-policy.js.map +1 -0
- package/dist/default/media/live-window.js +36 -0
- package/dist/default/media/live-window.js.map +1 -0
- package/dist/default/media/primitives/select-tracks.js +1 -24
- package/dist/default/media/primitives/select-tracks.js.map +1 -1
- package/dist/default/media/types/index.js +15 -1
- package/dist/default/media/types/index.js.map +1 -1
- package/dist/default/media/utils/tracks.js +14 -0
- package/dist/default/media/utils/tracks.js.map +1 -1
- package/dist/default/mux-audio.js +3 -0
- package/dist/default/mux-background-video.js +3 -0
- package/dist/default/mux-video.js +3 -0
- package/dist/default/playback/adapters/hls-audio/adapter.js +186 -0
- package/dist/default/playback/adapters/hls-audio/adapter.js.map +1 -0
- package/dist/default/playback/adapters/hls-audio/media.js +9 -0
- package/dist/default/playback/adapters/hls-audio/media.js.map +1 -0
- package/dist/default/playback/adapters/hls-background-video/adapter.js +123 -0
- package/dist/default/playback/adapters/hls-background-video/adapter.js.map +1 -0
- package/dist/default/playback/adapters/hls-background-video/host.js +60 -0
- package/dist/default/playback/adapters/hls-background-video/host.js.map +1 -0
- package/dist/default/playback/adapters/hls-background-video/media.js +21 -0
- package/dist/default/playback/adapters/hls-background-video/media.js.map +1 -0
- package/dist/default/playback/adapters/hls-video/adapter.js +316 -0
- package/dist/default/playback/adapters/hls-video/adapter.js.map +1 -0
- package/dist/default/playback/adapters/hls-video/error-surface.js +51 -0
- package/dist/default/playback/adapters/hls-video/error-surface.js.map +1 -0
- package/dist/default/playback/adapters/hls-video/media-tracks.js +126 -0
- package/dist/default/playback/adapters/hls-video/media-tracks.js.map +1 -0
- package/dist/default/playback/adapters/hls-video/media.js +11 -0
- package/dist/default/playback/adapters/hls-video/media.js.map +1 -0
- package/dist/default/playback/adapters/mux-audio/media.js +26 -0
- package/dist/default/playback/adapters/mux-audio/media.js.map +1 -0
- package/dist/default/playback/adapters/mux-video/adapter.js +92 -0
- package/dist/default/playback/adapters/mux-video/adapter.js.map +1 -0
- package/dist/default/playback/adapters/mux-video/media.js +23 -0
- package/dist/default/playback/adapters/mux-video/media.js.map +1 -0
- package/dist/default/playback/behaviors/collect-errors.js +77 -0
- package/dist/default/playback/behaviors/collect-errors.js.map +1 -0
- package/dist/default/playback/behaviors/dom/end-of-stream.js +1 -0
- package/dist/default/playback/behaviors/dom/end-of-stream.js.map +1 -1
- package/dist/default/playback/behaviors/dom/seek-to-live-edge.js +132 -0
- package/dist/default/playback/behaviors/dom/seek-to-live-edge.js.map +1 -0
- package/dist/default/playback/behaviors/dom/sync-live-seekable-range.js +26 -0
- package/dist/default/playback/behaviors/dom/sync-live-seekable-range.js.map +1 -0
- package/dist/default/playback/behaviors/dom/update-mediasource-duration.js +29 -7
- package/dist/default/playback/behaviors/dom/update-mediasource-duration.js.map +1 -1
- package/dist/default/playback/behaviors/establish-start-media-time.js +78 -4
- package/dist/default/playback/behaviors/establish-start-media-time.js.map +1 -1
- package/dist/default/playback/behaviors/resolve-track.js +29 -8
- package/dist/default/playback/behaviors/resolve-track.js.map +1 -1
- package/dist/default/playback/behaviors/track-switching.js +18 -9
- package/dist/default/playback/behaviors/track-switching.js.map +1 -1
- package/dist/default/playback/engines/hls/engine-audio-only.js +9 -5
- package/dist/default/playback/engines/hls/engine-audio-only.js.map +1 -1
- package/dist/{dev/playback/engines/background-video/engine.js → default/playback/engines/hls/engine-background-video.js} +3 -3
- package/dist/default/playback/engines/hls/engine-background-video.js.map +1 -0
- package/dist/default/playback/engines/hls/engine.js +19 -6
- package/dist/default/playback/engines/hls/engine.js.map +1 -1
- package/dist/default/playback/primitives/error-messages.js +39 -0
- package/dist/default/playback/primitives/error-messages.js.map +1 -0
- package/dist/default/playback/primitives/live-window.js +66 -0
- package/dist/default/playback/primitives/live-window.js.map +1 -0
- package/dist/default/playback/primitives/report-track-conditions.js +86 -0
- package/dist/default/playback/primitives/report-track-conditions.js.map +1 -0
- package/dist/dev/core/signals/when.js +38 -0
- package/dist/dev/core/signals/when.js.map +1 -0
- package/dist/dev/core/tasks/delayed-reschedule.js +31 -0
- package/dist/dev/core/tasks/delayed-reschedule.js.map +1 -0
- package/dist/dev/core/tasks/task.d.ts +52 -1
- package/dist/dev/core/tasks/task.d.ts.map +1 -1
- package/dist/dev/core/tasks/task.js +133 -3
- package/dist/dev/core/tasks/task.js.map +1 -1
- package/dist/dev/hls-audio.d.ts +3 -0
- package/dist/dev/hls-audio.js +3 -0
- package/dist/dev/hls-background-video.d.ts +3 -0
- package/dist/dev/hls-background-video.js +3 -0
- package/dist/dev/hls-video.d.ts +5 -0
- package/dist/dev/hls-video.js +4 -0
- package/dist/dev/hls.d.ts +6 -5
- package/dist/dev/hls.js +6 -5
- package/dist/dev/media/dom/capabilities.js +2 -0
- package/dist/dev/media/dom/capabilities.js.map +1 -1
- package/dist/dev/media/errors.d.ts +82 -0
- package/dist/dev/media/errors.d.ts.map +1 -0
- package/dist/dev/media/errors.js +62 -0
- package/dist/dev/media/errors.js.map +1 -0
- package/dist/dev/media/hls/parse-media-playlist.js +167 -16
- package/dist/dev/media/hls/parse-media-playlist.js.map +1 -1
- package/dist/dev/media/hls/parse-multivariant.js +14 -3
- package/dist/dev/media/hls/parse-multivariant.js.map +1 -1
- package/dist/dev/media/hls/reload-policy.js +71 -0
- package/dist/dev/media/hls/reload-policy.js.map +1 -0
- package/dist/dev/media/live-window.js +36 -0
- package/dist/dev/media/live-window.js.map +1 -0
- package/dist/dev/media/primitives/select-tracks.js +1 -24
- package/dist/dev/media/primitives/select-tracks.js.map +1 -1
- package/dist/dev/media/types/index.d.ts +125 -9
- package/dist/dev/media/types/index.d.ts.map +1 -1
- package/dist/dev/media/types/index.js +15 -1
- package/dist/dev/media/types/index.js.map +1 -1
- package/dist/dev/media/utils/tracks.js +14 -0
- package/dist/dev/media/utils/tracks.js.map +1 -1
- package/dist/dev/mux-audio.d.ts +4 -0
- package/dist/dev/mux-audio.js +3 -0
- package/dist/dev/mux-background-video.d.ts +3 -0
- package/dist/dev/mux-background-video.js +3 -0
- package/dist/dev/mux-video.d.ts +4 -0
- package/dist/dev/mux-video.js +3 -0
- package/dist/dev/playback/adapters/hls-audio/adapter.d.ts +54 -0
- package/dist/dev/playback/adapters/hls-audio/adapter.d.ts.map +1 -0
- package/dist/dev/playback/adapters/hls-audio/adapter.js +186 -0
- package/dist/dev/playback/adapters/hls-audio/adapter.js.map +1 -0
- package/dist/dev/playback/adapters/hls-audio/media.d.ts +10 -0
- package/dist/dev/playback/adapters/hls-audio/media.d.ts.map +1 -0
- package/dist/dev/playback/adapters/hls-audio/media.js +9 -0
- package/dist/dev/playback/adapters/hls-audio/media.js.map +1 -0
- package/dist/dev/playback/adapters/hls-background-video/adapter.d.ts +59 -0
- package/dist/dev/playback/adapters/hls-background-video/adapter.d.ts.map +1 -0
- package/dist/dev/playback/adapters/hls-background-video/adapter.js +123 -0
- package/dist/dev/playback/adapters/hls-background-video/adapter.js.map +1 -0
- package/dist/dev/playback/adapters/hls-background-video/host.d.ts +38 -0
- package/dist/dev/playback/adapters/hls-background-video/host.d.ts.map +1 -0
- package/dist/dev/playback/adapters/hls-background-video/host.js +60 -0
- package/dist/dev/playback/adapters/hls-background-video/host.js.map +1 -0
- package/dist/dev/playback/adapters/hls-background-video/media.d.ts +20 -0
- package/dist/dev/playback/adapters/hls-background-video/media.d.ts.map +1 -0
- package/dist/dev/playback/adapters/hls-background-video/media.js +21 -0
- package/dist/dev/playback/adapters/hls-background-video/media.js.map +1 -0
- package/dist/dev/playback/adapters/hls-video/adapter.d.ts +63 -0
- package/dist/dev/playback/adapters/hls-video/adapter.d.ts.map +1 -0
- package/dist/dev/playback/adapters/hls-video/adapter.js +316 -0
- package/dist/dev/playback/adapters/hls-video/adapter.js.map +1 -0
- package/dist/dev/playback/adapters/hls-video/error-surface.d.ts +18 -0
- package/dist/dev/playback/adapters/hls-video/error-surface.d.ts.map +1 -0
- package/dist/dev/playback/adapters/hls-video/error-surface.js +51 -0
- package/dist/dev/playback/adapters/hls-video/error-surface.js.map +1 -0
- package/dist/dev/playback/adapters/hls-video/media-tracks.d.ts +22 -0
- package/dist/dev/playback/adapters/hls-video/media-tracks.d.ts.map +1 -0
- package/dist/dev/playback/adapters/hls-video/media-tracks.js +126 -0
- package/dist/dev/playback/adapters/hls-video/media-tracks.js.map +1 -0
- package/dist/dev/playback/adapters/hls-video/media.d.ts +10 -0
- package/dist/dev/playback/adapters/hls-video/media.d.ts.map +1 -0
- package/dist/dev/playback/adapters/hls-video/media.js +11 -0
- package/dist/dev/playback/adapters/hls-video/media.js.map +1 -0
- package/dist/dev/playback/adapters/mux-audio/media.d.ts +28 -0
- package/dist/dev/playback/adapters/mux-audio/media.d.ts.map +1 -0
- package/dist/dev/playback/adapters/mux-audio/media.js +26 -0
- package/dist/dev/playback/adapters/mux-audio/media.js.map +1 -0
- package/dist/dev/playback/adapters/mux-video/adapter.d.ts +33 -0
- package/dist/dev/playback/adapters/mux-video/adapter.d.ts.map +1 -0
- package/dist/dev/playback/adapters/mux-video/adapter.js +92 -0
- package/dist/dev/playback/adapters/mux-video/adapter.js.map +1 -0
- package/dist/dev/playback/adapters/mux-video/media.d.ts +24 -0
- package/dist/dev/playback/adapters/mux-video/media.d.ts.map +1 -0
- package/dist/dev/playback/adapters/mux-video/media.js +23 -0
- package/dist/dev/playback/adapters/mux-video/media.js.map +1 -0
- package/dist/dev/playback/behaviors/collect-errors.js +77 -0
- package/dist/dev/playback/behaviors/collect-errors.js.map +1 -0
- package/dist/dev/playback/behaviors/dom/end-of-stream.js +1 -0
- package/dist/dev/playback/behaviors/dom/end-of-stream.js.map +1 -1
- package/dist/dev/playback/behaviors/dom/seek-to-live-edge.js +132 -0
- package/dist/dev/playback/behaviors/dom/seek-to-live-edge.js.map +1 -0
- package/dist/dev/playback/behaviors/dom/sync-live-seekable-range.js +26 -0
- package/dist/dev/playback/behaviors/dom/sync-live-seekable-range.js.map +1 -0
- package/dist/dev/playback/behaviors/dom/update-mediasource-duration.js +29 -7
- package/dist/dev/playback/behaviors/dom/update-mediasource-duration.js.map +1 -1
- package/dist/dev/playback/behaviors/establish-start-media-time.d.ts +5 -0
- package/dist/dev/playback/behaviors/establish-start-media-time.d.ts.map +1 -1
- package/dist/dev/playback/behaviors/establish-start-media-time.js +78 -4
- package/dist/dev/playback/behaviors/establish-start-media-time.js.map +1 -1
- package/dist/dev/playback/behaviors/resolve-track.js +29 -8
- package/dist/dev/playback/behaviors/resolve-track.js.map +1 -1
- package/dist/dev/playback/behaviors/track-switching.js +18 -9
- package/dist/dev/playback/behaviors/track-switching.js.map +1 -1
- package/dist/dev/playback/engines/hls/engine-audio-only.d.ts +34 -17
- package/dist/dev/playback/engines/hls/engine-audio-only.d.ts.map +1 -1
- package/dist/dev/playback/engines/hls/engine-audio-only.js +9 -5
- package/dist/dev/playback/engines/hls/engine-audio-only.js.map +1 -1
- package/dist/dev/playback/engines/{background-video/engine.d.ts → hls/engine-background-video.d.ts} +7 -7
- package/dist/dev/playback/engines/hls/engine-background-video.d.ts.map +1 -0
- package/dist/{default/playback/engines/background-video/engine.js → dev/playback/engines/hls/engine-background-video.js} +3 -3
- package/dist/dev/playback/engines/hls/engine-background-video.js.map +1 -0
- package/dist/dev/playback/engines/hls/engine.d.ts +43 -15
- package/dist/dev/playback/engines/hls/engine.d.ts.map +1 -1
- package/dist/dev/playback/engines/hls/engine.js +19 -6
- package/dist/dev/playback/engines/hls/engine.js.map +1 -1
- package/dist/dev/playback/primitives/error-messages.js +39 -0
- package/dist/dev/playback/primitives/error-messages.js.map +1 -0
- package/dist/dev/playback/primitives/live-window.js +66 -0
- package/dist/dev/playback/primitives/live-window.js.map +1 -0
- package/dist/dev/playback/primitives/report-track-conditions.d.ts +11 -0
- package/dist/dev/playback/primitives/report-track-conditions.d.ts.map +1 -0
- package/dist/dev/playback/primitives/report-track-conditions.js +86 -0
- package/dist/dev/playback/primitives/report-track-conditions.js.map +1 -0
- package/package.json +32 -6
- package/dist/default/background-video.js +0 -3
- package/dist/default/playback/engines/background-video/adapter.js +0 -158
- package/dist/default/playback/engines/background-video/adapter.js.map +0 -1
- package/dist/default/playback/engines/background-video/engine.js.map +0 -1
- package/dist/default/playback/engines/hls/adapter-audio-only.js +0 -124
- package/dist/default/playback/engines/hls/adapter-audio-only.js.map +0 -1
- package/dist/default/playback/engines/hls/adapter.js +0 -120
- package/dist/default/playback/engines/hls/adapter.js.map +0 -1
- package/dist/dev/background-video.d.ts +0 -3
- package/dist/dev/background-video.js +0 -3
- package/dist/dev/playback/engines/background-video/adapter.d.ts +0 -59
- package/dist/dev/playback/engines/background-video/adapter.d.ts.map +0 -1
- package/dist/dev/playback/engines/background-video/adapter.js +0 -158
- package/dist/dev/playback/engines/background-video/adapter.js.map +0 -1
- package/dist/dev/playback/engines/background-video/engine.d.ts.map +0 -1
- package/dist/dev/playback/engines/background-video/engine.js.map +0 -1
- package/dist/dev/playback/engines/hls/adapter-audio-only.d.ts +0 -46
- package/dist/dev/playback/engines/hls/adapter-audio-only.d.ts.map +0 -1
- package/dist/dev/playback/engines/hls/adapter-audio-only.js +0 -124
- package/dist/dev/playback/engines/hls/adapter-audio-only.js.map +0 -1
- package/dist/dev/playback/engines/hls/adapter.d.ts +0 -42
- package/dist/dev/playback/engines/hls/adapter.d.ts.map +0 -1
- package/dist/dev/playback/engines/hls/adapter.js +0 -120
- package/dist/dev/playback/engines/hls/adapter.js.map +0 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { pickTrackUnderPixelArea } from "../../../media/primitives/select-tracks.js";
|
|
2
|
+
import { createBackgroundVideoEngine } from "../../engines/hls/engine-background-video.js";
|
|
3
|
+
//#region src/playback/adapters/hls-background-video/adapter.ts
|
|
4
|
+
const hlsBackgroundVideoMediaDefaultProps = { src: "" };
|
|
5
|
+
/**
|
|
6
|
+
* Mixin that adds the background-video SPF playback engine to any base class,
|
|
7
|
+
* for an HLS URL.
|
|
8
|
+
*
|
|
9
|
+
* `src` is the whole surface, and the picker always pins the top rendition on
|
|
10
|
+
* offer. There is no cap of its own because the manifest is the better place to
|
|
11
|
+
* narrow one: a delivery param — `?max_resolution=720p` on a Mux stream URL, for
|
|
12
|
+
* one — keeps the renditions it excludes out of the manifest entirely, rather
|
|
13
|
+
* than fetched-then-unpicked. Deriving a cap from the screen instead is on the
|
|
14
|
+
* roadmap, and lands here when it does.
|
|
15
|
+
*
|
|
16
|
+
* `@videojs/spf/mux-background-video` is this same Media under a Mux-flavored
|
|
17
|
+
* name — an alias, not a variant. Nothing about the surface changes with the
|
|
18
|
+
* import path.
|
|
19
|
+
*
|
|
20
|
+
* Everything else the use case fixes rather than exposes: video-only, looping,
|
|
21
|
+
* muted, autoplaying, loading as soon as there is a source. `attach` writes that
|
|
22
|
+
* onto the element and nothing here declares `loop` / `muted` / `autoplay` /
|
|
23
|
+
* `preload` of its own — a host-bound Media inherits all four from the host
|
|
24
|
+
* already, and shadowing them with fixed values would only make reads describe
|
|
25
|
+
* an intention rather than what the element is doing.
|
|
26
|
+
*
|
|
27
|
+
* A new src re-resolves the presentation, tearing down the state, SourceBuffers,
|
|
28
|
+
* and in-flight requests the previous one built before the next begins. The
|
|
29
|
+
* engine instance and the attached media element are both kept, so neither has to
|
|
30
|
+
* be rewired.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* class HlsBackgroundVideoMedia extends HlsBackgroundVideoMediaMixin(BackgroundVideoHost) {}
|
|
34
|
+
*
|
|
35
|
+
* const media = new HlsBackgroundVideoMedia();
|
|
36
|
+
* media.attach(document.querySelector('video'));
|
|
37
|
+
* media.src = 'https://stream.mux.com/PLAYBACK_ID.m3u8?max_resolution=720p';
|
|
38
|
+
* media.play();
|
|
39
|
+
*/
|
|
40
|
+
function HlsBackgroundVideoMediaMixin(BaseClass) {
|
|
41
|
+
class HlsBackgroundVideoMediaImpl extends BaseClass {
|
|
42
|
+
#engine;
|
|
43
|
+
#config;
|
|
44
|
+
#signals;
|
|
45
|
+
/** Pending loadstart listener from a deferred play() retry, if any. */
|
|
46
|
+
#loadstartListener = null;
|
|
47
|
+
constructor(...args) {
|
|
48
|
+
super(...args);
|
|
49
|
+
const { config } = args?.[0] ?? {};
|
|
50
|
+
this.#config = config;
|
|
51
|
+
this.#engine = this.#createEngine();
|
|
52
|
+
}
|
|
53
|
+
get engine() {
|
|
54
|
+
return this.#engine;
|
|
55
|
+
}
|
|
56
|
+
attach(mediaElement) {
|
|
57
|
+
super.attach?.(mediaElement);
|
|
58
|
+
mediaElement.loop = true;
|
|
59
|
+
mediaElement.muted = true;
|
|
60
|
+
mediaElement.autoplay = true;
|
|
61
|
+
mediaElement.preload = "auto";
|
|
62
|
+
this.#signals.context.mediaElement.set(mediaElement);
|
|
63
|
+
}
|
|
64
|
+
detach() {
|
|
65
|
+
this.#cancelPendingPlay();
|
|
66
|
+
this.#signals.context.mediaElement.set(void 0);
|
|
67
|
+
super.detach?.();
|
|
68
|
+
}
|
|
69
|
+
destroy() {
|
|
70
|
+
this.#cancelPendingPlay();
|
|
71
|
+
this.#engine.destroy();
|
|
72
|
+
}
|
|
73
|
+
get src() {
|
|
74
|
+
return this.#signals.state.presentation.get()?.url ?? "";
|
|
75
|
+
}
|
|
76
|
+
set src(value) {
|
|
77
|
+
if (value === this.src) return;
|
|
78
|
+
this.#cancelPendingPlay();
|
|
79
|
+
this.#signals.state.presentation.set(value ? { url: value } : void 0);
|
|
80
|
+
}
|
|
81
|
+
async play() {
|
|
82
|
+
const mediaElement = this.#signals.context.mediaElement.get();
|
|
83
|
+
if (!mediaElement) return Promise.reject(/* @__PURE__ */ new Error("HlsBackgroundVideoMediaElement: no media element attached"));
|
|
84
|
+
try {
|
|
85
|
+
return await mediaElement.play();
|
|
86
|
+
} catch (err) {
|
|
87
|
+
if (this.src) return new Promise((resolve, reject) => {
|
|
88
|
+
const listener = () => {
|
|
89
|
+
this.#loadstartListener = null;
|
|
90
|
+
mediaElement.play().then(resolve, reject);
|
|
91
|
+
};
|
|
92
|
+
this.#loadstartListener = listener;
|
|
93
|
+
mediaElement.addEventListener("loadstart", listener, { once: true });
|
|
94
|
+
});
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
#createEngine() {
|
|
99
|
+
const adapterPicker = (presentation) => {
|
|
100
|
+
return pickTrackUnderPixelArea((presentation.selectionSets?.find((s) => s.type === "video"))?.switchingSets[0]?.tracks ?? [])?.id;
|
|
101
|
+
};
|
|
102
|
+
return createBackgroundVideoEngine({
|
|
103
|
+
picker: adapterPicker,
|
|
104
|
+
...this.#config,
|
|
105
|
+
onSignalsReady: (signals) => {
|
|
106
|
+
this.#signals = signals;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
#cancelPendingPlay() {
|
|
111
|
+
if (!this.#loadstartListener) return;
|
|
112
|
+
this.#signals.context.mediaElement.get()?.removeEventListener("loadstart", this.#loadstartListener);
|
|
113
|
+
this.#loadstartListener = null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return HlsBackgroundVideoMediaImpl;
|
|
117
|
+
}
|
|
118
|
+
/** Standalone SPF background-video adapter with no base class. */
|
|
119
|
+
var HlsBackgroundVideoMediaElement = class extends HlsBackgroundVideoMediaMixin(class {}) {};
|
|
120
|
+
//#endregion
|
|
121
|
+
export { HlsBackgroundVideoMediaElement, HlsBackgroundVideoMediaMixin, hlsBackgroundVideoMediaDefaultProps };
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","names":["#config","#engine","#createEngine","#signals","#cancelPendingPlay","#loadstartListener"],"sources":["../../../../../src/playback/adapters/hls-background-video/adapter.ts"],"sourcesContent":["import type { Constructor, MixinReturn } from '@videojs/utils/types';\nimport type { Composition } from '../../../core/composition/create-composition';\nimport { pickTrackUnderPixelArea, type TrackPicker } from '../../../media/primitives/select-tracks';\nimport type { VideoSelectionSet } from '../../../media/types';\nimport {\n type BackgroundVideoEngineConfig,\n type BackgroundVideoEngineContext,\n type BackgroundVideoEngineSignals,\n type BackgroundVideoEngineState,\n createBackgroundVideoEngine,\n} from '../../engines/hls/engine-background-video';\n\nexport interface HlsBackgroundVideoMediaProps {\n src: string;\n}\n\nexport const hlsBackgroundVideoMediaDefaultProps: HlsBackgroundVideoMediaProps = {\n src: '',\n};\n\nexport interface HlsBackgroundVideoMediaAPI extends HlsBackgroundVideoMediaProps {\n readonly engine: Composition<BackgroundVideoEngineState, BackgroundVideoEngineContext>;\n attach(mediaElement: HTMLMediaElement): void;\n detach(): void;\n destroy(): void;\n play(): Promise<void>;\n}\n\n/**\n * Mixin that adds the background-video SPF playback engine to any base class,\n * for an HLS URL.\n *\n * `src` is the whole surface, and the picker always pins the top rendition on\n * offer. There is no cap of its own because the manifest is the better place to\n * narrow one: a delivery param — `?max_resolution=720p` on a Mux stream URL, for\n * one — keeps the renditions it excludes out of the manifest entirely, rather\n * than fetched-then-unpicked. Deriving a cap from the screen instead is on the\n * roadmap, and lands here when it does.\n *\n * `@videojs/spf/mux-background-video` is this same Media under a Mux-flavored\n * name — an alias, not a variant. Nothing about the surface changes with the\n * import path.\n *\n * Everything else the use case fixes rather than exposes: video-only, looping,\n * muted, autoplaying, loading as soon as there is a source. `attach` writes that\n * onto the element and nothing here declares `loop` / `muted` / `autoplay` /\n * `preload` of its own — a host-bound Media inherits all four from the host\n * already, and shadowing them with fixed values would only make reads describe\n * an intention rather than what the element is doing.\n *\n * A new src re-resolves the presentation, tearing down the state, SourceBuffers,\n * and in-flight requests the previous one built before the next begins. The\n * engine instance and the attached media element are both kept, so neither has to\n * be rewired.\n *\n * @example\n * class HlsBackgroundVideoMedia extends HlsBackgroundVideoMediaMixin(BackgroundVideoHost) {}\n *\n * const media = new HlsBackgroundVideoMedia();\n * media.attach(document.querySelector('video'));\n * media.src = 'https://stream.mux.com/PLAYBACK_ID.m3u8?max_resolution=720p';\n * media.play();\n */\nexport function HlsBackgroundVideoMediaMixin<Base extends Constructor<any>>(BaseClass: Base) {\n class HlsBackgroundVideoMediaImpl extends BaseClass {\n #engine: Composition<BackgroundVideoEngineState, BackgroundVideoEngineContext>;\n #config: BackgroundVideoEngineConfig;\n #signals!: BackgroundVideoEngineSignals;\n\n /** Pending loadstart listener from a deferred play() retry, if any. */\n #loadstartListener: (() => void) | null = null;\n\n constructor(...args: any[]) {\n super(...args);\n\n const { config } = args?.[0] ?? {};\n this.#config = config;\n this.#engine = this.#createEngine();\n }\n\n get engine(): Composition<BackgroundVideoEngineState, BackgroundVideoEngineContext> {\n return this.#engine;\n }\n\n // -------------------------------------------------------------------------\n // Media element lifecycle\n // -------------------------------------------------------------------------\n\n attach(mediaElement: HTMLMediaElement): void {\n super.attach?.(mediaElement);\n // The one place the fixed behavior is stated. Muted and autoplay are what\n // let it start without a gesture, loop is the defining behavior, and\n // `preload` says out loud what the engine does regardless — it subtracts\n // preload monitoring and loads from the moment it has a source.\n mediaElement.loop = true;\n mediaElement.muted = true;\n mediaElement.autoplay = true;\n mediaElement.preload = 'auto';\n\n this.#signals.context.mediaElement.set(mediaElement);\n }\n\n detach(): void {\n this.#cancelPendingPlay();\n this.#signals.context.mediaElement.set(undefined);\n super.detach?.();\n }\n\n destroy(): void {\n this.#cancelPendingPlay();\n this.#engine.destroy();\n }\n\n // -------------------------------------------------------------------------\n // src — synchronous IDL attribute (WHATWG §4.8.11.2)\n // -------------------------------------------------------------------------\n\n get src(): string {\n return this.#signals.state.presentation.get()?.url ?? '';\n }\n\n set src(value: string) {\n // Same line the HLS Medias draw: the presentation is set from a fresh\n // object every time, so re-resolving a URL already playing would restart\n // it for no reason.\n if (value === this.src) return;\n\n this.#cancelPendingPlay();\n this.#signals.state.presentation.set(value ? { url: value } : undefined);\n }\n\n // -------------------------------------------------------------------------\n // play() — WHATWG §4.8.11.8\n // Delegates to the attached media element's native play().\n // -------------------------------------------------------------------------\n\n async play(): Promise<void> {\n const mediaElement = this.#signals.context.mediaElement.get();\n if (!mediaElement) {\n return Promise.reject(new Error('HlsBackgroundVideoMediaElement: no media element attached'));\n }\n\n try {\n return await mediaElement.play();\n } catch (err) {\n // If we have a pending HLS source, the rejection may be because MSE\n // hasn't attached a blob URL yet. Wait for loadstart (src assigned by\n // MSE setup) and retry once.\n if (this.src) {\n return new Promise<void>((resolve, reject) => {\n const listener = () => {\n this.#loadstartListener = null;\n mediaElement.play().then(resolve, reject);\n };\n this.#loadstartListener = listener;\n mediaElement.addEventListener('loadstart', listener, { once: true });\n });\n }\n throw err;\n }\n }\n\n // -------------------------------------------------------------------------\n // Private\n // -------------------------------------------------------------------------\n\n #createEngine(): Composition<BackgroundVideoEngineState, BackgroundVideoEngineContext> {\n // No cap to apply, so the pick is whichever rendition is largest. Passing\n // no maximum is what makes that the answer, rather than a rule of its own.\n const adapterPicker: TrackPicker = (presentation) => {\n const videoSet = presentation.selectionSets?.find((s) => s.type === 'video') as VideoSelectionSet | undefined;\n const tracks = videoSet?.switchingSets[0]?.tracks ?? [];\n return pickTrackUnderPixelArea(tracks)?.id;\n };\n\n return createBackgroundVideoEngine({\n picker: adapterPicker,\n ...this.#config,\n onSignalsReady: (signals) => {\n this.#signals = signals;\n },\n });\n }\n\n #cancelPendingPlay(): void {\n if (!this.#loadstartListener) return;\n const mediaElement = this.#signals.context.mediaElement.get();\n mediaElement?.removeEventListener('loadstart', this.#loadstartListener);\n this.#loadstartListener = null;\n }\n }\n\n return HlsBackgroundVideoMediaImpl as unknown as MixinReturn<Base, HlsBackgroundVideoMediaAPI>;\n}\n\n/** Standalone SPF background-video adapter with no base class. */\nexport class HlsBackgroundVideoMediaElement extends HlsBackgroundVideoMediaMixin(class {}) {}\n"],"mappings":";;;AAgBA,MAAa,sCAAoE,EAC/E,KAAK,GACP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,6BAA4D,WAAiB;CAC3F,MAAM,oCAAoC,UAAU;EAClD;EACA;EACA;;EAGA,qBAA0C;EAE1C,YAAY,GAAG,MAAa;GAC1B,MAAM,GAAG,IAAI;GAEb,MAAM,EAAE,WAAW,OAAO,MAAM,CAAC;GACjC,KAAKA,UAAU;GACf,KAAKC,UAAU,KAAKC,cAAc;EACpC;EAEA,IAAI,SAAgF;GAClF,OAAO,KAAKD;EACd;EAMA,OAAO,cAAsC;GAC3C,MAAM,SAAS,YAAY;GAK3B,aAAa,OAAO;GACpB,aAAa,QAAQ;GACrB,aAAa,WAAW;GACxB,aAAa,UAAU;GAEvB,KAAKE,SAAS,QAAQ,aAAa,IAAI,YAAY;EACrD;EAEA,SAAe;GACb,KAAKC,mBAAmB;GACxB,KAAKD,SAAS,QAAQ,aAAa,IAAI,KAAA,CAAS;GAChD,MAAM,SAAS;EACjB;EAEA,UAAgB;GACd,KAAKC,mBAAmB;GACxB,KAAKH,QAAQ,QAAQ;EACvB;EAMA,IAAI,MAAc;GAChB,OAAO,KAAKE,SAAS,MAAM,aAAa,IAAI,CAAC,EAAE,OAAO;EACxD;EAEA,IA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ts
|
|
2
|
+
/**
|
|
3
|
+
* The `<video>` binding a background video uses: somewhere to keep the attached
|
|
4
|
+
* element, and the four properties the Media fixes on it.
|
|
5
|
+
*
|
|
6
|
+
* That is the whole surface anything here reaches. The engine drives playback,
|
|
7
|
+
* the element exposes `src` and nothing else, and the background player
|
|
8
|
+
* subscribes to no store features, so nothing asks a background video for
|
|
9
|
+
* `currentTime`, `play()`, picture-in-picture, fullscreen, forwarded events, or
|
|
10
|
+
* media components. Holding the host to what is reachable is what keeps this
|
|
11
|
+
* entry free of `@videojs/media`, and small enough to suit a component whose
|
|
12
|
+
* whole pitch is its size.
|
|
13
|
+
*
|
|
14
|
+
* An `EventTarget`, because a Media is one: the store and the element layers
|
|
15
|
+
* take anything they attach as an event source, and inheriting the three methods
|
|
16
|
+
* satisfies that for free rather than by stubbing them.
|
|
17
|
+
*
|
|
18
|
+
* ⚠️ It still implements too little to carry the rest of the media surface, which
|
|
19
|
+
* bounds what may consume it: a store feature reading a property outside this set
|
|
20
|
+
* gets `undefined` rather than an error. A Media needing more of that surface
|
|
21
|
+
* belongs on a host that provides it.
|
|
22
|
+
*/
|
|
23
|
+
var BackgroundVideoHost = class extends EventTarget {
|
|
24
|
+
#target = null;
|
|
25
|
+
attach(target) {
|
|
26
|
+
if (!target || this.#target === target) return;
|
|
27
|
+
this.#target = target;
|
|
28
|
+
}
|
|
29
|
+
detach() {
|
|
30
|
+
this.#target = null;
|
|
31
|
+
}
|
|
32
|
+
get loop() {
|
|
33
|
+
return this.#target?.loop ?? false;
|
|
34
|
+
}
|
|
35
|
+
set loop(value) {
|
|
36
|
+
if (this.#target) this.#target.loop = value;
|
|
37
|
+
}
|
|
38
|
+
get muted() {
|
|
39
|
+
return this.#target?.muted ?? false;
|
|
40
|
+
}
|
|
41
|
+
set muted(value) {
|
|
42
|
+
if (this.#target) this.#target.muted = value;
|
|
43
|
+
}
|
|
44
|
+
get autoplay() {
|
|
45
|
+
return this.#target?.autoplay ?? false;
|
|
46
|
+
}
|
|
47
|
+
set autoplay(value) {
|
|
48
|
+
if (this.#target) this.#target.autoplay = value;
|
|
49
|
+
}
|
|
50
|
+
get preload() {
|
|
51
|
+
return this.#target?.preload ?? "metadata";
|
|
52
|
+
}
|
|
53
|
+
set preload(value) {
|
|
54
|
+
if (this.#target) this.#target.preload = value;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { BackgroundVideoHost };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","names":["#target"],"sources":["../../../../../src/playback/adapters/hls-background-video/host.ts"],"sourcesContent":["/**\n * The `<video>` binding a background video uses: somewhere to keep the attached\n * element, and the four properties the Media fixes on it.\n *\n * That is the whole surface anything here reaches. The engine drives playback,\n * the element exposes `src` and nothing else, and the background player\n * subscribes to no store features, so nothing asks a background video for\n * `currentTime`, `play()`, picture-in-picture, fullscreen, forwarded events, or\n * media components. Holding the host to what is reachable is what keeps this\n * entry free of `@videojs/media`, and small enough to suit a component whose\n * whole pitch is its size.\n *\n * An `EventTarget`, because a Media is one: the store and the element layers\n * take anything they attach as an event source, and inheriting the three methods\n * satisfies that for free rather than by stubbing them.\n *\n * ⚠️ It still implements too little to carry the rest of the media surface, which\n * bounds what may consume it: a store feature reading a property outside this set\n * gets `undefined` rather than an error. A Media needing more of that surface\n * belongs on a host that provides it.\n */\nexport class BackgroundVideoHost extends EventTarget {\n #target: HTMLVideoElement | null = null;\n\n attach(target: HTMLVideoElement): void {\n if (!target || this.#target === target) return;\n this.#target = target;\n }\n\n detach(): void {\n this.#target = null;\n }\n\n // Read back off the element rather than stored, so they describe what is\n // playing instead of what was asked for — see the adapter's note on why the\n // Media declares none of these itself.\n get loop(): boolean {\n return this.#target?.loop ?? false;\n }\n\n set loop(value: boolean) {\n if (this.#target) this.#target.loop = value;\n }\n\n get muted(): boolean {\n return this.#target?.muted ?? false;\n }\n\n set muted(value: boolean) {\n if (this.#target) this.#target.muted = value;\n }\n\n get autoplay(): boolean {\n return this.#target?.autoplay ?? false;\n }\n\n set autoplay(value: boolean) {\n if (this.#target) this.#target.autoplay = value;\n }\n\n get preload(): HTMLVideoElement['preload'] {\n return this.#target?.preload ?? 'metadata';\n }\n\n set preload(value: HTMLVideoElement['preload']) {\n if (this.#target) this.#target.preload = value;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,sBAAb,cAAyC,YAAY;CACnD,UAAmC;CAEnC,OAAO,QAAgC;EACrC,IAAI,CAAC,UAAU,KAAKA,YAAY,QAAQ;EACxC,KAAKA,UAAU;CACjB;CAEA,SAAe;EACb,KAAKA,UAAU;CACjB;CAKA,IAAI,OAAgB;EAClB,OAAO,KAAKA,SAAS,QAAQ;CAC/B;CAEA,IAAI,KAAK,OAAgB;EACvB,IAAI,KAAKA,SAAS,KAAKA,QAAQ,OAAO;CACxC;CAEA,IAAI,QAAiB;EACnB,OAAO,KAAKA,SAAS,SAAS;CAChC;CAEA,IAAI,MAAM,OAAgB;EACxB,IAAI,KAAKA,SAAS,KAAKA,QAAQ,QAAQ;CACzC;CAEA,IAAI,WAAoB;EACtB,OAAO,KAAKA,SAAS,YAAY;CACnC;CAEA,IAAI,SAAS,OAAgB;EAC3B,IAAI,KAAKA,SAAS,KAAKA,QAAQ,WAAW;CAC5C;CAEA,IAAI,UAAuC;EACzC,OAAO,KAAKA,SAAS,WAAW;CAClC;CAEA,IAAI,QAAQ,OAAoC;EAC9C,IAAI,KAAKA,SAAS,KAAKA,QAAQ,UAAU;CAC3C;AACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HlsBackgroundVideoMediaMixin } from "./adapter.js";
|
|
2
|
+
import { BackgroundVideoHost } from "./host.js";
|
|
3
|
+
//#region src/playback/adapters/hls-background-video/media.ts
|
|
4
|
+
const HlsBackgroundVideoMediaBase = HlsBackgroundVideoMediaMixin(BackgroundVideoHost);
|
|
5
|
+
/**
|
|
6
|
+
* The background-video Media, bound to a `<video>` through
|
|
7
|
+
* {@link BackgroundVideoHost}.
|
|
8
|
+
*
|
|
9
|
+
* That host carries the attached element and the four properties `attach` fixes,
|
|
10
|
+
* which is all this Media's surface needs, and it is local — so this entry has
|
|
11
|
+
* no `@videojs/media` dependency.
|
|
12
|
+
*
|
|
13
|
+
* No `MediaTracksMixin`, unlike `HlsVideoMedia`: the engine subtracts audio and
|
|
14
|
+
* text entirely and pins one video rendition for the session, so there are no
|
|
15
|
+
* track lists for a consumer to project or switch between.
|
|
16
|
+
*/
|
|
17
|
+
var HlsBackgroundVideoMedia = class extends HlsBackgroundVideoMediaBase {};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { HlsBackgroundVideoMedia };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=media.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.js","names":[],"sources":["../../../../../src/playback/adapters/hls-background-video/media.ts"],"sourcesContent":["import { HlsBackgroundVideoMediaMixin } from './adapter';\nimport { BackgroundVideoHost } from './host';\n\nconst HlsBackgroundVideoMediaBase = HlsBackgroundVideoMediaMixin(BackgroundVideoHost);\n\n/**\n * The background-video Media, bound to a `<video>` through\n * {@link BackgroundVideoHost}.\n *\n * That host carries the attached element and the four properties `attach` fixes,\n * which is all this Media's surface needs, and it is local — so this entry has\n * no `@videojs/media` dependency.\n *\n * No `MediaTracksMixin`, unlike `HlsVideoMedia`: the engine subtracts audio and\n * text entirely and pins one video rendition for the session, so there are no\n * track lists for a consumer to project or switch between.\n */\nexport class HlsBackgroundVideoMedia extends HlsBackgroundVideoMediaBase {}\n"],"mappings":";;;AAGA,MAAM,8BAA8B,6BAA6B,mBAAmB;;;;;;;;;;;;;AAcpF,IAAa,0BAAb,cAA6C,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { effect } from "../../../core/signals/effect.js";
|
|
2
|
+
import { deriveStreamType, getMediaPlaylistMetadata, isResolvedPresentation, isResolvedTrack } from "../../../media/types/index.js";
|
|
3
|
+
import { findTrackById } from "../../../media/utils/tracks.js";
|
|
4
|
+
import { SVTA_NO_SUPPORTED_AUDIO_TRACK, SVTA_NO_SUPPORTED_VIDEO_TRACK, SVTA_UNSUPPORTED_PLAYBACK_FEATURE } from "../../../media/errors.js";
|
|
5
|
+
import { resolveLiveLatency } from "../../../media/hls/reload-policy.js";
|
|
6
|
+
import { getLiveEdge, liveTrackId } from "../../primitives/live-window.js";
|
|
7
|
+
import { createHlsVideoEngine } from "../../engines/hls/engine.js";
|
|
8
|
+
import { DVR_EXPERIMENTAL_MESSAGE, LOW_LATENCY_UNSUPPORTED_MESSAGE, UNSUPPORTED_PLAYBACK_FEATURE_MESSAGE } from "../../primitives/error-messages.js";
|
|
9
|
+
import { firstFatal, hasUnsupportedFeatureCause, withAlternativeMediaSuggestion } from "./error-surface.js";
|
|
10
|
+
import { MediaStreamTypes } from "@videojs/media";
|
|
11
|
+
//#region src/playback/adapters/hls-video/adapter.ts
|
|
12
|
+
const hlsVideoMediaDefaultProps = {
|
|
13
|
+
src: "",
|
|
14
|
+
preload: "",
|
|
15
|
+
disableRemotePlayback: false,
|
|
16
|
+
streamType: MediaStreamTypes.UNKNOWN
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* `targetLiveWindow` per the media-ui-extensions live-edge proposal: `NaN` for
|
|
20
|
+
* on-demand (or nothing resolved yet), `0` for standard sliding-window live,
|
|
21
|
+
* `Infinity` for DVR (`#EXT-X-PLAYLIST-TYPE:EVENT` — the window grows from the
|
|
22
|
+
* start). Read from the timeline-bearing track's playlist metadata.
|
|
23
|
+
*/
|
|
24
|
+
function deriveTargetLiveWindow(presentation, trackId) {
|
|
25
|
+
if (!isResolvedPresentation(presentation) || !trackId) return NaN;
|
|
26
|
+
const track = findTrackById(presentation, trackId);
|
|
27
|
+
if (!track || !isResolvedTrack(track)) return NaN;
|
|
28
|
+
const metadata = getMediaPlaylistMetadata(track);
|
|
29
|
+
if (!metadata) return NaN;
|
|
30
|
+
if (metadata.playlistType === "EVENT") return Number.POSITIVE_INFINITY;
|
|
31
|
+
return deriveStreamType(metadata) === "live" ? 0 : NaN;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Which reported conditions this composition treats as **fatal** — the ones that
|
|
35
|
+
* reach `error` and fire `'error'`. Severity isn't part of an SVTA code
|
|
36
|
+
* (§Approach: "impact varies with player implementation"), and here it also
|
|
37
|
+
* varies by composition, so it's decided at this boundary rather than by the
|
|
38
|
+
* reporter.
|
|
39
|
+
*
|
|
40
|
+
* An allow-list, deliberately: only *verdicts* are here. The per-rendition causes
|
|
41
|
+
* `resolve-track` reports (unsupported format, unsupported DRM) stay in the
|
|
42
|
+
* sequence as context — one unplayable rendition doesn't fail the source, and
|
|
43
|
+
* promoting a cause would put a dialog over a mixed source that goes on to play.
|
|
44
|
+
*/
|
|
45
|
+
const FATAL_SVTA_CODES = /* @__PURE__ */ new Set([SVTA_NO_SUPPORTED_VIDEO_TRACK, SVTA_NO_SUPPORTED_AUDIO_TRACK]);
|
|
46
|
+
/**
|
|
47
|
+
* Mixin that adds SPF playback engine behavior to any base class.
|
|
48
|
+
*
|
|
49
|
+
* Implements the src/play() contract per the WHATWG HTML spec so that SPF can
|
|
50
|
+
* be used anywhere a media element API is expected.
|
|
51
|
+
*
|
|
52
|
+
* A single engine instance is created at construction and recycled across src
|
|
53
|
+
* changes.
|
|
54
|
+
*
|
|
55
|
+
* @fires streamtypechange - Fired when the detected stream type changes. Read `streamType` for the new value.
|
|
56
|
+
* @fires targetlivewindowchange - Fired when the target live window changes. Read `targetLiveWindow` for the new value.
|
|
57
|
+
* @fires error - Fired when a fatal condition is reported. Read `error` for it.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* class HlsVideoMedia extends HlsVideoMediaMixin(HTMLVideoElementHost) {}
|
|
61
|
+
*
|
|
62
|
+
* const media = new HlsVideoMedia();
|
|
63
|
+
* media.attach(document.querySelector('video'));
|
|
64
|
+
* media.src = 'https://stream.mux.com/abc123.m3u8';
|
|
65
|
+
*/
|
|
66
|
+
function HlsVideoMediaMixin(BaseClass) {
|
|
67
|
+
class HlsVideoMediaImpl extends BaseClass {
|
|
68
|
+
/**
|
|
69
|
+
* A complete sentence naming the Media to reach for when this one can't play
|
|
70
|
+
* a source — `Try the hls.js-backed Mux media instead: import the hls-js
|
|
71
|
+
* flavor in place of the spf one.` Appended to the copy this adapter
|
|
72
|
+
* surfaces, and to the notices it logs. Name the flavor, not an import path:
|
|
73
|
+
* a Media is reached through several packages, each with its own counterpart.
|
|
74
|
+
*
|
|
75
|
+
* Empty here: `hls-video` has no better-equipped sibling to point at.
|
|
76
|
+
* A Media that does (a Mux Video built on this engine, whose hls.js-backed
|
|
77
|
+
* counterpart plays MPEG-TS and DRM) overrides this static, and its copy gains
|
|
78
|
+
* the second sentence with no other change.
|
|
79
|
+
*/
|
|
80
|
+
static get alternativeMediaSuggestion() {}
|
|
81
|
+
#engine;
|
|
82
|
+
#config;
|
|
83
|
+
#signals;
|
|
84
|
+
#preload = hlsVideoMediaDefaultProps.preload;
|
|
85
|
+
#disableRemotePlayback = hlsVideoMediaDefaultProps.disableRemotePlayback;
|
|
86
|
+
#streamType = hlsVideoMediaDefaultProps.streamType;
|
|
87
|
+
#isUserStreamType = false;
|
|
88
|
+
#targetLiveWindow = NaN;
|
|
89
|
+
#error = null;
|
|
90
|
+
/**
|
|
91
|
+
* The *reported* condition currently surfaced, which is what the re-fire
|
|
92
|
+
* latch keys on. Not `#error.code`: that's the code this adapter chose to
|
|
93
|
+
* surface, and a later cause can change the choice for a condition already
|
|
94
|
+
* announced.
|
|
95
|
+
*/
|
|
96
|
+
#reportedCode = null;
|
|
97
|
+
/** Notices already logged for the current source; cleared when it unloads. */
|
|
98
|
+
#noticed = /* @__PURE__ */ new Set();
|
|
99
|
+
#stopLiveSync;
|
|
100
|
+
#stopErrorSync;
|
|
101
|
+
/** Pending loadstart listener from a deferred play() retry, if any. */
|
|
102
|
+
#loadstartListener = null;
|
|
103
|
+
constructor(...args) {
|
|
104
|
+
super(...args);
|
|
105
|
+
const { config } = args?.[0] ?? {};
|
|
106
|
+
this.#config = config;
|
|
107
|
+
this.#engine = this.#createEngine();
|
|
108
|
+
this.#stopLiveSync = effect(() => {
|
|
109
|
+
const presentation = this.#signals.state.presentation.get();
|
|
110
|
+
this.#setDetectedStreamType(presentation?.streamType ?? MediaStreamTypes.UNKNOWN);
|
|
111
|
+
this.#setTargetLiveWindow(deriveTargetLiveWindow(presentation, liveTrackId(this.#signals.state)));
|
|
112
|
+
this.#reportDeliveryNotices(presentation);
|
|
113
|
+
});
|
|
114
|
+
this.#stopErrorSync = effect(() => {
|
|
115
|
+
const errors = this.#signals.state.errors.get();
|
|
116
|
+
this.#setError(firstFatal(errors, FATAL_SVTA_CODES), errors);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Underlying playback engine — the low-level SPF reactive composition that
|
|
121
|
+
* drives playback. An advanced escape hatch for direct engine access;
|
|
122
|
+
* normal playback is driven through this element's own properties and
|
|
123
|
+
* methods.
|
|
124
|
+
*/
|
|
125
|
+
get engine() {
|
|
126
|
+
return this.#engine;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The current fatal error, or `null`. Only *fatal* conditions appear here —
|
|
130
|
+
* the engine reports non-fatal ones too (they stay in `engine.state.errors`),
|
|
131
|
+
* and promoting them would tell a consumer playback had failed when it
|
|
132
|
+
* hadn't. Resets per source. Fires `'error'` when set.
|
|
133
|
+
*/
|
|
134
|
+
get error() {
|
|
135
|
+
return this.#error;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The source's stream type — `'live'`, `'on-demand'`, or `'unknown'` until
|
|
139
|
+
* a media playlist has been parsed. Setting a non-`'unknown'` value pins a
|
|
140
|
+
* user override (detection stops updating it); setting `'unknown'` reverts
|
|
141
|
+
* to the engine's detected value.
|
|
142
|
+
*/
|
|
143
|
+
get streamType() {
|
|
144
|
+
return this.#streamType;
|
|
145
|
+
}
|
|
146
|
+
set streamType(value) {
|
|
147
|
+
if (value === MediaStreamTypes.UNKNOWN) {
|
|
148
|
+
this.#isUserStreamType = false;
|
|
149
|
+
this.#updateStreamType(this.#signals.state.presentation.get()?.streamType ?? MediaStreamTypes.UNKNOWN);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
this.#isUserStreamType = true;
|
|
153
|
+
this.#updateStreamType(value);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Presentation time marking the start of the live-edge window — playback at
|
|
157
|
+
* `currentTime >= liveEdgeStart` counts as "at the live edge" (the same
|
|
158
|
+
* target the engine's `seekToLiveEdge` seeks to: window end − HOLD-BACK).
|
|
159
|
+
* `NaN` when the stream isn't live or nothing is resolved yet. Derived at
|
|
160
|
+
* read time from the engine's live window — no change event; re-read on
|
|
161
|
+
* `timeupdate`/`progress` (as the store's live feature does).
|
|
162
|
+
*/
|
|
163
|
+
get liveEdgeStart() {
|
|
164
|
+
return getLiveEdge({
|
|
165
|
+
state: this.#signals.state,
|
|
166
|
+
config: { resolveLiveLatency }
|
|
167
|
+
})?.liveEdgeStart ?? NaN;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The target live window: `NaN` for on-demand (or unknown), `0` for
|
|
171
|
+
* standard sliding-window live, `Infinity` for DVR
|
|
172
|
+
* (`#EXT-X-PLAYLIST-TYPE:EVENT`). Fires `targetlivewindowchange` on change.
|
|
173
|
+
*/
|
|
174
|
+
get targetLiveWindow() {
|
|
175
|
+
return this.#targetLiveWindow;
|
|
176
|
+
}
|
|
177
|
+
#setDetectedStreamType(value) {
|
|
178
|
+
if (this.#isUserStreamType) return;
|
|
179
|
+
this.#updateStreamType(value);
|
|
180
|
+
}
|
|
181
|
+
#updateStreamType(value) {
|
|
182
|
+
if (this.#streamType === value) return;
|
|
183
|
+
this.#streamType = value;
|
|
184
|
+
this.dispatchEvent?.(new Event("streamtypechange"));
|
|
185
|
+
}
|
|
186
|
+
#setTargetLiveWindow(value) {
|
|
187
|
+
if (Object.is(this.#targetLiveWindow, value)) return;
|
|
188
|
+
this.#targetLiveWindow = value;
|
|
189
|
+
this.dispatchEvent?.(new Event("targetlivewindowchange"));
|
|
190
|
+
}
|
|
191
|
+
#setError(reported, errors) {
|
|
192
|
+
if (!reported) {
|
|
193
|
+
this.#error = null;
|
|
194
|
+
this.#reportedCode = null;
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (this.#reportedCode === reported.code) return;
|
|
198
|
+
this.#reportedCode = reported.code;
|
|
199
|
+
const unsupported = hasUnsupportedFeatureCause(errors);
|
|
200
|
+
if (unsupported) console.error(this.#withSuggestion(UNSUPPORTED_PLAYBACK_FEATURE_MESSAGE), { conditions: errors });
|
|
201
|
+
this.#error = {
|
|
202
|
+
code: unsupported ? SVTA_UNSUPPORTED_PLAYBACK_FEATURE : reported.code,
|
|
203
|
+
message: reported.message ?? "",
|
|
204
|
+
...reported.data === void 0 ? {} : { data: reported.data }
|
|
205
|
+
};
|
|
206
|
+
this.dispatchEvent?.(new Event("error"));
|
|
207
|
+
}
|
|
208
|
+
attach(mediaElement) {
|
|
209
|
+
super.attach?.(mediaElement);
|
|
210
|
+
this.#signals.context.mediaElement.set(mediaElement);
|
|
211
|
+
}
|
|
212
|
+
detach() {
|
|
213
|
+
this.#cancelPendingPlay();
|
|
214
|
+
this.#signals.context.mediaElement.set(void 0);
|
|
215
|
+
super.detach?.();
|
|
216
|
+
}
|
|
217
|
+
destroy() {
|
|
218
|
+
this.#cancelPendingPlay();
|
|
219
|
+
this.#stopLiveSync();
|
|
220
|
+
this.#stopErrorSync();
|
|
221
|
+
this.#engine.destroy();
|
|
222
|
+
}
|
|
223
|
+
/** Preload type (`'none'` / `'metadata'` / `'auto'`). */
|
|
224
|
+
get preload() {
|
|
225
|
+
return this.#preload;
|
|
226
|
+
}
|
|
227
|
+
set preload(value) {
|
|
228
|
+
this.#preload = value;
|
|
229
|
+
if (value) this.#signals.state.preload.set(value);
|
|
230
|
+
}
|
|
231
|
+
get disableRemotePlayback() {
|
|
232
|
+
return this.#disableRemotePlayback;
|
|
233
|
+
}
|
|
234
|
+
set disableRemotePlayback(value) {
|
|
235
|
+
this.#disableRemotePlayback = value;
|
|
236
|
+
this.#signals.state.disableRemotePlayback.set(value);
|
|
237
|
+
}
|
|
238
|
+
get src() {
|
|
239
|
+
return this.#signals.state.presentation.get()?.url ?? "";
|
|
240
|
+
}
|
|
241
|
+
set src(value) {
|
|
242
|
+
if (value === this.src) return;
|
|
243
|
+
this.#cancelPendingPlay();
|
|
244
|
+
this.#signals.state.presentation.set(value ? { url: value } : void 0);
|
|
245
|
+
}
|
|
246
|
+
play() {
|
|
247
|
+
const mediaElement = this.#signals.context.mediaElement.get();
|
|
248
|
+
if (!mediaElement) return Promise.reject(/* @__PURE__ */ new Error("HlsVideoMediaElement: no media element attached"));
|
|
249
|
+
this.#signals.state.loadActivated.set(true);
|
|
250
|
+
return mediaElement.play().catch((err) => {
|
|
251
|
+
if (this.src) return new Promise((resolve, reject) => {
|
|
252
|
+
const listener = () => {
|
|
253
|
+
this.#loadstartListener = null;
|
|
254
|
+
mediaElement.play().then(resolve, reject);
|
|
255
|
+
};
|
|
256
|
+
this.#loadstartListener = listener;
|
|
257
|
+
mediaElement.addEventListener("loadstart", listener, { once: true });
|
|
258
|
+
});
|
|
259
|
+
throw err;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/** `message`, plus the alternative-Media sentence when this class names one. */
|
|
263
|
+
#withSuggestion(message) {
|
|
264
|
+
return withAlternativeMediaSuggestion(message, this);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Log what this engine is delivering differently from what the playlist asked
|
|
268
|
+
* for. Neither condition stops playback, so neither is an error — they go to
|
|
269
|
+
* the console rather than the error surface.
|
|
270
|
+
*
|
|
271
|
+
* Once per source, not per parse: a live playlist reloads every target
|
|
272
|
+
* duration, and the timeline track re-parses on each one. Keyed on the notice
|
|
273
|
+
* rather than latched with a boolean so the two are independent, and cleared
|
|
274
|
+
* when the presentation unresolves so the next source starts quiet.
|
|
275
|
+
*/
|
|
276
|
+
#reportDeliveryNotices(presentation) {
|
|
277
|
+
if (!isResolvedPresentation(presentation)) {
|
|
278
|
+
this.#noticed.clear();
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const trackId = liveTrackId(this.#signals.state);
|
|
282
|
+
const track = trackId ? findTrackById(presentation, trackId) : void 0;
|
|
283
|
+
if (!track || !isResolvedTrack(track)) return;
|
|
284
|
+
const metadata = getMediaPlaylistMetadata(track);
|
|
285
|
+
if (!metadata) return;
|
|
286
|
+
if (metadata.lowLatency && !this.#noticed.has("lowLatency")) {
|
|
287
|
+
this.#noticed.add("lowLatency");
|
|
288
|
+
console.warn(this.#withSuggestion(LOW_LATENCY_UNSUPPORTED_MESSAGE));
|
|
289
|
+
}
|
|
290
|
+
if (metadata.playlistType === "EVENT" && !this.#noticed.has("dvr")) {
|
|
291
|
+
this.#noticed.add("dvr");
|
|
292
|
+
console.warn(this.#withSuggestion(DVR_EXPERIMENTAL_MESSAGE));
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
#createEngine() {
|
|
296
|
+
return createHlsVideoEngine({
|
|
297
|
+
...this.#config,
|
|
298
|
+
onSignalsReady: (signals) => {
|
|
299
|
+
this.#signals = signals;
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
#cancelPendingPlay() {
|
|
304
|
+
if (!this.#loadstartListener) return;
|
|
305
|
+
this.#signals.context.mediaElement.get()?.removeEventListener("loadstart", this.#loadstartListener);
|
|
306
|
+
this.#loadstartListener = null;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return HlsVideoMediaImpl;
|
|
310
|
+
}
|
|
311
|
+
/** Standalone SPF media adapter with no base class. */
|
|
312
|
+
var HlsVideoMediaElement = class extends HlsVideoMediaMixin(class {}) {};
|
|
313
|
+
//#endregion
|
|
314
|
+
export { HlsVideoMediaElement, HlsVideoMediaMixin, hlsVideoMediaDefaultProps };
|
|
315
|
+
|
|
316
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","names":["#engine","#config","#createEngine","#stopLiveSync","#signals","#setDetectedStreamType","#setTargetLiveWindow","#reportDeliveryNotices","#stopErrorSync","#setError","#error","#streamType","#isUserStreamType","#updateStreamType","#targetLiveWindow","#reportedCode","#withSuggestion","#cancelPendingPlay","#preload","#disableRemotePlayback","#loadstartListener","#noticed"],"sources":["../../../../../src/playback/adapters/hls-video/adapter.ts"],"sourcesContent":["import { type MediaStreamType, MediaStreamTypes } from '@videojs/media';\nimport type { Constructor, MixinReturn } from '@videojs/utils/types';\nimport type { Composition } from '../../../core/composition/create-composition';\nimport { effect } from '../../../core/signals/effect';\nimport {\n SVTA_NO_SUPPORTED_AUDIO_TRACK,\n SVTA_NO_SUPPORTED_VIDEO_TRACK,\n SVTA_UNSUPPORTED_PLAYBACK_FEATURE,\n type SvtaError,\n} from '../../../media/errors';\nimport { resolveLiveLatency } from '../../../media/hls/reload-policy';\nimport {\n deriveStreamType,\n getMediaPlaylistMetadata,\n isResolvedPresentation,\n isResolvedTrack,\n type MaybeResolvedPresentation,\n} from '../../../media/types';\nimport { findTrackById } from '../../../media/utils/tracks';\nimport {\n createHlsVideoEngine,\n type HlsVideoEngineConfig,\n type HlsVideoEngineContext,\n type HlsVideoEngineSignals,\n type HlsVideoEngineState,\n} from '../../engines/hls/engine';\nimport {\n DVR_EXPERIMENTAL_MESSAGE,\n LOW_LATENCY_UNSUPPORTED_MESSAGE,\n UNSUPPORTED_PLAYBACK_FEATURE_MESSAGE,\n} from '../../primitives/error-messages';\nimport { getLiveEdge, type LiveWindowState, liveTrackId } from '../../primitives/live-window';\nimport {\n firstFatal,\n type HlsVideoMediaError,\n hasUnsupportedFeatureCause,\n withAlternativeMediaSuggestion,\n} from './error-surface';\n\n/**\n * The media-level stream type: the engine's detected stream type (`'live'` /\n * `'on-demand'`) plus `'unknown'` for \"no playlist parsed yet.\" `@videojs/media`'s\n * {@link MediaStreamType} itself, kept under its own name because that is what\n * this adapter's `streamType` property is documented against.\n */\nexport type HlsVideoMediaStreamType = MediaStreamType;\n\nexport type { HlsVideoMediaError } from './error-surface';\n\nexport interface HlsVideoMediaProps {\n src: string;\n preload: '' | 'none' | 'metadata' | 'auto';\n disableRemotePlayback: boolean;\n streamType: HlsVideoMediaStreamType;\n}\n\nexport const hlsVideoMediaDefaultProps: HlsVideoMediaProps = {\n src: '',\n preload: '',\n disableRemotePlayback: false,\n streamType: MediaStreamTypes.UNKNOWN,\n};\n\nexport interface HlsVideoMediaAPI extends HlsVideoMediaProps {\n readonly engine: Composition<HlsVideoEngineState, HlsVideoEngineContext>;\n readonly error: HlsVideoMediaError | null;\n readonly liveEdgeStart: number;\n readonly targetLiveWindow: number;\n attach(mediaElement: HTMLMediaElement): void;\n detach(): void;\n destroy(): void;\n play(): Promise<void>;\n}\n\n/**\n * `targetLiveWindow` per the media-ui-extensions live-edge proposal: `NaN` for\n * on-demand (or nothing resolved yet), `0` for standard sliding-window live,\n * `Infinity` for DVR (`#EXT-X-PLAYLIST-TYPE:EVENT` — the window grows from the\n * start). Read from the timeline-bearing track's playlist metadata.\n */\nfunction deriveTargetLiveWindow(\n presentation: MaybeResolvedPresentation | undefined,\n trackId: string | undefined\n): number {\n if (!isResolvedPresentation(presentation) || !trackId) return Number.NaN;\n const track = findTrackById(presentation, trackId);\n if (!track || !isResolvedTrack(track)) return Number.NaN;\n const metadata = getMediaPlaylistMetadata(track);\n if (!metadata) return Number.NaN;\n if (metadata.playlistType === 'EVENT') return Number.POSITIVE_INFINITY;\n return deriveStreamType(metadata) === 'live' ? 0 : Number.NaN;\n}\n\n// ============================================================================\n// Error surface\n// ============================================================================\n\n/**\n * Which reported conditions this composition treats as **fatal** — the ones that\n * reach `error` and fire `'error'`. Severity isn't part of an SVTA code\n * (§Approach: \"impact varies with player implementation\"), and here it also\n * varies by composition, so it's decided at this boundary rather than by the\n * reporter.\n *\n * An allow-list, deliberately: only *verdicts* are here. The per-rendition causes\n * `resolve-track` reports (unsupported format, unsupported DRM) stay in the\n * sequence as context — one unplayable rendition doesn't fail the source, and\n * promoting a cause would put a dialog over a mixed source that goes on to play.\n */\nconst FATAL_SVTA_CODES: ReadonlySet<number> = new Set<number>([\n SVTA_NO_SUPPORTED_VIDEO_TRACK,\n SVTA_NO_SUPPORTED_AUDIO_TRACK,\n]);\n\n/**\n * Mixin that adds SPF playback engine behavior to any base class.\n *\n * Implements the src/play() contract per the WHATWG HTML spec so that SPF can\n * be used anywhere a media element API is expected.\n *\n * A single engine instance is created at construction and recycled across src\n * changes.\n *\n * @fires streamtypechange - Fired when the detected stream type changes. Read `streamType` for the new value.\n * @fires targetlivewindowchange - Fired when the target live window changes. Read `targetLiveWindow` for the new value.\n * @fires error - Fired when a fatal condition is reported. Read `error` for it.\n *\n * @example\n * class HlsVideoMedia extends HlsVideoMediaMixin(HTMLVideoElementHost) {}\n *\n * const media = new HlsVideoMedia();\n * media.attach(document.querySelector('video'));\n * media.src = 'https://stream.mux.com/abc123.m3u8';\n */\nexport function HlsVideoMediaMixin<Base extends Constructor<any>>(BaseClass: Base) {\n class HlsVideoMediaImpl extends BaseClass {\n /**\n * A complete sentence naming the Media to reach for when this one can't play\n * a source — `Try the hls.js-backed Mux media instead: import the hls-js\n * flavor in place of the spf one.` Appended to the copy this adapter\n * surfaces, and to the notices it logs. Name the flavor, not an import path:\n * a Media is reached through several packages, each with its own counterpart.\n *\n * Empty here: `hls-video` has no better-equipped sibling to point at.\n * A Media that does (a Mux Video built on this engine, whose hls.js-backed\n * counterpart plays MPEG-TS and DRM) overrides this static, and its copy gains\n * the second sentence with no other change.\n */\n static get alternativeMediaSuggestion(): string | undefined {\n return undefined;\n }\n\n readonly #engine: Composition<HlsVideoEngineState, HlsVideoEngineContext>;\n #config: HlsVideoEngineConfig;\n #signals!: HlsVideoEngineSignals;\n #preload: '' | 'none' | 'metadata' | 'auto' = hlsVideoMediaDefaultProps.preload;\n #disableRemotePlayback: boolean = hlsVideoMediaDefaultProps.disableRemotePlayback;\n #streamType: HlsVideoMediaStreamType = hlsVideoMediaDefaultProps.streamType;\n #isUserStreamType = false;\n #targetLiveWindow = Number.NaN;\n #error: HlsVideoMediaError | null = null;\n /**\n * The *reported* condition currently surfaced, which is what the re-fire\n * latch keys on. Not `#error.code`: that's the code this adapter chose to\n * surface, and a later cause can change the choice for a condition already\n * announced.\n */\n #reportedCode: number | null = null;\n /** Notices already logged for the current source; cleared when it unloads. */\n #noticed = new Set<string>();\n #stopLiveSync: () => void;\n #stopErrorSync: () => void;\n\n /** Pending loadstart listener from a deferred play() retry, if any. */\n #loadstartListener: (() => void) | null = null;\n\n constructor(...args: any[]) {\n super(...args);\n\n const { config } = args?.[0] ?? {};\n this.#config = config;\n this.#engine = this.#createEngine();\n\n // Mirror the engine's live/stream-type detection onto the media surface,\n // firing the change events the store features listen for. One effect over\n // the presentation + selection signals; `liveEdgeStart` is deliberately\n // NOT cached here — it's derived at read time (the store re-reads it on\n // `timeupdate`/`progress`), so a sliding window needs no event churn.\n this.#stopLiveSync = effect(() => {\n const presentation = this.#signals.state.presentation.get();\n this.#setDetectedStreamType(presentation?.streamType ?? MediaStreamTypes.UNKNOWN);\n this.#setTargetLiveWindow(deriveTargetLiveWindow(presentation, liveTrackId(this.#signals.state)));\n this.#reportDeliveryNotices(presentation);\n });\n\n // Promote the first fatal condition out of the engine's reported sequence\n // onto the media surface. Clearing rides the same signal: `collectErrors`\n // resets the slot per source, so a new source starts with no error without\n // this needing its own source-change hook.\n this.#stopErrorSync = effect(() => {\n const errors = this.#signals.state.errors.get();\n this.#setError(firstFatal(errors, FATAL_SVTA_CODES), errors);\n });\n }\n\n /**\n * Underlying playback engine — the low-level SPF reactive composition that\n * drives playback. An advanced escape hatch for direct engine access;\n * normal playback is driven through this element's own properties and\n * methods.\n */\n get engine(): Composition<HlsVideoEngineState, HlsVideoEngineContext> {\n return this.#engine;\n }\n\n // -------------------------------------------------------------------------\n // Live surface — streamType / targetLiveWindow / liveEdgeStart\n // (the MediaStreamTypeCapability + MediaLiveCapability contract the player\n // store's stream-type and live features consume)\n // -------------------------------------------------------------------------\n\n /**\n * The current fatal error, or `null`. Only *fatal* conditions appear here —\n * the engine reports non-fatal ones too (they stay in `engine.state.errors`),\n * and promoting them would tell a consumer playback had failed when it\n * hadn't. Resets per source. Fires `'error'` when set.\n */\n get error(): HlsVideoMediaError | null {\n return this.#error;\n }\n\n /**\n * The source's stream type — `'live'`, `'on-demand'`, or `'unknown'` until\n * a media playlist has been parsed. Setting a non-`'unknown'` value pins a\n * user override (detection stops updating it); setting `'unknown'` reverts\n * to the engine's detected value.\n */\n get streamType(): HlsVideoMediaStreamType {\n return this.#streamType;\n }\n\n set streamType(value: HlsVideoMediaStreamType) {\n if (value === MediaStreamTypes.UNKNOWN) {\n this.#isUserStreamType = false;\n this.#updateStreamType(this.#signals.state.presentation.get()?.streamType ?? MediaStreamTypes.UNKNOWN);\n return;\n }\n this.#isUserStreamType = true;\n this.#updateStreamType(value);\n }\n\n /**\n * Presentation time marking the start of the live-edge window — playback at\n * `currentTime >= liveEdgeStart` counts as \"at the live edge\" (the same\n * target the engine's `seekToLiveEdge` seeks to: window end − HOLD-BACK).\n * `NaN` when the stream isn't live or nothing is resolved yet. Derived at\n * read time from the engine's live window — no change event; re-read on\n * `timeupdate`/`progress` (as the store's live feature does).\n */\n get liveEdgeStart(): number {\n const edge = getLiveEdge({\n state: this.#signals.state as LiveWindowState,\n config: { resolveLiveLatency },\n });\n return edge?.liveEdgeStart ?? Number.NaN;\n }\n\n /**\n * The target live window: `NaN` for on-demand (or unknown), `0` for\n * standard sliding-window live, `Infinity` for DVR\n * (`#EXT-X-PLAYLIST-TYPE:EVENT`). Fires `targetlivewindowchange` on change.\n */\n get targetLiveWindow(): number {\n return this.#targetLiveWindow;\n }\n\n #setDetectedStreamType(value: HlsVideoMediaStreamType): void {\n if (this.#isUserStreamType) return;\n this.#updateStreamType(value);\n }\n\n #updateStreamType(value: HlsVideoMediaStreamType): void {\n if (this.#streamType === value) return;\n this.#streamType = value;\n // Optional-chained: with an EventTarget-less base (`HlsVideoMediaElement`\n // standalone) there's nowhere to dispatch; hosts forward it to listeners.\n this.dispatchEvent?.(new Event('streamtypechange'));\n }\n\n #setTargetLiveWindow(value: number): void {\n if (Object.is(this.#targetLiveWindow, value)) return;\n this.#targetLiveWindow = value;\n this.dispatchEvent?.(new Event('targetlivewindowchange'));\n }\n\n #setError(reported: SvtaError | undefined, errors: readonly SvtaError[] | undefined): void {\n if (!reported) {\n // Cleared (new source). No event: `'error'` announces a failure, and\n // consumers reset their own copy on source change.\n this.#error = null;\n this.#reportedCode = null;\n return;\n }\n // Keyed on the code, not the object: a later append re-runs this effect\n // with an equal-but-new array, and re-firing `'error'` for a condition\n // already surfaced would look like a second failure.\n if (this.#reportedCode === reported.code) return;\n this.#reportedCode = reported.code;\n\n // A verdict says a type emptied; the causes say whether anything could\n // have played it. When they include something this engine simply doesn't\n // implement, that's the more useful thing to tell a consumer, so it\n // replaces the verdict's code on the surface.\n const unsupported = hasUnsupportedFeatureCause(errors);\n if (unsupported) {\n // The only place this engine explains itself in prose, and it's a\n // console: the viewer-facing sentence is the consumer's to localize from\n // the code. Conditions ride along structured so the specifics stay\n // inspectable.\n console.error(this.#withSuggestion(UNSUPPORTED_PLAYBACK_FEATURE_MESSAGE), { conditions: errors });\n }\n\n this.#error = {\n code: unsupported ? SVTA_UNSUPPORTED_PLAYBACK_FEATURE : reported.code,\n message: reported.message ?? '',\n ...(reported.data === undefined ? {} : { data: reported.data }),\n };\n this.dispatchEvent?.(new Event('error'));\n }\n\n // -------------------------------------------------------------------------\n // Media element lifecycle\n // -------------------------------------------------------------------------\n\n attach(mediaElement: HTMLMediaElement): void {\n super.attach?.(mediaElement);\n this.#signals.context.mediaElement.set(mediaElement);\n }\n\n detach(): void {\n this.#cancelPendingPlay();\n this.#signals.context.mediaElement.set(undefined);\n super.detach?.();\n }\n\n destroy(): void {\n this.#cancelPendingPlay();\n this.#stopLiveSync();\n this.#stopErrorSync();\n this.#engine.destroy();\n }\n\n // -------------------------------------------------------------------------\n // preload — synchronous IDL attribute (WHATWG §4.8.11.2)\n // -------------------------------------------------------------------------\n\n /** Preload type (`'none'` / `'metadata'` / `'auto'`). */\n get preload(): '' | 'none' | 'metadata' | 'auto' {\n return this.#preload;\n }\n\n set preload(value: '' | 'none' | 'metadata' | 'auto') {\n this.#preload = value;\n if (value) {\n this.#signals.state.preload.set(value);\n }\n // value = '' resets the IDL mirror (so `get preload` reflects '') but does\n // not patch state — the engine keeps its current preload until an explicit\n // W3C value replaces it.\n }\n\n // -------------------------------------------------------------------------\n // disableRemotePlayback — synchronous IDL attribute (WHATWG Remote Playback)\n // Author intent for whether the AirPlay/remote picker is offered. Mirrors\n // the DOM attribute name; the value flows to `state.disableRemotePlayback`,\n // which `setupAirPlay` reads to honor an explicit opt-out. The underlying\n // <video>'s own `disableRemotePlayback` stays programmatically managed\n // (ManagedMediaSource needs it `true` to open; AirPlay flips it `false` once\n // the source is open), so author intent and the effective flag stay distinct.\n // -------------------------------------------------------------------------\n\n get disableRemotePlayback(): boolean {\n return this.#disableRemotePlayback;\n }\n\n set disableRemotePlayback(value: boolean) {\n this.#disableRemotePlayback = value;\n this.#signals.state.disableRemotePlayback.set(value);\n }\n\n // -------------------------------------------------------------------------\n // src — synchronous IDL attribute (WHATWG §4.8.11.2)\n // Each assignment overwrites the engine's presentation state in place. The\n // resolver FSM routes back through teardown → rebuild on the same engine,\n // mirroring how the browser's load algorithm resets media state on src change\n // — without recreating the engine or re-capturing its signals. Setting an\n // empty src un-resolves the presentation, tearing the current source down to\n // the engine's fresh-but-attached \"no source\" state.\n // -------------------------------------------------------------------------\n\n get src(): string {\n return this.#signals.state.presentation.get()?.url ?? '';\n }\n\n set src(value: string) {\n // Assigning the URL already playing is not a request to reload it. The\n // presentation is set from a fresh object every time, so re-resolving an\n // unchanged URL restarts playback — which is what a caller changing only\n // the parts of a structured source that describe images, rather than the\n // stream, would get. The hls.js Media draws the same line: it announces\n // every source change and loads only when the URL or engine config moves.\n if (value === this.src) return;\n\n this.#cancelPendingPlay();\n this.#signals.state.presentation.set(value ? { url: value } : undefined);\n }\n\n // -------------------------------------------------------------------------\n // play() — WHATWG §4.8.11.8\n // Delegates to the attached media element's native play().\n // -------------------------------------------------------------------------\n\n play(): Promise<void> {\n const mediaElement = this.#signals.context.mediaElement.get();\n if (!mediaElement) {\n return Promise.reject(new Error('HlsVideoMediaElement: no media element attached'));\n }\n\n // Signal play intent — enables loading even with preload=\"none\"\n this.#signals.state.loadActivated.set(true);\n\n return mediaElement.play().catch((err: unknown) => {\n // If we have a pending HLS source, the rejection may be because MSE\n // hasn't attached a blob URL yet. Wait for loadstart (src assigned\n // by MSE setup) and retry once.\n if (this.src) {\n return new Promise<void>((resolve, reject) => {\n const listener = () => {\n this.#loadstartListener = null;\n mediaElement.play().then(resolve, reject);\n };\n this.#loadstartListener = listener;\n mediaElement.addEventListener('loadstart', listener, { once: true });\n });\n }\n throw err;\n });\n }\n\n // -------------------------------------------------------------------------\n // Private\n // -------------------------------------------------------------------------\n\n /** `message`, plus the alternative-Media sentence when this class names one. */\n #withSuggestion(message: string): string {\n return withAlternativeMediaSuggestion(message, this);\n }\n\n /**\n * Log what this engine is delivering differently from what the playlist asked\n * for. Neither condition stops playback, so neither is an error — they go to\n * the console rather than the error surface.\n *\n * Once per source, not per parse: a live playlist reloads every target\n * duration, and the timeline track re-parses on each one. Keyed on the notice\n * rather than latched with a boolean so the two are independent, and cleared\n * when the presentation unresolves so the next source starts quiet.\n */\n #reportDeliveryNotices(presentation: MaybeResolvedPresentation | undefined): void {\n if (!isResolvedPresentation(presentation)) {\n this.#noticed.clear();\n return;\n }\n\n const trackId = liveTrackId(this.#signals.state);\n const track = trackId ? findTrackById(presentation, trackId) : undefined;\n if (!track || !isResolvedTrack(track)) return;\n const metadata = getMediaPlaylistMetadata(track);\n if (!metadata) return;\n\n if (metadata.lowLatency && !this.#noticed.has('lowLatency')) {\n this.#noticed.add('lowLatency');\n console.warn(this.#withSuggestion(LOW_LATENCY_UNSUPPORTED_MESSAGE));\n }\n if (metadata.playlistType === 'EVENT' && !this.#noticed.has('dvr')) {\n this.#noticed.add('dvr');\n console.warn(this.#withSuggestion(DVR_EXPERIMENTAL_MESSAGE));\n }\n }\n\n #createEngine(): Composition<HlsVideoEngineState, HlsVideoEngineContext> {\n return createHlsVideoEngine({\n ...this.#config,\n onSignalsReady: (signals) => {\n this.#signals = signals;\n },\n });\n }\n\n #cancelPendingPlay(): void {\n if (!this.#loadstartListener) return;\n const mediaElement = this.#signals.context.mediaElement.get();\n mediaElement?.removeEventListener('loadstart', this.#loadstartListener);\n this.#loadstartListener = null;\n }\n }\n\n // `MixinReturn` sources statics from `Base`, so the adapter's own static needs\n // adding back to the type or callers can't read it.\n return HlsVideoMediaImpl as unknown as MixinReturn<Base, HlsVideoMediaAPI> & {\n readonly alternativeMediaSuggestion: string | undefined;\n };\n}\n\n/** Standalone SPF media adapter with no base class. */\nexport class HlsVideoMediaElement extends HlsVideoMediaMixin(class {}) {}\n"],"mappings":";;;;;;;;;;;AAwDA,MAAa,4BAAgD;CAC3D,KAAK;CACL,SAAS;CACT,uBAAuB;CACvB,YAAY,iBAAiB;AAC/B;;;;;;;AAmBA,SAAS,uBACP,cACA,SACQ;CACR,IAAI,CAAC,uBAAuB,YAAY,KAAK,CAAC,SAAS,OAAO;CAC9D,MAAM,QAAQ,cAAc,cAAc,OAAO;CACjD,IAAI,CAAC,SAAS,CAAC,gBAAgB,KAAK,GAAG,OAAO;CAC9C,MAAM,WAAW,yBAAyB,KAAK;CAC/C,IAAI,CAAC,UAAU,OAAO;CACtB,IAAI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