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