@videojs/hlsjs-video 10.3.0 → 10.5.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/default/adapter.js +1 -1
- package/dist/default/text-tracks.js +139 -65
- package/dist/dev/adapter.js +1 -1
- package/dist/dev/adapter.js.map +1 -1
- package/dist/dev/text-tracks.js +139 -65
- package/dist/dev/text-tracks.js.map +1 -1
- package/package.json +6 -6
package/dist/default/adapter.js
CHANGED
|
@@ -206,7 +206,7 @@ var HlsJsAdapter = class HlsJsAdapter extends HTMLVideoAdapter {
|
|
|
206
206
|
}
|
|
207
207
|
async load() {
|
|
208
208
|
this.#loadRequested = null;
|
|
209
|
-
if (this.remote
|
|
209
|
+
if (this.remote?.state === "connected") {
|
|
210
210
|
this.dispatchEvent(new HlsMediaEvent("loadstart"));
|
|
211
211
|
return super.load();
|
|
212
212
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import Hls from "hls.js";
|
|
2
2
|
import { isCaptionOrSubtitleTrack, listen } from "@videojs/utils/dom";
|
|
3
|
+
import { isNil } from "@videojs/utils/predicate";
|
|
3
4
|
//#region src/text-tracks.ts
|
|
4
5
|
/** Marks the `<track>` elements created here for hls.js's own text tracks. */
|
|
5
6
|
const HLS_TRACK_ATTR = "data-removeondestroy";
|
|
6
|
-
/** Marks the subset created from hls.js's CEA-608/708 announcements, which are announced one track at a time. */
|
|
7
|
-
const CC_TRACK_ATTR = "data-cc";
|
|
8
7
|
/** `HTMLTrackElement.LOADED` — the element parsed its resource and will not parse it again. */
|
|
9
8
|
const TRACK_LOADED = 2;
|
|
10
9
|
/**
|
|
@@ -28,20 +27,12 @@ function withPreservedTextTracks(media, action) {
|
|
|
28
27
|
for (const snapshot of snapshots) restoreTextTrack(snapshot);
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
|
-
/** Disables and removes every text track created for the current hls.js source. */
|
|
32
|
-
function removeHlsTextTracks(media) {
|
|
33
|
-
const trackEls = media?.querySelectorAll(`track[${HLS_TRACK_ATTR}]`) ?? [];
|
|
34
|
-
for (const trackEl of trackEls) {
|
|
35
|
-
trackEl.track.mode = "disabled";
|
|
36
|
-
trackEl.remove();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
30
|
function snapshotTextTracks(media) {
|
|
40
31
|
const snapshots = [];
|
|
41
32
|
for (const trackEl of media.querySelectorAll("track")) {
|
|
42
33
|
if (trackEl.hasAttribute(HLS_TRACK_ATTR)) continue;
|
|
43
34
|
const { track } = trackEl;
|
|
44
|
-
if (track.mode === "disabled" && trackEl.readyState
|
|
35
|
+
if (track.mode === "disabled" && trackEl.readyState < TRACK_LOADED) continue;
|
|
45
36
|
snapshots.push({
|
|
46
37
|
track,
|
|
47
38
|
mode: track.mode,
|
|
@@ -75,24 +66,58 @@ function withReadableCues(track, action) {
|
|
|
75
66
|
* When `renderTextTracksNatively: false`, hls.js fires `NON_NATIVE_TEXT_TRACKS_FOUND` with track metadata and
|
|
76
67
|
* `CUES_PARSED` with VTTCues. This mixin creates `<track>` elements on the media target and forwards cues into them. It
|
|
77
68
|
* also syncs user track-mode changes back to hls.js via `engine.subtitleTrack`.
|
|
69
|
+
*
|
|
70
|
+
* The tracks belong to the source, not to the media element. A new manifest or the engine's destruction drops them.
|
|
71
|
+
* hls.js's own detach/attach, e.g. `hls.recoverMediaError()`, leaves them where they are: hls.js announces the subtitle
|
|
72
|
+
* set again only when its list changes, and each CC track only once 608 data shows up, and keeping the elements keeps
|
|
73
|
+
* their modes, cues and place among the other `<track>` elements. Only the adapter letting go of the element unmounts
|
|
74
|
+
* them, and the next attach mounts the same elements again with their modes and cues.
|
|
78
75
|
*/
|
|
79
76
|
function HlsJsTextTracksMixin(BaseClass) {
|
|
80
77
|
class HlsJsTextTracks extends BaseClass {
|
|
81
78
|
#disconnect = null;
|
|
79
|
+
/** The tracks of the current source, by the id hls.js addresses their cues with. */
|
|
80
|
+
#tracks = /* @__PURE__ */ new Map();
|
|
82
81
|
constructor(...args) {
|
|
83
82
|
super(...args);
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
const { engine } = this;
|
|
84
|
+
if (!engine) return;
|
|
85
|
+
engine.on(Hls.Events.MANIFEST_LOADING, () => {
|
|
86
|
+
this.#reset();
|
|
86
87
|
this.#init();
|
|
87
88
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
engine.on(Hls.Events.MEDIA_ATTACHED, () => {
|
|
90
|
+
this.#init();
|
|
91
|
+
this.#mount();
|
|
92
|
+
});
|
|
93
|
+
engine.on(Hls.Events.MEDIA_DETACHED, () => this.#disconnectListeners());
|
|
94
|
+
engine.on(Hls.Events.DESTROYING, () => this.#reset());
|
|
95
|
+
}
|
|
96
|
+
/** The adapter lets go of the element, unlike hls.js's own detach/attach, so the tracks leave it too. */
|
|
97
|
+
detach() {
|
|
98
|
+
this.#unmount();
|
|
99
|
+
super.detach();
|
|
91
100
|
}
|
|
92
|
-
#
|
|
101
|
+
#disconnectListeners() {
|
|
93
102
|
this.#disconnect?.abort();
|
|
94
103
|
this.#disconnect = null;
|
|
95
|
-
|
|
104
|
+
}
|
|
105
|
+
#reset() {
|
|
106
|
+
this.#disconnectListeners();
|
|
107
|
+
this.#unmount();
|
|
108
|
+
this.#tracks.clear();
|
|
109
|
+
}
|
|
110
|
+
/** Mounts the tracks of the current source that are not on the media element yet. */
|
|
111
|
+
#mount() {
|
|
112
|
+
const media = this.target;
|
|
113
|
+
if (!media) return;
|
|
114
|
+
for (const [id, track] of this.#tracks) if (track.el?.parentNode !== media) mountTrack(media, id, track, null);
|
|
115
|
+
}
|
|
116
|
+
#unmount() {
|
|
117
|
+
for (const track of this.#tracks.values()) unmountTrack(track);
|
|
118
|
+
}
|
|
119
|
+
#trackFor(textTrack) {
|
|
120
|
+
for (const track of this.#tracks.values()) if (track.el?.track === textTrack) return track;
|
|
96
121
|
}
|
|
97
122
|
#init() {
|
|
98
123
|
this.#disconnect?.abort();
|
|
@@ -101,32 +126,35 @@ function HlsJsTextTracksMixin(BaseClass) {
|
|
|
101
126
|
const { engine } = this;
|
|
102
127
|
if (!engine || !this.target) return;
|
|
103
128
|
const media = this.target;
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const ccOwned = trackEl.hasAttribute(CC_TRACK_ATTR);
|
|
111
|
-
if (!replaced && (ccBatch || ccOwned)) continue;
|
|
112
|
-
trackEl.track.mode = "disabled";
|
|
113
|
-
trackEl.remove();
|
|
129
|
+
const onTracksFound = (_event, { tracks }) => {
|
|
130
|
+
const incoming = new Map(tracks.map((info) => [trackIdFor(info), info]));
|
|
131
|
+
if (!tracks.every(isClosedCaptions)) for (const [id, track] of this.#tracks) {
|
|
132
|
+
if (isClosedCaptions(track.info) || incoming.has(id)) continue;
|
|
133
|
+
unmountTrack(track);
|
|
134
|
+
this.#tracks.delete(id);
|
|
114
135
|
}
|
|
115
|
-
for (const
|
|
116
|
-
const
|
|
117
|
-
|
|
136
|
+
for (const [id, info] of incoming) {
|
|
137
|
+
const track = this.#tracks.get(id);
|
|
138
|
+
if (!track) {
|
|
139
|
+
this.#tracks.set(id, {
|
|
140
|
+
info,
|
|
141
|
+
mode: null,
|
|
142
|
+
el: null
|
|
143
|
+
});
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const changed = !describesSameTrack(track.info, info);
|
|
147
|
+
track.info = info;
|
|
148
|
+
if (changed) replaceTrack(media, id, track);
|
|
118
149
|
}
|
|
150
|
+
this.#mount();
|
|
119
151
|
};
|
|
120
152
|
const onCuesParsed = (_event, { track, cues }) => {
|
|
121
|
-
const textTrack =
|
|
153
|
+
const textTrack = this.#tracks.get(track)?.el?.track;
|
|
122
154
|
if (!textTrack) return;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
cues.forEach((cue) => {
|
|
126
|
-
if (textTrack.cues?.getCueById(cue.id)) return;
|
|
127
|
-
textTrack.addCue(cue);
|
|
155
|
+
withReadableCues(textTrack, () => {
|
|
156
|
+
for (const cue of cues) if (!textTrack.cues?.getCueById(cue.id)) textTrack.addCue(cue);
|
|
128
157
|
});
|
|
129
|
-
if (disabled) textTrack.mode = "disabled";
|
|
130
158
|
};
|
|
131
159
|
let lastShowingTrack;
|
|
132
160
|
const onTextTrackChange = () => {
|
|
@@ -136,16 +164,10 @@ function HlsJsTextTracksMixin(BaseClass) {
|
|
|
136
164
|
const showingChanged = showingTrack !== lastShowingTrack;
|
|
137
165
|
lastShowingTrack = showingTrack;
|
|
138
166
|
if (!showingTrack) return;
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
if (engine.subtitleTrack < 0 || showingTrack?.id !== hlsTrackId) {
|
|
144
|
-
const idx = engine.subtitleTracks.findIndex(({ lang, name, type, default: defaultTrack }) => {
|
|
145
|
-
return showingTrack.id === "default" && defaultTrack || lang === showingTrack.language && name === showingTrack.label && type.toLowerCase() === showingTrack.kind;
|
|
146
|
-
});
|
|
147
|
-
engine.subtitleTrack = idx;
|
|
148
|
-
}
|
|
167
|
+
const track = this.#trackFor(showingTrack);
|
|
168
|
+
if (showingChanged && track) refreshCues(showingTrack);
|
|
169
|
+
const index = track?.info.subtitleTrack?.id ?? -1;
|
|
170
|
+
if (engine.subtitleTrack !== index) engine.subtitleTrack = index;
|
|
149
171
|
};
|
|
150
172
|
engine.on(Hls.Events.NON_NATIVE_TEXT_TRACKS_FOUND, onTracksFound);
|
|
151
173
|
engine.on(Hls.Events.CUES_PARSED, onCuesParsed);
|
|
@@ -158,10 +180,6 @@ function HlsJsTextTracksMixin(BaseClass) {
|
|
|
158
180
|
}
|
|
159
181
|
return HlsJsTextTracks;
|
|
160
182
|
}
|
|
161
|
-
function isHlsTextTrack(media, track) {
|
|
162
|
-
const trackEls = media.querySelectorAll(`track[${HLS_TRACK_ATTR}]`);
|
|
163
|
-
return Array.from(trackEls).some((trackEl) => trackEl.track === track);
|
|
164
|
-
}
|
|
165
183
|
/**
|
|
166
184
|
* Makes the media element render the cues of a track that just became the showing one.
|
|
167
185
|
*
|
|
@@ -176,18 +194,74 @@ function refreshCues(track) {
|
|
|
176
194
|
track.addCue(cue);
|
|
177
195
|
}
|
|
178
196
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
197
|
+
/** CEA-608/708 tracks are the ones hls.js announces with an `_id`, one at a time. */
|
|
198
|
+
function isClosedCaptions(info) {
|
|
199
|
+
return !isNil(info._id);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* NOTE: Undocumented identifiers hls.js addresses CUES_PARSED with: `_id` for CEA-608/708 tracks, and `default` or
|
|
203
|
+
* `subtitles` plus the group-local index it stamps on `subtitleTrack.id` for the subtitle set. See:
|
|
204
|
+
* https://github.com/video-dev/hls.js/blob/master/src/controller/timeline-controller.ts
|
|
205
|
+
*/
|
|
206
|
+
function trackIdFor({ _id, default: isDefault, subtitleTrack }) {
|
|
207
|
+
return _id ?? (isDefault ? "default" : `subtitles${subtitleTrack?.id}`);
|
|
208
|
+
}
|
|
209
|
+
/** Whether a new announcement of a track would build the same `<track>` element. */
|
|
210
|
+
function describesSameTrack(a, b) {
|
|
211
|
+
const langOf = ({ subtitleTrack, closedCaptions }) => (subtitleTrack ?? closedCaptions)?.lang;
|
|
212
|
+
return a.kind === b.kind && a.label === b.label && !!a.default === !!b.default && langOf(a) === langOf(b);
|
|
213
|
+
}
|
|
214
|
+
/** Adds the track's element to the media element, moving it off another one, or builds it on the first mount. */
|
|
215
|
+
function mountTrack(media, id, track, before) {
|
|
216
|
+
unmountTrack(track);
|
|
217
|
+
const el = track.el ?? createTrackElement(id, track.info);
|
|
218
|
+
media.insertBefore(el, before);
|
|
219
|
+
track.el = el;
|
|
220
|
+
if (track.mode) restoreMode(el.track, track.mode);
|
|
221
|
+
}
|
|
222
|
+
function createTrackElement(id, info) {
|
|
223
|
+
const kind = info.kind;
|
|
224
|
+
const lang = (info.subtitleTrack ?? info.closedCaptions)?.lang;
|
|
225
|
+
const el = document.createElement("track");
|
|
226
|
+
el.id = id;
|
|
227
|
+
el.kind = kind;
|
|
228
|
+
el.label = info.label;
|
|
229
|
+
if (lang) el.srclang = lang;
|
|
230
|
+
if (info.default) el.default = true;
|
|
231
|
+
el.track.mode = isCaptionOrSubtitleTrack({ kind }) ? "disabled" : "hidden";
|
|
232
|
+
el.setAttribute(HLS_TRACK_ATTR, "");
|
|
233
|
+
return el;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Gives a track hls.js announced under a reused id, e.g. after a switch to a level with another subtitle group, a new
|
|
237
|
+
* element in the old one's place: the old element holds the previous playlist's cues, and the store only reads a
|
|
238
|
+
* track's kind, label and language when it is added.
|
|
239
|
+
*/
|
|
240
|
+
function replaceTrack(media, id, track) {
|
|
241
|
+
const { el } = track;
|
|
242
|
+
if (!el) return;
|
|
243
|
+
const mounted = el.parentNode === media;
|
|
244
|
+
const next = el.nextSibling;
|
|
245
|
+
unmountTrack(track);
|
|
246
|
+
track.el = null;
|
|
247
|
+
if (mounted) mountTrack(media, id, track, next);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Sets a remounted track's mode so the browser keeps it. Once any track shows, Chrome turns on the subtitle track in
|
|
251
|
+
* the user's language too, unless script set that track's mode after its element was added. Setting the mode it already
|
|
252
|
+
* has does not count, so a track restored to it goes through another mode first.
|
|
253
|
+
*/
|
|
254
|
+
function restoreMode(track, mode) {
|
|
255
|
+
if (track.mode === mode) track.mode = mode === "disabled" ? "hidden" : "disabled";
|
|
256
|
+
track.mode = mode;
|
|
257
|
+
}
|
|
258
|
+
/** Disables and removes the track's element, remembering its mode for the next mount. */
|
|
259
|
+
function unmountTrack(track) {
|
|
260
|
+
const { el } = track;
|
|
261
|
+
if (!el?.parentNode) return;
|
|
262
|
+
track.mode = el.track.mode;
|
|
263
|
+
el.track.mode = "disabled";
|
|
264
|
+
el.remove();
|
|
191
265
|
}
|
|
192
266
|
//#endregion
|
|
193
|
-
export { HlsJsTextTracksMixin,
|
|
267
|
+
export { HlsJsTextTracksMixin, withPreservedTextTracks };
|
package/dist/dev/adapter.js
CHANGED
|
@@ -206,7 +206,7 @@ var HlsJsAdapter = class HlsJsAdapter extends HTMLVideoAdapter {
|
|
|
206
206
|
}
|
|
207
207
|
async load() {
|
|
208
208
|
this.#loadRequested = null;
|
|
209
|
-
if (this.remote
|
|
209
|
+
if (this.remote?.state === "connected") {
|
|
210
210
|
this.dispatchEvent(new HlsMediaEvent("loadstart"));
|
|
211
211
|
return super.load();
|
|
212
212
|
}
|
package/dist/dev/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","names":["Hls"],"sources":["../../src/adapter.ts"],"sourcesContent":["import {\n bridgeEvents,\n type DrmSystemsConfig,\n KeySystems,\n type MediaResolution,\n type MediaStreamType,\n MediaStreamTypes,\n} from '@videojs/media';\nimport { getMediaEngineName, HTMLVideoAdapter } from '@videojs/media/dom';\nimport { type NativeHlsConfig, NativeHlsAdapter, type NativeHlsSource } from '@videojs/native-hls-video';\nimport { deepEqual } from '@videojs/utils/object';\nimport Hls, { type HlsConfig as HlsJsConfig } from 'hls.js';\n\nimport { HlsJsOnlyAdapter } from './hls-js-only';\n\nexport type PreloadType = '' | 'none' | 'metadata' | 'auto';\n\nexport type { MediaResolution };\n\nexport { Hls };\n\n/** How hls.js plays a source: through Media Source Extensions, or the browser's native HLS support. */\nexport type PlaybackType = 'mse' | 'native' | (string & {});\n/** A source's MIME type, such as `application/vnd.apple.mpegurl` for HLS or `video/mp4`. */\nexport type SourceType = 'application/vnd.apple.mpegurl' | 'video/mp4' | (string & {});\nexport type StreamType = MediaStreamType;\n\n/** @internal */\nexport const PlaybackTypes = {\n MSE: 'mse',\n NATIVE: 'native',\n};\n\n/** @internal */\nexport const ContentTypes = {\n M3U8: 'application/vnd.apple.mpegurl',\n MP4: 'video/mp4',\n};\n\n/**\n * Every MIME type that means HLS in the wild, lowercased. `application/vnd.apple.mpegurl` is the registered one, but\n * `application/x-mpegURL` predates it and is what most servers, CDNs, and older Video.js guides hand out, so a source\n * naming any of these has to reach hls.js rather than fall through to native playback.\n */\nconst HLS_CONTENT_TYPES: ReadonlySet<string> = new Set([\n ContentTypes.M3U8,\n 'application/x-mpegurl',\n 'application/mpegurl',\n 'audio/mpegurl',\n 'audio/x-mpegurl',\n]);\n\nconst MP4_CONTENT_TYPES: ReadonlySet<string> = new Set([ContentTypes.MP4]);\n\n/** @internal */\nexport const StreamTypes = MediaStreamTypes;\n\nexport interface HlsJsAdapterProps {\n src: string;\n source: HlsSource | null;\n preload: PreloadType;\n streamType: StreamType;\n disableRemotePlayback: boolean;\n}\n\n/**\n * Structured HLS source: which source to play, plus how to play it.\n *\n * Playback options are namespaced by engine. There are two paths here — hls.js and the browser's own HLS support — and\n * only one of them runs, so a source describes both without either engine reading the other's options.\n *\n * `preferPlayback` and the engine options are all read when the engine is constructed, so changing any of them\n * recreates it.\n */\nexport interface HlsSource {\n /** Manifest URL. Mirrors the host's `src` property. */\n src?: string | undefined;\n /**\n * MIME type of the source. Takes precedence over inference from `src`.\n *\n * Matched case-insensitively, and the legacy HLS spellings (`application/x-mpegURL`, `audio/mpegurl`, …) count as\n * `application/vnd.apple.mpegurl`. Anything unrecognized is treated as a URL the browser plays on its own.\n */\n type?: SourceType | undefined;\n /**\n * Preferred playback path: `'mse'` for hls.js, `'native'` for the browser's own HLS support. Ignored when the\n * preferred path cannot play the source.\n */\n preferPlayback?: PlaybackType | undefined;\n /**\n * License servers for protected content, keyed by EME key system id.\n *\n * Engine neutral, because which engine plays is decided later: hls.js is handed every system named here (with EME\n * switched on), and native playback negotiates the `com.apple.fps` entry itself. Name every system you hold a license\n * server for — which one is used is the browser's choice.\n */\n drm?: DrmSystemsConfig | undefined;\n /**\n * Highest resolution adaptive bitrate selection may choose on its own.\n *\n * A ceiling on automatic selection, not a filter on what is available: renditions above it stay in `videoRenditions`\n * and can still be selected by hand. Matching is by pixel area, so a `'720p'` cap admits any rendition at or below\n * 1280×720 worth of pixels. When every rendition sits above the cap, the smallest one is used.\n *\n * Applied live — changing it never rebuilds the playback engine. Requires the hls.js (MSE) engine; native HLS\n * playback ignores it.\n *\n * For Mux sources this is distinct from `playback.maxResolution`, which asks Mux to leave higher renditions out of\n * the manifest altogether.\n */\n maxAutoResolution?: MediaResolution | undefined;\n /**\n * Whether the element's rendered size caps automatic selection. Defaults to `true`.\n *\n * A 400px-wide player has no use for a 4K rendition, so selection is held to the smallest rendition that still covers\n * the element, measured in device pixels — a `2` device pixel ratio asks for twice what a CSS measurement would. The\n * cap follows the element as it resizes, and `minAutoResolution` bounds how far down it can go. Set it to `false` for\n * a player whose layout size understates what it needs, such as one that goes fullscreen without a resize.\n *\n * Which rendition covers the element is hls.js's own judgement, weighed on the largest dimension rather than pixel\n * area, so it can land elsewhere than `maxAutoResolution` would for the same ladder.\n *\n * Applied live — changing it never rebuilds the playback engine. Requires the hls.js (MSE) engine; native HLS\n * playback ignores it. Setting hls.js's own `capLevelToPlayerSize` through `source.engine.hlsJs` is a different\n * thing: it stops the loop _every_ cap here is evaluated on, and takes a rebuild.\n */\n capRenditionToPlayerSize?: boolean | undefined;\n /**\n * Lowest resolution `capRenditionToPlayerSize` may cap down to. Defaults to `'720p'`.\n *\n * Not a quality floor. It bounds the size-derived cap and nothing else: when bandwidth is poor, adaptive selection\n * still drops below it, because the cap is a ceiling and selection stays free underneath. Nor does it raise an\n * explicit `maxAutoResolution` — asking for at most `'360p'` alongside a `'720p'` floor yields `'360p'`.\n *\n * The default exists because the low rungs of a ladder are there for poor network conditions, and capping a small\n * player to them looks worse than its size suggests. Name a lower rung to weaken the floor, or `'270p'` to lift it\n * for any real ladder.\n *\n * Applied live — changing it never rebuilds the playback engine. Requires the hls.js (MSE) engine; native HLS\n * playback ignores it.\n */\n minAutoResolution?: MediaResolution | undefined;\n /**\n * Playback options, keyed by the engine that reads them. Only one of the two engines below ends up playing, and each\n * reads only its own key.\n */\n engine?: HlsEngineConfig | undefined;\n}\n\n/** The engines an HLS source can configure. */\nexport interface HlsEngineConfig {\n /**\n * Hls.js's own configuration, passed through untouched. A `drmSystems` of its own replaces `source.drm` for hls.js —\n * an escape hatch for licensing MSE playback differently, or for the parts of hls.js's DRM configuration `source.drm`\n * does not cover.\n */\n hlsJs?: Partial<HlsJsConfig> | undefined;\n /**\n * Options for the browser's own HLS playback, used whenever the native path is the one taken. Its `drmSystems`\n * replaces `source.drm` for that path in the same way.\n */\n nativeHls?: NativeHlsConfig | undefined;\n}\n\nclass HlsMediaEvent extends Event {}\n\n/**\n * @fires sourcechange - Fired when `source` changes, either directly or by resolving a new `src`. Read `source` for the\n * new value.\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 */\nexport class HlsJsAdapter extends HTMLVideoAdapter implements HlsJsAdapterProps {\n static readonly defaultProps: HlsJsAdapterProps = {\n src: '',\n source: null,\n preload: 'metadata',\n streamType: MediaStreamTypes.UNKNOWN,\n disableRemotePlayback: false,\n };\n\n #delegate: HlsJsOnlyAdapter | NativeHlsAdapter | null = null;\n #mediaElement: HTMLVideoElement | null = null;\n #src = HlsJsAdapter.defaultProps.src;\n #source: HlsSource | null = HlsJsAdapter.defaultProps.source;\n #preload = HlsJsAdapter.defaultProps.preload;\n #streamType: StreamType = HlsJsAdapter.defaultProps.streamType;\n #isUserStreamType = false;\n #loadRequested?: Promise<void> | null;\n #prevEngineConfigKey?: Record<string, any> | null;\n /**\n * The author's `disableRemotePlayback`, not the element's current value. Tracked because engines (hls.js or SPF) may\n * alter the value internally. Cached here for cases where this value is set before the delegate is created so it can\n * later be forwarded.\n */\n #authorDisableRemotePlayback?: boolean;\n\n constructor() {\n super();\n // Cancel the native loadstart event, it's handled in the load method.\n this.addEventListener('loadstart', this.#stopTargetLoadStartEvent);\n }\n\n attach(target: HTMLVideoElement) {\n this.#mediaElement = target;\n super.attach(target);\n this.#delegate?.attach(target);\n }\n\n detach() {\n this.#delegate?.detach();\n super.detach();\n this.#mediaElement = null;\n }\n\n destroy() {\n this.detach();\n this.#engineDestroy();\n super.destroy();\n this.removeEventListener('loadstart', this.#stopTargetLoadStartEvent);\n }\n\n /**\n * Underlying playback engine — the hls.js `Hls` instance when playing via MSE, otherwise `null`. An advanced escape\n * hatch for direct engine access; normal playback is driven through this element's own properties and methods.\n */\n get engine() {\n return this.#delegate?.engine ?? null;\n }\n\n /**\n * Engine this media is playing through, reported to analytics such as Mux Data: `hlsjs` via MSE, `browser` for native\n * HLS, or `undefined` until a source loads. Read from the instance because the engine is picked per source.\n */\n get engineName(): string | undefined {\n return getMediaEngineName(this.#delegate);\n }\n\n get error() {\n return this.#delegate?.error ?? null;\n }\n\n /** Populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */\n get videoTracks() {\n return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.videoTracks : undefined;\n }\n\n /** Populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */\n get audioTracks() {\n return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.audioTracks : undefined;\n }\n\n /** Selectable quality levels, populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */\n get videoRenditions() {\n return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.videoRenditions : undefined;\n }\n\n /** Selectable audio variants, populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */\n get audioRenditions() {\n return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.audioRenditions : undefined;\n }\n\n /**\n * Media source URL. Assigning it replaces the identity half of `source` and leaves `type` and the engine options\n * intact, so changing the URL never disturbs engine configuration.\n */\n get src() {\n return this.#src;\n }\n\n set src(src: string) {\n // `src` says which source to play; every other field says how to play it, so\n // they carry over.\n const { type, preferPlayback, drm, engine, maxAutoResolution, capRenditionToPlayerSize, minAutoResolution } =\n this.#source ?? {};\n const next: HlsSource = {\n ...(type && { type }),\n ...(preferPlayback && { preferPlayback }),\n ...(drm && { drm }),\n ...(engine && { engine }),\n ...(maxAutoResolution && { maxAutoResolution }),\n // Definedness, not truthiness: `false` is the value worth naming, and the\n // falsy one, so the neighbors' pattern would drop it.\n ...(capRenditionToPlayerSize !== undefined && { capRenditionToPlayerSize }),\n ...(minAutoResolution && { minAutoResolution }),\n ...(src && { src }),\n };\n\n // Everything happens in the `source` setter, so there is one path for storing\n // it, deciding on a load, and dispatching `sourcechange`.\n this.source = Object.keys(next).length > 0 ? next : null;\n }\n\n /**\n * Structured source: what to play (`src`, an optional `type`) plus how to play it (`preferPlayback`, `engine`).\n * Assigning it derives `src`.\n *\n * Sources are compared structurally, so reassigning an equivalent object is a no-op. Only a change to the engine\n * options (or to the resolved content type) recreates the playback engine.\n */\n get source(): HlsSource | null {\n return this.#source;\n }\n\n set source(value: HlsSource | null) {\n const source = value ?? null;\n // Changing anything takes a new object, so handing the same one back costs\n // nothing.\n if (source === this.#source) return;\n\n const src = source?.src ?? '';\n const srcChanged = this.#src !== src;\n\n this.#source = source;\n this.#src = src;\n\n // Deliberately outside the engine config key below, so it reaches the engine\n // already running.\n this.#applyRenditionCaps();\n\n // Assigning is always a source change, so it is always announced.\n this.dispatchEvent(new Event('sourcechange'));\n\n // Only reload for something playback depends on. Subclasses add params that\n // describe images rather than the stream — Mux's `poster` and `storyboard` —\n // and changing one of those must not restart what is already playing.\n if (srcChanged || this.#shouldEngineUpdate(this.#engineConfigKey())) this.#requestLoad();\n }\n\n /** Preload type (`'none'` / `'metadata'` / `'auto'`). */\n get preload() {\n return this.#preload;\n }\n\n set preload(value) {\n this.#preload = value;\n\n if (this.#delegate) {\n this.#delegate.preload = value;\n }\n }\n\n /** Whether remote playback (AirPlay, Google Cast) is disabled for this media. */\n get disableRemotePlayback() {\n return super.disableRemotePlayback;\n }\n\n set disableRemotePlayback(value: boolean) {\n this.#authorDisableRemotePlayback = value;\n super.disableRemotePlayback = value;\n\n if (this.#delegate instanceof HlsJsOnlyAdapter) {\n this.#delegate.disableRemotePlayback = value;\n }\n }\n\n /** Current stream type (`'on-demand'` / `'live'` / `'unknown'`). */\n get streamType(): StreamType {\n return this.#delegate?.streamType ?? this.#streamType;\n }\n\n set streamType(value: StreamType) {\n this.#isUserStreamType = value !== StreamTypes.UNKNOWN;\n\n if (this.#delegate) {\n this.#delegate.streamType = value;\n this.#streamType = this.#delegate.streamType;\n return;\n }\n\n if (this.#streamType === value) return;\n\n this.#streamType = value;\n this.dispatchEvent(new HlsMediaEvent('streamtypechange'));\n }\n\n /**\n * Presentation time marking the start of the Live Edge Window.\n *\n * Derived from the delegate on every read; `NaN` when no delegate is attached or the stream is not live.\n */\n get liveEdgeStart() {\n return this.#delegate?.liveEdgeStart ?? Number.NaN;\n }\n\n /**\n * Seekable range size for live content. `0` for standard live, `Infinity` for DVR, `NaN` for on-demand or unknown.\n * Fires `targetlivewindowchange` when the value changes (bridged from the delegate).\n */\n get targetLiveWindow() {\n return this.#delegate?.targetLiveWindow ?? Number.NaN;\n }\n\n async load() {\n this.#loadRequested = null;\n\n if (this.remote.state === 'connected') {\n this.dispatchEvent(new HlsMediaEvent('loadstart'));\n return super.load();\n }\n\n if (this.#shouldEngineUpdate(this.#engineConfigKey())) {\n this.#engineDestroy();\n this.#prevEngineConfigKey = this.#engineConfigKey();\n\n // Read the stored source, not the `source` getter: subclasses override the\n // getter to return what was assigned to them, while the fields below come\n // from what they resolved and handed down (Mux fills in the DRM options).\n const { type, preferPlayback, drm, engine, maxAutoResolution, capRenditionToPlayerSize, minAutoResolution } =\n this.#source ?? {};\n const { hlsJs, nativeHls } = engine ?? {};\n const contentType = resolveContentType(type, this.src);\n const useMse = Hls.isSupported() && contentType === ContentTypes.M3U8 && preferPlayback !== PlaybackTypes.NATIVE;\n\n if (__DEV__ && type && !contentType) {\n console.warn(\n `[vjs-media] Unrecognized \\`source.type\\` \"${type}\". HLS sources should use \\`${ContentTypes.M3U8}\\` (or \\`application/x-mpegURL\\`); the browser is being handed this source to play natively, so hls.js features such as quality selection are unavailable.`\n );\n }\n\n if (__DEV__ && !useMse) {\n const ignored = Object.entries({ maxAutoResolution, capRenditionToPlayerSize, minAutoResolution })\n .filter(([, value]) => value !== undefined)\n .map(([key]) => `\\`${key}\\``);\n\n if (ignored.length > 0) {\n const [verb, pronoun] = ignored.length > 1 ? ['require', 'them'] : ['requires', 'it'];\n\n console.warn(\n `[vjs-media] ${ignored.join(', ')} ${verb} the hls.js (MSE) engine; native HLS playback ignores ${pronoun}.`\n );\n }\n }\n\n this.#delegate = useMse\n ? new HlsJsOnlyAdapter({ config: withDrmSystems(hlsJs, drm) })\n : this.#createNativeDelegate(drm, nativeHls, hlsJs);\n\n bridgeEvents(this.#delegate, this);\n\n // Apply user `streamType` before `attach()` so native delegates do not run\n // synchronous duration-based detection first and emit a transient value.\n if (this.#isUserStreamType) {\n this.#delegate.streamType = this.#streamType;\n }\n\n this.#delegate.preload = this.preload;\n this.#applyRenditionCaps();\n\n // Forward the author intent to the delegate, in case it was captured before it existed.\n if (this.#authorDisableRemotePlayback !== undefined && this.#delegate instanceof HlsJsOnlyAdapter) {\n this.#delegate.disableRemotePlayback = this.#authorDisableRemotePlayback;\n }\n\n if (this.#mediaElement) {\n this.#delegate.attach(this.#mediaElement);\n }\n }\n\n if (this.#delegate) {\n this.dispatchEvent(new HlsMediaEvent('loadstart'));\n this.#delegate.src = this.src;\n }\n }\n\n /**\n * A native delegate carrying the native half of the source — the DRM configuration and the native engine options,\n * which it applies the same precedence to. Its `src` is assigned separately, once the delegate is wired up, and\n * carries what is set here forward.\n */\n #createNativeDelegate(\n drm: DrmSystemsConfig | undefined,\n nativeHls: NativeHlsConfig | undefined,\n hlsJs: Partial<HlsJsConfig> | undefined\n ) {\n if (__DEV__) {\n // The delegate applies the same precedence, so the warning has to read — and\n // name — whatever it will end up licensing against. An escape hatch replaces\n // `source.drm` rather than adding to it, so pointing at the wrong one of the\n // two would send a reader looking in a field that is already correct.\n const drmSystems = nativeHls?.drmSystems ?? drm;\n const field = nativeHls?.drmSystems ? 'source.engine.nativeHls.drmSystems' : 'source.drm';\n const isProtected = hlsJs?.emeEnabled || hlsJs?.drmSystems || Object.keys(drmSystems ?? {}).length > 0;\n\n if (isProtected && !drmSystems?.[KeySystems.FAIRPLAY]) {\n console.warn(\n `[vjs-drm] Native HLS playback negotiates FairPlay itself and never sees the hls.js DRM configuration, and no \\`${KeySystems.FAIRPLAY}\\` license server is named in \\`${field}\\`. DRM-protected media will not play.`\n );\n }\n }\n\n const media = new NativeHlsAdapter();\n const source: NativeHlsSource = {\n ...(drm && { drm }),\n ...(nativeHls && { engine: { nativeHls } }),\n };\n\n if (Object.keys(source).length > 0) media.source = source;\n\n return media;\n }\n\n /** Push the source's rendition caps down; only the hls.js engine has a lever. */\n #applyRenditionCaps() {\n if (this.#delegate instanceof HlsJsOnlyAdapter) {\n this.#delegate.maxAutoResolution = this.#source?.maxAutoResolution;\n this.#delegate.capRenditionToPlayerSize = this.#source?.capRenditionToPlayerSize;\n this.#delegate.minAutoResolution = this.#source?.minAutoResolution;\n }\n }\n\n #stopTargetLoadStartEvent = (event: Event) => {\n if (!(event instanceof HlsMediaEvent)) event.stopImmediatePropagation();\n };\n\n async #requestLoad() {\n if (this.#loadRequested) return;\n\n await (this.#loadRequested = Promise.resolve());\n this.#loadRequested = null;\n this.load();\n }\n\n #shouldEngineUpdate(nextEngineConfigKey: Record<string, any>) {\n return !deepEqual(this.#prevEngineConfigKey, nextEngineConfigKey);\n }\n\n /**\n * Every value the engine is constructed from. Compared structurally, so equivalent engine options never trigger a\n * rebuild — including nested ones like `drmSystems`, which a flat comparison would see as changed whenever the object\n * identity did.\n */\n #engineConfigKey() {\n const { type, preferPlayback, drm, engine } = this.#source ?? {};\n\n return { drm, engine, preferPlayback, contentType: resolveContentType(type, this.src) };\n }\n\n #engineDestroy() {\n this.#delegate?.destroy();\n this.#delegate = null;\n this.#prevEngineConfigKey = null;\n this.#loadRequested = null;\n\n // Delegate teardown already emits `streamtypechange` (bridged); only sync cache.\n if (!this.#isUserStreamType) this.#streamType = StreamTypes.UNKNOWN;\n }\n}\n\n/**\n * Hls.js configuration with the source's DRM licensing folded in. hls.js takes `drmSystems` in the same shape as\n * `source.drm`, so the standardized config is what it plays from unless `engine.hlsJs` names servers of its own.\n *\n * Hls.js runs key exchange only while `emeEnabled` is set, so configured DRM switches it on — short of an explicit\n * `emeEnabled: false`, which stays a way to describe a source's licensing without acting on it.\n */\nfunction withDrmSystems(\n hlsJs: Partial<HlsJsConfig> | undefined,\n drm: DrmSystemsConfig | undefined\n): Partial<HlsJsConfig> {\n const drmSystems = hlsJs?.drmSystems ?? drm;\n if (!drmSystems || Object.keys(drmSystems).length === 0) return { ...hlsJs };\n\n // hls.js declares `serverCertificateUrl` without `undefined`, which an\n // omittable property here is allowed to carry. The values are the same.\n return { emeEnabled: true, ...hlsJs, drmSystems: drmSystems as HlsJsConfig['drmSystems'] };\n}\n\n/**\n * The canonical content type the engine decision is made on: an explicit `type` folded onto its canonical spelling, or\n * what the URL suggests when there is none. An explicit type nobody recognizes resolves to `undefined` rather than\n * falling back to inference — the author said what the source is, and guessing over them would make `type` mean\n * different things depending on its value.\n */\nfunction resolveContentType(type: string | undefined, src: string): SourceType | undefined {\n if (!type) return inferContentType(src);\n\n // Parameters (`; charset=...`) and case carry no meaning for the engine choice.\n const normalized = (type.split(';')[0] ?? '').trim().toLowerCase();\n if (HLS_CONTENT_TYPES.has(normalized)) return ContentTypes.M3U8;\n\n if (MP4_CONTENT_TYPES.has(normalized)) return ContentTypes.MP4;\n\n return undefined;\n}\n\nfunction inferContentType(src: string): SourceType {\n const path = src.split(/[?#]/)[0] ?? '';\n if (path.endsWith('.mp4')) return ContentTypes.MP4;\n\n return ContentTypes.M3U8;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OAAO;EAAE,YAAY;EAAM,GAAG;EAAmB;CAAwC;AAC3F;;;;;;;AAQA,SAAS,mBAAmB,MAA0B,KAAqC;CACzF,IAAI,CAAC,MAAM,OAAO,iBAAiB,GAAG;CAGtC,MAAM,cAAc,KAAK,MAAM,GAAG,CAAC,CAAC,MAAM,GAAA,CAAI,KAAK,CAAC,CAAC,YAAY;CACjE,IAAI,kBAAkB,IAAI,UAAU,GAAG,OAAO,aAAa;CAE3D,IAAI,kBAAkB,IAAI,UAAU,GAAG,OAAO,aAAa;AAG7D;AAEA,SAAS,iBAAiB,KAAyB;CAEjD,KADa,IAAI,MAAM,MAAM,CAAC,CAAC,MAAM,GAAA,CAC5B,SAAS,MAAM,GAAG,OAAO,aAAa;CAE/C,OAAO,aAAa;AACtB"}
|
|
1
|
+
{"version":3,"file":"adapter.js","names":["Hls"],"sources":["../../src/adapter.ts"],"sourcesContent":["import {\n bridgeEvents,\n type DrmSystemsConfig,\n KeySystems,\n type MediaResolution,\n type MediaStreamType,\n MediaStreamTypes,\n} from '@videojs/media';\nimport { getMediaEngineName, HTMLVideoAdapter } from '@videojs/media/dom';\nimport { type NativeHlsConfig, NativeHlsAdapter, type NativeHlsSource } from '@videojs/native-hls-video';\nimport { deepEqual } from '@videojs/utils/object';\nimport Hls, { type HlsConfig as HlsJsConfig } from 'hls.js';\n\nimport { HlsJsOnlyAdapter } from './hls-js-only';\n\nexport type PreloadType = '' | 'none' | 'metadata' | 'auto';\n\nexport type { MediaResolution };\n\nexport { Hls };\n\n/** How hls.js plays a source: through Media Source Extensions, or the browser's native HLS support. */\nexport type PlaybackType = 'mse' | 'native' | (string & {});\n/** A source's MIME type, such as `application/vnd.apple.mpegurl` for HLS or `video/mp4`. */\nexport type SourceType = 'application/vnd.apple.mpegurl' | 'video/mp4' | (string & {});\nexport type StreamType = MediaStreamType;\n\n/** @internal */\nexport const PlaybackTypes = {\n MSE: 'mse',\n NATIVE: 'native',\n};\n\n/** @internal */\nexport const ContentTypes = {\n M3U8: 'application/vnd.apple.mpegurl',\n MP4: 'video/mp4',\n};\n\n/**\n * Every MIME type that means HLS in the wild, lowercased. `application/vnd.apple.mpegurl` is the registered one, but\n * `application/x-mpegURL` predates it and is what most servers, CDNs, and older Video.js guides hand out, so a source\n * naming any of these has to reach hls.js rather than fall through to native playback.\n */\nconst HLS_CONTENT_TYPES: ReadonlySet<string> = new Set([\n ContentTypes.M3U8,\n 'application/x-mpegurl',\n 'application/mpegurl',\n 'audio/mpegurl',\n 'audio/x-mpegurl',\n]);\n\nconst MP4_CONTENT_TYPES: ReadonlySet<string> = new Set([ContentTypes.MP4]);\n\n/** @internal */\nexport const StreamTypes = MediaStreamTypes;\n\nexport interface HlsJsAdapterProps {\n src: string;\n source: HlsSource | null;\n preload: PreloadType;\n streamType: StreamType;\n disableRemotePlayback: boolean;\n}\n\n/**\n * Structured HLS source: which source to play, plus how to play it.\n *\n * Playback options are namespaced by engine. There are two paths here — hls.js and the browser's own HLS support — and\n * only one of them runs, so a source describes both without either engine reading the other's options.\n *\n * `preferPlayback` and the engine options are all read when the engine is constructed, so changing any of them\n * recreates it.\n */\nexport interface HlsSource {\n /** Manifest URL. Mirrors the host's `src` property. */\n src?: string | undefined;\n /**\n * MIME type of the source. Takes precedence over inference from `src`.\n *\n * Matched case-insensitively, and the legacy HLS spellings (`application/x-mpegURL`, `audio/mpegurl`, …) count as\n * `application/vnd.apple.mpegurl`. Anything unrecognized is treated as a URL the browser plays on its own.\n */\n type?: SourceType | undefined;\n /**\n * Preferred playback path: `'mse'` for hls.js, `'native'` for the browser's own HLS support. Ignored when the\n * preferred path cannot play the source.\n */\n preferPlayback?: PlaybackType | undefined;\n /**\n * License servers for protected content, keyed by EME key system id.\n *\n * Engine neutral, because which engine plays is decided later: hls.js is handed every system named here (with EME\n * switched on), and native playback negotiates the `com.apple.fps` entry itself. Name every system you hold a license\n * server for — which one is used is the browser's choice.\n */\n drm?: DrmSystemsConfig | undefined;\n /**\n * Highest resolution adaptive bitrate selection may choose on its own.\n *\n * A ceiling on automatic selection, not a filter on what is available: renditions above it stay in `videoRenditions`\n * and can still be selected by hand. Matching is by pixel area, so a `'720p'` cap admits any rendition at or below\n * 1280×720 worth of pixels. When every rendition sits above the cap, the smallest one is used.\n *\n * Applied live — changing it never rebuilds the playback engine. Requires the hls.js (MSE) engine; native HLS\n * playback ignores it.\n *\n * For Mux sources this is distinct from `playback.maxResolution`, which asks Mux to leave higher renditions out of\n * the manifest altogether.\n */\n maxAutoResolution?: MediaResolution | undefined;\n /**\n * Whether the element's rendered size caps automatic selection. Defaults to `true`.\n *\n * A 400px-wide player has no use for a 4K rendition, so selection is held to the smallest rendition that still covers\n * the element, measured in device pixels — a `2` device pixel ratio asks for twice what a CSS measurement would. The\n * cap follows the element as it resizes, and `minAutoResolution` bounds how far down it can go. Set it to `false` for\n * a player whose layout size understates what it needs, such as one that goes fullscreen without a resize.\n *\n * Which rendition covers the element is hls.js's own judgement, weighed on the largest dimension rather than pixel\n * area, so it can land elsewhere than `maxAutoResolution` would for the same ladder.\n *\n * Applied live — changing it never rebuilds the playback engine. Requires the hls.js (MSE) engine; native HLS\n * playback ignores it. Setting hls.js's own `capLevelToPlayerSize` through `source.engine.hlsJs` is a different\n * thing: it stops the loop _every_ cap here is evaluated on, and takes a rebuild.\n */\n capRenditionToPlayerSize?: boolean | undefined;\n /**\n * Lowest resolution `capRenditionToPlayerSize` may cap down to. Defaults to `'720p'`.\n *\n * Not a quality floor. It bounds the size-derived cap and nothing else: when bandwidth is poor, adaptive selection\n * still drops below it, because the cap is a ceiling and selection stays free underneath. Nor does it raise an\n * explicit `maxAutoResolution` — asking for at most `'360p'` alongside a `'720p'` floor yields `'360p'`.\n *\n * The default exists because the low rungs of a ladder are there for poor network conditions, and capping a small\n * player to them looks worse than its size suggests. Name a lower rung to weaken the floor, or `'270p'` to lift it\n * for any real ladder.\n *\n * Applied live — changing it never rebuilds the playback engine. Requires the hls.js (MSE) engine; native HLS\n * playback ignores it.\n */\n minAutoResolution?: MediaResolution | undefined;\n /**\n * Playback options, keyed by the engine that reads them. Only one of the two engines below ends up playing, and each\n * reads only its own key.\n */\n engine?: HlsEngineConfig | undefined;\n}\n\n/** The engines an HLS source can configure. */\nexport interface HlsEngineConfig {\n /**\n * Hls.js's own configuration, passed through untouched. A `drmSystems` of its own replaces `source.drm` for hls.js —\n * an escape hatch for licensing MSE playback differently, or for the parts of hls.js's DRM configuration `source.drm`\n * does not cover.\n */\n hlsJs?: Partial<HlsJsConfig> | undefined;\n /**\n * Options for the browser's own HLS playback, used whenever the native path is the one taken. Its `drmSystems`\n * replaces `source.drm` for that path in the same way.\n */\n nativeHls?: NativeHlsConfig | undefined;\n}\n\nclass HlsMediaEvent extends Event {}\n\n/**\n * @fires sourcechange - Fired when `source` changes, either directly or by resolving a new `src`. Read `source` for the\n * new value.\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 */\nexport class HlsJsAdapter extends HTMLVideoAdapter implements HlsJsAdapterProps {\n static readonly defaultProps: HlsJsAdapterProps = {\n src: '',\n source: null,\n preload: 'metadata',\n streamType: MediaStreamTypes.UNKNOWN,\n disableRemotePlayback: false,\n };\n\n #delegate: HlsJsOnlyAdapter | NativeHlsAdapter | null = null;\n #mediaElement: HTMLVideoElement | null = null;\n #src = HlsJsAdapter.defaultProps.src;\n #source: HlsSource | null = HlsJsAdapter.defaultProps.source;\n #preload = HlsJsAdapter.defaultProps.preload;\n #streamType: StreamType = HlsJsAdapter.defaultProps.streamType;\n #isUserStreamType = false;\n #loadRequested?: Promise<void> | null;\n #prevEngineConfigKey?: Record<string, any> | null;\n /**\n * The author's `disableRemotePlayback`, not the element's current value. Tracked because engines (hls.js or SPF) may\n * alter the value internally. Cached here for cases where this value is set before the delegate is created so it can\n * later be forwarded.\n */\n #authorDisableRemotePlayback?: boolean;\n\n constructor() {\n super();\n // Cancel the native loadstart event, it's handled in the load method.\n this.addEventListener('loadstart', this.#stopTargetLoadStartEvent);\n }\n\n attach(target: HTMLVideoElement) {\n this.#mediaElement = target;\n super.attach(target);\n this.#delegate?.attach(target);\n }\n\n detach() {\n this.#delegate?.detach();\n super.detach();\n this.#mediaElement = null;\n }\n\n destroy() {\n this.detach();\n this.#engineDestroy();\n super.destroy();\n this.removeEventListener('loadstart', this.#stopTargetLoadStartEvent);\n }\n\n /**\n * Underlying playback engine — the hls.js `Hls` instance when playing via MSE, otherwise `null`. An advanced escape\n * hatch for direct engine access; normal playback is driven through this element's own properties and methods.\n */\n get engine() {\n return this.#delegate?.engine ?? null;\n }\n\n /**\n * Engine this media is playing through, reported to analytics such as Mux Data: `hlsjs` via MSE, `browser` for native\n * HLS, or `undefined` until a source loads. Read from the instance because the engine is picked per source.\n */\n get engineName(): string | undefined {\n return getMediaEngineName(this.#delegate);\n }\n\n get error() {\n return this.#delegate?.error ?? null;\n }\n\n /** Populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */\n get videoTracks() {\n return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.videoTracks : undefined;\n }\n\n /** Populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */\n get audioTracks() {\n return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.audioTracks : undefined;\n }\n\n /** Selectable quality levels, populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */\n get videoRenditions() {\n return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.videoRenditions : undefined;\n }\n\n /** Selectable audio variants, populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */\n get audioRenditions() {\n return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.audioRenditions : undefined;\n }\n\n /**\n * Media source URL. Assigning it replaces the identity half of `source` and leaves `type` and the engine options\n * intact, so changing the URL never disturbs engine configuration.\n */\n get src() {\n return this.#src;\n }\n\n set src(src: string) {\n // `src` says which source to play; every other field says how to play it, so\n // they carry over.\n const { type, preferPlayback, drm, engine, maxAutoResolution, capRenditionToPlayerSize, minAutoResolution } =\n this.#source ?? {};\n const next: HlsSource = {\n ...(type && { type }),\n ...(preferPlayback && { preferPlayback }),\n ...(drm && { drm }),\n ...(engine && { engine }),\n ...(maxAutoResolution && { maxAutoResolution }),\n // Definedness, not truthiness: `false` is the value worth naming, and the\n // falsy one, so the neighbors' pattern would drop it.\n ...(capRenditionToPlayerSize !== undefined && { capRenditionToPlayerSize }),\n ...(minAutoResolution && { minAutoResolution }),\n ...(src && { src }),\n };\n\n // Everything happens in the `source` setter, so there is one path for storing\n // it, deciding on a load, and dispatching `sourcechange`.\n this.source = Object.keys(next).length > 0 ? next : null;\n }\n\n /**\n * Structured source: what to play (`src`, an optional `type`) plus how to play it (`preferPlayback`, `engine`).\n * Assigning it derives `src`.\n *\n * Sources are compared structurally, so reassigning an equivalent object is a no-op. Only a change to the engine\n * options (or to the resolved content type) recreates the playback engine.\n */\n get source(): HlsSource | null {\n return this.#source;\n }\n\n set source(value: HlsSource | null) {\n const source = value ?? null;\n // Changing anything takes a new object, so handing the same one back costs\n // nothing.\n if (source === this.#source) return;\n\n const src = source?.src ?? '';\n const srcChanged = this.#src !== src;\n\n this.#source = source;\n this.#src = src;\n\n // Deliberately outside the engine config key below, so it reaches the engine\n // already running.\n this.#applyRenditionCaps();\n\n // Assigning is always a source change, so it is always announced.\n this.dispatchEvent(new Event('sourcechange'));\n\n // Only reload for something playback depends on. Subclasses add params that\n // describe images rather than the stream — Mux's `poster` and `storyboard` —\n // and changing one of those must not restart what is already playing.\n if (srcChanged || this.#shouldEngineUpdate(this.#engineConfigKey())) this.#requestLoad();\n }\n\n /** Preload type (`'none'` / `'metadata'` / `'auto'`). */\n get preload() {\n return this.#preload;\n }\n\n set preload(value) {\n this.#preload = value;\n\n if (this.#delegate) {\n this.#delegate.preload = value;\n }\n }\n\n /** Whether remote playback (AirPlay, Google Cast) is disabled for this media. */\n get disableRemotePlayback() {\n return super.disableRemotePlayback;\n }\n\n set disableRemotePlayback(value: boolean) {\n this.#authorDisableRemotePlayback = value;\n super.disableRemotePlayback = value;\n\n if (this.#delegate instanceof HlsJsOnlyAdapter) {\n this.#delegate.disableRemotePlayback = value;\n }\n }\n\n /** Current stream type (`'on-demand'` / `'live'` / `'unknown'`). */\n get streamType(): StreamType {\n return this.#delegate?.streamType ?? this.#streamType;\n }\n\n set streamType(value: StreamType) {\n this.#isUserStreamType = value !== StreamTypes.UNKNOWN;\n\n if (this.#delegate) {\n this.#delegate.streamType = value;\n this.#streamType = this.#delegate.streamType;\n return;\n }\n\n if (this.#streamType === value) return;\n\n this.#streamType = value;\n this.dispatchEvent(new HlsMediaEvent('streamtypechange'));\n }\n\n /**\n * Presentation time marking the start of the Live Edge Window.\n *\n * Derived from the delegate on every read; `NaN` when no delegate is attached or the stream is not live.\n */\n get liveEdgeStart() {\n return this.#delegate?.liveEdgeStart ?? Number.NaN;\n }\n\n /**\n * Seekable range size for live content. `0` for standard live, `Infinity` for DVR, `NaN` for on-demand or unknown.\n * Fires `targetlivewindowchange` when the value changes (bridged from the delegate).\n */\n get targetLiveWindow() {\n return this.#delegate?.targetLiveWindow ?? Number.NaN;\n }\n\n async load() {\n this.#loadRequested = null;\n\n if (this.remote?.state === 'connected') {\n this.dispatchEvent(new HlsMediaEvent('loadstart'));\n return super.load();\n }\n\n if (this.#shouldEngineUpdate(this.#engineConfigKey())) {\n this.#engineDestroy();\n this.#prevEngineConfigKey = this.#engineConfigKey();\n\n // Read the stored source, not the `source` getter: subclasses override the\n // getter to return what was assigned to them, while the fields below come\n // from what they resolved and handed down (Mux fills in the DRM options).\n const { type, preferPlayback, drm, engine, maxAutoResolution, capRenditionToPlayerSize, minAutoResolution } =\n this.#source ?? {};\n const { hlsJs, nativeHls } = engine ?? {};\n const contentType = resolveContentType(type, this.src);\n const useMse = Hls.isSupported() && contentType === ContentTypes.M3U8 && preferPlayback !== PlaybackTypes.NATIVE;\n\n if (__DEV__ && type && !contentType) {\n console.warn(\n `[vjs-media] Unrecognized \\`source.type\\` \"${type}\". HLS sources should use \\`${ContentTypes.M3U8}\\` (or \\`application/x-mpegURL\\`); the browser is being handed this source to play natively, so hls.js features such as quality selection are unavailable.`\n );\n }\n\n if (__DEV__ && !useMse) {\n const ignored = Object.entries({ maxAutoResolution, capRenditionToPlayerSize, minAutoResolution })\n .filter(([, value]) => value !== undefined)\n .map(([key]) => `\\`${key}\\``);\n\n if (ignored.length > 0) {\n const [verb, pronoun] = ignored.length > 1 ? ['require', 'them'] : ['requires', 'it'];\n\n console.warn(\n `[vjs-media] ${ignored.join(', ')} ${verb} the hls.js (MSE) engine; native HLS playback ignores ${pronoun}.`\n );\n }\n }\n\n this.#delegate = useMse\n ? new HlsJsOnlyAdapter({ config: withDrmSystems(hlsJs, drm) })\n : this.#createNativeDelegate(drm, nativeHls, hlsJs);\n\n bridgeEvents(this.#delegate, this);\n\n // Apply user `streamType` before `attach()` so native delegates do not run\n // synchronous duration-based detection first and emit a transient value.\n if (this.#isUserStreamType) {\n this.#delegate.streamType = this.#streamType;\n }\n\n this.#delegate.preload = this.preload;\n this.#applyRenditionCaps();\n\n // Forward the author intent to the delegate, in case it was captured before it existed.\n if (this.#authorDisableRemotePlayback !== undefined && this.#delegate instanceof HlsJsOnlyAdapter) {\n this.#delegate.disableRemotePlayback = this.#authorDisableRemotePlayback;\n }\n\n if (this.#mediaElement) {\n this.#delegate.attach(this.#mediaElement);\n }\n }\n\n if (this.#delegate) {\n this.dispatchEvent(new HlsMediaEvent('loadstart'));\n this.#delegate.src = this.src;\n }\n }\n\n /**\n * A native delegate carrying the native half of the source — the DRM configuration and the native engine options,\n * which it applies the same precedence to. Its `src` is assigned separately, once the delegate is wired up, and\n * carries what is set here forward.\n */\n #createNativeDelegate(\n drm: DrmSystemsConfig | undefined,\n nativeHls: NativeHlsConfig | undefined,\n hlsJs: Partial<HlsJsConfig> | undefined\n ) {\n if (__DEV__) {\n // The delegate applies the same precedence, so the warning has to read — and\n // name — whatever it will end up licensing against. An escape hatch replaces\n // `source.drm` rather than adding to it, so pointing at the wrong one of the\n // two would send a reader looking in a field that is already correct.\n const drmSystems = nativeHls?.drmSystems ?? drm;\n const field = nativeHls?.drmSystems ? 'source.engine.nativeHls.drmSystems' : 'source.drm';\n const isProtected = hlsJs?.emeEnabled || hlsJs?.drmSystems || Object.keys(drmSystems ?? {}).length > 0;\n\n if (isProtected && !drmSystems?.[KeySystems.FAIRPLAY]) {\n console.warn(\n `[vjs-drm] Native HLS playback negotiates FairPlay itself and never sees the hls.js DRM configuration, and no \\`${KeySystems.FAIRPLAY}\\` license server is named in \\`${field}\\`. DRM-protected media will not play.`\n );\n }\n }\n\n const media = new NativeHlsAdapter();\n const source: NativeHlsSource = {\n ...(drm && { drm }),\n ...(nativeHls && { engine: { nativeHls } }),\n };\n\n if (Object.keys(source).length > 0) media.source = source;\n\n return media;\n }\n\n /** Push the source's rendition caps down; only the hls.js engine has a lever. */\n #applyRenditionCaps() {\n if (this.#delegate instanceof HlsJsOnlyAdapter) {\n this.#delegate.maxAutoResolution = this.#source?.maxAutoResolution;\n this.#delegate.capRenditionToPlayerSize = this.#source?.capRenditionToPlayerSize;\n this.#delegate.minAutoResolution = this.#source?.minAutoResolution;\n }\n }\n\n #stopTargetLoadStartEvent = (event: Event) => {\n if (!(event instanceof HlsMediaEvent)) event.stopImmediatePropagation();\n };\n\n async #requestLoad() {\n if (this.#loadRequested) return;\n\n await (this.#loadRequested = Promise.resolve());\n this.#loadRequested = null;\n this.load();\n }\n\n #shouldEngineUpdate(nextEngineConfigKey: Record<string, any>) {\n return !deepEqual(this.#prevEngineConfigKey, nextEngineConfigKey);\n }\n\n /**\n * Every value the engine is constructed from. Compared structurally, so equivalent engine options never trigger a\n * rebuild — including nested ones like `drmSystems`, which a flat comparison would see as changed whenever the object\n * identity did.\n */\n #engineConfigKey() {\n const { type, preferPlayback, drm, engine } = this.#source ?? {};\n\n return { drm, engine, preferPlayback, contentType: resolveContentType(type, this.src) };\n }\n\n #engineDestroy() {\n this.#delegate?.destroy();\n this.#delegate = null;\n this.#prevEngineConfigKey = null;\n this.#loadRequested = null;\n\n // Delegate teardown already emits `streamtypechange` (bridged); only sync cache.\n if (!this.#isUserStreamType) this.#streamType = StreamTypes.UNKNOWN;\n }\n}\n\n/**\n * Hls.js configuration with the source's DRM licensing folded in. hls.js takes `drmSystems` in the same shape as\n * `source.drm`, so the standardized config is what it plays from unless `engine.hlsJs` names servers of its own.\n *\n * Hls.js runs key exchange only while `emeEnabled` is set, so configured DRM switches it on — short of an explicit\n * `emeEnabled: false`, which stays a way to describe a source's licensing without acting on it.\n */\nfunction withDrmSystems(\n hlsJs: Partial<HlsJsConfig> | undefined,\n drm: DrmSystemsConfig | undefined\n): Partial<HlsJsConfig> {\n const drmSystems = hlsJs?.drmSystems ?? drm;\n if (!drmSystems || Object.keys(drmSystems).length === 0) return { ...hlsJs };\n\n // hls.js declares `serverCertificateUrl` without `undefined`, which an\n // omittable property here is allowed to carry. The values are the same.\n return { emeEnabled: true, ...hlsJs, drmSystems: drmSystems as HlsJsConfig['drmSystems'] };\n}\n\n/**\n * The canonical content type the engine decision is made on: an explicit `type` folded onto its canonical spelling, or\n * what the URL suggests when there is none. An explicit type nobody recognizes resolves to `undefined` rather than\n * falling back to inference — the author said what the source is, and guessing over them would make `type` mean\n * different things depending on its value.\n */\nfunction resolveContentType(type: string | undefined, src: string): SourceType | undefined {\n if (!type) return inferContentType(src);\n\n // Parameters (`; charset=...`) and case carry no meaning for the engine choice.\n const normalized = (type.split(';')[0] ?? '').trim().toLowerCase();\n if (HLS_CONTENT_TYPES.has(normalized)) return ContentTypes.M3U8;\n\n if (MP4_CONTENT_TYPES.has(normalized)) return ContentTypes.MP4;\n\n return undefined;\n}\n\nfunction inferContentType(src: string): SourceType {\n const path = src.split(/[?#]/)[0] ?? '';\n if (path.endsWith('.mp4')) return ContentTypes.MP4;\n\n return ContentTypes.M3U8;\n}\n"],"mappings":";;;;;;;;AA4BA,MAAa,gBAAgB;CAC3B,KA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;;;;AAQA,SAAS,mBAAmB,MAA0B,KAAqC;CACzF,IAAI,CAAC,MAAM,OAAO,iBAAiB,GAAG;CAGtC,MAAM,cAAc,KAAK,MAAM,GAAG,CAAC,CAAC,MAAM,GAAA,CAAI,KAAK,CAAC,CAAC,YAAY;CACjE,IAAI,kBAAkB,IAAI,UAAU,GAAG,OAAO,aAAa;CAE3D,IAAI,kBAAkB,IAAI,UAAU,GAAG,OAAO,aAAa;AAG7D;AAEA,SAAS,iBAAiB,KAAyB;CAEjD,KADa,IAAI,MAAM,MAAM,CAAC,CAAC,MAAM,GAAA,CAC5B,SAAS,MAAM,GAAG,OAAO,aAAa;CAE/C,OAAO,aAAa;AACtB"}
|
package/dist/dev/text-tracks.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import Hls from "hls.js";
|
|
2
2
|
import { isCaptionOrSubtitleTrack, listen } from "@videojs/utils/dom";
|
|
3
|
+
import { isNil } from "@videojs/utils/predicate";
|
|
3
4
|
//#region src/text-tracks.ts
|
|
4
5
|
/** Marks the `<track>` elements created here for hls.js's own text tracks. */
|
|
5
6
|
const HLS_TRACK_ATTR = "data-removeondestroy";
|
|
6
|
-
/** Marks the subset created from hls.js's CEA-608/708 announcements, which are announced one track at a time. */
|
|
7
|
-
const CC_TRACK_ATTR = "data-cc";
|
|
8
7
|
/** `HTMLTrackElement.LOADED` — the element parsed its resource and will not parse it again. */
|
|
9
8
|
const TRACK_LOADED = 2;
|
|
10
9
|
/**
|
|
@@ -28,20 +27,12 @@ function withPreservedTextTracks(media, action) {
|
|
|
28
27
|
for (const snapshot of snapshots) restoreTextTrack(snapshot);
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
|
-
/** Disables and removes every text track created for the current hls.js source. */
|
|
32
|
-
function removeHlsTextTracks(media) {
|
|
33
|
-
const trackEls = media?.querySelectorAll(`track[${HLS_TRACK_ATTR}]`) ?? [];
|
|
34
|
-
for (const trackEl of trackEls) {
|
|
35
|
-
trackEl.track.mode = "disabled";
|
|
36
|
-
trackEl.remove();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
30
|
function snapshotTextTracks(media) {
|
|
40
31
|
const snapshots = [];
|
|
41
32
|
for (const trackEl of media.querySelectorAll("track")) {
|
|
42
33
|
if (trackEl.hasAttribute(HLS_TRACK_ATTR)) continue;
|
|
43
34
|
const { track } = trackEl;
|
|
44
|
-
if (track.mode === "disabled" && trackEl.readyState
|
|
35
|
+
if (track.mode === "disabled" && trackEl.readyState < TRACK_LOADED) continue;
|
|
45
36
|
snapshots.push({
|
|
46
37
|
track,
|
|
47
38
|
mode: track.mode,
|
|
@@ -75,24 +66,58 @@ function withReadableCues(track, action) {
|
|
|
75
66
|
* When `renderTextTracksNatively: false`, hls.js fires `NON_NATIVE_TEXT_TRACKS_FOUND` with track metadata and
|
|
76
67
|
* `CUES_PARSED` with VTTCues. This mixin creates `<track>` elements on the media target and forwards cues into them. It
|
|
77
68
|
* also syncs user track-mode changes back to hls.js via `engine.subtitleTrack`.
|
|
69
|
+
*
|
|
70
|
+
* The tracks belong to the source, not to the media element. A new manifest or the engine's destruction drops them.
|
|
71
|
+
* hls.js's own detach/attach, e.g. `hls.recoverMediaError()`, leaves them where they are: hls.js announces the subtitle
|
|
72
|
+
* set again only when its list changes, and each CC track only once 608 data shows up, and keeping the elements keeps
|
|
73
|
+
* their modes, cues and place among the other `<track>` elements. Only the adapter letting go of the element unmounts
|
|
74
|
+
* them, and the next attach mounts the same elements again with their modes and cues.
|
|
78
75
|
*/
|
|
79
76
|
function HlsJsTextTracksMixin(BaseClass) {
|
|
80
77
|
class HlsJsTextTracks extends BaseClass {
|
|
81
78
|
#disconnect = null;
|
|
79
|
+
/** The tracks of the current source, by the id hls.js addresses their cues with. */
|
|
80
|
+
#tracks = /* @__PURE__ */ new Map();
|
|
82
81
|
constructor(...args) {
|
|
83
82
|
super(...args);
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
const { engine } = this;
|
|
84
|
+
if (!engine) return;
|
|
85
|
+
engine.on(Hls.Events.MANIFEST_LOADING, () => {
|
|
86
|
+
this.#reset();
|
|
86
87
|
this.#init();
|
|
87
88
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
engine.on(Hls.Events.MEDIA_ATTACHED, () => {
|
|
90
|
+
this.#init();
|
|
91
|
+
this.#mount();
|
|
92
|
+
});
|
|
93
|
+
engine.on(Hls.Events.MEDIA_DETACHED, () => this.#disconnectListeners());
|
|
94
|
+
engine.on(Hls.Events.DESTROYING, () => this.#reset());
|
|
95
|
+
}
|
|
96
|
+
/** The adapter lets go of the element, unlike hls.js's own detach/attach, so the tracks leave it too. */
|
|
97
|
+
detach() {
|
|
98
|
+
this.#unmount();
|
|
99
|
+
super.detach();
|
|
91
100
|
}
|
|
92
|
-
#
|
|
101
|
+
#disconnectListeners() {
|
|
93
102
|
this.#disconnect?.abort();
|
|
94
103
|
this.#disconnect = null;
|
|
95
|
-
|
|
104
|
+
}
|
|
105
|
+
#reset() {
|
|
106
|
+
this.#disconnectListeners();
|
|
107
|
+
this.#unmount();
|
|
108
|
+
this.#tracks.clear();
|
|
109
|
+
}
|
|
110
|
+
/** Mounts the tracks of the current source that are not on the media element yet. */
|
|
111
|
+
#mount() {
|
|
112
|
+
const media = this.target;
|
|
113
|
+
if (!media) return;
|
|
114
|
+
for (const [id, track] of this.#tracks) if (track.el?.parentNode !== media) mountTrack(media, id, track, null);
|
|
115
|
+
}
|
|
116
|
+
#unmount() {
|
|
117
|
+
for (const track of this.#tracks.values()) unmountTrack(track);
|
|
118
|
+
}
|
|
119
|
+
#trackFor(textTrack) {
|
|
120
|
+
for (const track of this.#tracks.values()) if (track.el?.track === textTrack) return track;
|
|
96
121
|
}
|
|
97
122
|
#init() {
|
|
98
123
|
this.#disconnect?.abort();
|
|
@@ -101,32 +126,35 @@ function HlsJsTextTracksMixin(BaseClass) {
|
|
|
101
126
|
const { engine } = this;
|
|
102
127
|
if (!engine || !this.target) return;
|
|
103
128
|
const media = this.target;
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const ccOwned = trackEl.hasAttribute(CC_TRACK_ATTR);
|
|
111
|
-
if (!replaced && (ccBatch || ccOwned)) continue;
|
|
112
|
-
trackEl.track.mode = "disabled";
|
|
113
|
-
trackEl.remove();
|
|
129
|
+
const onTracksFound = (_event, { tracks }) => {
|
|
130
|
+
const incoming = new Map(tracks.map((info) => [trackIdFor(info), info]));
|
|
131
|
+
if (!tracks.every(isClosedCaptions)) for (const [id, track] of this.#tracks) {
|
|
132
|
+
if (isClosedCaptions(track.info) || incoming.has(id)) continue;
|
|
133
|
+
unmountTrack(track);
|
|
134
|
+
this.#tracks.delete(id);
|
|
114
135
|
}
|
|
115
|
-
for (const
|
|
116
|
-
const
|
|
117
|
-
|
|
136
|
+
for (const [id, info] of incoming) {
|
|
137
|
+
const track = this.#tracks.get(id);
|
|
138
|
+
if (!track) {
|
|
139
|
+
this.#tracks.set(id, {
|
|
140
|
+
info,
|
|
141
|
+
mode: null,
|
|
142
|
+
el: null
|
|
143
|
+
});
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const changed = !describesSameTrack(track.info, info);
|
|
147
|
+
track.info = info;
|
|
148
|
+
if (changed) replaceTrack(media, id, track);
|
|
118
149
|
}
|
|
150
|
+
this.#mount();
|
|
119
151
|
};
|
|
120
152
|
const onCuesParsed = (_event, { track, cues }) => {
|
|
121
|
-
const textTrack =
|
|
153
|
+
const textTrack = this.#tracks.get(track)?.el?.track;
|
|
122
154
|
if (!textTrack) return;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
cues.forEach((cue) => {
|
|
126
|
-
if (textTrack.cues?.getCueById(cue.id)) return;
|
|
127
|
-
textTrack.addCue(cue);
|
|
155
|
+
withReadableCues(textTrack, () => {
|
|
156
|
+
for (const cue of cues) if (!textTrack.cues?.getCueById(cue.id)) textTrack.addCue(cue);
|
|
128
157
|
});
|
|
129
|
-
if (disabled) textTrack.mode = "disabled";
|
|
130
158
|
};
|
|
131
159
|
let lastShowingTrack;
|
|
132
160
|
const onTextTrackChange = () => {
|
|
@@ -136,16 +164,10 @@ function HlsJsTextTracksMixin(BaseClass) {
|
|
|
136
164
|
const showingChanged = showingTrack !== lastShowingTrack;
|
|
137
165
|
lastShowingTrack = showingTrack;
|
|
138
166
|
if (!showingTrack) return;
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
if (engine.subtitleTrack < 0 || showingTrack?.id !== hlsTrackId) {
|
|
144
|
-
const idx = engine.subtitleTracks.findIndex(({ lang, name, type, default: defaultTrack }) => {
|
|
145
|
-
return showingTrack.id === "default" && defaultTrack || lang === showingTrack.language && name === showingTrack.label && type.toLowerCase() === showingTrack.kind;
|
|
146
|
-
});
|
|
147
|
-
engine.subtitleTrack = idx;
|
|
148
|
-
}
|
|
167
|
+
const track = this.#trackFor(showingTrack);
|
|
168
|
+
if (showingChanged && track) refreshCues(showingTrack);
|
|
169
|
+
const index = track?.info.subtitleTrack?.id ?? -1;
|
|
170
|
+
if (engine.subtitleTrack !== index) engine.subtitleTrack = index;
|
|
149
171
|
};
|
|
150
172
|
engine.on(Hls.Events.NON_NATIVE_TEXT_TRACKS_FOUND, onTracksFound);
|
|
151
173
|
engine.on(Hls.Events.CUES_PARSED, onCuesParsed);
|
|
@@ -158,10 +180,6 @@ function HlsJsTextTracksMixin(BaseClass) {
|
|
|
158
180
|
}
|
|
159
181
|
return HlsJsTextTracks;
|
|
160
182
|
}
|
|
161
|
-
function isHlsTextTrack(media, track) {
|
|
162
|
-
const trackEls = media.querySelectorAll(`track[${HLS_TRACK_ATTR}]`);
|
|
163
|
-
return Array.from(trackEls).some((trackEl) => trackEl.track === track);
|
|
164
|
-
}
|
|
165
183
|
/**
|
|
166
184
|
* Makes the media element render the cues of a track that just became the showing one.
|
|
167
185
|
*
|
|
@@ -176,20 +194,76 @@ function refreshCues(track) {
|
|
|
176
194
|
track.addCue(cue);
|
|
177
195
|
}
|
|
178
196
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
197
|
+
/** CEA-608/708 tracks are the ones hls.js announces with an `_id`, one at a time. */
|
|
198
|
+
function isClosedCaptions(info) {
|
|
199
|
+
return !isNil(info._id);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* NOTE: Undocumented identifiers hls.js addresses CUES_PARSED with: `_id` for CEA-608/708 tracks, and `default` or
|
|
203
|
+
* `subtitles` plus the group-local index it stamps on `subtitleTrack.id` for the subtitle set. See:
|
|
204
|
+
* https://github.com/video-dev/hls.js/blob/master/src/controller/timeline-controller.ts
|
|
205
|
+
*/
|
|
206
|
+
function trackIdFor({ _id, default: isDefault, subtitleTrack }) {
|
|
207
|
+
return _id ?? (isDefault ? "default" : `subtitles${subtitleTrack?.id}`);
|
|
208
|
+
}
|
|
209
|
+
/** Whether a new announcement of a track would build the same `<track>` element. */
|
|
210
|
+
function describesSameTrack(a, b) {
|
|
211
|
+
const langOf = ({ subtitleTrack, closedCaptions }) => (subtitleTrack ?? closedCaptions)?.lang;
|
|
212
|
+
return a.kind === b.kind && a.label === b.label && !!a.default === !!b.default && langOf(a) === langOf(b);
|
|
213
|
+
}
|
|
214
|
+
/** Adds the track's element to the media element, moving it off another one, or builds it on the first mount. */
|
|
215
|
+
function mountTrack(media, id, track, before) {
|
|
216
|
+
unmountTrack(track);
|
|
217
|
+
const el = track.el ?? createTrackElement(id, track.info);
|
|
218
|
+
media.insertBefore(el, before);
|
|
219
|
+
track.el = el;
|
|
220
|
+
if (track.mode) restoreMode(el.track, track.mode);
|
|
221
|
+
}
|
|
222
|
+
function createTrackElement(id, info) {
|
|
223
|
+
const kind = info.kind;
|
|
224
|
+
const lang = (info.subtitleTrack ?? info.closedCaptions)?.lang;
|
|
225
|
+
const el = document.createElement("track");
|
|
226
|
+
el.id = id;
|
|
227
|
+
el.kind = kind;
|
|
228
|
+
el.label = info.label;
|
|
229
|
+
if (lang) el.srclang = lang;
|
|
230
|
+
if (info.default) el.default = true;
|
|
231
|
+
el.track.mode = isCaptionOrSubtitleTrack({ kind }) ? "disabled" : "hidden";
|
|
232
|
+
el.setAttribute(HLS_TRACK_ATTR, "");
|
|
233
|
+
return el;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Gives a track hls.js announced under a reused id, e.g. after a switch to a level with another subtitle group, a new
|
|
237
|
+
* element in the old one's place: the old element holds the previous playlist's cues, and the store only reads a
|
|
238
|
+
* track's kind, label and language when it is added.
|
|
239
|
+
*/
|
|
240
|
+
function replaceTrack(media, id, track) {
|
|
241
|
+
const { el } = track;
|
|
242
|
+
if (!el) return;
|
|
243
|
+
const mounted = el.parentNode === media;
|
|
244
|
+
const next = el.nextSibling;
|
|
245
|
+
unmountTrack(track);
|
|
246
|
+
track.el = null;
|
|
247
|
+
if (mounted) mountTrack(media, id, track, next);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Sets a remounted track's mode so the browser keeps it. Once any track shows, Chrome turns on the subtitle track in
|
|
251
|
+
* the user's language too, unless script set that track's mode after its element was added. Setting the mode it already
|
|
252
|
+
* has does not count, so a track restored to it goes through another mode first.
|
|
253
|
+
*/
|
|
254
|
+
function restoreMode(track, mode) {
|
|
255
|
+
if (track.mode === mode) track.mode = mode === "disabled" ? "hidden" : "disabled";
|
|
256
|
+
track.mode = mode;
|
|
257
|
+
}
|
|
258
|
+
/** Disables and removes the track's element, remembering its mode for the next mount. */
|
|
259
|
+
function unmountTrack(track) {
|
|
260
|
+
const { el } = track;
|
|
261
|
+
if (!el?.parentNode) return;
|
|
262
|
+
track.mode = el.track.mode;
|
|
263
|
+
el.track.mode = "disabled";
|
|
264
|
+
el.remove();
|
|
191
265
|
}
|
|
192
266
|
//#endregion
|
|
193
|
-
export { HlsJsTextTracksMixin,
|
|
267
|
+
export { HlsJsTextTracksMixin, withPreservedTextTracks };
|
|
194
268
|
|
|
195
269
|
//# sourceMappingURL=text-tracks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-tracks.js","names":[],"sources":["../../src/text-tracks.ts"],"sourcesContent":["import type { HTMLMediaTargetLike } from '@videojs/media/dom';\nimport { isCaptionOrSubtitleTrack, listen } from '@videojs/utils/dom';\nimport type { Constructor } from '@videojs/utils/types';\nimport type { CuesParsedData, NonNativeTextTracksData } from 'hls.js';\nimport Hls from 'hls.js';\n\nimport type { HlsEngineHost } from './types';\n\n/** Marks the `<track>` elements created here for hls.js's own text tracks. */\nconst HLS_TRACK_ATTR = 'data-removeondestroy';\n\n/** Marks the subset created from hls.js's CEA-608/708 announcements, which are announced one track at a time. */\nconst CC_TRACK_ATTR = 'data-cc';\n\n/** `HTMLTrackElement.LOADED` — the element parsed its resource and will not parse it again. */\nconst TRACK_LOADED = 2;\n\ninterface TextTrackSnapshot {\n track: TextTrack;\n mode: TextTrackMode;\n cues: TextTrackCue[];\n}\n\n/**\n * Runs an hls.js call that attaches, detaches, or loads a source, leaving the `<track>` children hls.js does not own\n * the way it found them.\n *\n * Hls.js resets _every_ text track on the media element at those points: it clears the cues of all of them and disables\n * the ones it takes for subtitles, without checking which tracks it created. Tracks sideloaded from `<track>` elements\n * are collateral damage, and losing their cues is permanent — an element that finished loading is never parsed again,\n * so the track keeps reporting `showing` while rendering nothing. It surfaces whenever a `<track>` outlives a source\n * assignment, most visibly when `src` arrives after the element connected and its default track already loaded.\n *\n * Cues are the objects the browser parsed, so putting back the ones hls.js took restores the track without refetching\n * its resource.\n */\nexport function withPreservedTextTracks(media: HTMLMediaElement | null, action: () => void): void {\n const snapshots = media ? snapshotTextTracks(media) : [];\n\n try {\n action();\n } finally {\n for (const snapshot of snapshots) restoreTextTrack(snapshot);\n }\n}\n\n/** Disables and removes every text track created for the current hls.js source. */\nexport function removeHlsTextTracks(media: HTMLMediaTargetLike | null): void {\n const trackEls = media?.querySelectorAll<HTMLTrackElement>(`track[${HLS_TRACK_ATTR}]`) ?? [];\n\n for (const trackEl of trackEls) {\n trackEl.track.mode = 'disabled';\n trackEl.remove();\n }\n}\n\nfunction snapshotTextTracks(media: HTMLMediaElement): TextTrackSnapshot[] {\n const snapshots: TextTrackSnapshot[] = [];\n\n for (const trackEl of media.querySelectorAll('track')) {\n // Tracks created for hls.js are rebuilt from the manifest on every load.\n if (trackEl.hasAttribute(HLS_TRACK_ATTR)) continue;\n\n const { track } = trackEl;\n // A disabled track stays disabled through anything hls.js does, and only\n // holds cues if it was enabled long enough to load them. Skipping the rest\n // keeps the mode juggling below off the common path.\n if (track.mode === 'disabled' && trackEl.readyState !== TRACK_LOADED) continue;\n\n snapshots.push({\n track,\n mode: track.mode,\n cues: withReadableCues(track, () => Array.from(track.cues ?? [])),\n });\n }\n\n return snapshots;\n}\n\nfunction restoreTextTrack({ track, mode, cues }: TextTrackSnapshot): void {\n if (track.mode !== mode) track.mode = mode;\n\n if (!cues.length) return;\n\n withReadableCues(track, () => {\n const present = new Set<TextTrackCue>(track.cues ?? []);\n\n for (const cue of cues) {\n if (!present.has(cue)) track.addCue(cue);\n }\n });\n}\n\n/** Reads or writes cues through a mode that exposes them, leaving the track's own mode intact. */\nfunction withReadableCues<T>(track: TextTrack, action: () => T): T {\n const { mode } = track;\n\n if (mode === 'disabled') track.mode = 'hidden';\n\n try {\n return action();\n } finally {\n if (mode === 'disabled') track.mode = mode;\n }\n}\n\n/**\n * Bridges hls.js non-native text tracks to native `<track>` elements so the rest of the player can treat them like any\n * other text track.\n *\n * When `renderTextTracksNatively: false`, hls.js fires `NON_NATIVE_TEXT_TRACKS_FOUND` with track metadata and\n * `CUES_PARSED` with VTTCues. This mixin creates `<track>` elements on the media target and forwards cues into them. It\n * also syncs user track-mode changes back to hls.js via `engine.subtitleTrack`.\n */\nexport function HlsJsTextTracksMixin<Base extends Constructor<HlsEngineHost>>(BaseClass: Base) {\n class HlsJsTextTracks extends (BaseClass as Constructor<HlsEngineHost>) {\n #disconnect: AbortController | null = null;\n\n constructor(...args: any[]) {\n super(...args);\n\n // A new manifest invalidates the tracks built from the previous one. Attaching media does not: it rebinds the\n // handlers to the element hls.js drives now, and the tracks of the load in progress have to survive it.\n this.engine?.on(Hls.Events.MANIFEST_LOADING, () => {\n removeHlsTextTracks(this.target);\n this.#init();\n });\n this.engine?.on(Hls.Events.MEDIA_ATTACHED, () => this.#init());\n this.engine?.on(Hls.Events.MEDIA_DETACHED, () => this.#destroy());\n this.engine?.on(Hls.Events.DESTROYING, () => this.#destroy());\n }\n\n #destroy(): void {\n this.#disconnect?.abort();\n this.#disconnect = null;\n removeHlsTextTracks(this.target);\n }\n\n #init(): void {\n this.#disconnect?.abort();\n this.#disconnect = new AbortController();\n\n const { signal } = this.#disconnect;\n const { engine } = this;\n if (!engine || !this.target) return;\n\n // The hls.js delegate always binds to the real `<video>` element.\n const media = this.target as HTMLVideoElement;\n\n // NOTE: Undocumented identifiers hls.js addresses CUES_PARSED with: `_id` for CEA-608/708 tracks, and\n // `default` or `subtitles` plus the group-local index it stamps on `subtitleTrack.id` for the subtitle set.\n // See: https://github.com/video-dev/hls.js/blob/master/src/controller/timeline-controller.ts\n const trackIdFor = ({ _id, default: isDefault, subtitleTrack }: NonNativeTextTracksData['tracks'][number]) =>\n _id ?? (isDefault ? 'default' : `subtitles${subtitleTrack?.id}`);\n\n const onTracksFound = (_event: string, data: NonNativeTextTracksData) => {\n // The subtitle set arrives in one batch, and each CC track arrives alone once 608 data shows up in the\n // stream. Replace only what is being re-announced, so a CC announcement does not destroy the subtitle set\n // and a fresh subtitle set does not destroy the CC tracks.\n const incomingIds = new Set(data.tracks.map(trackIdFor));\n const ccBatch = data.tracks.every((trackObj) => trackObj._id != null);\n\n for (const trackEl of media.querySelectorAll<HTMLTrackElement>(`track[${HLS_TRACK_ATTR}]`)) {\n const replaced = incomingIds.has(trackEl.id);\n const ccOwned = trackEl.hasAttribute(CC_TRACK_ATTR);\n if (!replaced && (ccBatch || ccOwned)) continue;\n\n trackEl.track.mode = 'disabled';\n trackEl.remove();\n }\n\n for (const trackObj of data.tracks) {\n const baseTrackObj = trackObj.subtitleTrack ?? trackObj.closedCaptions;\n\n addTextTrack(\n media,\n trackObj.kind as TextTrackKind,\n trackObj.label,\n baseTrackObj?.lang,\n trackIdFor(trackObj),\n trackObj.default,\n trackObj._id != null\n );\n }\n };\n\n const onCuesParsed = (_event: string, { track, cues }: CuesParsedData) => {\n const textTrack = media.textTracks.getTrackById(track);\n if (!textTrack) return;\n\n const disabled = textTrack.mode === 'disabled';\n\n if (disabled) {\n textTrack.mode = 'hidden';\n }\n\n cues.forEach((cue: VTTCue) => {\n if (textTrack.cues?.getCueById(cue.id)) return;\n\n textTrack.addCue(cue);\n });\n\n if (disabled) {\n textTrack.mode = 'disabled';\n }\n };\n\n let lastShowingTrack: TextTrack | undefined;\n\n const onTextTrackChange = () => {\n const showingTrack = Array.from(media.textTracks).find((textTrack) => {\n return textTrack.id && textTrack.mode === 'showing' && isCaptionOrSubtitleTrack(textTrack);\n });\n const showingChanged = showingTrack !== lastShowingTrack;\n\n lastShowingTrack = showingTrack;\n\n if (!showingTrack) return;\n\n // Only on a new showing track: `onCuesParsed` fires `change` for every batch it forwards to a disabled\n // track, and refreshing each time would re-render the active cue several times a second.\n if (showingChanged && isHlsTextTrack(media, showingTrack)) refreshCues(showingTrack);\n\n if (!engine.subtitleTracks.length) return;\n\n const currentHlsTrack = engine.subtitleTracks[engine.subtitleTrack];\n\n // If hls.subtitleTrack is -1 or its id changed compared to the one that is showing load the new subtitle track.\n const hlsTrackId = !currentHlsTrack\n ? undefined\n : currentHlsTrack.default\n ? 'default'\n : `${engine.subtitleTracks[engine.subtitleTrack]?.type.toLowerCase()}${engine.subtitleTrack}`;\n\n if (engine.subtitleTrack < 0 || showingTrack?.id !== hlsTrackId) {\n const idx = engine.subtitleTracks.findIndex(({ lang, name, type, default: defaultTrack }) => {\n return (\n (showingTrack.id === 'default' && defaultTrack) ||\n (lang === showingTrack.language &&\n name === showingTrack.label &&\n type.toLowerCase() === showingTrack.kind)\n );\n });\n\n // After the subtitleTrack is set here, hls.js will load the playlist and CUES_PARSED events will be fired below.\n // A closed-caption track has no entry in `subtitleTracks`, so picking one assigns -1, which only stops\n // subtitle loading: CEA-608 cues come from the video segments.\n engine.subtitleTrack = idx;\n }\n };\n\n engine.on(Hls.Events.NON_NATIVE_TEXT_TRACKS_FOUND, onTracksFound);\n engine.on(Hls.Events.CUES_PARSED, onCuesParsed);\n listen(media.textTracks, 'change', onTextTrackChange, { signal });\n\n signal.addEventListener(\n 'abort',\n () => {\n engine.off(Hls.Events.NON_NATIVE_TEXT_TRACKS_FOUND, onTracksFound);\n engine.off(Hls.Events.CUES_PARSED, onCuesParsed);\n },\n { once: true }\n );\n }\n }\n\n return HlsJsTextTracks as unknown as Base;\n}\n\nfunction isHlsTextTrack(media: HTMLMediaElement, track: TextTrack): boolean {\n const trackEls = media.querySelectorAll<HTMLTrackElement>(`track[${HLS_TRACK_ATTR}]`);\n\n return Array.from(trackEls).some((trackEl) => trackEl.track === track);\n}\n\n/**\n * Makes the media element render the cues of a track that just became the showing one.\n *\n * The `<track>` elements created here have no `src`, so their load fails. WebKit only hands a re-enabled track's cues\n * back to the media element when its `<track>` loaded, so a track turned off and on again lists its cues but renders\n * none; Chrome has a similar rendering bug. Adding a cue that is already on the track is a no-op in WebKit, so each cue\n * is removed before it is added back.\n */\nfunction refreshCues(track: TextTrack): void {\n for (const cue of Array.from(track.cues ?? [])) {\n track.removeCue(cue);\n track.addCue(cue);\n }\n}\n\nfunction addTextTrack(\n mediaEl: HTMLMediaElement,\n kind: TextTrackKind,\n label: string,\n lang?: string,\n id?: string,\n defaultTrack?: boolean,\n ccOwned?: boolean\n): TextTrack {\n const trackEl = document.createElement('track');\n\n trackEl.kind = kind;\n trackEl.label = label;\n\n if (lang) {\n // This attribute must be present if the element's kind attribute is in the subtitles state.\n trackEl.srclang = lang;\n }\n\n if (id) {\n trackEl.id = id;\n }\n\n if (defaultTrack) {\n trackEl.default = true;\n }\n\n trackEl.track.mode = isCaptionOrSubtitleTrack({ kind }) ? 'disabled' : 'hidden';\n\n // Add data attribute to identify tracks that should be removed when switching sources/destroying hls.js instance.\n trackEl.setAttribute(HLS_TRACK_ATTR, '');\n\n if (ccOwned) trackEl.setAttribute(CC_TRACK_ATTR, '');\n\n mediaEl.append(trackEl);\n\n return trackEl.track as TextTrack;\n}\n"],"mappings":";;;;AASA,MAAM,iBAAiB;;AAGvB,MAAM,gBAAgB;;AAGtB,MAAM,eAAe;;;;;;;;;;;;;;AAqBrB,SAAgB,wBAAwB,OAAgC,QAA0B;CAChG,MAAM,YAAY,QAAQ,mBAAmB,KAAK,IAAI,CAAC;CAEvD,IAAI;EACF,OAAO;CACT,UAAU;EACR,KAAK,MAAM,YAAY,WAAW,iBAAiB,QAAQ;CAC7D;AACF;;AAGA,SAAgB,oBAAoB,OAAyC;CAC3E,MAAM,WAAW,OAAO,iBAAmC,SAAS,eAAe,EAAE,KAAK,CAAC;CAE3F,KAAK,MAAM,WAAW,UAAU;EAC9B,QAAQ,MAAM,OAAO;EACrB,QAAQ,OAAO;CACjB;AACF;AAEA,SAAS,mBAAmB,OAA8C;CACxE,MAAM,YAAiC,CAAC;CAExC,KAAK,MAAM,WAAW,MAAM,iBAAiB,OAAO,GAAG;EAErD,IAAI,QAAQ,aAAa,cAAc,GAAG;EAE1C,MAAM,EAAE,UAAU;EAIlB,IAAI,MAAM,SAAS,cAAc,QAAQ,eAAe,cAAc;EAEtE,UAAU,KAAK;GACb;GACA,MAAM,MAAM;GACZ,MAAM,iBAAiB,aAAa,MAAM,KAAK,MAAM,QAAQ,CAAC,CAAC,CAAC;EAClE,CAAC;CACH;CAEA,OAAO;AACT;AAEA,SAAS,iBAAiB,EAAE,OAAO,MAAM,QAA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AAU;CAGpB,IAAI,IACF,QAAQ,KAAK;CAGf,IAAI,cACF,QAAQ,UAAU;CAGpB,QAAQ,MAAM,OAAO,yBAAyB,EAAE,KAAK,CAAC,IAAI,aAAa;CAGvE,QAAQ,aAAa,gBAAgB,EAAE;CAEvC,IAAI,SAAS,QAAQ,aAAa,eAAe,EAAE;CAEnD,QAAQ,OAAO,OAAO;CAEtB,OAAO,QAAQ;AACjB"}
|
|
1
|
+
{"version":3,"file":"text-tracks.js","names":[],"sources":["../../src/text-tracks.ts"],"sourcesContent":["import { isCaptionOrSubtitleTrack, listen } from '@videojs/utils/dom';\nimport { isNil } from '@videojs/utils/predicate';\nimport type { Constructor } from '@videojs/utils/types';\nimport type { CuesParsedData, NonNativeTextTrack, NonNativeTextTracksData } from 'hls.js';\nimport Hls from 'hls.js';\n\nimport type { HlsEngineHost } from './types';\n\n/** Marks the `<track>` elements created here for hls.js's own text tracks. */\nconst HLS_TRACK_ATTR = 'data-removeondestroy';\n\n/** `HTMLTrackElement.LOADED` — the element parsed its resource and will not parse it again. */\nconst TRACK_LOADED = 2;\n\ninterface TextTrackSnapshot {\n track: TextTrack;\n mode: TextTrackMode;\n cues: TextTrackCue[];\n}\n\n/**\n * Runs an hls.js call that attaches, detaches, or loads a source, leaving the `<track>` children hls.js does not own\n * the way it found them.\n *\n * Hls.js resets _every_ text track on the media element at those points: it clears the cues of all of them and disables\n * the ones it takes for subtitles, without checking which tracks it created. Tracks sideloaded from `<track>` elements\n * are collateral damage, and losing their cues is permanent — an element that finished loading is never parsed again,\n * so the track keeps reporting `showing` while rendering nothing. It surfaces whenever a `<track>` outlives a source\n * assignment, most visibly when `src` arrives after the element connected and its default track already loaded.\n *\n * Cues are the objects the browser parsed, so putting back the ones hls.js took restores the track without refetching\n * its resource.\n */\nexport function withPreservedTextTracks(media: HTMLMediaElement | null, action: () => void): void {\n const snapshots = media ? snapshotTextTracks(media) : [];\n\n try {\n action();\n } finally {\n for (const snapshot of snapshots) restoreTextTrack(snapshot);\n }\n}\n\nfunction snapshotTextTracks(media: HTMLMediaElement): TextTrackSnapshot[] {\n const snapshots: TextTrackSnapshot[] = [];\n\n for (const trackEl of media.querySelectorAll('track')) {\n // Tracks created for hls.js are rebuilt from the manifest on every load.\n if (trackEl.hasAttribute(HLS_TRACK_ATTR)) continue;\n\n const { track } = trackEl;\n // A disabled track stays disabled through anything hls.js does, and only\n // holds cues if it was enabled long enough to load them. Skipping the rest\n // keeps the mode juggling below off the common path. A track without `src`\n // settles in the error state, yet can hold cues written to it from code.\n if (track.mode === 'disabled' && trackEl.readyState < TRACK_LOADED) continue;\n\n snapshots.push({\n track,\n mode: track.mode,\n cues: withReadableCues(track, () => Array.from(track.cues ?? [])),\n });\n }\n\n return snapshots;\n}\n\nfunction restoreTextTrack({ track, mode, cues }: TextTrackSnapshot): void {\n if (track.mode !== mode) track.mode = mode;\n\n if (!cues.length) return;\n\n withReadableCues(track, () => {\n const present = new Set<TextTrackCue>(track.cues ?? []);\n\n for (const cue of cues) {\n if (!present.has(cue)) track.addCue(cue);\n }\n });\n}\n\n/** Reads or writes cues through a mode that exposes them, leaving the track's own mode intact. */\nfunction withReadableCues<T>(track: TextTrack, action: () => T): T {\n const { mode } = track;\n\n if (mode === 'disabled') track.mode = 'hidden';\n\n try {\n return action();\n } finally {\n if (mode === 'disabled') track.mode = mode;\n }\n}\n\n/** A text track hls.js announced for the current source. */\ninterface HlsTextTrack {\n info: NonNativeTextTrack;\n /** The mode the track had when its element was last removed, put back when it is mounted again. */\n mode: TextTrackMode | null;\n /** The track's `<track>` element, kept while unmounted so mounting it again keeps its cues. */\n el: HTMLTrackElement | null;\n}\n\n/**\n * Bridges hls.js non-native text tracks to native `<track>` elements so the rest of the player can treat them like any\n * other text track.\n *\n * When `renderTextTracksNatively: false`, hls.js fires `NON_NATIVE_TEXT_TRACKS_FOUND` with track metadata and\n * `CUES_PARSED` with VTTCues. This mixin creates `<track>` elements on the media target and forwards cues into them. It\n * also syncs user track-mode changes back to hls.js via `engine.subtitleTrack`.\n *\n * The tracks belong to the source, not to the media element. A new manifest or the engine's destruction drops them.\n * hls.js's own detach/attach, e.g. `hls.recoverMediaError()`, leaves them where they are: hls.js announces the subtitle\n * set again only when its list changes, and each CC track only once 608 data shows up, and keeping the elements keeps\n * their modes, cues and place among the other `<track>` elements. Only the adapter letting go of the element unmounts\n * them, and the next attach mounts the same elements again with their modes and cues.\n */\nexport function HlsJsTextTracksMixin<Base extends Constructor<HlsEngineHost>>(BaseClass: Base) {\n class HlsJsTextTracks extends (BaseClass as Constructor<HlsEngineHost>) {\n #disconnect: AbortController | null = null;\n /** The tracks of the current source, by the id hls.js addresses their cues with. */\n #tracks = new Map<string, HlsTextTrack>();\n\n constructor(...args: any[]) {\n super(...args);\n\n const { engine } = this;\n if (!engine) return;\n\n engine.on(Hls.Events.MANIFEST_LOADING, () => {\n this.#reset();\n this.#init();\n });\n engine.on(Hls.Events.MEDIA_ATTACHED, () => {\n this.#init();\n this.#mount();\n });\n engine.on(Hls.Events.MEDIA_DETACHED, () => this.#disconnectListeners());\n engine.on(Hls.Events.DESTROYING, () => this.#reset());\n }\n\n /** The adapter lets go of the element, unlike hls.js's own detach/attach, so the tracks leave it too. */\n detach(): void {\n this.#unmount();\n super.detach();\n }\n\n #disconnectListeners(): void {\n this.#disconnect?.abort();\n this.#disconnect = null;\n }\n\n #reset(): void {\n this.#disconnectListeners();\n this.#unmount();\n this.#tracks.clear();\n }\n\n /** Mounts the tracks of the current source that are not on the media element yet. */\n #mount(): void {\n // SAFETY: the hls.js delegate always binds to the real `<video>` element.\n const media = this.target as HTMLVideoElement | null;\n if (!media) return;\n\n for (const [id, track] of this.#tracks) {\n if (track.el?.parentNode !== media) mountTrack(media, id, track, null);\n }\n }\n\n #unmount(): void {\n for (const track of this.#tracks.values()) unmountTrack(track);\n }\n\n #trackFor(textTrack: TextTrack): HlsTextTrack | undefined {\n for (const track of this.#tracks.values()) {\n if (track.el?.track === textTrack) return track;\n }\n\n return undefined;\n }\n\n #init(): void {\n this.#disconnect?.abort();\n this.#disconnect = new AbortController();\n\n const { signal } = this.#disconnect;\n const { engine } = this;\n if (!engine || !this.target) return;\n\n // The hls.js delegate always binds to the real `<video>` element.\n const media = this.target as HTMLVideoElement;\n\n const onTracksFound = (_event: string, { tracks }: NonNativeTextTracksData) => {\n // The subtitle set arrives in one batch and replaces the previous set. Each CC track arrives alone once 608 data\n // shows up in the stream, again after every re-attach, and leaves the other tracks alone.\n const incoming = new Map(tracks.map((info) => [trackIdFor(info), info]));\n\n if (!tracks.every(isClosedCaptions)) {\n for (const [id, track] of this.#tracks) {\n if (isClosedCaptions(track.info) || incoming.has(id)) continue;\n\n unmountTrack(track);\n this.#tracks.delete(id);\n }\n }\n\n for (const [id, info] of incoming) {\n const track = this.#tracks.get(id);\n\n if (!track) {\n this.#tracks.set(id, { info, mode: null, el: null });\n continue;\n }\n\n const changed = !describesSameTrack(track.info, info);\n\n track.info = info;\n\n if (changed) replaceTrack(media, id, track);\n }\n\n this.#mount();\n };\n\n const onCuesParsed = (_event: string, { track, cues }: CuesParsedData) => {\n const textTrack = this.#tracks.get(track)?.el?.track;\n if (!textTrack) return;\n\n withReadableCues(textTrack, () => {\n for (const cue of cues) {\n if (!textTrack.cues?.getCueById(cue.id)) textTrack.addCue(cue);\n }\n });\n };\n\n let lastShowingTrack: TextTrack | undefined;\n\n const onTextTrackChange = () => {\n const showingTrack = Array.from(media.textTracks).find((textTrack) => {\n return textTrack.id && textTrack.mode === 'showing' && isCaptionOrSubtitleTrack(textTrack);\n });\n const showingChanged = showingTrack !== lastShowingTrack;\n\n lastShowingTrack = showingTrack;\n\n if (!showingTrack) return;\n\n const track = this.#trackFor(showingTrack);\n\n // Only on a new showing track: `onCuesParsed` fires `change` for every batch it forwards to a disabled\n // track, and refreshing each time would re-render the active cue several times a second.\n if (showingChanged && track) refreshCues(showingTrack);\n\n // hls.js stamps each subtitle playlist's index in `subtitleTracks` on its `id`, and loads the playlist of the\n // index `subtitleTrack` is set to; CUES_PARSED then fills the track. Any other showing track, CC or sideloaded,\n // selects -1, which only stops subtitle loading: CEA-608 cues come from the video segments.\n const index = track?.info.subtitleTrack?.id ?? -1;\n\n if (engine.subtitleTrack !== index) engine.subtitleTrack = index;\n };\n\n engine.on(Hls.Events.NON_NATIVE_TEXT_TRACKS_FOUND, onTracksFound);\n engine.on(Hls.Events.CUES_PARSED, onCuesParsed);\n listen(media.textTracks, 'change', onTextTrackChange, { signal });\n\n signal.addEventListener(\n 'abort',\n () => {\n engine.off(Hls.Events.NON_NATIVE_TEXT_TRACKS_FOUND, onTracksFound);\n engine.off(Hls.Events.CUES_PARSED, onCuesParsed);\n },\n { once: true }\n );\n }\n }\n\n return HlsJsTextTracks as unknown as Base;\n}\n\n/**\n * Makes the media element render the cues of a track that just became the showing one.\n *\n * The `<track>` elements created here have no `src`, so their load fails. WebKit only hands a re-enabled track's cues\n * back to the media element when its `<track>` loaded, so a track turned off and on again lists its cues but renders\n * none; Chrome has a similar rendering bug. Adding a cue that is already on the track is a no-op in WebKit, so each cue\n * is removed before it is added back.\n */\nfunction refreshCues(track: TextTrack): void {\n for (const cue of Array.from(track.cues ?? [])) {\n track.removeCue(cue);\n track.addCue(cue);\n }\n}\n\n/** CEA-608/708 tracks are the ones hls.js announces with an `_id`, one at a time. */\nfunction isClosedCaptions(info: NonNativeTextTrack): boolean {\n return !isNil(info._id);\n}\n\n/**\n * NOTE: Undocumented identifiers hls.js addresses CUES_PARSED with: `_id` for CEA-608/708 tracks, and `default` or\n * `subtitles` plus the group-local index it stamps on `subtitleTrack.id` for the subtitle set. See:\n * https://github.com/video-dev/hls.js/blob/master/src/controller/timeline-controller.ts\n */\nfunction trackIdFor({ _id, default: isDefault, subtitleTrack }: NonNativeTextTrack): string {\n return _id ?? (isDefault ? 'default' : `subtitles${subtitleTrack?.id}`);\n}\n\n/** Whether a new announcement of a track would build the same `<track>` element. */\nfunction describesSameTrack(a: NonNativeTextTrack, b: NonNativeTextTrack): boolean {\n const langOf = ({ subtitleTrack, closedCaptions }: NonNativeTextTrack) => (subtitleTrack ?? closedCaptions)?.lang;\n\n return a.kind === b.kind && a.label === b.label && !!a.default === !!b.default && langOf(a) === langOf(b);\n}\n\n/** Adds the track's element to the media element, moving it off another one, or builds it on the first mount. */\nfunction mountTrack(media: HTMLMediaElement, id: string, track: HlsTextTrack, before: Node | null): void {\n unmountTrack(track);\n\n const el = track.el ?? createTrackElement(id, track.info);\n\n media.insertBefore(el, before);\n track.el = el;\n\n if (track.mode) restoreMode(el.track, track.mode);\n}\n\nfunction createTrackElement(id: string, info: NonNativeTextTrack): HTMLTrackElement {\n const kind = info.kind as TextTrackKind;\n const lang = (info.subtitleTrack ?? info.closedCaptions)?.lang;\n const el = document.createElement('track');\n\n el.id = id;\n el.kind = kind;\n el.label = info.label;\n\n // Required when the element's kind is subtitles.\n if (lang) el.srclang = lang;\n\n if (info.default) el.default = true;\n\n el.track.mode = isCaptionOrSubtitleTrack({ kind }) ? 'disabled' : 'hidden';\n\n // Lets `withPreservedTextTracks` tell these tracks from sideloaded ones.\n el.setAttribute(HLS_TRACK_ATTR, '');\n\n return el;\n}\n\n/**\n * Gives a track hls.js announced under a reused id, e.g. after a switch to a level with another subtitle group, a new\n * element in the old one's place: the old element holds the previous playlist's cues, and the store only reads a\n * track's kind, label and language when it is added.\n */\nfunction replaceTrack(media: HTMLMediaElement, id: string, track: HlsTextTrack): void {\n const { el } = track;\n if (!el) return;\n\n const mounted = el.parentNode === media;\n const next = el.nextSibling;\n\n unmountTrack(track);\n track.el = null;\n\n if (mounted) mountTrack(media, id, track, next);\n}\n\n/**\n * Sets a remounted track's mode so the browser keeps it. Once any track shows, Chrome turns on the subtitle track in\n * the user's language too, unless script set that track's mode after its element was added. Setting the mode it already\n * has does not count, so a track restored to it goes through another mode first.\n */\nfunction restoreMode(track: TextTrack, mode: TextTrackMode): void {\n if (track.mode === mode) track.mode = mode === 'disabled' ? 'hidden' : 'disabled';\n\n track.mode = mode;\n}\n\n/** Disables and removes the track's element, remembering its mode for the next mount. */\nfunction unmountTrack(track: HlsTextTrack): void {\n const { el } = track;\n if (!el?.parentNode) return;\n\n track.mode = el.track.mode;\n el.track.mode = 'disabled';\n el.remove();\n}\n"],"mappings":";;;;;AASA,MAAM,iBAAiB;;AAGvB,MAAM,eAAe;;;;;;;;;;;;;;AAqBrB,SAAgB,wBAAwB,OAAgC,QAA0B;CAChG,MAAM,YAAY,QAAQ,mBAAmB,KAAK,IAAI,CAAC;CAEvD,IAAI;EACF,OAAO;CACT,UAAU;EACR,KAAK,MAAM,YAAY,WAAW,iBAAiB,QAAQ;CAC7D;AACF;AAEA,SAAS,mBAAmB,OAA8C;CACxE,MAAM,YAAiC,CAAC;CAExC,KAAK,MAAM,WAAW,MAAM,iBAAiB,OAAO,GAAG;EAErD,IAAI,QAAQ,aAAa,cAAc,GAAG;EAE1C,MAAM,EAAE,UAAU;EAKlB,IAAI,MAAM,SAAS,cAAc,QAAQ,aAAa,cAAc;EAEpE,UAAU,KAAK;GACb;GACA,MAAM,MAAM;GACZ,MAAM,iBAAiB,aAAa,MAAM,KAAK,MAAM,QAAQ,CAAC,CAAC,CAAC;EAClE,CAAC;CACH;CAEA,OAAO;AACT;AAEA,SAAS,iBAAiB,EAAE,OAAO,MAAM,QAAiC;CACxE,IAAI,MAAM,SAAS,MAAM,MAAM,OAAO;CAEtC,IAAI,CAAC,KAAK,QAAQ;CAElB,iBAAiB,aAAa;EAC5B,MAAM,UAAU,IAAI,IAAkB,MAAM,QAAQ,CAAC,CAAC;EAEtD,KAAK,MAAM,OAAO,MAChB,IAAI,CAAC,QAAQ,IAAI,GAAG,GAAG,MAAM,OAAO,GAAG;CAE3C,CAAC;AACH;;AAGA,SAAS,iBAAoB,OAAkB,QAAoB;CACjE,MAAM,EAAE,SAAS;CAEjB,IAAI,SAAS,YAAY,MAAM,OAAO;CAEtC,IAAI;EACF,OAAO,OAAO;CAChB,UAAU;EACR,IAAI,SAAS,YAAY,MAAM,OAA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MAAM;CAC7B,MAAM,KAAK;CAEX,IAAI,MAAM,MAAM,YAAY,GAAG,OAAO,MAAM,IAAI;AAClD;AAEA,SAAS,mBAAmB,IAAY,MAA4C;CAClF,MAAM,OAAO,KAAK;CAClB,MAAM,QAAQ,KAAK,iBAAiB,KAAK,eAAA,EAAiB;CAC1D,MAAM,KAAK,SAAS,cAAc,OAAO;CAEzC,GAAG,KAAK;CACR,GAAG,OAAO;CACV,GAAG,QAAQ,KAAK;CAGhB,IAAI,MAAM,GAAG,UAAU;CAEvB,IAAI,KAAK,SAAS,GAAG,UAAU;CAE/B,GAAG,MAAM,OAAO,yBAAyB,EAAE,KAAK,CAAC,IAAI,aAAa;CAGlE,GAAG,aAAa,gBAAgB,EAAE;CAElC,OAAO;AACT;;;;;;AAOA,SAAS,aAAa,OAAyB,IAAY,OAA2B;CACpF,MAAM,EAAE,OAAO;CACf,IAAI,CAAC,IAAI;CAET,MAAM,UAAU,GAAG,eAAe;CAClC,MAAM,OAAO,GAAG;CAEhB,aAAa,KAAK;CAClB,MAAM,KAAK;CAEX,IAAI,SAAS,WAAW,OAAO,IAAI,OAAO,IAAI;AAChD;;;;;;AAOA,SAAS,YAAY,OAAkB,MAA2B;CAChE,IAAI,MAAM,SAAS,MAAM,MAAM,OAAO,SAAS,aAAa,WAAW;CAEvE,MAAM,OAAO;AACf;;AAGA,SAAS,aAAa,OAA2B;CAC/C,MAAM,EAAE,OAAO;CACf,IAAI,CAAC,IAAI,YAAY;CAErB,MAAM,OAAO,GAAG,MAAM;CACtB,GAAG,MAAM,OAAO;CAChB,GAAG,OAAO;AACZ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@videojs/hlsjs-video",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.5.0",
|
|
4
4
|
"description": "hls.js playback adapter for Video.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hls",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@videojs/media": "10.
|
|
39
|
-
"@videojs/native-hls-video": "10.
|
|
40
|
-
"@videojs/spf": "10.
|
|
41
|
-
"@videojs/utils": "10.
|
|
42
|
-
"hls.js": "1.7.
|
|
38
|
+
"@videojs/media": "10.5.0",
|
|
39
|
+
"@videojs/native-hls-video": "10.5.0",
|
|
40
|
+
"@videojs/spf": "10.5.0",
|
|
41
|
+
"@videojs/utils": "10.5.0",
|
|
42
|
+
"hls.js": "1.7.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"jsdom": "^26.1.0",
|