@hanifhan1f/vidstack-react 1.12.33 → 1.12.35
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/dev/chunks/{vidstack-3rdEWplD.js → vidstack-B-DU-_xu.js} +55 -3
- package/dev/chunks/{vidstack-CniPzPQc.js → vidstack-C3VHrHPf.js} +155 -15
- package/dev/chunks/{vidstack-BOPSNTgH.js → vidstack-CjLj3q5w.js} +5 -57
- package/dev/chunks/{vidstack-BNwnoM-l.js → vidstack-DpWioszb.js} +1 -1
- package/dev/chunks/{vidstack-S_S6XDnL.js → vidstack-t48GJbb5.js} +1 -1
- package/dev/player/vidstack-default-components.js +4 -4
- package/dev/player/vidstack-default-layout.js +4 -4
- package/dev/player/vidstack-plyr-layout.js +3 -3
- package/dev/vidstack.js +5 -5
- package/package.json +1 -1
- package/player/layouts/default.d.ts +9 -1
- package/prod/chunks/{vidstack-BlPINAXN.js → vidstack-BI5-IK9v.js} +55 -3
- package/prod/chunks/{vidstack-CbejzCJs.js → vidstack-BgAMJr1Y.js} +155 -15
- package/prod/chunks/{vidstack-Bh7M8kL6.js → vidstack-DKWmxvB4.js} +5 -57
- package/prod/chunks/{vidstack-DhSvljmQ.js → vidstack-NR84X5HE.js} +1 -1
- package/prod/chunks/{vidstack-BS445j5D.js → vidstack-jSJ0Meez.js} +1 -1
- package/prod/player/vidstack-default-components.js +4 -4
- package/prod/player/vidstack-default-layout.js +4 -4
- package/prod/player/vidstack-plyr-layout.js +3 -3
- package/prod/vidstack.js +5 -5
- package/{dev/chunks/vidstack-DTow20pt.js → server/chunks/vidstack-CSX6ausI.js} +55 -3
- package/server/chunks/{vidstack-CoGzBr_V.js → vidstack-CePUWLrW.js} +5 -57
- package/{dev/chunks/vidstack-CvWDiSTs.js → server/chunks/vidstack-D7sOBYbw.js} +1 -1
- package/server/chunks/{vidstack-VGPw_CQP.js → vidstack-DqUb8JgU.js} +1 -1
- package/server/chunks/{vidstack-i9a2TQLO.js → vidstack-Dvh6BtYs.js} +155 -15
- package/server/player/vidstack-default-components.js +4 -4
- package/server/player/vidstack-default-layout.js +4 -4
- package/server/player/vidstack-plyr-layout.js +3 -3
- package/server/vidstack.js +5 -5
- package/dev/chunks/vidstack-B-FM4-oZ.js +0 -668
- package/dev/chunks/vidstack-B92UncBI.js +0 -61
- package/dev/chunks/vidstack-BDiAEW1N.js +0 -11691
- package/dev/chunks/vidstack-BPymmnxm.js +0 -551
- package/dev/chunks/vidstack-BSZY6sbC.js +0 -180
- package/dev/chunks/vidstack-BSpAxhO6.js +0 -643
- package/dev/chunks/vidstack-BVVxkUlq.js +0 -288
- package/dev/chunks/vidstack-BXgKy_7V.js +0 -11693
- package/dev/chunks/vidstack-BalWqr4j.js +0 -1422
- package/dev/chunks/vidstack-Bfi_jCvb.js +0 -476
- package/dev/chunks/vidstack-BoLZuw80.js +0 -34
- package/dev/chunks/vidstack-BrqDQG-r.js +0 -643
- package/dev/chunks/vidstack-C3QPOZNd.js +0 -476
- package/dev/chunks/vidstack-C7BwfK5c.js +0 -1537
- package/dev/chunks/vidstack-CEUjDh4x.js +0 -34
- package/dev/chunks/vidstack-CFOPpDTy.js +0 -476
- package/dev/chunks/vidstack-CFZ0rYJz.js +0 -34
- package/dev/chunks/vidstack-CKsUl4ll.js +0 -1384
- package/dev/chunks/vidstack-CM82l-7o.js +0 -551
- package/dev/chunks/vidstack-CQSHFVu7.js +0 -401
- package/dev/chunks/vidstack-CXrXBlpD.js +0 -11692
- package/dev/chunks/vidstack-CevuS08D.js +0 -1504
- package/dev/chunks/vidstack-CkRXb9Ia.js +0 -1537
- package/dev/chunks/vidstack-CqNX679o.js +0 -669
- package/dev/chunks/vidstack-Csfg08VS.js +0 -551
- package/dev/chunks/vidstack-CzU-uC5f.js +0 -189
- package/dev/chunks/vidstack-D2Bi2Td9.js +0 -1537
- package/dev/chunks/vidstack-D3ZXOE4d.js +0 -643
- package/dev/chunks/vidstack-D6_9yy0x.js +0 -643
- package/dev/chunks/vidstack-DJQOTrl6.js +0 -180
- package/dev/chunks/vidstack-DNbKNc4R.js +0 -288
- package/dev/chunks/vidstack-DOtIyh4c.js +0 -288
- package/dev/chunks/vidstack-DY2iivhG.js +0 -84
- package/dev/chunks/vidstack-DjqYvkVp.js +0 -84
- package/dev/chunks/vidstack-Dov8gjdq.js +0 -401
- package/dev/chunks/vidstack-DqaqkU4T.js +0 -9
- package/dev/chunks/vidstack-DwdhbP5c.js +0 -189
- package/dev/chunks/vidstack-DweQYzVw.js +0 -180
- package/dev/chunks/vidstack-FuCbl228.js +0 -226
- package/dev/chunks/vidstack-H9OdEKUQ.js +0 -375
- package/dev/chunks/vidstack-KntYDWMe.js +0 -668
- package/dev/chunks/vidstack-L5mw2iPb.js +0 -375
- package/dev/chunks/vidstack-NCBSBZE-.js +0 -61
- package/dev/chunks/vidstack-PREbBNMG.js +0 -125
- package/dev/chunks/vidstack-UWMPvwsa.js +0 -1537
- package/dev/chunks/vidstack-f6WXkmfP.js +0 -375
- package/dev/chunks/vidstack-gqKBE4xH.js +0 -376
- package/dev/chunks/vidstack-iRuTLfhk.js +0 -61
- package/dev/chunks/vidstack-lYFZKRUc.js +0 -401
- package/dev/chunks/vidstack-oOGofWSl.js +0 -668
- package/dev/chunks/vidstack-vh0BKYWJ.js +0 -84
- package/prod/chunks/vidstack-0Foyib2F.js +0 -34
- package/prod/chunks/vidstack-58ZavMvv.js +0 -159
- package/prod/chunks/vidstack-B0SSIHIv.js +0 -1537
- package/prod/chunks/vidstack-B9nEslvl.js +0 -11197
- package/prod/chunks/vidstack-BCBskRpc.js +0 -664
- package/prod/chunks/vidstack-BOObgZd8.js +0 -504
- package/prod/chunks/vidstack-BZVrgeRF.js +0 -9
- package/prod/chunks/vidstack-B_9VGrZQ.js +0 -504
- package/prod/chunks/vidstack-B_wD853-.js +0 -386
- package/prod/chunks/vidstack-BbPEqH3g.js +0 -11196
- package/prod/chunks/vidstack-Bm2UemPE.js +0 -470
- package/prod/chunks/vidstack-Bp_hAwzI.js +0 -61
- package/prod/chunks/vidstack-C4tNkfXj.js +0 -470
- package/prod/chunks/vidstack-C4tuISYG.js +0 -1504
- package/prod/chunks/vidstack-C5Rzkyfp.js +0 -375
- package/prod/chunks/vidstack-CKapDFwB.js +0 -376
- package/prod/chunks/vidstack-CNJwYQRW.js +0 -84
- package/prod/chunks/vidstack-CQll06Hv.js +0 -34
- package/prod/chunks/vidstack-CVzVtf1j.js +0 -61
- package/prod/chunks/vidstack-CYK75vJF.js +0 -1382
- package/prod/chunks/vidstack-CZNlvfmV.js +0 -288
- package/prod/chunks/vidstack-CiQEyk_l.js +0 -189
- package/prod/chunks/vidstack-CiTWSpv_.js +0 -34
- package/prod/chunks/vidstack-CikQpsuo.js +0 -1537
- package/prod/chunks/vidstack-CtxjO6HG.js +0 -84
- package/prod/chunks/vidstack-CzjHdPIT.js +0 -375
- package/prod/chunks/vidstack-D0XCUWbp.js +0 -159
- package/prod/chunks/vidstack-D3cSYtez.js +0 -663
- package/prod/chunks/vidstack-D91K36KQ.js +0 -206
- package/prod/chunks/vidstack-DJThTSEm.js +0 -125
- package/prod/chunks/vidstack-DTyDOhwS.js +0 -504
- package/prod/chunks/vidstack-DVMwXUgY.js +0 -189
- package/prod/chunks/vidstack-DXSNXDnS.js +0 -1384
- package/prod/chunks/vidstack-D_Sd7838.js +0 -663
- package/prod/chunks/vidstack-D_ijTIbV.js +0 -11198
- package/prod/chunks/vidstack-DdiGCJVp.js +0 -504
- package/prod/chunks/vidstack-DgGDsAKh.js +0 -375
- package/prod/chunks/vidstack-DgsBXr1J.js +0 -84
- package/prod/chunks/vidstack-DhC5F6c8.js +0 -470
- package/prod/chunks/vidstack-Djmla_FM.js +0 -545
- package/prod/chunks/vidstack-DpQw1Y33.js +0 -663
- package/prod/chunks/vidstack-DrEorv9m.js +0 -189
- package/prod/chunks/vidstack-Ma9rwtR0.js +0 -386
- package/prod/chunks/vidstack-VTpvHAdU.js +0 -1537
- package/prod/chunks/vidstack-dbLRgf2L.js +0 -159
- package/prod/chunks/vidstack-ehqxnvc9.js +0 -1537
- package/prod/chunks/vidstack-jIPoNqhj.js +0 -545
- package/prod/chunks/vidstack-lc8NHly9.js +0 -288
- package/prod/chunks/vidstack-rHvQ8f6c.js +0 -288
- package/prod/chunks/vidstack-rKV98aQH.js +0 -545
- package/prod/chunks/vidstack-uA7h-Bsq.js +0 -386
- package/prod/chunks/vidstack-xo_SmgiV.js +0 -84
- package/prod/chunks/vidstack-xvxeRtaN.js +0 -61
- package/server/chunks/vidstack--ufi23Q6.js +0 -1537
- package/server/chunks/vidstack-B3AXUfgF.js +0 -189
- package/server/chunks/vidstack-B4rJ1ZKK.js +0 -376
- package/server/chunks/vidstack-BJCx78pm.js +0 -386
- package/server/chunks/vidstack-BTdEfKqV.js +0 -84
- package/server/chunks/vidstack-BV_VpWlJ.js +0 -1537
- package/server/chunks/vidstack-BtitkRvR.js +0 -11198
- package/server/chunks/vidstack-BtqWstSj.js +0 -375
- package/server/chunks/vidstack-BweZhuNd.js +0 -1537
- package/server/chunks/vidstack-ByG5MvLs.js +0 -545
- package/server/chunks/vidstack-C-HdFsZi.js +0 -84
- package/server/chunks/vidstack-C0xOpWYR.js +0 -470
- package/server/chunks/vidstack-C481iXqe.js +0 -386
- package/server/chunks/vidstack-C4iWXMC-.js +0 -545
- package/server/chunks/vidstack-C5zFBMwg.js +0 -386
- package/server/chunks/vidstack-CEh38XpD.js +0 -288
- package/server/chunks/vidstack-CSiPajWY.js +0 -470
- package/server/chunks/vidstack-CbNRZgUA.js +0 -11197
- package/server/chunks/vidstack-CgXa6YO3.js +0 -61
- package/server/chunks/vidstack-CkMAeO-e.js +0 -34
- package/server/chunks/vidstack-Cm0qnRvu.js +0 -11196
- package/server/chunks/vidstack-Ct1NFlBa.js +0 -1537
- package/server/chunks/vidstack-CyFwkPiu.js +0 -470
- package/server/chunks/vidstack-D4t_SZbb.js +0 -1416
- package/server/chunks/vidstack-D7D9kiW6.js +0 -34
- package/server/chunks/vidstack-DH6N0AoF.js +0 -375
- package/server/chunks/vidstack-DJJmNib6.js +0 -504
- package/server/chunks/vidstack-DKr7br9D.js +0 -34
- package/server/chunks/vidstack-DM-5dPT-.js +0 -663
- package/server/chunks/vidstack-DOIUveQF.js +0 -504
- package/server/chunks/vidstack-DTn72IA8.js +0 -1504
- package/server/chunks/vidstack-DWfS9vAY.js +0 -84
- package/server/chunks/vidstack-DWt5LAKE.js +0 -375
- package/server/chunks/vidstack-DY51lx0R.js +0 -189
- package/server/chunks/vidstack-DbNoKLjz.js +0 -664
- package/server/chunks/vidstack-Dbs_rXUT.js +0 -663
- package/server/chunks/vidstack-DeS67_gx.js +0 -9
- package/server/chunks/vidstack-DiHlnSws.js +0 -1384
- package/server/chunks/vidstack-DnoqxmOs.js +0 -125
- package/server/chunks/vidstack-DsZKgA8y.js +0 -663
- package/server/chunks/vidstack-DtQSvsQr.js +0 -189
- package/server/chunks/vidstack-E7eUOyFt.js +0 -288
- package/server/chunks/vidstack-JkJEYEQM.js +0 -159
- package/server/chunks/vidstack-KhtuR229.js +0 -504
- package/server/chunks/vidstack-NXcLNXxO.js +0 -84
- package/server/chunks/vidstack-OKdxH1xx.js +0 -189
- package/server/chunks/vidstack-SkX-mSrw.js +0 -206
- package/server/chunks/vidstack-X1Hex9PH.js +0 -84
- package/server/chunks/vidstack-iVN8uBAv.js +0 -288
- package/server/chunks/vidstack-jlaBqZq5.js +0 -61
- package/server/chunks/vidstack-m8aA99tE.js +0 -159
- package/server/chunks/vidstack-rUHVQoo3.js +0 -61
- package/server/chunks/vidstack-rWs25cS9.js +0 -159
- package/server/chunks/vidstack-uyCXITen.js +0 -504
- package/server/chunks/vidstack-yf18YVAb.js +0 -545
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { peek, listenEvent, effect, DOMEvent, isString, camelToKebabCase, isUndefined, isFunction } from './vidstack-D_bWd66h.js';
|
|
4
|
-
import { QualitySymbol, RAFLoop, TextTrack, TextTrackSymbol, ListSymbol, IS_CHROME, coerceToError, loadScript, VideoProvider, isHLSSupported, preconnect } from './vidstack-CbNRZgUA.js';
|
|
5
|
-
import 'react';
|
|
6
|
-
import '@floating-ui/dom';
|
|
7
|
-
|
|
8
|
-
const toDOMEventType = (type) => camelToKebabCase(type);
|
|
9
|
-
class HLSController {
|
|
10
|
-
#video;
|
|
11
|
-
#ctx;
|
|
12
|
-
#instance = null;
|
|
13
|
-
#stopLiveSync = null;
|
|
14
|
-
config = {};
|
|
15
|
-
#callbacks = /* @__PURE__ */ new Set();
|
|
16
|
-
get instance() {
|
|
17
|
-
return this.#instance;
|
|
18
|
-
}
|
|
19
|
-
constructor(video, ctx) {
|
|
20
|
-
this.#video = video;
|
|
21
|
-
this.#ctx = ctx;
|
|
22
|
-
}
|
|
23
|
-
setup(ctor) {
|
|
24
|
-
const { streamType } = this.#ctx.$state;
|
|
25
|
-
const isLive = peek(streamType).includes("live"), isLiveLowLatency = peek(streamType).includes("ll-");
|
|
26
|
-
this.#instance = new ctor({
|
|
27
|
-
lowLatencyMode: isLiveLowLatency,
|
|
28
|
-
backBufferLength: isLiveLowLatency ? 4 : isLive ? 8 : void 0,
|
|
29
|
-
renderTextTracksNatively: false,
|
|
30
|
-
...this.config
|
|
31
|
-
});
|
|
32
|
-
const dispatcher = this.#dispatchHLSEvent.bind(this);
|
|
33
|
-
for (const event of Object.values(ctor.Events)) this.#instance.on(event, dispatcher);
|
|
34
|
-
this.#instance.on(ctor.Events.ERROR, this.#onError.bind(this));
|
|
35
|
-
for (const callback of this.#callbacks) callback(this.#instance);
|
|
36
|
-
this.#ctx.player.dispatch("hls-instance", {
|
|
37
|
-
detail: this.#instance
|
|
38
|
-
});
|
|
39
|
-
this.#instance.attachMedia(this.#video);
|
|
40
|
-
this.#instance.on(ctor.Events.AUDIO_TRACK_SWITCHED, this.#onAudioSwitch.bind(this));
|
|
41
|
-
this.#instance.on(ctor.Events.LEVEL_SWITCHED, this.#onLevelSwitched.bind(this));
|
|
42
|
-
this.#instance.on(ctor.Events.LEVEL_LOADED, this.#onLevelLoaded.bind(this));
|
|
43
|
-
this.#instance.on(ctor.Events.LEVEL_UPDATED, this.#onLevelUpdated.bind(this));
|
|
44
|
-
this.#instance.on(ctor.Events.NON_NATIVE_TEXT_TRACKS_FOUND, this.#onTracksFound.bind(this));
|
|
45
|
-
this.#instance.on(ctor.Events.CUES_PARSED, this.#onCuesParsed.bind(this));
|
|
46
|
-
this.#ctx.qualities[QualitySymbol.enableAuto] = this.#enableAutoQuality.bind(this);
|
|
47
|
-
listenEvent(this.#ctx.qualities, "change", this.#onUserQualityChange.bind(this));
|
|
48
|
-
listenEvent(this.#ctx.audioTracks, "change", this.#onUserAudioChange.bind(this));
|
|
49
|
-
this.#stopLiveSync = effect(this.#liveSync.bind(this));
|
|
50
|
-
}
|
|
51
|
-
#createDOMEvent(type, data) {
|
|
52
|
-
return new DOMEvent(toDOMEventType(type), { detail: data });
|
|
53
|
-
}
|
|
54
|
-
#liveSync() {
|
|
55
|
-
if (!this.#ctx.$state.live()) return;
|
|
56
|
-
const raf = new RAFLoop(this.#liveSyncPosition.bind(this));
|
|
57
|
-
raf.start();
|
|
58
|
-
return raf.stop.bind(raf);
|
|
59
|
-
}
|
|
60
|
-
#liveSyncPosition() {
|
|
61
|
-
this.#ctx.$state.liveSyncPosition.set(this.#instance?.liveSyncPosition ?? Infinity);
|
|
62
|
-
}
|
|
63
|
-
#dispatchHLSEvent(type, data) {
|
|
64
|
-
this.#ctx.player?.dispatch(this.#createDOMEvent(type, data));
|
|
65
|
-
}
|
|
66
|
-
#onTracksFound(eventType, data) {
|
|
67
|
-
const event = this.#createDOMEvent(eventType, data);
|
|
68
|
-
let currentTrack = -1;
|
|
69
|
-
for (let i = 0; i < data.tracks.length; i++) {
|
|
70
|
-
const nonNativeTrack = data.tracks[i], init = nonNativeTrack.subtitleTrack ?? nonNativeTrack.closedCaptions, track = new TextTrack({
|
|
71
|
-
id: `hls-${nonNativeTrack.kind}-${i}`,
|
|
72
|
-
src: init?.url,
|
|
73
|
-
label: nonNativeTrack.label,
|
|
74
|
-
language: init?.lang,
|
|
75
|
-
kind: nonNativeTrack.kind,
|
|
76
|
-
default: nonNativeTrack.default
|
|
77
|
-
});
|
|
78
|
-
track[TextTrackSymbol.readyState] = 2;
|
|
79
|
-
track[TextTrackSymbol.onModeChange] = () => {
|
|
80
|
-
if (track.mode === "showing") {
|
|
81
|
-
this.#instance.subtitleTrack = i;
|
|
82
|
-
currentTrack = i;
|
|
83
|
-
} else if (currentTrack === i) {
|
|
84
|
-
this.#instance.subtitleTrack = -1;
|
|
85
|
-
currentTrack = -1;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
this.#ctx.textTracks.add(track, event);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
#onCuesParsed(eventType, data) {
|
|
92
|
-
const index = this.#instance?.subtitleTrack, track = this.#ctx.textTracks.getById(`hls-${data.type}-${index}`);
|
|
93
|
-
if (!track) return;
|
|
94
|
-
const event = this.#createDOMEvent(eventType, data);
|
|
95
|
-
for (const cue of data.cues) {
|
|
96
|
-
cue.positionAlign = "auto";
|
|
97
|
-
track.addCue(cue, event);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
#onAudioSwitch(eventType, data) {
|
|
101
|
-
const track = this.#ctx.audioTracks[data.id];
|
|
102
|
-
if (track) {
|
|
103
|
-
const trigger = this.#createDOMEvent(eventType, data);
|
|
104
|
-
this.#ctx.audioTracks[ListSymbol.select](track, true, trigger);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
#onLevelSwitched(eventType, data) {
|
|
108
|
-
const quality = this.#ctx.qualities[data.level];
|
|
109
|
-
if (quality) {
|
|
110
|
-
const trigger = this.#createDOMEvent(eventType, data);
|
|
111
|
-
this.#ctx.qualities[ListSymbol.select](quality, true, trigger);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
#onLevelUpdated(eventType, data) {
|
|
115
|
-
if (data.details.totalduration > 0) {
|
|
116
|
-
this.#ctx.$state.inferredLiveDVRWindow.set(data.details.totalduration);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
#onLevelLoaded(eventType, data) {
|
|
120
|
-
if (this.#ctx.$state.canPlay()) return;
|
|
121
|
-
const { type, live, totalduration: duration, targetduration } = data.details, trigger = this.#createDOMEvent(eventType, data);
|
|
122
|
-
this.#ctx.notify(
|
|
123
|
-
"stream-type-change",
|
|
124
|
-
live ? type === "EVENT" && Number.isFinite(duration) && targetduration >= 10 ? "live:dvr" : "live" : "on-demand",
|
|
125
|
-
trigger
|
|
126
|
-
);
|
|
127
|
-
this.#ctx.notify("duration-change", duration, trigger);
|
|
128
|
-
const media = this.#instance.media;
|
|
129
|
-
if (this.#instance.currentLevel === -1) {
|
|
130
|
-
this.#ctx.qualities[QualitySymbol.setAuto](true, trigger);
|
|
131
|
-
}
|
|
132
|
-
for (const remoteTrack of this.#instance.audioTracks) {
|
|
133
|
-
const localTrack = {
|
|
134
|
-
id: remoteTrack.id.toString(),
|
|
135
|
-
label: remoteTrack.name,
|
|
136
|
-
language: remoteTrack.lang || "",
|
|
137
|
-
kind: "main"
|
|
138
|
-
};
|
|
139
|
-
this.#ctx.audioTracks[ListSymbol.add](localTrack, trigger);
|
|
140
|
-
}
|
|
141
|
-
for (const level of this.#instance.levels) {
|
|
142
|
-
const videoQuality = {
|
|
143
|
-
id: level.id?.toString() ?? level.height + "p",
|
|
144
|
-
width: level.width,
|
|
145
|
-
height: level.height,
|
|
146
|
-
codec: level.codecSet,
|
|
147
|
-
bitrate: level.bitrate
|
|
148
|
-
};
|
|
149
|
-
this.#ctx.qualities[ListSymbol.add](videoQuality, trigger);
|
|
150
|
-
}
|
|
151
|
-
media.dispatchEvent(new DOMEvent("canplay", { trigger }));
|
|
152
|
-
}
|
|
153
|
-
#onError(eventType, data) {
|
|
154
|
-
if (data.fatal) {
|
|
155
|
-
switch (data.type) {
|
|
156
|
-
case "mediaError":
|
|
157
|
-
this.#instance?.recoverMediaError();
|
|
158
|
-
break;
|
|
159
|
-
default:
|
|
160
|
-
this.#onFatalError(data.error);
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
#onFatalError(error) {
|
|
166
|
-
this.#ctx.notify("error", {
|
|
167
|
-
message: error.message,
|
|
168
|
-
code: 1,
|
|
169
|
-
error
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
#enableAutoQuality() {
|
|
173
|
-
if (this.#instance) this.#instance.currentLevel = -1;
|
|
174
|
-
}
|
|
175
|
-
#onUserQualityChange() {
|
|
176
|
-
const { qualities } = this.#ctx;
|
|
177
|
-
if (!this.#instance || qualities.auto) return;
|
|
178
|
-
this.#instance[qualities.switch + "Level"] = qualities.selectedIndex;
|
|
179
|
-
if (IS_CHROME) {
|
|
180
|
-
this.#video.currentTime = this.#video.currentTime;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
#onUserAudioChange() {
|
|
184
|
-
const { audioTracks } = this.#ctx;
|
|
185
|
-
if (this.#instance && this.#instance.audioTrack !== audioTracks.selectedIndex) {
|
|
186
|
-
this.#instance.audioTrack = audioTracks.selectedIndex;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
onInstance(callback) {
|
|
190
|
-
this.#callbacks.add(callback);
|
|
191
|
-
return () => this.#callbacks.delete(callback);
|
|
192
|
-
}
|
|
193
|
-
loadSource(src) {
|
|
194
|
-
if (!isString(src.src)) return;
|
|
195
|
-
this.#instance?.loadSource(src.src);
|
|
196
|
-
}
|
|
197
|
-
destroy() {
|
|
198
|
-
this.#instance?.destroy();
|
|
199
|
-
this.#instance = null;
|
|
200
|
-
this.#stopLiveSync?.();
|
|
201
|
-
this.#stopLiveSync = null;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
class HLSLibLoader {
|
|
206
|
-
#lib;
|
|
207
|
-
#ctx;
|
|
208
|
-
#callback;
|
|
209
|
-
constructor(lib, ctx, callback) {
|
|
210
|
-
this.#lib = lib;
|
|
211
|
-
this.#ctx = ctx;
|
|
212
|
-
this.#callback = callback;
|
|
213
|
-
this.#startLoading();
|
|
214
|
-
}
|
|
215
|
-
async #startLoading() {
|
|
216
|
-
const callbacks = {
|
|
217
|
-
onLoadStart: this.#onLoadStart.bind(this),
|
|
218
|
-
onLoaded: this.#onLoaded.bind(this),
|
|
219
|
-
onLoadError: this.#onLoadError.bind(this)
|
|
220
|
-
};
|
|
221
|
-
let ctor = await loadHLSScript(this.#lib, callbacks);
|
|
222
|
-
if (isUndefined(ctor) && !isString(this.#lib)) ctor = await importHLS(this.#lib, callbacks);
|
|
223
|
-
if (!ctor) return null;
|
|
224
|
-
if (!ctor.isSupported()) {
|
|
225
|
-
const message = "[vidstack] `hls.js` is not supported in this environment";
|
|
226
|
-
this.#ctx.player.dispatch(new DOMEvent("hls-unsupported"));
|
|
227
|
-
this.#ctx.notify("error", { message, code: 4 });
|
|
228
|
-
return null;
|
|
229
|
-
}
|
|
230
|
-
return ctor;
|
|
231
|
-
}
|
|
232
|
-
#onLoadStart() {
|
|
233
|
-
this.#ctx.player.dispatch(new DOMEvent("hls-lib-load-start"));
|
|
234
|
-
}
|
|
235
|
-
#onLoaded(ctor) {
|
|
236
|
-
this.#ctx.player.dispatch(
|
|
237
|
-
new DOMEvent("hls-lib-loaded", {
|
|
238
|
-
detail: ctor
|
|
239
|
-
})
|
|
240
|
-
);
|
|
241
|
-
this.#callback(ctor);
|
|
242
|
-
}
|
|
243
|
-
#onLoadError(e) {
|
|
244
|
-
const error = coerceToError(e);
|
|
245
|
-
this.#ctx.player.dispatch(
|
|
246
|
-
new DOMEvent("hls-lib-load-error", {
|
|
247
|
-
detail: error
|
|
248
|
-
})
|
|
249
|
-
);
|
|
250
|
-
this.#ctx.notify("error", {
|
|
251
|
-
message: error.message,
|
|
252
|
-
code: 4,
|
|
253
|
-
error
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
async function importHLS(loader, callbacks = {}) {
|
|
258
|
-
if (isUndefined(loader)) return void 0;
|
|
259
|
-
callbacks.onLoadStart?.();
|
|
260
|
-
if (loader.prototype && loader.prototype !== Function) {
|
|
261
|
-
callbacks.onLoaded?.(loader);
|
|
262
|
-
return loader;
|
|
263
|
-
}
|
|
264
|
-
try {
|
|
265
|
-
const ctor = (await loader())?.default;
|
|
266
|
-
if (ctor && !!ctor.isSupported) {
|
|
267
|
-
callbacks.onLoaded?.(ctor);
|
|
268
|
-
} else {
|
|
269
|
-
throw Error(
|
|
270
|
-
false ? "[vidstack] failed importing `hls.js`. Dynamic import returned invalid constructor." : ""
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
return ctor;
|
|
274
|
-
} catch (err) {
|
|
275
|
-
callbacks.onLoadError?.(err);
|
|
276
|
-
}
|
|
277
|
-
return void 0;
|
|
278
|
-
}
|
|
279
|
-
async function loadHLSScript(src, callbacks = {}) {
|
|
280
|
-
if (!isString(src)) return void 0;
|
|
281
|
-
callbacks.onLoadStart?.();
|
|
282
|
-
try {
|
|
283
|
-
await loadScript(src);
|
|
284
|
-
if (!isFunction(window.Hls)) {
|
|
285
|
-
throw Error(
|
|
286
|
-
false ? "[vidstack] failed loading `hls.js`. Could not find a valid `Hls` constructor on window" : ""
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
const ctor = window.Hls;
|
|
290
|
-
callbacks.onLoaded?.(ctor);
|
|
291
|
-
return ctor;
|
|
292
|
-
} catch (err) {
|
|
293
|
-
callbacks.onLoadError?.(err);
|
|
294
|
-
}
|
|
295
|
-
return void 0;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
const JS_DELIVR_CDN = "https://cdn.jsdelivr.net";
|
|
299
|
-
class HLSProvider extends VideoProvider {
|
|
300
|
-
$$PROVIDER_TYPE = "HLS";
|
|
301
|
-
#ctor = null;
|
|
302
|
-
#controller = new HLSController(this.video, this.ctx);
|
|
303
|
-
/**
|
|
304
|
-
* The `hls.js` constructor.
|
|
305
|
-
*/
|
|
306
|
-
get ctor() {
|
|
307
|
-
return this.#ctor;
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* The current `hls.js` instance.
|
|
311
|
-
*/
|
|
312
|
-
get instance() {
|
|
313
|
-
return this.#controller.instance;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Whether `hls.js` is supported in this environment.
|
|
317
|
-
*/
|
|
318
|
-
static supported = isHLSSupported();
|
|
319
|
-
get type() {
|
|
320
|
-
return "hls";
|
|
321
|
-
}
|
|
322
|
-
get canLiveSync() {
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
#library = `${JS_DELIVR_CDN}/npm/hls.js@^1.5.0/dist/hls${".min.js"}`;
|
|
326
|
-
/**
|
|
327
|
-
* The `hls.js` configuration object.
|
|
328
|
-
*
|
|
329
|
-
* @see {@link https://github.com/video-dev/hls.js/blob/master/docs/API.md#fine-tuning}
|
|
330
|
-
*/
|
|
331
|
-
get config() {
|
|
332
|
-
return this.#controller.config;
|
|
333
|
-
}
|
|
334
|
-
set config(config) {
|
|
335
|
-
this.#controller.config = config;
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* The `hls.js` constructor (supports dynamic imports) or a URL of where it can be found.
|
|
339
|
-
*
|
|
340
|
-
* @defaultValue `https://cdn.jsdelivr.net/npm/hls.js@^1.0.0/dist/hls.min.js`
|
|
341
|
-
*/
|
|
342
|
-
get library() {
|
|
343
|
-
return this.#library;
|
|
344
|
-
}
|
|
345
|
-
set library(library) {
|
|
346
|
-
this.#library = library;
|
|
347
|
-
}
|
|
348
|
-
preconnect() {
|
|
349
|
-
if (!isString(this.#library)) return;
|
|
350
|
-
preconnect(this.#library);
|
|
351
|
-
}
|
|
352
|
-
setup() {
|
|
353
|
-
super.setup();
|
|
354
|
-
new HLSLibLoader(this.#library, this.ctx, (ctor) => {
|
|
355
|
-
this.#ctor = ctor;
|
|
356
|
-
this.#controller.setup(ctor);
|
|
357
|
-
this.ctx.notify("provider-setup", this);
|
|
358
|
-
const src = peek(this.ctx.$state.source);
|
|
359
|
-
if (src) this.loadSource(src);
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
async loadSource(src, preload) {
|
|
363
|
-
if (!isString(src.src)) {
|
|
364
|
-
this.removeSource();
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
this.media.preload = preload || "";
|
|
368
|
-
this.appendSource(src, "application/x-mpegurl");
|
|
369
|
-
this.#controller.loadSource(src);
|
|
370
|
-
this.currentSrc = src;
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* The given callback is invoked when a new `hls.js` instance is created and right before it's
|
|
374
|
-
* attached to media.
|
|
375
|
-
*/
|
|
376
|
-
onInstance(callback) {
|
|
377
|
-
const instance = this.#controller.instance;
|
|
378
|
-
if (instance) callback(instance);
|
|
379
|
-
return this.#controller.onInstance(callback);
|
|
380
|
-
}
|
|
381
|
-
destroy() {
|
|
382
|
-
this.#controller.destroy();
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
export { HLSProvider };
|