@videojs/hlsjs-video 10.1.0 → 10.3.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 +8 -1
- package/dist/default/cap-level.js +8 -17
- package/dist/default/hls-js-only.js +3 -0
- package/dist/default/live.js +6 -17
- package/dist/default/media-tracks.js +20 -10
- package/dist/default/preload.js +12 -2
- package/dist/default/request-credentials.js +3 -3
- package/dist/default/text-tracks.js +38 -13
- package/dist/dev/adapter.d.ts +5 -0
- package/dist/dev/adapter.js +8 -1
- package/dist/dev/adapter.js.map +1 -1
- package/dist/dev/cap-level.js +8 -17
- package/dist/dev/cap-level.js.map +1 -1
- package/dist/dev/hls-js-only.js +3 -0
- package/dist/dev/hls-js-only.js.map +1 -1
- package/dist/dev/live.js +6 -17
- package/dist/dev/live.js.map +1 -1
- package/dist/dev/media-tracks.js +20 -10
- package/dist/dev/media-tracks.js.map +1 -1
- package/dist/dev/preload.js +12 -2
- package/dist/dev/preload.js.map +1 -1
- package/dist/dev/request-credentials.js +3 -3
- package/dist/dev/request-credentials.js.map +1 -1
- package/dist/dev/text-tracks.js +38 -13
- package/dist/dev/text-tracks.js.map +1 -1
- package/package.json +8 -9
package/dist/default/adapter.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HlsJsOnlyAdapter } from "./hls-js-only.js";
|
|
2
2
|
import { MediaStreamTypes, bridgeEvents } from "@videojs/media";
|
|
3
|
-
import { HTMLVideoAdapter } from "@videojs/media/dom";
|
|
3
|
+
import { HTMLVideoAdapter, getMediaEngineName } from "@videojs/media/dom";
|
|
4
4
|
import { NativeHlsAdapter } from "@videojs/native-hls-video";
|
|
5
5
|
import { deepEqual } from "@videojs/utils/object";
|
|
6
6
|
import Hls$1 from "hls.js";
|
|
@@ -89,6 +89,13 @@ var HlsJsAdapter = class HlsJsAdapter extends HTMLVideoAdapter {
|
|
|
89
89
|
get engine() {
|
|
90
90
|
return this.#delegate?.engine ?? null;
|
|
91
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Engine this media is playing through, reported to analytics such as Mux Data: `hlsjs` via MSE, `browser` for native
|
|
94
|
+
* HLS, or `undefined` until a source loads. Read from the instance because the engine is picked per source.
|
|
95
|
+
*/
|
|
96
|
+
get engineName() {
|
|
97
|
+
return getMediaEngineName(this.#delegate);
|
|
98
|
+
}
|
|
92
99
|
get error() {
|
|
93
100
|
return this.#delegate?.error ?? null;
|
|
94
101
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Hls from "hls.js";
|
|
1
|
+
import Hls, { CapLevelController } from "hls.js";
|
|
2
2
|
//#region src/cap-level.ts
|
|
3
3
|
/**
|
|
4
4
|
* Floor applied to the player-size cap unless a source names another.
|
|
@@ -65,22 +65,21 @@ function levelIndexAtOrAbove(levels, resolution) {
|
|
|
65
65
|
/**
|
|
66
66
|
* Build the `capLevelController` class to hand to the hls.js constructor.
|
|
67
67
|
*
|
|
68
|
-
* `hls.autoLevelCapping`
|
|
69
|
-
* interval for as long as `capLevelToPlayerSize` is on — and it is on by
|
|
70
|
-
* outside is undone
|
|
71
|
-
* with it.
|
|
68
|
+
* `hls.autoLevelCapping` is rewritten by hls.js's own `CapLevelController` whenever the element resizes (or on a
|
|
69
|
+
* one-second interval where `ResizeObserver` is missing) for as long as `capLevelToPlayerSize` is on — and it is on by
|
|
70
|
+
* default here. Assigning the property from outside is undone on the next measurement, so a cap has to be applied from
|
|
71
|
+
* inside the controller rather than in competition with it.
|
|
72
72
|
*
|
|
73
73
|
* The only seam hls.js offers is `getMaxLevel()`, which every value the capping loop writes passes through. Overriding
|
|
74
|
-
* it makes the requested ceiling part of the same
|
|
74
|
+
* it makes the requested ceiling part of the same computation.
|
|
75
75
|
*
|
|
76
76
|
* @param policy - Live cap inputs, re-read on every evaluation.
|
|
77
77
|
* @param BaseController - Controller to layer on top of, so a controller passed through
|
|
78
78
|
* `source.engine.capLevelController` keeps its behavior.
|
|
79
79
|
*/
|
|
80
|
-
function createCapLevelController(policy, BaseController = Hls.DefaultConfig.capLevelController) {
|
|
80
|
+
function createCapLevelController(policy, BaseController = Hls.DefaultConfig.capLevelController ?? CapLevelController) {
|
|
81
81
|
return class RenditionCapLevelController extends BaseController {
|
|
82
82
|
#hls;
|
|
83
|
-
#capping = false;
|
|
84
83
|
#measuringWithoutSize = false;
|
|
85
84
|
constructor(hls) {
|
|
86
85
|
super(hls);
|
|
@@ -95,14 +94,6 @@ function createCapLevelController(policy, BaseController = Hls.DefaultConfig.cap
|
|
|
95
94
|
if (policy.controller === this) policy.controller = void 0;
|
|
96
95
|
super.destroy();
|
|
97
96
|
}
|
|
98
|
-
startCapping() {
|
|
99
|
-
this.#capping = true;
|
|
100
|
-
super.startCapping();
|
|
101
|
-
}
|
|
102
|
-
stopCapping() {
|
|
103
|
-
this.#capping = false;
|
|
104
|
-
super.stopCapping();
|
|
105
|
-
}
|
|
106
97
|
/**
|
|
107
98
|
* Hls.js derives its player-size ceiling from these two, so reporting an unbounded measurement is how
|
|
108
99
|
* `capToPlayerSize: false` switches that ceiling off while leaving the rest of the base controller intact.
|
|
@@ -163,7 +154,7 @@ function createCapLevelController(policy, BaseController = Hls.DefaultConfig.cap
|
|
|
163
154
|
this.#applyResolutionCap();
|
|
164
155
|
}
|
|
165
156
|
apply() {
|
|
166
|
-
if (this.#
|
|
157
|
+
if (this.#hls.config.capLevelToPlayerSize) {
|
|
167
158
|
this.detectPlayerSize();
|
|
168
159
|
return;
|
|
169
160
|
}
|
package/dist/default/live.js
CHANGED
|
@@ -4,7 +4,6 @@ import Hls from "hls.js";
|
|
|
4
4
|
function HlsJsLiveMixin(BaseClass) {
|
|
5
5
|
class HlsJsLive extends BaseClass {
|
|
6
6
|
#targetLiveWindow = NaN;
|
|
7
|
-
#liveEdgeStartOffset;
|
|
8
7
|
#seekToLiveAbort = null;
|
|
9
8
|
#seekToLivePending = false;
|
|
10
9
|
constructor(...args) {
|
|
@@ -29,22 +28,18 @@ function HlsJsLiveMixin(BaseClass) {
|
|
|
29
28
|
return this.#targetLiveWindow;
|
|
30
29
|
}
|
|
31
30
|
get liveEdgeStart() {
|
|
32
|
-
if (this.#
|
|
31
|
+
if (Number.isNaN(this.#targetLiveWindow)) return NaN;
|
|
33
32
|
const { target } = this;
|
|
34
|
-
if (!target) return NaN;
|
|
35
|
-
|
|
36
|
-
if (!seekable.length) return NaN;
|
|
37
|
-
return seekable.end(seekable.length - 1) - this.#liveEdgeStartOffset;
|
|
33
|
+
if (!target?.seekable.length) return NaN;
|
|
34
|
+
return this.engine?.liveSyncPosition ?? NaN;
|
|
38
35
|
}
|
|
39
36
|
#derive(details) {
|
|
40
37
|
if (!details.live) return this.#reset();
|
|
41
38
|
const info = getStreamInfoFromHlsjsLevelDetails(details);
|
|
42
|
-
this.#liveEdgeStartOffset = info.liveEdgeStartOffset;
|
|
43
39
|
this.#updateConfig(info);
|
|
44
40
|
this.#setTargetLiveWindow(info.targetLiveWindow);
|
|
45
41
|
}
|
|
46
42
|
#reset() {
|
|
47
|
-
this.#liveEdgeStartOffset = void 0;
|
|
48
43
|
this.#setTargetLiveWindow(NaN);
|
|
49
44
|
}
|
|
50
45
|
#updateConfig({ streamType, lowLatency }) {
|
|
@@ -98,16 +93,10 @@ function HlsJsLiveMixin(BaseClass) {
|
|
|
98
93
|
}
|
|
99
94
|
const getStreamInfoFromHlsjsLevelDetails = (levelDetails) => {
|
|
100
95
|
const playlistType = levelDetails.type;
|
|
101
|
-
const streamType = toStreamTypeFromPlaylistType(playlistType);
|
|
102
|
-
const targetLiveWindow = toTargetLiveWindowFromPlaylistType(playlistType);
|
|
103
|
-
const lowLatency = !!levelDetails.partList?.length;
|
|
104
|
-
let liveEdgeStartOffset;
|
|
105
|
-
if (streamType === MediaStreamTypes.LIVE) liveEdgeStartOffset = lowLatency ? levelDetails.partHoldBack || levelDetails.partTarget * 2 : levelDetails.holdBack || levelDetails.targetduration * 3;
|
|
106
96
|
return {
|
|
107
|
-
streamType,
|
|
108
|
-
targetLiveWindow,
|
|
109
|
-
|
|
110
|
-
lowLatency
|
|
97
|
+
streamType: toStreamTypeFromPlaylistType(playlistType),
|
|
98
|
+
targetLiveWindow: toTargetLiveWindowFromPlaylistType(playlistType),
|
|
99
|
+
lowLatency: !!levelDetails.partList?.length
|
|
111
100
|
};
|
|
112
101
|
};
|
|
113
102
|
const toStreamTypeFromPlaylistType = (playlistType) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Hls from "hls.js";
|
|
2
2
|
//#region src/media-tracks.ts
|
|
3
|
-
function
|
|
4
|
-
return `${
|
|
3
|
+
function getRenditionKey(width, height, codec, bitrate) {
|
|
4
|
+
return `${width}x${height}|${codec}|${bitrate}`;
|
|
5
5
|
}
|
|
6
6
|
function getAudioTrackKind(audioTrack) {
|
|
7
7
|
return audioTrack.default ? "main" : "alternative";
|
|
@@ -15,7 +15,6 @@ function getAudioTrackKind(audioTrack) {
|
|
|
15
15
|
*/
|
|
16
16
|
function HlsJsMediaTracksMixin(BaseClass) {
|
|
17
17
|
class HlsJsMediaTracks extends BaseClass {
|
|
18
|
-
#levelIdMap = /* @__PURE__ */ new Map();
|
|
19
18
|
#currentVideoTrack = null;
|
|
20
19
|
constructor(...args) {
|
|
21
20
|
super(...args);
|
|
@@ -33,13 +32,11 @@ function HlsJsMediaTracksMixin(BaseClass) {
|
|
|
33
32
|
}
|
|
34
33
|
#onManifestParsed = (_event, data) => {
|
|
35
34
|
this.#removeAllMediaTracks();
|
|
36
|
-
this.#levelIdMap.clear();
|
|
37
35
|
const videoTrack = this.addVideoTrack("main");
|
|
38
36
|
this.#currentVideoTrack = videoTrack;
|
|
39
37
|
videoTrack.selected = true;
|
|
40
38
|
for (const [id, level] of data.levels.entries()) {
|
|
41
39
|
const rendition = videoTrack.addRendition(level.url[0] ?? "", level.width, level.height, level.videoCodec, level.bitrate);
|
|
42
|
-
this.#levelIdMap.set(getLevelKey(level), `${id}`);
|
|
43
40
|
rendition.id = `${id}`;
|
|
44
41
|
}
|
|
45
42
|
};
|
|
@@ -75,9 +72,22 @@ function HlsJsMediaTracksMixin(BaseClass) {
|
|
|
75
72
|
for (const track of enabledTracks) if (track !== selectedTrack) track.enabled = false;
|
|
76
73
|
};
|
|
77
74
|
#onLevelsUpdated = (_event, data) => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
const videoTrack = this.#currentVideoTrack;
|
|
76
|
+
if (!videoTrack) return;
|
|
77
|
+
const renditionsByKey = /* @__PURE__ */ new Map();
|
|
78
|
+
for (const rendition of this.videoRenditions) {
|
|
79
|
+
const key = getRenditionKey(rendition.width, rendition.height, rendition.codec, rendition.bitrate);
|
|
80
|
+
renditionsByKey.set(key, [...renditionsByKey.get(key) ?? [], rendition]);
|
|
81
|
+
}
|
|
82
|
+
const current = /* @__PURE__ */ new Set();
|
|
83
|
+
for (const [index, level] of data.levels.entries()) {
|
|
84
|
+
const key = getRenditionKey(level.width, level.height, level.videoCodec, level.bitrate);
|
|
85
|
+
const rendition = renditionsByKey.get(key)?.shift() ?? videoTrack.addRendition(level.url[0] ?? "", level.width, level.height, level.videoCodec, level.bitrate);
|
|
86
|
+
rendition.id = `${index}`;
|
|
87
|
+
current.add(rendition);
|
|
88
|
+
}
|
|
89
|
+
for (const rendition of [...this.videoRenditions]) if (rendition.id && !current.has(rendition)) videoTrack.removeRendition(rendition);
|
|
90
|
+
this.#switchRendition();
|
|
81
91
|
};
|
|
82
92
|
#onLevelSwitched = (_event, data) => {
|
|
83
93
|
const activeId = `${data.level}`;
|
|
@@ -86,7 +96,8 @@ function HlsJsMediaTracksMixin(BaseClass) {
|
|
|
86
96
|
#switchRendition = () => {
|
|
87
97
|
const { engine } = this;
|
|
88
98
|
if (!engine) return;
|
|
89
|
-
const
|
|
99
|
+
const selected = this.videoRenditions[this.videoRenditions.selectedIndex];
|
|
100
|
+
const level = selected?.id ? Number(selected.id) : this.videoRenditions.selectedIndex;
|
|
90
101
|
if (level !== engine.manualLevel) engine.nextLevel = level;
|
|
91
102
|
};
|
|
92
103
|
#teardown = () => {
|
|
@@ -101,7 +112,6 @@ function HlsJsMediaTracksMixin(BaseClass) {
|
|
|
101
112
|
this.audioTracks.removeEventListener("change", this.#switchAudioTrack);
|
|
102
113
|
this.videoRenditions.removeEventListener("change", this.#switchRendition);
|
|
103
114
|
this.#removeAllMediaTracks();
|
|
104
|
-
this.#levelIdMap.clear();
|
|
105
115
|
this.#currentVideoTrack = null;
|
|
106
116
|
};
|
|
107
117
|
#removeAllMediaTracks() {
|
package/dist/default/preload.js
CHANGED
|
@@ -4,10 +4,13 @@ import Hls from "hls.js";
|
|
|
4
4
|
* Manages HLS preload behavior by mapping the media element's `preload` attribute to hls.js `startLoad` / buffer-limit
|
|
5
5
|
* configuration.
|
|
6
6
|
*
|
|
7
|
-
* - `'auto'` or already playing → full buffer limits, immediate start.
|
|
7
|
+
* - `'auto'`, `autoplay`, or already playing → full buffer limits, immediate start.
|
|
8
8
|
* - `'metadata'` → minimal buffer (1 byte / 1 second), limits raised on play.
|
|
9
9
|
* - `'none'` / `''` → no start, deferred load on play.
|
|
10
10
|
*
|
|
11
|
+
* `autoplay` overrides `preload`, as it does for a native `<video>`: the browser only starts it once enough has loaded,
|
|
12
|
+
* so a load deferred until `play` would never begin.
|
|
13
|
+
*
|
|
11
14
|
* Loading is started at most once per source. Widening the limits afterwards is a plain config write, never a second
|
|
12
15
|
* `startLoad()`.
|
|
13
16
|
*/
|
|
@@ -35,6 +38,13 @@ function HlsJsPreloadMixin(BaseClass) {
|
|
|
35
38
|
this.#preload = value;
|
|
36
39
|
this.#init();
|
|
37
40
|
}
|
|
41
|
+
get autoplay() {
|
|
42
|
+
return super.autoplay;
|
|
43
|
+
}
|
|
44
|
+
set autoplay(value) {
|
|
45
|
+
super.autoplay = value;
|
|
46
|
+
this.#init();
|
|
47
|
+
}
|
|
38
48
|
#destroy() {
|
|
39
49
|
this.#preloadAbort?.abort();
|
|
40
50
|
this.#preloadAbort = null;
|
|
@@ -71,7 +81,7 @@ function HlsJsPreloadMixin(BaseClass) {
|
|
|
71
81
|
this.#loadStarted = true;
|
|
72
82
|
engine.startLoad();
|
|
73
83
|
};
|
|
74
|
-
if (this.preload === "auto" || !target.paused) {
|
|
84
|
+
if (this.preload === "auto" || target.autoplay || !target.paused) {
|
|
75
85
|
load();
|
|
76
86
|
return;
|
|
77
87
|
}
|
|
@@ -18,13 +18,13 @@ function isCredentialed(crossOrigin) {
|
|
|
18
18
|
function withRequestCredentials(config, crossOrigin) {
|
|
19
19
|
const { xhrSetup, fetchSetup } = config;
|
|
20
20
|
return {
|
|
21
|
-
async xhrSetup(xhr, url) {
|
|
21
|
+
async xhrSetup(xhr, url, context) {
|
|
22
22
|
if (isCredentialed(crossOrigin())) xhr.withCredentials = true;
|
|
23
|
-
await xhrSetup?.(xhr, url);
|
|
23
|
+
await xhrSetup?.call(this, xhr, url, context);
|
|
24
24
|
},
|
|
25
25
|
fetchSetup(context, initParams) {
|
|
26
26
|
if (isCredentialed(crossOrigin())) initParams.credentials = "include";
|
|
27
|
-
return fetchSetup ? fetchSetup(context, initParams) : new Request(context.url, initParams);
|
|
27
|
+
return fetchSetup ? fetchSetup.call(this, context, initParams) : new Request(context.url, initParams);
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
}
|
|
@@ -3,6 +3,8 @@ import { isCaptionOrSubtitleTrack, listen } from "@videojs/utils/dom";
|
|
|
3
3
|
//#region src/text-tracks.ts
|
|
4
4
|
/** Marks the `<track>` elements created here for hls.js's own text tracks. */
|
|
5
5
|
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";
|
|
6
8
|
/** `HTMLTrackElement.LOADED` — the element parsed its resource and will not parse it again. */
|
|
7
9
|
const TRACK_LOADED = 2;
|
|
8
10
|
/**
|
|
@@ -99,15 +101,20 @@ function HlsJsTextTracksMixin(BaseClass) {
|
|
|
99
101
|
const { engine } = this;
|
|
100
102
|
if (!engine || !this.target) return;
|
|
101
103
|
const media = this.target;
|
|
104
|
+
const trackIdFor = ({ _id, default: isDefault, subtitleTrack }) => _id ?? (isDefault ? "default" : `subtitles${subtitleTrack?.id}`);
|
|
102
105
|
const onTracksFound = (_event, data) => {
|
|
103
|
-
|
|
106
|
+
const incomingIds = new Set(data.tracks.map(trackIdFor));
|
|
107
|
+
const ccBatch = data.tracks.every((trackObj) => trackObj._id != null);
|
|
108
|
+
for (const trackEl of media.querySelectorAll(`track[${HLS_TRACK_ATTR}]`)) {
|
|
109
|
+
const replaced = incomingIds.has(trackEl.id);
|
|
110
|
+
const ccOwned = trackEl.hasAttribute(CC_TRACK_ATTR);
|
|
111
|
+
if (!replaced && (ccBatch || ccOwned)) continue;
|
|
112
|
+
trackEl.track.mode = "disabled";
|
|
113
|
+
trackEl.remove();
|
|
114
|
+
}
|
|
104
115
|
for (const trackObj of data.tracks) {
|
|
105
116
|
const baseTrackObj = trackObj.subtitleTrack ?? trackObj.closedCaptions;
|
|
106
|
-
|
|
107
|
-
return lang === baseTrackObj?.lang && name === trackObj.label && type.toLowerCase() === trackObj.kind;
|
|
108
|
-
});
|
|
109
|
-
const id = trackObj._id ?? trackObj.default ? "default" : `${trackObj.kind}${idx}`;
|
|
110
|
-
addTextTrack(media, trackObj.kind, trackObj.label, baseTrackObj?.lang, id, trackObj.default);
|
|
117
|
+
addTextTrack(media, trackObj.kind, trackObj.label, baseTrackObj?.lang, trackIdFor(trackObj), trackObj.default, trackObj._id != null);
|
|
111
118
|
}
|
|
112
119
|
};
|
|
113
120
|
const onCuesParsed = (_event, { track, cues }) => {
|
|
@@ -121,12 +128,16 @@ function HlsJsTextTracksMixin(BaseClass) {
|
|
|
121
128
|
});
|
|
122
129
|
if (disabled) textTrack.mode = "disabled";
|
|
123
130
|
};
|
|
131
|
+
let lastShowingTrack;
|
|
124
132
|
const onTextTrackChange = () => {
|
|
125
|
-
if (!engine.subtitleTracks.length) return;
|
|
126
133
|
const showingTrack = Array.from(media.textTracks).find((textTrack) => {
|
|
127
134
|
return textTrack.id && textTrack.mode === "showing" && isCaptionOrSubtitleTrack(textTrack);
|
|
128
135
|
});
|
|
136
|
+
const showingChanged = showingTrack !== lastShowingTrack;
|
|
137
|
+
lastShowingTrack = showingTrack;
|
|
129
138
|
if (!showingTrack) return;
|
|
139
|
+
if (showingChanged && isHlsTextTrack(media, showingTrack)) refreshCues(showingTrack);
|
|
140
|
+
if (!engine.subtitleTracks.length) return;
|
|
130
141
|
const currentHlsTrack = engine.subtitleTracks[engine.subtitleTrack];
|
|
131
142
|
const hlsTrackId = !currentHlsTrack ? void 0 : currentHlsTrack.default ? "default" : `${engine.subtitleTracks[engine.subtitleTrack]?.type.toLowerCase()}${engine.subtitleTrack}`;
|
|
132
143
|
if (engine.subtitleTrack < 0 || showingTrack?.id !== hlsTrackId) {
|
|
@@ -135,11 +146,6 @@ function HlsJsTextTracksMixin(BaseClass) {
|
|
|
135
146
|
});
|
|
136
147
|
engine.subtitleTrack = idx;
|
|
137
148
|
}
|
|
138
|
-
if (showingTrack?.id === hlsTrackId) {
|
|
139
|
-
if (showingTrack.cues) Array.from(showingTrack.cues).forEach((cue) => {
|
|
140
|
-
showingTrack.addCue(cue);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
149
|
};
|
|
144
150
|
engine.on(Hls.Events.NON_NATIVE_TEXT_TRACKS_FOUND, onTracksFound);
|
|
145
151
|
engine.on(Hls.Events.CUES_PARSED, onCuesParsed);
|
|
@@ -152,7 +158,25 @@ function HlsJsTextTracksMixin(BaseClass) {
|
|
|
152
158
|
}
|
|
153
159
|
return HlsJsTextTracks;
|
|
154
160
|
}
|
|
155
|
-
function
|
|
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
|
+
/**
|
|
166
|
+
* Makes the media element render the cues of a track that just became the showing one.
|
|
167
|
+
*
|
|
168
|
+
* The `<track>` elements created here have no `src`, so their load fails. WebKit only hands a re-enabled track's cues
|
|
169
|
+
* back to the media element when its `<track>` loaded, so a track turned off and on again lists its cues but renders
|
|
170
|
+
* 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
|
|
171
|
+
* is removed before it is added back.
|
|
172
|
+
*/
|
|
173
|
+
function refreshCues(track) {
|
|
174
|
+
for (const cue of Array.from(track.cues ?? [])) {
|
|
175
|
+
track.removeCue(cue);
|
|
176
|
+
track.addCue(cue);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function addTextTrack(mediaEl, kind, label, lang, id, defaultTrack, ccOwned) {
|
|
156
180
|
const trackEl = document.createElement("track");
|
|
157
181
|
trackEl.kind = kind;
|
|
158
182
|
trackEl.label = label;
|
|
@@ -161,6 +185,7 @@ function addTextTrack(mediaEl, kind, label, lang, id, defaultTrack) {
|
|
|
161
185
|
if (defaultTrack) trackEl.default = true;
|
|
162
186
|
trackEl.track.mode = isCaptionOrSubtitleTrack({ kind }) ? "disabled" : "hidden";
|
|
163
187
|
trackEl.setAttribute(HLS_TRACK_ATTR, "");
|
|
188
|
+
if (ccOwned) trackEl.setAttribute(CC_TRACK_ATTR, "");
|
|
164
189
|
mediaEl.append(trackEl);
|
|
165
190
|
return trackEl.track;
|
|
166
191
|
}
|
package/dist/dev/adapter.d.ts
CHANGED
|
@@ -147,6 +147,11 @@ export declare class HlsJsAdapter extends HTMLVideoAdapter implements HlsJsAdapt
|
|
|
147
147
|
* hatch for direct engine access; normal playback is driven through this element's own properties and methods.
|
|
148
148
|
*/
|
|
149
149
|
get engine(): Hls$1 | null;
|
|
150
|
+
/**
|
|
151
|
+
* Engine this media is playing through, reported to analytics such as Mux Data: `hlsjs` via MSE, `browser` for native
|
|
152
|
+
* HLS, or `undefined` until a source loads. Read from the instance because the engine is picked per source.
|
|
153
|
+
*/
|
|
154
|
+
get engineName(): string | undefined;
|
|
150
155
|
get error(): (import("@videojs/media").ErrorLike & import("@videojs/media").MediaError) | null;
|
|
151
156
|
/** Populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */
|
|
152
157
|
get videoTracks(): import("@videojs/media").VideoTrackListLike | undefined;
|
package/dist/dev/adapter.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HlsJsOnlyAdapter } from "./hls-js-only.js";
|
|
2
2
|
import { KeySystems, MediaStreamTypes, bridgeEvents } from "@videojs/media";
|
|
3
|
-
import { HTMLVideoAdapter } from "@videojs/media/dom";
|
|
3
|
+
import { HTMLVideoAdapter, getMediaEngineName } from "@videojs/media/dom";
|
|
4
4
|
import { NativeHlsAdapter } from "@videojs/native-hls-video";
|
|
5
5
|
import { deepEqual } from "@videojs/utils/object";
|
|
6
6
|
import Hls$1 from "hls.js";
|
|
@@ -89,6 +89,13 @@ var HlsJsAdapter = class HlsJsAdapter extends HTMLVideoAdapter {
|
|
|
89
89
|
get engine() {
|
|
90
90
|
return this.#delegate?.engine ?? null;
|
|
91
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Engine this media is playing through, reported to analytics such as Mux Data: `hlsjs` via MSE, `browser` for native
|
|
94
|
+
* HLS, or `undefined` until a source loads. Read from the instance because the engine is picked per source.
|
|
95
|
+
*/
|
|
96
|
+
get engineName() {
|
|
97
|
+
return getMediaEngineName(this.#delegate);
|
|
98
|
+
}
|
|
92
99
|
get error() {
|
|
93
100
|
return this.#delegate?.error ?? null;
|
|
94
101
|
}
|
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 { 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 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,KAAK;CACL,QAAQ;AACV;;AAGA,MAAa,eAAe;CAC1B,MAAM;CACN,KAAK;AACP;;;;;;AAOA,MAAM,oCAAyC,IAAI,IAAI;CACrD,aAAa;CACb;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,oCAAyC,IAAI,IAAI,CAAC,aAAa,GAAG,CAAC;;AAGzE,MAAa,cAAc;AA6G3B,IAAM,gBAAN,cAA4B,MAAM,CAAC;;;;;;;AAQnC,IAAa,eAAb,MAAa,qBAAqB,iBAA8C;;EAC5B,KAAA,eAAA;GAChD,KAAK;GACL,QAAQ;GACR,SAAS;GACT,YAAY,iBAAiB;GAC7B,uBAAuB;EACzB;;CAEA,YAAwD;CACxD,gBAAyC;CACzC,OAAO,aAAa,aAAa;CACjC,UAA4B,aAAa,aAAa;CACtD,WAAW,aAAa,aAAa;CACrC,cAA0B,aAAa,aAAa;CACpD,oBAAoB;CACpB;CACA;;;;;;CAMA;CAEA,cAAc;EACZ,MAAM;EAEN,KAAK,iBAAiB,aAAa,KAAK,yBAAyB;CACnE;CAEA,OAAO,QAA0B;EAC/B,KAAK,gBAAgB;EACrB,MAAM,OAAO,MAAM;EACnB,KAAK,WAAW,OAAO,MAAM;CAC/B;CAEA,SAAS;EACP,KAAK,WAAW,OAAO;EACvB,MAAM,OAAO;EACb,KAA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K,WAAW,QAAQ;EACxB,KAAK,YAAY;EACjB,KAAK,uBAAuB;EAC5B,KAAK,iBAAiB;EAGtB,IAAI,CAAC,KAAK,mBAAmB,KAAK,cAAc,YAAY;CAC9D;AACF;;;;;;;;AASA,SAAS,eACP,OACA,KACsB;CACtB,MAAM,aAAa,OAAO,cAAc;CACxC,IAAI,CAAC,cAAc,OAAO,KAAK,UAAU,CAAC,CAAC,WAAW,GAAG,OAAO,EAAE,GAAG,MAAM;CAI3E,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,KAAK;CACL,QAAQ;AACV;;AAGA,MAAa,eAAe;CAC1B,MAAM;CACN,KAAK;AACP;;;;;;AAOA,MAAM,oCAAyC,IAAI,IAAI;CACrD,aAAa;CACb;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,oCAAyC,IAAI,IAAI,CAAC,aAAa,GAAG,CAAC;;AAGzE,MAAa,cAAc;AA6G3B,IAAM,gBAAN,cAA4B,MAAM,CAAC;;;;;;;AAQnC,IAAa,eAAb,MAAa,qBAAqB,iBAA8C;;EAC5B,KAAA,eAAA;GAChD,KAAK;GACL,QAAQ;GACR,SAAS;GACT,YAAY,iBAAiB;GAC7B,uBAAuB;EACzB;;CAEA,YAAwD;CACxD,gBAAyC;CACzC,OAAO,aAAa,aAAa;CACjC,UAA4B,aAAa,aAAa;CACtD,WAAW,aAAa,aAAa;CACrC,cAA0B,aAAa,aAAa;CACpD,oBAAoB;CACpB;CACA;;;;;;CAMA;CAEA,cAAc;EACZ,MAAM;EAEN,KAAK,iBAAiB,aAAa,KAAK,yBAAyB;CACnE;CAEA,OAAO,QAA0B;EAC/B,KAAK,gBAAgB;EACrB,MAAM,OAAO,MAAM;EACnB,KAAK,WAAW,OAAO,MAAM;CAC/B;CAEA,SAAS;EACP,KAAK,WAAW,OAAO;EACvB,MAAM,OAAO;EACb,KAAK,gBAAgB;CACvB;CAEA,UAAU;EACR,KAAK,OAAO;EACZ,KAAK,eAAe;EACpB,MAAM,QAAQ;EACd,KAAK,oBAAoB,aAAa,KAAK,yBAAy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C5B,KAAK,iBAAiB;EAGtB,IAAI,CAAC,KAAK,mBAAmB,KAAK,cAAc,YAAY;CAC9D;AACF;;;;;;;;AASA,SAAS,eACP,OACA,KACsB;CACtB,MAAM,aAAa,OAAO,cAAc;CACxC,IAAI,CAAC,cAAc,OAAO,KAAK,UAAU,CAAC,CAAC,WAAW,GAAG,OAAO,EAAE,GAAG,MAAM;CAI3E,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"}
|
package/dist/dev/cap-level.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Hls from "hls.js";
|
|
1
|
+
import Hls, { CapLevelController } from "hls.js";
|
|
2
2
|
//#region src/cap-level.ts
|
|
3
3
|
/**
|
|
4
4
|
* Floor applied to the player-size cap unless a source names another.
|
|
@@ -65,22 +65,21 @@ function levelIndexAtOrAbove(levels, resolution) {
|
|
|
65
65
|
/**
|
|
66
66
|
* Build the `capLevelController` class to hand to the hls.js constructor.
|
|
67
67
|
*
|
|
68
|
-
* `hls.autoLevelCapping`
|
|
69
|
-
* interval for as long as `capLevelToPlayerSize` is on — and it is on by
|
|
70
|
-
* outside is undone
|
|
71
|
-
* with it.
|
|
68
|
+
* `hls.autoLevelCapping` is rewritten by hls.js's own `CapLevelController` whenever the element resizes (or on a
|
|
69
|
+
* one-second interval where `ResizeObserver` is missing) for as long as `capLevelToPlayerSize` is on — and it is on by
|
|
70
|
+
* default here. Assigning the property from outside is undone on the next measurement, so a cap has to be applied from
|
|
71
|
+
* inside the controller rather than in competition with it.
|
|
72
72
|
*
|
|
73
73
|
* The only seam hls.js offers is `getMaxLevel()`, which every value the capping loop writes passes through. Overriding
|
|
74
|
-
* it makes the requested ceiling part of the same
|
|
74
|
+
* it makes the requested ceiling part of the same computation.
|
|
75
75
|
*
|
|
76
76
|
* @param policy - Live cap inputs, re-read on every evaluation.
|
|
77
77
|
* @param BaseController - Controller to layer on top of, so a controller passed through
|
|
78
78
|
* `source.engine.capLevelController` keeps its behavior.
|
|
79
79
|
*/
|
|
80
|
-
function createCapLevelController(policy, BaseController = Hls.DefaultConfig.capLevelController) {
|
|
80
|
+
function createCapLevelController(policy, BaseController = Hls.DefaultConfig.capLevelController ?? CapLevelController) {
|
|
81
81
|
return class RenditionCapLevelController extends BaseController {
|
|
82
82
|
#hls;
|
|
83
|
-
#capping = false;
|
|
84
83
|
#measuringWithoutSize = false;
|
|
85
84
|
constructor(hls) {
|
|
86
85
|
super(hls);
|
|
@@ -95,14 +94,6 @@ function createCapLevelController(policy, BaseController = Hls.DefaultConfig.cap
|
|
|
95
94
|
if (policy.controller === this) policy.controller = void 0;
|
|
96
95
|
super.destroy();
|
|
97
96
|
}
|
|
98
|
-
startCapping() {
|
|
99
|
-
this.#capping = true;
|
|
100
|
-
super.startCapping();
|
|
101
|
-
}
|
|
102
|
-
stopCapping() {
|
|
103
|
-
this.#capping = false;
|
|
104
|
-
super.stopCapping();
|
|
105
|
-
}
|
|
106
97
|
/**
|
|
107
98
|
* Hls.js derives its player-size ceiling from these two, so reporting an unbounded measurement is how
|
|
108
99
|
* `capToPlayerSize: false` switches that ceiling off while leaving the rest of the base controller intact.
|
|
@@ -163,7 +154,7 @@ function createCapLevelController(policy, BaseController = Hls.DefaultConfig.cap
|
|
|
163
154
|
this.#applyResolutionCap();
|
|
164
155
|
}
|
|
165
156
|
apply() {
|
|
166
|
-
if (this.#
|
|
157
|
+
if (this.#hls.config.capLevelToPlayerSize) {
|
|
167
158
|
this.detectPlayerSize();
|
|
168
159
|
return;
|
|
169
160
|
}
|