@locpd/vidstack 1.12.14
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/LICENSE +21 -0
- package/README.md +22 -0
- package/analyze.json.d.ts +8 -0
- package/bundle.d.ts +1 -0
- package/cdn/chunks/vidstack-2f5gzOW6.js +1 -0
- package/cdn/chunks/vidstack-BYgY9wmd.js +1 -0
- package/cdn/chunks/vidstack-BfBBPhXV.js +1 -0
- package/cdn/chunks/vidstack-Bjo5esRp.js +1 -0
- package/cdn/chunks/vidstack-BuL67v3q.js +1 -0
- package/cdn/chunks/vidstack-C0msPRTd.js +3 -0
- package/cdn/chunks/vidstack-CJNLoJPa.js +1 -0
- package/cdn/chunks/vidstack-CQSpZ7X8.js +16 -0
- package/cdn/chunks/vidstack-C_AxqLKV.js +1 -0
- package/cdn/chunks/vidstack-CioT3Yw2.js +1 -0
- package/cdn/chunks/vidstack-CrqkytHl.js +1 -0
- package/cdn/chunks/vidstack-D0M8R0ZU.js +1 -0
- package/cdn/chunks/vidstack-D40FSa5B.js +3 -0
- package/cdn/chunks/vidstack-DD2JwFVU.js +1 -0
- package/cdn/chunks/vidstack-DRH_1tFW.js +1 -0
- package/cdn/chunks/vidstack-DfDZuHNP.js +1 -0
- package/cdn/chunks/vidstack-DiNS2Vx5.js +1 -0
- package/cdn/chunks/vidstack-xjJ-ui_l.js +1 -0
- package/cdn/providers/vidstack-audio-2Dt_Ivbp.js +1 -0
- package/cdn/providers/vidstack-dash-CUtD4e6q.js +1 -0
- package/cdn/providers/vidstack-google-cast-BdORATUX.js +1 -0
- package/cdn/providers/vidstack-hls-R25Kb6DP.js +1 -0
- package/cdn/providers/vidstack-html-DaAUJYsD.js +1 -0
- package/cdn/providers/vidstack-video-Csvox7SO.js +1 -0
- package/cdn/providers/vidstack-vimeo-D4Z96kg2.js +1 -0
- package/cdn/providers/vidstack-youtube-DiND6h3s.js +1 -0
- package/cdn/vidstack.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-2f5gzOW6.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-45yH5los.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-BBVMdOnf.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-BB_ulI_T.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-BcAewM33.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-BfBBPhXV.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-Bxv1Qnxe.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-C2ZbG62f.js +3 -0
- package/cdn/with-layouts/chunks/vidstack-CCYIOKgL.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-CL6PeIO1.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-C_AxqLKV.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-CifDkwDH.js +795 -0
- package/cdn/with-layouts/chunks/vidstack-Cry7aD59.js +3 -0
- package/cdn/with-layouts/chunks/vidstack-D065okCn.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-DGuMoXmI.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-DRH_1tFW.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-DVBs1XoQ.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-Dge3KT8k.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-DiNS2Vx5.js +1 -0
- package/cdn/with-layouts/chunks/vidstack-HvYfJoen.js +1 -0
- package/cdn/with-layouts/providers/vidstack-audio-DE5vKIzW.js +1 -0
- package/cdn/with-layouts/providers/vidstack-dash-CA2agUuZ.js +1 -0
- package/cdn/with-layouts/providers/vidstack-google-cast-CGs-t8HM.js +1 -0
- package/cdn/with-layouts/providers/vidstack-hls-BHMbMFFR.js +1 -0
- package/cdn/with-layouts/providers/vidstack-html-Dm9gmNk6.js +1 -0
- package/cdn/with-layouts/providers/vidstack-video-C5it_Lbl.js +1 -0
- package/cdn/with-layouts/providers/vidstack-vimeo-BabLn9sy.js +1 -0
- package/cdn/with-layouts/providers/vidstack-youtube-D8UlccUL.js +1 -0
- package/cdn/with-layouts/vidstack.js +1 -0
- package/dev/chunks/vidstack-B7Zi3v_O.js +104 -0
- package/dev/chunks/vidstack-BFg1ZqiG.js +91 -0
- package/dev/chunks/vidstack-BGB2pa9s.js +58 -0
- package/dev/chunks/vidstack-BaIbHZE3.js +1519 -0
- package/dev/chunks/vidstack-Bb2rASIc.js +5188 -0
- package/dev/chunks/vidstack-Bcmx8pmK.js +224 -0
- package/dev/chunks/vidstack-Bl4b0Nen.js +29 -0
- package/dev/chunks/vidstack-Bo5OTJ06.js +58 -0
- package/dev/chunks/vidstack-BoAGnlRt.js +58 -0
- package/dev/chunks/vidstack-Bpr4fI4n.js +7 -0
- package/dev/chunks/vidstack-Bt8MP2DK.js +204 -0
- package/dev/chunks/vidstack-Bu2kfzUd.js +1637 -0
- package/dev/chunks/vidstack-C-ffXlSV.js +2995 -0
- package/dev/chunks/vidstack-C-ztJq-f.js +109 -0
- package/dev/chunks/vidstack-CFNlaVTR.js +55 -0
- package/dev/chunks/vidstack-C_l97D5j.js +254 -0
- package/dev/chunks/vidstack-CjhKISI0.js +114 -0
- package/dev/chunks/vidstack-CofXIJAy.js +57 -0
- package/dev/chunks/vidstack-CwTj4H1w.js +18 -0
- package/dev/chunks/vidstack-DDwbYVHV.js +66 -0
- package/dev/chunks/vidstack-DFImIcIL.js +11 -0
- package/dev/chunks/vidstack-DGDvUbvO.js +33 -0
- package/dev/chunks/vidstack-DO0kqA99.js +107 -0
- package/dev/chunks/vidstack-DXxIKXmd.js +50 -0
- package/dev/chunks/vidstack-DajrMUR0.js +297 -0
- package/dev/chunks/vidstack-DbBJlz7I.js +10 -0
- package/dev/chunks/vidstack-Dihypf8P.js +11 -0
- package/dev/chunks/vidstack-DlAhl87f.js +1193 -0
- package/dev/chunks/vidstack-Dm1xEU9Q.js +34 -0
- package/dev/chunks/vidstack-Dv_LIPFu.js +14 -0
- package/dev/chunks/vidstack-igYn0Apa.js +254 -0
- package/dev/chunks/vidstack-krOAtKMi.js +32 -0
- package/dev/chunks/vidstack-qh1N5_f_.js +26 -0
- package/dev/chunks/vidstack-rB-wqXw1.js +107 -0
- package/dev/chunks/vidstack-zG6PIeGg.js +66 -0
- package/dev/define/plyr-layout.js +51 -0
- package/dev/define/templates/plyr-layout.js +571 -0
- package/dev/define/templates/vidstack-audio-layout.js +167 -0
- package/dev/define/templates/vidstack-video-layout.js +390 -0
- package/dev/define/vidstack-icons.js +1 -0
- package/dev/define/vidstack-player-default-layout.js +21 -0
- package/dev/define/vidstack-player-layouts.js +25 -0
- package/dev/define/vidstack-player-ui.js +70 -0
- package/dev/define/vidstack-player.js +19 -0
- package/dev/global/plyr.js +501 -0
- package/dev/global/vidstack-player.js +129 -0
- package/dev/providers/vidstack-audio.js +35 -0
- package/dev/providers/vidstack-dash.js +516 -0
- package/dev/providers/vidstack-google-cast.js +474 -0
- package/dev/providers/vidstack-hls.js +408 -0
- package/dev/providers/vidstack-html.js +567 -0
- package/dev/providers/vidstack-video.js +207 -0
- package/dev/providers/vidstack-vimeo.js +554 -0
- package/dev/providers/vidstack-youtube.js +286 -0
- package/dev/vidstack-elements.js +36 -0
- package/dev/vidstack.js +91 -0
- package/dom.d.ts +91 -0
- package/elements.d.ts +1433 -0
- package/empty.vtt +1 -0
- package/global/player.d.ts +52 -0
- package/global/plyr.d.ts +343 -0
- package/google-cast.d.ts +1422 -0
- package/icons.d.ts +1 -0
- package/index.d.ts +402 -0
- package/package.json +199 -0
- package/player/index.d.ts +3 -0
- package/player/layouts/default.d.ts +3 -0
- package/player/layouts/index.d.ts +3 -0
- package/player/layouts/plyr.d.ts +3 -0
- package/player/styles/base.css +153 -0
- package/player/styles/default/buffering.css +55 -0
- package/player/styles/default/buttons.css +175 -0
- package/player/styles/default/captions.css +181 -0
- package/player/styles/default/chapter-title.css +26 -0
- package/player/styles/default/controls.css +56 -0
- package/player/styles/default/gestures.css +19 -0
- package/player/styles/default/icons.css +6 -0
- package/player/styles/default/keyboard.css +148 -0
- package/player/styles/default/layouts/audio.css +417 -0
- package/player/styles/default/layouts/video.css +590 -0
- package/player/styles/default/menus.css +959 -0
- package/player/styles/default/poster.css +52 -0
- package/player/styles/default/sliders.css +391 -0
- package/player/styles/default/theme.css +2461 -0
- package/player/styles/default/thumbnail.css +40 -0
- package/player/styles/default/time.css +45 -0
- package/player/styles/default/tooltips.css +141 -0
- package/player/styles/plyr/theme.css +1237 -0
- package/player/ui.d.ts +3 -0
- package/plugins.d.ts +19 -0
- package/plugins.js +13 -0
- package/prod/chunks/vidstack-B01xzxC4.js +7 -0
- package/prod/chunks/vidstack-BCeb7ryV.js +201 -0
- package/prod/chunks/vidstack-BGSTndAW.js +1590 -0
- package/prod/chunks/vidstack-BPitBBjh.js +1519 -0
- package/prod/chunks/vidstack-BQlOPwOu.js +45 -0
- package/prod/chunks/vidstack-BSDzlwxO.js +4778 -0
- package/prod/chunks/vidstack-BT0m6zEi.js +109 -0
- package/prod/chunks/vidstack-BTigPj2h.js +55 -0
- package/prod/chunks/vidstack-BiyXcJ_M.js +107 -0
- package/prod/chunks/vidstack-BoVf5n1M.js +2985 -0
- package/prod/chunks/vidstack-Bq6c3Bam.js +58 -0
- package/prod/chunks/vidstack-ByLCIBtB.js +297 -0
- package/prod/chunks/vidstack-C2US-gSO.js +248 -0
- package/prod/chunks/vidstack-C9vIqaYT.js +10 -0
- package/prod/chunks/vidstack-CF6fixCQ.js +1193 -0
- package/prod/chunks/vidstack-CTojmhKq.js +66 -0
- package/prod/chunks/vidstack-ChQTHmIQ.js +77 -0
- package/prod/chunks/vidstack-Cm6_unwd.js +246 -0
- package/prod/chunks/vidstack-CwTj4H1w.js +18 -0
- package/prod/chunks/vidstack-D3ltXc3a.js +33 -0
- package/prod/chunks/vidstack-D5EzK014.js +14 -0
- package/prod/chunks/vidstack-DDXt6fpN.js +58 -0
- package/prod/chunks/vidstack-DJDnh4xT.js +11 -0
- package/prod/chunks/vidstack-DXxIKXmd.js +50 -0
- package/prod/chunks/vidstack-D_-9AA6_.js +29 -0
- package/prod/chunks/vidstack-DbkZGjSn.js +107 -0
- package/prod/chunks/vidstack-Dihypf8P.js +11 -0
- package/prod/chunks/vidstack-Dm1xEU9Q.js +34 -0
- package/prod/chunks/vidstack-Dq5Yu0Vr.js +205 -0
- package/prod/chunks/vidstack-DqAw8m9J.js +26 -0
- package/prod/chunks/vidstack-DsPOyKtl.js +57 -0
- package/prod/chunks/vidstack-krOAtKMi.js +32 -0
- package/prod/chunks/vidstack-nLyr4NEP.js +58 -0
- package/prod/chunks/vidstack-xMS8dnYq.js +114 -0
- package/prod/chunks/vidstack-yEGTpgeA.js +104 -0
- package/prod/define/plyr-layout.js +51 -0
- package/prod/define/templates/plyr-layout.js +571 -0
- package/prod/define/templates/vidstack-audio-layout.js +167 -0
- package/prod/define/templates/vidstack-video-layout.js +390 -0
- package/prod/define/vidstack-icons.js +1 -0
- package/prod/define/vidstack-player-default-layout.js +21 -0
- package/prod/define/vidstack-player-layouts.js +25 -0
- package/prod/define/vidstack-player-ui.js +70 -0
- package/prod/define/vidstack-player.js +19 -0
- package/prod/global/plyr.js +493 -0
- package/prod/global/vidstack-player.js +129 -0
- package/prod/providers/vidstack-audio.js +35 -0
- package/prod/providers/vidstack-dash.js +501 -0
- package/prod/providers/vidstack-google-cast.js +468 -0
- package/prod/providers/vidstack-hls.js +393 -0
- package/prod/providers/vidstack-html.js +555 -0
- package/prod/providers/vidstack-video.js +204 -0
- package/prod/providers/vidstack-vimeo.js +548 -0
- package/prod/providers/vidstack-youtube.js +286 -0
- package/prod/vidstack-elements.js +36 -0
- package/prod/vidstack.js +158 -0
- package/server/chunks/vidstack-6juFdkKy.js +29 -0
- package/server/chunks/vidstack-B7iHmv7_.js +307 -0
- package/server/chunks/vidstack-BmxyML9v.js +1619 -0
- package/server/chunks/vidstack-BskfxwD3.js +566 -0
- package/server/chunks/vidstack-BvLV0SMz.js +4642 -0
- package/server/chunks/vidstack-BvWwluXZ.js +205 -0
- package/server/chunks/vidstack-C-413dj2.js +8 -0
- package/server/chunks/vidstack-C26K8z_-.js +55 -0
- package/server/chunks/vidstack-CJJiksDz.js +107 -0
- package/server/chunks/vidstack-CUNv52x1.js +141 -0
- package/server/chunks/vidstack-CqyBCODe.js +295 -0
- package/server/chunks/vidstack-CwTj4H1w.js +18 -0
- package/server/chunks/vidstack-DHAyGSOl.js +1502 -0
- package/server/chunks/vidstack-DLU3cjcp.js +381 -0
- package/server/chunks/vidstack-DXxIKXmd.js +50 -0
- package/server/chunks/vidstack-DbtDXDS2.js +104 -0
- package/server/chunks/vidstack-Dm1xEU9Q.js +34 -0
- package/server/chunks/vidstack-DzTHw_bw.js +207 -0
- package/server/chunks/vidstack-Wn3NH5Sg.js +1566 -0
- package/server/chunks/vidstack-krOAtKMi.js +32 -0
- package/server/chunks/vidstack-wNViAkr4.js +3045 -0
- package/server/define/plyr-layout.js +16 -0
- package/server/define/vidstack-icons.js +1 -0
- package/server/define/vidstack-player-default-layout.js +13 -0
- package/server/define/vidstack-player-layouts.js +16 -0
- package/server/define/vidstack-player-ui.js +11 -0
- package/server/define/vidstack-player.js +6 -0
- package/server/global/plyr.js +322 -0
- package/server/global/vidstack-player.js +58 -0
- package/server/vidstack-elements.js +46 -0
- package/server/vidstack.js +148 -0
- package/tailwind.cjs +101 -0
- package/tailwind.d.cts +15 -0
- package/types/vidstack-BOvzfZjK.d.ts +1269 -0
- package/types/vidstack-Cttpg6GU.d.ts +7474 -0
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
import { loadScript, preconnect } from '../chunks/vidstack-zG6PIeGg.js';
|
|
2
|
+
import { canPlayVideoType, canPlayAudioType, IS_CHROME, isDASHSupported } from '../chunks/vidstack-CjhKISI0.js';
|
|
3
|
+
import { VideoProvider } from './vidstack-video.js';
|
|
4
|
+
import { listenEvent, effect, DOMEvent, isNumber, peek, isString, camelToKebabCase, isUndefined, isFunction } from '../chunks/vidstack-Bu2kfzUd.js';
|
|
5
|
+
import { QualitySymbol } from '../chunks/vidstack-Bpr4fI4n.js';
|
|
6
|
+
import { TextTrackSymbol, TextTrack } from '../chunks/vidstack-igYn0Apa.js';
|
|
7
|
+
import { ListSymbol } from '../chunks/vidstack-Dv_LIPFu.js';
|
|
8
|
+
import { RAFLoop } from '../chunks/vidstack-qh1N5_f_.js';
|
|
9
|
+
import { coerceToError } from '../chunks/vidstack-DbBJlz7I.js';
|
|
10
|
+
import './vidstack-html.js';
|
|
11
|
+
import '../chunks/vidstack-Dihypf8P.js';
|
|
12
|
+
import '../chunks/vidstack-Bo5OTJ06.js';
|
|
13
|
+
import '../chunks/vidstack-BGB2pa9s.js';
|
|
14
|
+
|
|
15
|
+
function getLangName(langCode) {
|
|
16
|
+
try {
|
|
17
|
+
const displayNames = new Intl.DisplayNames(navigator.languages, { type: "language" });
|
|
18
|
+
const languageName = displayNames.of(langCode);
|
|
19
|
+
return languageName ?? null;
|
|
20
|
+
} catch (err) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const toDOMEventType = (type) => `dash-${camelToKebabCase(type)}`;
|
|
26
|
+
class DASHController {
|
|
27
|
+
#video;
|
|
28
|
+
#ctx;
|
|
29
|
+
#instance = null;
|
|
30
|
+
#callbacks = /* @__PURE__ */ new Set();
|
|
31
|
+
#stopLiveSync = null;
|
|
32
|
+
config = {};
|
|
33
|
+
get instance() {
|
|
34
|
+
return this.#instance;
|
|
35
|
+
}
|
|
36
|
+
constructor(video, ctx) {
|
|
37
|
+
this.#video = video;
|
|
38
|
+
this.#ctx = ctx;
|
|
39
|
+
}
|
|
40
|
+
setup(ctor) {
|
|
41
|
+
this.#instance = ctor().create();
|
|
42
|
+
const dispatcher = this.#dispatchDASHEvent.bind(this);
|
|
43
|
+
for (const event of Object.values(ctor.events)) this.#instance.on(event, dispatcher);
|
|
44
|
+
this.#instance.on(ctor.events.ERROR, this.#onError.bind(this));
|
|
45
|
+
for (const callback of this.#callbacks) callback(this.#instance);
|
|
46
|
+
this.#ctx.player.dispatch("dash-instance", {
|
|
47
|
+
detail: this.#instance
|
|
48
|
+
});
|
|
49
|
+
this.#instance.initialize(this.#video, void 0, false);
|
|
50
|
+
this.#instance.updateSettings({
|
|
51
|
+
streaming: {
|
|
52
|
+
text: {
|
|
53
|
+
// Disabling text rendering by dash.
|
|
54
|
+
defaultEnabled: false,
|
|
55
|
+
dispatchForManualRendering: true
|
|
56
|
+
},
|
|
57
|
+
buffer: {
|
|
58
|
+
/// Enables buffer replacement when switching bitrates for faster switching.
|
|
59
|
+
fastSwitchEnabled: true
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
...this.config
|
|
63
|
+
});
|
|
64
|
+
this.#instance.on(ctor.events.FRAGMENT_LOADING_STARTED, this.#onFragmentLoadStart.bind(this));
|
|
65
|
+
this.#instance.on(
|
|
66
|
+
ctor.events.FRAGMENT_LOADING_COMPLETED,
|
|
67
|
+
this.#onFragmentLoadComplete.bind(this)
|
|
68
|
+
);
|
|
69
|
+
this.#instance.on(ctor.events.MANIFEST_LOADED, this.#onManifestLoaded.bind(this));
|
|
70
|
+
this.#instance.on(ctor.events.QUALITY_CHANGE_RENDERED, this.#onQualityChange.bind(this));
|
|
71
|
+
this.#instance.on(ctor.events.TEXT_TRACKS_ADDED, this.#onTextTracksAdded.bind(this));
|
|
72
|
+
this.#instance.on(ctor.events.TRACK_CHANGE_RENDERED, this.#onTrackChange.bind(this));
|
|
73
|
+
this.#ctx.qualities[QualitySymbol.enableAuto] = this.#enableAutoQuality.bind(this);
|
|
74
|
+
listenEvent(this.#ctx.qualities, "change", this.#onUserQualityChange.bind(this));
|
|
75
|
+
listenEvent(this.#ctx.audioTracks, "change", this.#onUserAudioChange.bind(this));
|
|
76
|
+
this.#stopLiveSync = effect(this.#liveSync.bind(this));
|
|
77
|
+
}
|
|
78
|
+
#createDOMEvent(event) {
|
|
79
|
+
return new DOMEvent(toDOMEventType(event.type), { detail: event });
|
|
80
|
+
}
|
|
81
|
+
#liveSync() {
|
|
82
|
+
if (!this.#ctx.$state.live()) return;
|
|
83
|
+
const raf = new RAFLoop(this.#liveSyncPosition.bind(this));
|
|
84
|
+
raf.start();
|
|
85
|
+
return raf.stop.bind(raf);
|
|
86
|
+
}
|
|
87
|
+
#liveSyncPosition() {
|
|
88
|
+
if (!this.#instance) return;
|
|
89
|
+
const position = this.#instance.duration() - this.#instance.time();
|
|
90
|
+
this.#ctx.$state.liveSyncPosition.set(!isNaN(position) ? position : Infinity);
|
|
91
|
+
}
|
|
92
|
+
#dispatchDASHEvent(event) {
|
|
93
|
+
this.#ctx.player?.dispatch(this.#createDOMEvent(event));
|
|
94
|
+
}
|
|
95
|
+
#currentTrack = null;
|
|
96
|
+
#cueTracker = {};
|
|
97
|
+
#onTextFragmentLoaded(event) {
|
|
98
|
+
const native = this.#currentTrack?.[TextTrackSymbol.native], cues = (native?.track).cues;
|
|
99
|
+
if (!native || !cues) return;
|
|
100
|
+
const id = this.#currentTrack.id, startIndex = this.#cueTracker[id] ?? 0, trigger = this.#createDOMEvent(event);
|
|
101
|
+
for (let i = startIndex; i < cues.length; i++) {
|
|
102
|
+
const cue = cues[i];
|
|
103
|
+
if (!cue.positionAlign) cue.positionAlign = "auto";
|
|
104
|
+
this.#currentTrack.addCue(cue, trigger);
|
|
105
|
+
}
|
|
106
|
+
this.#cueTracker[id] = cues.length;
|
|
107
|
+
}
|
|
108
|
+
#onTextTracksAdded(event) {
|
|
109
|
+
if (!this.#instance) return;
|
|
110
|
+
const data = event.tracks, nativeTextTracks = [...this.#video.textTracks].filter((track) => "manualMode" in track), trigger = this.#createDOMEvent(event);
|
|
111
|
+
for (let i = 0; i < nativeTextTracks.length; i++) {
|
|
112
|
+
const textTrackInfo = data[i], nativeTextTrack = nativeTextTracks[i];
|
|
113
|
+
const id = `dash-${textTrackInfo.kind}-${i}`, track = new TextTrack({
|
|
114
|
+
id,
|
|
115
|
+
label: textTrackInfo?.label ?? textTrackInfo.labels.find((t) => t.text)?.text ?? (textTrackInfo?.lang && getLangName(textTrackInfo.lang)) ?? textTrackInfo?.lang ?? void 0,
|
|
116
|
+
language: textTrackInfo.lang ?? void 0,
|
|
117
|
+
kind: textTrackInfo.kind,
|
|
118
|
+
default: textTrackInfo.defaultTrack
|
|
119
|
+
});
|
|
120
|
+
track[TextTrackSymbol.native] = {
|
|
121
|
+
managed: true,
|
|
122
|
+
track: nativeTextTrack
|
|
123
|
+
};
|
|
124
|
+
track[TextTrackSymbol.readyState] = 2;
|
|
125
|
+
track[TextTrackSymbol.onModeChange] = () => {
|
|
126
|
+
if (!this.#instance) return;
|
|
127
|
+
if (track.mode === "showing") {
|
|
128
|
+
this.#instance.setTextTrack(i);
|
|
129
|
+
this.#currentTrack = track;
|
|
130
|
+
} else {
|
|
131
|
+
this.#instance.setTextTrack(-1);
|
|
132
|
+
this.#currentTrack = null;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
this.#ctx.textTracks.add(track, trigger);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
#onTrackChange(event) {
|
|
139
|
+
const { mediaType, newMediaInfo } = event;
|
|
140
|
+
if (mediaType === "audio") {
|
|
141
|
+
const track = this.#ctx.audioTracks.getById(`dash-audio-${newMediaInfo.index}`);
|
|
142
|
+
if (track) {
|
|
143
|
+
const trigger = this.#createDOMEvent(event);
|
|
144
|
+
this.#ctx.audioTracks[ListSymbol.select](track, true, trigger);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
#onQualityChange(event) {
|
|
149
|
+
if (event.mediaType !== "video") return;
|
|
150
|
+
const quality = this.#ctx.qualities[event.newQuality];
|
|
151
|
+
if (quality) {
|
|
152
|
+
const trigger = this.#createDOMEvent(event);
|
|
153
|
+
this.#ctx.qualities[ListSymbol.select](quality, true, trigger);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
#onManifestLoaded(event) {
|
|
157
|
+
if (this.#ctx.$state.canPlay() || !this.#instance) return;
|
|
158
|
+
const { type, mediaPresentationDuration } = event.data, trigger = this.#createDOMEvent(event);
|
|
159
|
+
this.#ctx.notify("stream-type-change", type !== "static" ? "live" : "on-demand", trigger);
|
|
160
|
+
this.#ctx.notify("duration-change", mediaPresentationDuration, trigger);
|
|
161
|
+
this.#ctx.qualities[QualitySymbol.setAuto](true, trigger);
|
|
162
|
+
const media = this.#instance.getVideoElement();
|
|
163
|
+
const videoQualities = this.#instance.getTracksForTypeFromManifest(
|
|
164
|
+
"video",
|
|
165
|
+
event.data
|
|
166
|
+
);
|
|
167
|
+
const supportedVideoMimeType = [...new Set(videoQualities.map((e) => e.mimeType))].find(
|
|
168
|
+
(type2) => type2 && canPlayVideoType(media, type2)
|
|
169
|
+
);
|
|
170
|
+
const videoQuality = videoQualities.filter(
|
|
171
|
+
(track) => supportedVideoMimeType === track.mimeType
|
|
172
|
+
)[0];
|
|
173
|
+
let audioTracks = this.#instance.getTracksForTypeFromManifest(
|
|
174
|
+
"audio",
|
|
175
|
+
event.data
|
|
176
|
+
);
|
|
177
|
+
const supportedAudioMimeType = [...new Set(audioTracks.map((e) => e.mimeType))].find(
|
|
178
|
+
(type2) => type2 && canPlayAudioType(media, type2)
|
|
179
|
+
);
|
|
180
|
+
audioTracks = audioTracks.filter((track) => supportedAudioMimeType === track.mimeType);
|
|
181
|
+
videoQuality.bitrateList.forEach((bitrate, index) => {
|
|
182
|
+
const quality = {
|
|
183
|
+
id: bitrate.id?.toString() ?? `dash-bitrate-${index}`,
|
|
184
|
+
width: bitrate.width ?? 0,
|
|
185
|
+
height: bitrate.height ?? 0,
|
|
186
|
+
bitrate: bitrate.bandwidth ?? 0,
|
|
187
|
+
codec: videoQuality.codec,
|
|
188
|
+
index
|
|
189
|
+
};
|
|
190
|
+
this.#ctx.qualities[ListSymbol.add](quality, trigger);
|
|
191
|
+
});
|
|
192
|
+
if (isNumber(videoQuality.index)) {
|
|
193
|
+
const quality = this.#ctx.qualities[videoQuality.index];
|
|
194
|
+
if (quality) this.#ctx.qualities[ListSymbol.select](quality, true, trigger);
|
|
195
|
+
}
|
|
196
|
+
audioTracks.forEach((audioTrack, index) => {
|
|
197
|
+
const matchingLabel = audioTrack.labels.find((label2) => {
|
|
198
|
+
return navigator.languages.some((language) => {
|
|
199
|
+
return label2.lang && language.toLowerCase().startsWith(label2.lang.toLowerCase());
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
const label = matchingLabel || audioTrack.labels[0];
|
|
203
|
+
const localTrack = {
|
|
204
|
+
id: `dash-audio-${audioTrack?.index}`,
|
|
205
|
+
label: label?.text ?? (audioTrack.lang && getLangName(audioTrack.lang)) ?? audioTrack.lang ?? "",
|
|
206
|
+
language: audioTrack.lang ?? "",
|
|
207
|
+
kind: "main",
|
|
208
|
+
mimeType: audioTrack.mimeType,
|
|
209
|
+
codec: audioTrack.codec,
|
|
210
|
+
index
|
|
211
|
+
};
|
|
212
|
+
this.#ctx.audioTracks[ListSymbol.add](localTrack, trigger);
|
|
213
|
+
});
|
|
214
|
+
media.dispatchEvent(new DOMEvent("canplay", { trigger }));
|
|
215
|
+
}
|
|
216
|
+
#onError(event) {
|
|
217
|
+
const { type: eventType, error: data } = event;
|
|
218
|
+
{
|
|
219
|
+
this.#ctx.logger?.errorGroup(`[vidstack] DASH error \`${data.message}\``).labelledLog("Media Element", this.#video).labelledLog("DASH Instance", this.#instance).labelledLog("Event Type", eventType).labelledLog("Data", data).labelledLog("Src", peek(this.#ctx.$state.source)).labelledLog("Media Store", { ...this.#ctx.$state }).dispatch();
|
|
220
|
+
}
|
|
221
|
+
switch (data.code) {
|
|
222
|
+
case 27:
|
|
223
|
+
this.#onNetworkError(data);
|
|
224
|
+
break;
|
|
225
|
+
default:
|
|
226
|
+
this.#onFatalError(data);
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
#onFragmentLoadStart() {
|
|
231
|
+
if (this.#retryLoadingTimer >= 0) this.#clearRetryTimer();
|
|
232
|
+
}
|
|
233
|
+
#onFragmentLoadComplete(event) {
|
|
234
|
+
const mediaType = event.mediaType;
|
|
235
|
+
if (mediaType === "text") {
|
|
236
|
+
requestAnimationFrame(this.#onTextFragmentLoaded.bind(this, event));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
#retryLoadingTimer = -1;
|
|
240
|
+
#onNetworkError(error) {
|
|
241
|
+
this.#clearRetryTimer();
|
|
242
|
+
this.#instance?.play();
|
|
243
|
+
this.#retryLoadingTimer = window.setTimeout(() => {
|
|
244
|
+
this.#retryLoadingTimer = -1;
|
|
245
|
+
this.#onFatalError(error);
|
|
246
|
+
}, 5e3);
|
|
247
|
+
}
|
|
248
|
+
#clearRetryTimer() {
|
|
249
|
+
clearTimeout(this.#retryLoadingTimer);
|
|
250
|
+
this.#retryLoadingTimer = -1;
|
|
251
|
+
}
|
|
252
|
+
#onFatalError(error) {
|
|
253
|
+
this.#ctx.notify("error", {
|
|
254
|
+
message: error.message ?? "",
|
|
255
|
+
code: 1,
|
|
256
|
+
error
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
#enableAutoQuality() {
|
|
260
|
+
this.#switchAutoBitrate("video", true);
|
|
261
|
+
const { qualities } = this.#ctx;
|
|
262
|
+
this.#instance?.setQualityFor("video", qualities.selectedIndex, true);
|
|
263
|
+
}
|
|
264
|
+
#switchAutoBitrate(type, auto) {
|
|
265
|
+
this.#instance?.updateSettings({
|
|
266
|
+
streaming: { abr: { autoSwitchBitrate: { [type]: auto } } }
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
#onUserQualityChange() {
|
|
270
|
+
const { qualities } = this.#ctx;
|
|
271
|
+
if (!this.#instance || qualities.auto || !qualities.selected) return;
|
|
272
|
+
this.#switchAutoBitrate("video", false);
|
|
273
|
+
this.#instance.setQualityFor("video", qualities.selectedIndex, qualities.switch === "current");
|
|
274
|
+
if (IS_CHROME) {
|
|
275
|
+
this.#video.currentTime = this.#video.currentTime;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
#onUserAudioChange() {
|
|
279
|
+
if (!this.#instance) return;
|
|
280
|
+
const { audioTracks } = this.#ctx, selectedTrack = this.#instance.getTracksFor("audio").find(
|
|
281
|
+
(track) => audioTracks.selected && audioTracks.selected.id === `dash-audio-${track.index}`
|
|
282
|
+
);
|
|
283
|
+
if (selectedTrack) this.#instance.setCurrentTrack(selectedTrack);
|
|
284
|
+
}
|
|
285
|
+
#reset() {
|
|
286
|
+
this.#clearRetryTimer();
|
|
287
|
+
this.#currentTrack = null;
|
|
288
|
+
this.#cueTracker = {};
|
|
289
|
+
}
|
|
290
|
+
onInstance(callback) {
|
|
291
|
+
this.#callbacks.add(callback);
|
|
292
|
+
return () => this.#callbacks.delete(callback);
|
|
293
|
+
}
|
|
294
|
+
loadSource(src) {
|
|
295
|
+
this.#reset();
|
|
296
|
+
if (!isString(src.src)) return;
|
|
297
|
+
this.#instance?.attachSource(src.src);
|
|
298
|
+
}
|
|
299
|
+
destroy() {
|
|
300
|
+
this.#reset();
|
|
301
|
+
this.#instance?.destroy();
|
|
302
|
+
this.#instance = null;
|
|
303
|
+
this.#stopLiveSync?.();
|
|
304
|
+
this.#stopLiveSync = null;
|
|
305
|
+
this.#ctx?.logger?.info("\u{1F3D7}\uFE0F Destroyed DASH instance");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
class DASHLibLoader {
|
|
310
|
+
#lib;
|
|
311
|
+
#ctx;
|
|
312
|
+
#callback;
|
|
313
|
+
constructor(lib, ctx, callback) {
|
|
314
|
+
this.#lib = lib;
|
|
315
|
+
this.#ctx = ctx;
|
|
316
|
+
this.#callback = callback;
|
|
317
|
+
this.#startLoading();
|
|
318
|
+
}
|
|
319
|
+
async #startLoading() {
|
|
320
|
+
this.#ctx.logger?.info("\u{1F3D7}\uFE0F Loading DASH Library");
|
|
321
|
+
const callbacks = {
|
|
322
|
+
onLoadStart: this.#onLoadStart.bind(this),
|
|
323
|
+
onLoaded: this.#onLoaded.bind(this),
|
|
324
|
+
onLoadError: this.#onLoadError.bind(this)
|
|
325
|
+
};
|
|
326
|
+
let ctor = await loadDASHScript(this.#lib, callbacks);
|
|
327
|
+
if (isUndefined(ctor) && !isString(this.#lib)) ctor = await importDASH(this.#lib, callbacks);
|
|
328
|
+
if (!ctor) return null;
|
|
329
|
+
if (!window.dashjs.supportsMediaSource()) {
|
|
330
|
+
const message = "[vidstack] `dash.js` is not supported in this environment";
|
|
331
|
+
this.#ctx.logger?.error(message);
|
|
332
|
+
this.#ctx.player.dispatch(new DOMEvent("dash-unsupported"));
|
|
333
|
+
this.#ctx.notify("error", { message, code: 4 });
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
return ctor;
|
|
337
|
+
}
|
|
338
|
+
#onLoadStart() {
|
|
339
|
+
{
|
|
340
|
+
this.#ctx.logger?.infoGroup("Starting to load `dash.js`").labelledLog("URL", this.#lib).dispatch();
|
|
341
|
+
}
|
|
342
|
+
this.#ctx.player.dispatch(new DOMEvent("dash-lib-load-start"));
|
|
343
|
+
}
|
|
344
|
+
#onLoaded(ctor) {
|
|
345
|
+
{
|
|
346
|
+
this.#ctx.logger?.infoGroup("Loaded `dash.js`").labelledLog("Library", this.#lib).labelledLog("Constructor", ctor).dispatch();
|
|
347
|
+
}
|
|
348
|
+
this.#ctx.player.dispatch(
|
|
349
|
+
new DOMEvent("dash-lib-loaded", {
|
|
350
|
+
detail: ctor
|
|
351
|
+
})
|
|
352
|
+
);
|
|
353
|
+
this.#callback(ctor);
|
|
354
|
+
}
|
|
355
|
+
#onLoadError(e) {
|
|
356
|
+
const error = coerceToError(e);
|
|
357
|
+
{
|
|
358
|
+
this.#ctx.logger?.errorGroup("[vidstack] Failed to load `dash.js`").labelledLog("Library", this.#lib).labelledLog("Error", e).dispatch();
|
|
359
|
+
}
|
|
360
|
+
this.#ctx.player.dispatch(
|
|
361
|
+
new DOMEvent("dash-lib-load-error", {
|
|
362
|
+
detail: error
|
|
363
|
+
})
|
|
364
|
+
);
|
|
365
|
+
this.#ctx.notify("error", {
|
|
366
|
+
message: error.message,
|
|
367
|
+
code: 4,
|
|
368
|
+
error
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
async function importDASH(loader, callbacks = {}) {
|
|
373
|
+
if (isUndefined(loader)) return void 0;
|
|
374
|
+
callbacks.onLoadStart?.();
|
|
375
|
+
if (isDASHConstructor(loader)) {
|
|
376
|
+
callbacks.onLoaded?.(loader);
|
|
377
|
+
return loader;
|
|
378
|
+
}
|
|
379
|
+
if (isDASHNamespace(loader)) {
|
|
380
|
+
const ctor = loader.MediaPlayer;
|
|
381
|
+
callbacks.onLoaded?.(ctor);
|
|
382
|
+
return ctor;
|
|
383
|
+
}
|
|
384
|
+
try {
|
|
385
|
+
const ctor = (await loader())?.default;
|
|
386
|
+
if (isDASHNamespace(ctor)) {
|
|
387
|
+
callbacks.onLoaded?.(ctor.MediaPlayer);
|
|
388
|
+
return ctor.MediaPlayer;
|
|
389
|
+
}
|
|
390
|
+
if (ctor) {
|
|
391
|
+
callbacks.onLoaded?.(ctor);
|
|
392
|
+
} else {
|
|
393
|
+
throw Error(
|
|
394
|
+
true ? "[vidstack] failed importing `dash.js`. Dynamic import returned invalid object." : ""
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
return ctor;
|
|
398
|
+
} catch (err) {
|
|
399
|
+
callbacks.onLoadError?.(err);
|
|
400
|
+
}
|
|
401
|
+
return void 0;
|
|
402
|
+
}
|
|
403
|
+
async function loadDASHScript(src, callbacks = {}) {
|
|
404
|
+
if (!isString(src)) return void 0;
|
|
405
|
+
callbacks.onLoadStart?.();
|
|
406
|
+
try {
|
|
407
|
+
await loadScript(src);
|
|
408
|
+
if (!isFunction(window.dashjs.MediaPlayer)) {
|
|
409
|
+
throw Error(
|
|
410
|
+
true ? "[vidstack] failed loading `dash.js`. Could not find a valid `Dash` constructor on window" : ""
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
const ctor = window.dashjs.MediaPlayer;
|
|
414
|
+
callbacks.onLoaded?.(ctor);
|
|
415
|
+
return ctor;
|
|
416
|
+
} catch (err) {
|
|
417
|
+
callbacks.onLoadError?.(err);
|
|
418
|
+
}
|
|
419
|
+
return void 0;
|
|
420
|
+
}
|
|
421
|
+
function isDASHConstructor(value) {
|
|
422
|
+
return value && value.prototype && value.prototype !== Function;
|
|
423
|
+
}
|
|
424
|
+
function isDASHNamespace(value) {
|
|
425
|
+
return value && "MediaPlayer" in value;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const JS_DELIVR_CDN = "https://cdn.jsdelivr.net";
|
|
429
|
+
class DASHProvider extends VideoProvider {
|
|
430
|
+
$$PROVIDER_TYPE = "DASH";
|
|
431
|
+
#ctor = null;
|
|
432
|
+
#controller = new DASHController(this.video, this.ctx);
|
|
433
|
+
/**
|
|
434
|
+
* The `dash.js` constructor.
|
|
435
|
+
*/
|
|
436
|
+
get ctor() {
|
|
437
|
+
return this.#ctor;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* The current `dash.js` instance.
|
|
441
|
+
*/
|
|
442
|
+
get instance() {
|
|
443
|
+
return this.#controller.instance;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Whether `dash.js` is supported in this environment.
|
|
447
|
+
*/
|
|
448
|
+
static supported = isDASHSupported();
|
|
449
|
+
get type() {
|
|
450
|
+
return "dash";
|
|
451
|
+
}
|
|
452
|
+
get canLiveSync() {
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
#library = `${JS_DELIVR_CDN}/npm/dashjs@4.7.4/dist/dash${".all.debug.js" }`;
|
|
456
|
+
/**
|
|
457
|
+
* The `dash.js` configuration object.
|
|
458
|
+
*
|
|
459
|
+
* @see {@link https://cdn.dashjs.org/latest/jsdoc/module-Settings.html}
|
|
460
|
+
*/
|
|
461
|
+
get config() {
|
|
462
|
+
return this.#controller.config;
|
|
463
|
+
}
|
|
464
|
+
set config(config) {
|
|
465
|
+
this.#controller.config = config;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* The `dash.js` constructor (supports dynamic imports) or a URL of where it can be found.
|
|
469
|
+
*
|
|
470
|
+
* @defaultValue `https://cdn.jsdelivr.net/npm/dashjs@4.7.4/dist/dash.all.min.js`
|
|
471
|
+
*/
|
|
472
|
+
get library() {
|
|
473
|
+
return this.#library;
|
|
474
|
+
}
|
|
475
|
+
set library(library) {
|
|
476
|
+
this.#library = library;
|
|
477
|
+
}
|
|
478
|
+
preconnect() {
|
|
479
|
+
if (!isString(this.#library)) return;
|
|
480
|
+
preconnect(this.#library);
|
|
481
|
+
}
|
|
482
|
+
setup() {
|
|
483
|
+
super.setup();
|
|
484
|
+
new DASHLibLoader(this.#library, this.ctx, (ctor) => {
|
|
485
|
+
this.#ctor = ctor;
|
|
486
|
+
this.#controller.setup(ctor);
|
|
487
|
+
this.ctx.notify("provider-setup", this);
|
|
488
|
+
const src = peek(this.ctx.$state.source);
|
|
489
|
+
if (src) this.loadSource(src);
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
async loadSource(src, preload) {
|
|
493
|
+
if (!isString(src.src)) {
|
|
494
|
+
this.removeSource();
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
this.media.preload = preload || "";
|
|
498
|
+
this.appendSource(src, "application/x-mpegurl");
|
|
499
|
+
this.#controller.loadSource(src);
|
|
500
|
+
this.currentSrc = src;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* The given callback is invoked when a new `dash.js` instance is created and right before it's
|
|
504
|
+
* attached to media.
|
|
505
|
+
*/
|
|
506
|
+
onInstance(callback) {
|
|
507
|
+
const instance = this.#controller.instance;
|
|
508
|
+
if (instance) callback(instance);
|
|
509
|
+
return this.#controller.onInstance(callback);
|
|
510
|
+
}
|
|
511
|
+
destroy() {
|
|
512
|
+
this.#controller.destroy();
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export { DASHProvider };
|