@hanifhan1f/vidstack-react 1.12.30 → 1.12.31
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 +189 -0
- package/dev/chunks/vidstack-BRTBRJ_I.js +288 -0
- package/dev/chunks/vidstack-C56TjAKZ.js +61 -0
- package/dev/chunks/vidstack-C5tZAkKo.js +11694 -0
- package/dev/chunks/vidstack-CXjRKTos.js +401 -0
- package/dev/chunks/vidstack-C_xw7iZ2.js +34 -0
- package/dev/chunks/vidstack-CaaASbOf.js +476 -0
- package/dev/chunks/vidstack-D2Bi2Td9.js +1537 -0
- package/dev/chunks/vidstack-D95QIbAo.js +551 -0
- package/dev/chunks/vidstack-DnmOVAbr.js +643 -0
- package/dev/chunks/vidstack-Dnoefs4z.js +180 -0
- package/dev/chunks/vidstack-S_S6XDnL.js +375 -0
- package/dev/chunks/vidstack-oOGofWSl.js +668 -0
- package/dev/chunks/vidstack-vh0BKYWJ.js +84 -0
- package/dev/player/vidstack-default-components.js +8 -9
- package/dev/player/vidstack-default-icons.js +1 -1
- package/dev/player/vidstack-default-layout.js +8 -9
- package/dev/player/vidstack-plyr-layout.js +63 -77
- package/dev/player/vidstack-remotion.js +6 -6
- package/dev/vidstack.js +133 -22
- package/package.json +1 -1
- package/prod/chunks/vidstack-B0SSIHIv.js +1537 -0
- package/prod/chunks/vidstack-B3E9kXKq.js +34 -0
- package/prod/chunks/vidstack-BLWRqo3I.js +470 -0
- package/prod/chunks/vidstack-BXAOpsiW.js +61 -0
- package/prod/chunks/vidstack-BzPma_p3.js +288 -0
- package/prod/chunks/vidstack-C48MQkXV.js +11199 -0
- package/prod/chunks/vidstack-CKBLQMZi.js +159 -0
- package/prod/chunks/vidstack-CwlfLr4v.js +504 -0
- package/prod/chunks/vidstack-DVMwXUgY.js +189 -0
- package/prod/chunks/vidstack-D_Sd7838.js +663 -0
- package/prod/chunks/vidstack-DgsBXr1J.js +84 -0
- package/prod/chunks/vidstack-DhSvljmQ.js +375 -0
- package/prod/chunks/vidstack-DlPpeEXU.js +545 -0
- package/prod/chunks/vidstack-xwdT591E.js +386 -0
- package/prod/player/vidstack-default-components.js +8 -9
- package/prod/player/vidstack-default-icons.js +1 -1
- package/prod/player/vidstack-default-layout.js +8 -9
- package/prod/player/vidstack-plyr-layout.js +63 -77
- package/prod/player/vidstack-remotion.js +6 -6
- package/prod/vidstack.js +204 -22
- package/server/chunks/vidstack--ufi23Q6.js +1537 -0
- package/server/chunks/vidstack-3hd9uS5U.js +386 -0
- package/server/chunks/vidstack-B_l_DXPI.js +61 -0
- package/server/chunks/vidstack-Bb44UuL8.js +470 -0
- package/server/chunks/vidstack-Bu9QXEz1.js +159 -0
- package/server/chunks/vidstack-Cb_tNfNU.js +11199 -0
- package/server/chunks/vidstack-D9vUNwri.js +288 -0
- package/server/chunks/vidstack-DM-5dPT-.js +663 -0
- package/server/chunks/vidstack-DWfS9vAY.js +84 -0
- package/server/chunks/vidstack-DY51lx0R.js +189 -0
- package/server/chunks/vidstack-VGPw_CQP.js +375 -0
- package/server/chunks/vidstack-dz2TmHzm.js +34 -0
- package/server/chunks/vidstack-e0ZPAI-d.js +504 -0
- package/server/chunks/vidstack-zzooMghu.js +545 -0
- package/server/player/vidstack-default-components.js +8 -9
- package/server/player/vidstack-default-icons.js +1 -1
- package/server/player/vidstack-default-layout.js +8 -9
- package/server/player/vidstack-plyr-layout.js +63 -77
- package/server/player/vidstack-remotion.js +6 -6
- package/server/vidstack.js +204 -22
|
@@ -0,0 +1,386 @@
|
|
|
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-Cb_tNfNU.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 };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { appendParamsToURL, IS_SERVER } from './vidstack-Cb_tNfNU.js';
|
|
4
|
+
import { signal, listenEvent, effect, peek, isString } from './vidstack-D_bWd66h.js';
|
|
5
|
+
|
|
6
|
+
class EmbedProvider {
|
|
7
|
+
#iframe;
|
|
8
|
+
src = signal("");
|
|
9
|
+
/**
|
|
10
|
+
* Defines which referrer is sent when fetching the resource.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/referrerPolicy}
|
|
13
|
+
*/
|
|
14
|
+
referrerPolicy = null;
|
|
15
|
+
get iframe() {
|
|
16
|
+
return this.#iframe;
|
|
17
|
+
}
|
|
18
|
+
constructor(iframe) {
|
|
19
|
+
this.#iframe = iframe;
|
|
20
|
+
iframe.setAttribute("frameBorder", "0");
|
|
21
|
+
iframe.setAttribute("aria-hidden", "true");
|
|
22
|
+
iframe.setAttribute(
|
|
23
|
+
"allow",
|
|
24
|
+
"autoplay; fullscreen; encrypted-media; picture-in-picture; accelerometer; gyroscope"
|
|
25
|
+
);
|
|
26
|
+
if (this.referrerPolicy !== null) {
|
|
27
|
+
iframe.setAttribute("referrerpolicy", this.referrerPolicy);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
setup() {
|
|
31
|
+
listenEvent(window, "message", this.#onWindowMessage.bind(this));
|
|
32
|
+
listenEvent(this.#iframe, "load", this.onLoad.bind(this));
|
|
33
|
+
effect(this.#watchSrc.bind(this));
|
|
34
|
+
}
|
|
35
|
+
#watchSrc() {
|
|
36
|
+
const src = this.src();
|
|
37
|
+
if (!src.length) {
|
|
38
|
+
this.#iframe.setAttribute("src", "");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const params = peek(() => this.buildParams());
|
|
42
|
+
this.#iframe.setAttribute("src", appendParamsToURL(src, params));
|
|
43
|
+
}
|
|
44
|
+
postMessage(message, target) {
|
|
45
|
+
if (IS_SERVER) return;
|
|
46
|
+
this.#iframe.contentWindow?.postMessage(JSON.stringify(message), target ?? "*");
|
|
47
|
+
}
|
|
48
|
+
#onWindowMessage(event) {
|
|
49
|
+
const origin = this.getOrigin(), isOriginMatch = (event.source === null || event.source === this.#iframe?.contentWindow) && (!isString(origin) || origin === event.origin);
|
|
50
|
+
if (!isOriginMatch) return;
|
|
51
|
+
try {
|
|
52
|
+
const message = JSON.parse(event.data);
|
|
53
|
+
if (message) this.onMessage(message, event);
|
|
54
|
+
return;
|
|
55
|
+
} catch (e) {
|
|
56
|
+
}
|
|
57
|
+
if (event.data) this.onMessage(event.data, event);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { EmbedProvider };
|