@hanifhan1f/vidstack-react 1.12.19 → 1.12.22
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-BPymmnxm.js +551 -0
- package/dev/chunks/vidstack-BSpAxhO6.js +643 -0
- package/dev/chunks/vidstack-BoLZuw80.js +34 -0
- package/dev/chunks/vidstack-CFOPpDTy.js +476 -0
- package/dev/chunks/vidstack-CXrXBlpD.js +11692 -0
- package/dev/chunks/vidstack-DOtIyh4c.js +288 -0
- package/dev/chunks/vidstack-DY2iivhG.js +84 -0
- package/dev/chunks/vidstack-Dov8gjdq.js +401 -0
- package/dev/chunks/vidstack-DwdhbP5c.js +189 -0
- package/dev/chunks/vidstack-DweQYzVw.js +180 -0
- package/dev/chunks/vidstack-H9OdEKUQ.js +375 -0
- package/dev/chunks/vidstack-KntYDWMe.js +668 -0
- package/dev/chunks/vidstack-NCBSBZE-.js +61 -0
- package/dev/chunks/vidstack-UWMPvwsa.js +1537 -0
- package/dev/player/vidstack-default-components.js +5 -5
- package/dev/player/vidstack-default-layout.js +5 -5
- package/dev/player/vidstack-plyr-layout.js +4 -4
- package/dev/player/vidstack-remotion.js +3 -3
- package/dev/vidstack.js +7 -7
- package/package.json +1 -1
- package/player/styles/default/layouts/video.css +94 -77
- package/prod/chunks/vidstack-B9nEslvl.js +11197 -0
- package/prod/chunks/vidstack-BOObgZd8.js +504 -0
- package/prod/chunks/vidstack-B_wD853-.js +386 -0
- package/prod/chunks/vidstack-C4tNkfXj.js +470 -0
- package/prod/chunks/vidstack-CNJwYQRW.js +84 -0
- package/prod/chunks/vidstack-CVzVtf1j.js +61 -0
- package/prod/chunks/vidstack-CiQEyk_l.js +189 -0
- package/prod/chunks/vidstack-CiTWSpv_.js +34 -0
- package/prod/chunks/vidstack-CzjHdPIT.js +375 -0
- package/prod/chunks/vidstack-Djmla_FM.js +545 -0
- package/prod/chunks/vidstack-DpQw1Y33.js +663 -0
- package/prod/chunks/vidstack-VTpvHAdU.js +1537 -0
- package/prod/chunks/vidstack-dbLRgf2L.js +159 -0
- package/prod/chunks/vidstack-rHvQ8f6c.js +288 -0
- package/prod/player/vidstack-default-components.js +5 -5
- package/prod/player/vidstack-default-layout.js +5 -5
- package/prod/player/vidstack-plyr-layout.js +4 -4
- package/prod/player/vidstack-remotion.js +3 -3
- package/prod/vidstack.js +7 -7
- package/server/chunks/vidstack-BV_VpWlJ.js +1537 -0
- package/server/chunks/vidstack-ByG5MvLs.js +545 -0
- package/server/chunks/vidstack-C0xOpWYR.js +470 -0
- package/server/chunks/vidstack-C481iXqe.js +386 -0
- package/server/chunks/vidstack-CbNRZgUA.js +11197 -0
- package/server/chunks/vidstack-D7D9kiW6.js +34 -0
- package/server/chunks/vidstack-DJJmNib6.js +504 -0
- package/server/chunks/vidstack-DWt5LAKE.js +375 -0
- package/server/chunks/vidstack-DsZKgA8y.js +663 -0
- package/server/chunks/vidstack-NXcLNXxO.js +84 -0
- package/server/chunks/vidstack-OKdxH1xx.js +189 -0
- package/server/chunks/vidstack-iVN8uBAv.js +288 -0
- package/server/chunks/vidstack-m8aA99tE.js +159 -0
- package/server/chunks/vidstack-rUHVQoo3.js +61 -0
- package/server/player/vidstack-default-components.js +5 -5
- package/server/player/vidstack-default-layout.js +5 -5
- package/server/player/vidstack-plyr-layout.js +4 -4
- package/server/player/vidstack-remotion.js +3 -3
- package/server/vidstack.js +7 -7
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { createScope, signal, effect, peek, isString, deferredPromise, listenEvent, isArray } from './vidstack-D_bWd66h.js';
|
|
4
|
+
import { TimeRange, RAFLoop, preconnect, ListSymbol, TextTrack, QualitySymbol } from './vidstack-CXrXBlpD.js';
|
|
5
|
+
import { EmbedProvider } from './vidstack-NCBSBZE-.js';
|
|
6
|
+
import { resolveVimeoVideoId, getVimeoVideoInfo } from './vidstack-krOAtKMi.js';
|
|
7
|
+
import 'react';
|
|
8
|
+
import '@floating-ui/dom';
|
|
9
|
+
|
|
10
|
+
const trackedVimeoEvents = [
|
|
11
|
+
"bufferend",
|
|
12
|
+
"bufferstart",
|
|
13
|
+
// 'cuechange',
|
|
14
|
+
"durationchange",
|
|
15
|
+
"ended",
|
|
16
|
+
"enterpictureinpicture",
|
|
17
|
+
"error",
|
|
18
|
+
"fullscreenchange",
|
|
19
|
+
"leavepictureinpicture",
|
|
20
|
+
"loaded",
|
|
21
|
+
// 'loadeddata',
|
|
22
|
+
// 'loadedmetadata',
|
|
23
|
+
// 'loadstart',
|
|
24
|
+
"playProgress",
|
|
25
|
+
"loadProgress",
|
|
26
|
+
"pause",
|
|
27
|
+
"play",
|
|
28
|
+
"playbackratechange",
|
|
29
|
+
// 'progress',
|
|
30
|
+
"qualitychange",
|
|
31
|
+
"seeked",
|
|
32
|
+
"seeking",
|
|
33
|
+
// 'texttrackchange',
|
|
34
|
+
"timeupdate",
|
|
35
|
+
"volumechange",
|
|
36
|
+
"waiting"
|
|
37
|
+
// 'adstarted',
|
|
38
|
+
// 'adcompleted',
|
|
39
|
+
// 'aderror',
|
|
40
|
+
// 'adskipped',
|
|
41
|
+
// 'adallcompleted',
|
|
42
|
+
// 'adclicked',
|
|
43
|
+
// 'chapterchange',
|
|
44
|
+
// 'chromecastconnected',
|
|
45
|
+
// 'remoteplaybackavailabilitychange',
|
|
46
|
+
// 'remoteplaybackconnecting',
|
|
47
|
+
// 'remoteplaybackconnect',
|
|
48
|
+
// 'remoteplaybackdisconnect',
|
|
49
|
+
// 'liveeventended',
|
|
50
|
+
// 'liveeventstarted',
|
|
51
|
+
// 'livestreamoffline',
|
|
52
|
+
// 'livestreamonline',
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
class VimeoProvider extends EmbedProvider {
|
|
56
|
+
$$PROVIDER_TYPE = "VIMEO";
|
|
57
|
+
scope = createScope();
|
|
58
|
+
fullscreen;
|
|
59
|
+
#ctx;
|
|
60
|
+
#videoId = signal("");
|
|
61
|
+
#pro = signal(false);
|
|
62
|
+
#hash = null;
|
|
63
|
+
#currentSrc = null;
|
|
64
|
+
#fullscreenActive = false;
|
|
65
|
+
#seekableRange = new TimeRange(0, 0);
|
|
66
|
+
#timeRAF = new RAFLoop(this.#onAnimationFrame.bind(this));
|
|
67
|
+
#currentCue = null;
|
|
68
|
+
#chaptersTrack = null;
|
|
69
|
+
#promises = /* @__PURE__ */ new Map();
|
|
70
|
+
#videoInfoPromise = null;
|
|
71
|
+
constructor(iframe, ctx) {
|
|
72
|
+
super(iframe);
|
|
73
|
+
this.#ctx = ctx;
|
|
74
|
+
const self = this;
|
|
75
|
+
this.fullscreen = {
|
|
76
|
+
get active() {
|
|
77
|
+
return self.#fullscreenActive;
|
|
78
|
+
},
|
|
79
|
+
supported: true,
|
|
80
|
+
enter: () => this.#remote("requestFullscreen"),
|
|
81
|
+
exit: () => this.#remote("exitFullscreen")
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Whether tracking session data should be enabled on the embed, including cookies and analytics.
|
|
86
|
+
* This is turned off by default to be GDPR-compliant.
|
|
87
|
+
*
|
|
88
|
+
* @defaultValue `false`
|
|
89
|
+
*/
|
|
90
|
+
cookies = false;
|
|
91
|
+
title = true;
|
|
92
|
+
byline = true;
|
|
93
|
+
portrait = true;
|
|
94
|
+
color = "00ADEF";
|
|
95
|
+
get type() {
|
|
96
|
+
return "vimeo";
|
|
97
|
+
}
|
|
98
|
+
get currentSrc() {
|
|
99
|
+
return this.#currentSrc;
|
|
100
|
+
}
|
|
101
|
+
get videoId() {
|
|
102
|
+
return this.#videoId();
|
|
103
|
+
}
|
|
104
|
+
get hash() {
|
|
105
|
+
return this.#hash;
|
|
106
|
+
}
|
|
107
|
+
get isPro() {
|
|
108
|
+
return this.#pro();
|
|
109
|
+
}
|
|
110
|
+
preconnect() {
|
|
111
|
+
preconnect(this.getOrigin());
|
|
112
|
+
}
|
|
113
|
+
setup() {
|
|
114
|
+
super.setup();
|
|
115
|
+
effect(this.#watchVideoId.bind(this));
|
|
116
|
+
effect(this.#watchVideoInfo.bind(this));
|
|
117
|
+
effect(this.#watchPro.bind(this));
|
|
118
|
+
this.#ctx.notify("provider-setup", this);
|
|
119
|
+
}
|
|
120
|
+
destroy() {
|
|
121
|
+
this.#reset();
|
|
122
|
+
this.fullscreen = void 0;
|
|
123
|
+
const message = "provider destroyed";
|
|
124
|
+
for (const promises of this.#promises.values()) {
|
|
125
|
+
for (const { reject } of promises) reject(message);
|
|
126
|
+
}
|
|
127
|
+
this.#promises.clear();
|
|
128
|
+
this.#remote("destroy");
|
|
129
|
+
}
|
|
130
|
+
async play() {
|
|
131
|
+
return this.#remote("play");
|
|
132
|
+
}
|
|
133
|
+
async pause() {
|
|
134
|
+
return this.#remote("pause");
|
|
135
|
+
}
|
|
136
|
+
setMuted(muted) {
|
|
137
|
+
this.#remote("setMuted", muted);
|
|
138
|
+
}
|
|
139
|
+
setCurrentTime(time) {
|
|
140
|
+
this.#remote("seekTo", time);
|
|
141
|
+
this.#ctx.notify("seeking", time);
|
|
142
|
+
}
|
|
143
|
+
setVolume(volume) {
|
|
144
|
+
this.#remote("setVolume", volume);
|
|
145
|
+
this.#remote("setMuted", peek(this.#ctx.$state.muted));
|
|
146
|
+
}
|
|
147
|
+
setPlaybackRate(rate) {
|
|
148
|
+
this.#remote("setPlaybackRate", rate);
|
|
149
|
+
}
|
|
150
|
+
async loadSource(src) {
|
|
151
|
+
if (!isString(src.src)) {
|
|
152
|
+
this.#currentSrc = null;
|
|
153
|
+
this.#hash = null;
|
|
154
|
+
this.#videoId.set("");
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const { videoId, hash } = resolveVimeoVideoId(src.src);
|
|
158
|
+
this.#videoId.set(videoId ?? "");
|
|
159
|
+
this.#hash = hash ?? null;
|
|
160
|
+
this.#currentSrc = src;
|
|
161
|
+
}
|
|
162
|
+
#watchVideoId() {
|
|
163
|
+
this.#reset();
|
|
164
|
+
const videoId = this.#videoId();
|
|
165
|
+
if (!videoId) {
|
|
166
|
+
this.src.set("");
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this.src.set(`${this.getOrigin()}/video/${videoId}`);
|
|
170
|
+
this.#ctx.notify("load-start");
|
|
171
|
+
}
|
|
172
|
+
#watchVideoInfo() {
|
|
173
|
+
const videoId = this.#videoId();
|
|
174
|
+
if (!videoId) return;
|
|
175
|
+
const promise = deferredPromise(), abort = new AbortController();
|
|
176
|
+
this.#videoInfoPromise = promise;
|
|
177
|
+
getVimeoVideoInfo(videoId, abort, this.#hash).then((info) => {
|
|
178
|
+
promise.resolve(info);
|
|
179
|
+
}).catch((e) => {
|
|
180
|
+
promise.reject();
|
|
181
|
+
{
|
|
182
|
+
this.#ctx.logger?.warnGroup(`Failed to fetch vimeo video info for id \`${videoId}\`.`).labelledLog("Error", e).dispatch();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
return () => {
|
|
186
|
+
promise.reject();
|
|
187
|
+
abort.abort();
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
#watchPro() {
|
|
191
|
+
const isPro = this.#pro(), { $state, qualities } = this.#ctx;
|
|
192
|
+
$state.canSetPlaybackRate.set(isPro);
|
|
193
|
+
qualities[ListSymbol.setReadonly](!isPro);
|
|
194
|
+
if (isPro) {
|
|
195
|
+
return listenEvent(qualities, "change", () => {
|
|
196
|
+
if (qualities.auto) return;
|
|
197
|
+
const id = qualities.selected?.id;
|
|
198
|
+
if (id) this.#remote("setQuality", id);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
getOrigin() {
|
|
203
|
+
return "https://player.vimeo.com";
|
|
204
|
+
}
|
|
205
|
+
buildParams() {
|
|
206
|
+
const { keyDisabled } = this.#ctx.$props, { playsInline, nativeControls } = this.#ctx.$state, showControls = nativeControls();
|
|
207
|
+
return {
|
|
208
|
+
title: this.title,
|
|
209
|
+
byline: this.byline,
|
|
210
|
+
color: this.color,
|
|
211
|
+
portrait: this.portrait,
|
|
212
|
+
controls: showControls,
|
|
213
|
+
h: this.hash,
|
|
214
|
+
keyboard: showControls && !keyDisabled(),
|
|
215
|
+
transparent: true,
|
|
216
|
+
playsinline: playsInline(),
|
|
217
|
+
dnt: !this.cookies
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
#onAnimationFrame() {
|
|
221
|
+
this.#remote("getCurrentTime");
|
|
222
|
+
}
|
|
223
|
+
// Embed will sometimes dispatch 0 at end of playback.
|
|
224
|
+
#preventTimeUpdates = false;
|
|
225
|
+
#onTimeUpdate(time, trigger) {
|
|
226
|
+
if (this.#preventTimeUpdates && time === 0) return;
|
|
227
|
+
const { realCurrentTime, paused, bufferedEnd, seekableEnd, live } = this.#ctx.$state;
|
|
228
|
+
if (realCurrentTime() === time) return;
|
|
229
|
+
const prevTime = realCurrentTime();
|
|
230
|
+
this.#ctx.notify("time-change", time, trigger);
|
|
231
|
+
if (Math.abs(prevTime - time) > 1.5) {
|
|
232
|
+
this.#ctx.notify("seeking", time, trigger);
|
|
233
|
+
if (!paused() && bufferedEnd() < time) {
|
|
234
|
+
this.#ctx.notify("waiting", void 0, trigger);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (!live() && seekableEnd() - time < 0.01) {
|
|
238
|
+
this.#ctx.notify("end", void 0, trigger);
|
|
239
|
+
this.#preventTimeUpdates = true;
|
|
240
|
+
setTimeout(() => {
|
|
241
|
+
this.#preventTimeUpdates = false;
|
|
242
|
+
}, 500);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
#onSeeked(time, trigger) {
|
|
246
|
+
this.#ctx.notify("seeked", time, trigger);
|
|
247
|
+
}
|
|
248
|
+
#onLoaded(trigger) {
|
|
249
|
+
const videoId = this.#videoId();
|
|
250
|
+
this.#videoInfoPromise?.promise.then((info) => {
|
|
251
|
+
if (!info) return;
|
|
252
|
+
const { title, poster, duration, pro } = info;
|
|
253
|
+
this.#pro.set(pro);
|
|
254
|
+
this.#ctx.notify("title-change", title, trigger);
|
|
255
|
+
this.#ctx.notify("poster-change", poster, trigger);
|
|
256
|
+
this.#ctx.notify("duration-change", duration, trigger);
|
|
257
|
+
this.#onReady(duration, trigger);
|
|
258
|
+
}).catch(() => {
|
|
259
|
+
if (videoId !== this.#videoId()) return;
|
|
260
|
+
this.#remote("getVideoTitle");
|
|
261
|
+
this.#remote("getDuration");
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
#onReady(duration, trigger) {
|
|
265
|
+
const { nativeControls } = this.#ctx.$state, showEmbedControls = nativeControls();
|
|
266
|
+
this.#seekableRange = new TimeRange(0, duration);
|
|
267
|
+
const detail = {
|
|
268
|
+
buffered: new TimeRange(0, 0),
|
|
269
|
+
seekable: this.#seekableRange,
|
|
270
|
+
duration
|
|
271
|
+
};
|
|
272
|
+
this.#ctx.delegate.ready(detail, trigger);
|
|
273
|
+
if (!showEmbedControls) {
|
|
274
|
+
this.#remote("_hideOverlay");
|
|
275
|
+
}
|
|
276
|
+
this.#remote("getQualities");
|
|
277
|
+
this.#remote("getChapters");
|
|
278
|
+
}
|
|
279
|
+
#onMethod(method, data, trigger) {
|
|
280
|
+
switch (method) {
|
|
281
|
+
case "getVideoTitle":
|
|
282
|
+
const videoTitle = data;
|
|
283
|
+
this.#ctx.notify("title-change", videoTitle, trigger);
|
|
284
|
+
break;
|
|
285
|
+
case "getDuration":
|
|
286
|
+
const duration = data;
|
|
287
|
+
if (!this.#ctx.$state.canPlay()) {
|
|
288
|
+
this.#onReady(duration, trigger);
|
|
289
|
+
} else {
|
|
290
|
+
this.#ctx.notify("duration-change", duration, trigger);
|
|
291
|
+
}
|
|
292
|
+
break;
|
|
293
|
+
case "getCurrentTime":
|
|
294
|
+
this.#onTimeUpdate(data, trigger);
|
|
295
|
+
break;
|
|
296
|
+
case "getBuffered":
|
|
297
|
+
if (isArray(data) && data.length) {
|
|
298
|
+
this.#onLoadProgress(data[data.length - 1][1], trigger);
|
|
299
|
+
}
|
|
300
|
+
break;
|
|
301
|
+
case "setMuted":
|
|
302
|
+
case "getMuted":
|
|
303
|
+
this.#onVolumeChange(peek(this.#ctx.$state.volume), data, trigger);
|
|
304
|
+
break;
|
|
305
|
+
// case 'getTextTracks':
|
|
306
|
+
// this.#onTextTracksChange(data as VimeoTextTrack[], trigger);
|
|
307
|
+
// break;
|
|
308
|
+
case "getChapters":
|
|
309
|
+
this.#onChaptersChange(data);
|
|
310
|
+
break;
|
|
311
|
+
case "getQualities":
|
|
312
|
+
this.#onQualitiesChange(data, trigger);
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
this.#getPromise(method)?.resolve();
|
|
316
|
+
}
|
|
317
|
+
#attachListeners() {
|
|
318
|
+
for (const type of trackedVimeoEvents) {
|
|
319
|
+
this.#remote("addEventListener", type);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
#onPause(trigger) {
|
|
323
|
+
this.#timeRAF.stop();
|
|
324
|
+
this.#ctx.notify("pause", void 0, trigger);
|
|
325
|
+
}
|
|
326
|
+
async #onPlay(trigger) {
|
|
327
|
+
this.#timeRAF.start();
|
|
328
|
+
await this.#remote("getMuted");
|
|
329
|
+
this.#ctx.notify("play", void 0, trigger);
|
|
330
|
+
}
|
|
331
|
+
#onPlayProgress(trigger) {
|
|
332
|
+
const { paused } = this.#ctx.$state;
|
|
333
|
+
if (!paused() && !this.#preventTimeUpdates) {
|
|
334
|
+
this.#ctx.notify("playing", void 0, trigger);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
#onLoadProgress(buffered, trigger) {
|
|
338
|
+
const detail = {
|
|
339
|
+
buffered: new TimeRange(0, buffered),
|
|
340
|
+
seekable: this.#seekableRange
|
|
341
|
+
};
|
|
342
|
+
this.#ctx.notify("progress", detail, trigger);
|
|
343
|
+
}
|
|
344
|
+
#onBufferStart(trigger) {
|
|
345
|
+
this.#ctx.notify("waiting", void 0, trigger);
|
|
346
|
+
}
|
|
347
|
+
#onBufferEnd(trigger) {
|
|
348
|
+
const { paused } = this.#ctx.$state;
|
|
349
|
+
if (!paused()) this.#ctx.notify("playing", void 0, trigger);
|
|
350
|
+
}
|
|
351
|
+
async #onWaiting(trigger) {
|
|
352
|
+
const { paused } = this.#ctx.$state;
|
|
353
|
+
if (paused()) {
|
|
354
|
+
await this.#remote("getMuted");
|
|
355
|
+
this.#ctx.notify("play", void 0, trigger);
|
|
356
|
+
}
|
|
357
|
+
this.#ctx.notify("waiting", void 0, trigger);
|
|
358
|
+
}
|
|
359
|
+
#onVolumeChange(volume, muted, trigger) {
|
|
360
|
+
const detail = { volume, muted };
|
|
361
|
+
this.#ctx.notify("volume-change", detail, trigger);
|
|
362
|
+
}
|
|
363
|
+
// #onTextTrackChange(track: VimeoTextTrack, trigger: Event) {
|
|
364
|
+
// const textTrack = this.#ctx.textTracks.toArray().find((t) => t.language === track.language);
|
|
365
|
+
// if (textTrack) textTrack.mode = track.mode;
|
|
366
|
+
// }
|
|
367
|
+
// #onTextTracksChange(tracks: VimeoTextTrack[], trigger: Event) {
|
|
368
|
+
// for (const init of tracks) {
|
|
369
|
+
// const textTrack = new TextTrack({
|
|
370
|
+
// ...init,
|
|
371
|
+
// label: init.label.replace('auto-generated', 'auto'),
|
|
372
|
+
// });
|
|
373
|
+
// textTrack[TextTrackSymbol.readyState] = 2;
|
|
374
|
+
// this.#ctx.textTracks.add(textTrack, trigger);
|
|
375
|
+
// textTrack.setMode(init.mode, trigger);
|
|
376
|
+
// }
|
|
377
|
+
// }
|
|
378
|
+
// #onCueChange(cue: VimeoTextCue, trigger: Event) {
|
|
379
|
+
// const { textTracks, $state } = this.#ctx,
|
|
380
|
+
// { currentTime } = $state,
|
|
381
|
+
// track = textTracks.selected;
|
|
382
|
+
// if (this.#currentCue) track?.removeCue(this.#currentCue, trigger);
|
|
383
|
+
// this.#currentCue = new window.VTTCue(currentTime(), Number.MAX_SAFE_INTEGER, cue.text);
|
|
384
|
+
// track?.addCue(this.#currentCue, trigger);
|
|
385
|
+
// }
|
|
386
|
+
#onChaptersChange(chapters) {
|
|
387
|
+
this.#removeChapters();
|
|
388
|
+
if (!chapters.length) return;
|
|
389
|
+
const track = new TextTrack({
|
|
390
|
+
kind: "chapters",
|
|
391
|
+
default: true
|
|
392
|
+
}), { seekableEnd } = this.#ctx.$state;
|
|
393
|
+
for (let i = 0; i < chapters.length; i++) {
|
|
394
|
+
const chapter = chapters[i], nextChapter = chapters[i + 1];
|
|
395
|
+
track.addCue(
|
|
396
|
+
new window.VTTCue(
|
|
397
|
+
chapter.startTime,
|
|
398
|
+
nextChapter?.startTime ?? seekableEnd(),
|
|
399
|
+
chapter.title
|
|
400
|
+
)
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
this.#chaptersTrack = track;
|
|
404
|
+
this.#ctx.textTracks.add(track);
|
|
405
|
+
}
|
|
406
|
+
#removeChapters() {
|
|
407
|
+
if (!this.#chaptersTrack) return;
|
|
408
|
+
this.#ctx.textTracks.remove(this.#chaptersTrack);
|
|
409
|
+
this.#chaptersTrack = null;
|
|
410
|
+
}
|
|
411
|
+
#onQualitiesChange(qualities, trigger) {
|
|
412
|
+
this.#ctx.qualities[QualitySymbol.enableAuto] = qualities.some((q) => q.id === "auto") ? () => this.#remote("setQuality", "auto") : void 0;
|
|
413
|
+
for (const quality of qualities) {
|
|
414
|
+
if (quality.id === "auto") continue;
|
|
415
|
+
const height = +quality.id.slice(0, -1);
|
|
416
|
+
if (isNaN(height)) continue;
|
|
417
|
+
this.#ctx.qualities[ListSymbol.add](
|
|
418
|
+
{
|
|
419
|
+
id: quality.id,
|
|
420
|
+
width: height * (16 / 9),
|
|
421
|
+
height,
|
|
422
|
+
codec: "avc1,h.264",
|
|
423
|
+
bitrate: -1
|
|
424
|
+
},
|
|
425
|
+
trigger
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
this.#onQualityChange(
|
|
429
|
+
qualities.find((q) => q.active),
|
|
430
|
+
trigger
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
#onQualityChange({ id } = {}, trigger) {
|
|
434
|
+
if (!id) return;
|
|
435
|
+
const isAuto = id === "auto", newQuality = this.#ctx.qualities.getById(id);
|
|
436
|
+
if (isAuto) {
|
|
437
|
+
this.#ctx.qualities[QualitySymbol.setAuto](isAuto, trigger);
|
|
438
|
+
this.#ctx.qualities[ListSymbol.select](void 0, true, trigger);
|
|
439
|
+
} else {
|
|
440
|
+
this.#ctx.qualities[ListSymbol.select](newQuality ?? void 0, true, trigger);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
#onEvent(event, payload, trigger) {
|
|
444
|
+
switch (event) {
|
|
445
|
+
case "ready":
|
|
446
|
+
this.#attachListeners();
|
|
447
|
+
break;
|
|
448
|
+
case "loaded":
|
|
449
|
+
this.#onLoaded(trigger);
|
|
450
|
+
break;
|
|
451
|
+
case "play":
|
|
452
|
+
this.#onPlay(trigger);
|
|
453
|
+
break;
|
|
454
|
+
case "playProgress":
|
|
455
|
+
this.#onPlayProgress(trigger);
|
|
456
|
+
break;
|
|
457
|
+
case "pause":
|
|
458
|
+
this.#onPause(trigger);
|
|
459
|
+
break;
|
|
460
|
+
case "loadProgress":
|
|
461
|
+
this.#onLoadProgress(payload.seconds, trigger);
|
|
462
|
+
break;
|
|
463
|
+
case "waiting":
|
|
464
|
+
this.#onWaiting(trigger);
|
|
465
|
+
break;
|
|
466
|
+
case "bufferstart":
|
|
467
|
+
this.#onBufferStart(trigger);
|
|
468
|
+
break;
|
|
469
|
+
case "bufferend":
|
|
470
|
+
this.#onBufferEnd(trigger);
|
|
471
|
+
break;
|
|
472
|
+
case "volumechange":
|
|
473
|
+
this.#onVolumeChange(payload.volume, peek(this.#ctx.$state.muted), trigger);
|
|
474
|
+
break;
|
|
475
|
+
case "durationchange":
|
|
476
|
+
this.#seekableRange = new TimeRange(0, payload.duration);
|
|
477
|
+
this.#ctx.notify("duration-change", payload.duration, trigger);
|
|
478
|
+
break;
|
|
479
|
+
case "playbackratechange":
|
|
480
|
+
this.#ctx.notify("rate-change", payload.playbackRate, trigger);
|
|
481
|
+
break;
|
|
482
|
+
case "qualitychange":
|
|
483
|
+
this.#onQualityChange(payload, trigger);
|
|
484
|
+
break;
|
|
485
|
+
case "fullscreenchange":
|
|
486
|
+
this.#fullscreenActive = payload.fullscreen;
|
|
487
|
+
this.#ctx.notify("fullscreen-change", payload.fullscreen, trigger);
|
|
488
|
+
break;
|
|
489
|
+
case "enterpictureinpicture":
|
|
490
|
+
this.#ctx.notify("picture-in-picture-change", true, trigger);
|
|
491
|
+
break;
|
|
492
|
+
case "leavepictureinpicture":
|
|
493
|
+
this.#ctx.notify("picture-in-picture-change", false, trigger);
|
|
494
|
+
break;
|
|
495
|
+
case "ended":
|
|
496
|
+
this.#ctx.notify("end", void 0, trigger);
|
|
497
|
+
break;
|
|
498
|
+
case "error":
|
|
499
|
+
this.#onError(payload, trigger);
|
|
500
|
+
break;
|
|
501
|
+
case "seek":
|
|
502
|
+
case "seeked":
|
|
503
|
+
this.#onSeeked(payload.seconds, trigger);
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
#onError(error, trigger) {
|
|
508
|
+
const { message, method } = error;
|
|
509
|
+
if (method === "setPlaybackRate") {
|
|
510
|
+
this.#pro.set(false);
|
|
511
|
+
}
|
|
512
|
+
if (method) {
|
|
513
|
+
this.#getPromise(method)?.reject(message);
|
|
514
|
+
}
|
|
515
|
+
{
|
|
516
|
+
this.#ctx.logger?.errorGroup(`[vimeo]: ${message}`).labelledLog("Error", error).labelledLog("Provider", this).labelledLog("Event", trigger).dispatch();
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
onMessage(message, event) {
|
|
520
|
+
if (message.event) {
|
|
521
|
+
this.#onEvent(message.event, message.data, event);
|
|
522
|
+
} else if (message.method) {
|
|
523
|
+
this.#onMethod(message.method, message.value, event);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
onLoad() {
|
|
527
|
+
}
|
|
528
|
+
async #remote(command, arg) {
|
|
529
|
+
let promise = deferredPromise(), promises = this.#promises.get(command);
|
|
530
|
+
if (!promises) this.#promises.set(command, promises = []);
|
|
531
|
+
promises.push(promise);
|
|
532
|
+
this.postMessage({
|
|
533
|
+
method: command,
|
|
534
|
+
value: arg
|
|
535
|
+
});
|
|
536
|
+
return promise.promise;
|
|
537
|
+
}
|
|
538
|
+
#reset() {
|
|
539
|
+
this.#timeRAF.stop();
|
|
540
|
+
this.#seekableRange = new TimeRange(0, 0);
|
|
541
|
+
this.#videoInfoPromise = null;
|
|
542
|
+
this.#currentCue = null;
|
|
543
|
+
this.#pro.set(false);
|
|
544
|
+
this.#removeChapters();
|
|
545
|
+
}
|
|
546
|
+
#getPromise(command) {
|
|
547
|
+
return this.#promises.get(command)?.shift();
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export { VimeoProvider };
|