@biggive/components 202609171513.0.0 → 202609210628.0.0

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.
@@ -0,0 +1,2825 @@
1
+ /*! @vimeo/player v2.30.4 | (c) 2026 Vimeo | MIT License | https://github.com/vimeo/player.js */
2
+ /**
3
+ * @module lib/functions
4
+ */
5
+
6
+ /**
7
+ * Check to see this is a Node environment.
8
+ * @type {boolean}
9
+ */
10
+ /* global global */
11
+ const isNode = typeof global !== 'undefined' && {}.toString.call(global) === '[object global]';
12
+
13
+ /**
14
+ * Check to see if this is a Bun environment.
15
+ * @see https://bun.sh/guides/util/detect-bun
16
+ * @type {boolean}
17
+ */
18
+ const isBun = typeof Bun !== 'undefined';
19
+
20
+ /**
21
+ * Check to see if this is a Deno environment.
22
+ * @see https://docs.deno.com/api/deno/~/Deno
23
+ * @type {boolean}
24
+ */
25
+ const isDeno = typeof Deno !== 'undefined';
26
+
27
+ /**
28
+ * Check to see if this is a Cloudflare Worker environment.
29
+ * @see https://community.cloudflare.com/t/how-to-detect-the-cloudflare-worker-runtime/293715
30
+ * @type {boolean}
31
+ */
32
+ const isCloudflareWorker = typeof WebSocketPair === 'function' && typeof caches?.default !== 'undefined';
33
+
34
+ /**
35
+ * Check if this is a server runtime
36
+ * @type {boolean}
37
+ */
38
+ const isServerRuntime = isNode || isBun || isDeno || isCloudflareWorker;
39
+
40
+ /**
41
+ * Get the name of the method for a given getter or setter.
42
+ *
43
+ * @param {string} prop The name of the property.
44
+ * @param {string} type Either “get” or “set”.
45
+ * @return {string}
46
+ */
47
+ function getMethodName(prop, type) {
48
+ if (prop.indexOf(type.toLowerCase()) === 0) {
49
+ return prop;
50
+ }
51
+ return `${type.toLowerCase()}${prop.substr(0, 1).toUpperCase()}${prop.substr(1)}`;
52
+ }
53
+
54
+ /**
55
+ * Check to see if the object is a DOM Element.
56
+ *
57
+ * @param {*} element The object to check.
58
+ * @return {boolean}
59
+ */
60
+ function isDomElement(element) {
61
+ return Boolean(element && element.nodeType === 1 && 'nodeName' in element && element.ownerDocument && element.ownerDocument.defaultView);
62
+ }
63
+
64
+ /**
65
+ * Check to see whether the value is a number.
66
+ *
67
+ * @see http://dl.dropboxusercontent.com/u/35146/js/tests/isNumber.html
68
+ * @param {*} value The value to check.
69
+ * @param {boolean} integer Check if the value is an integer.
70
+ * @return {boolean}
71
+ */
72
+ function isInteger(value) {
73
+ // eslint-disable-next-line eqeqeq
74
+ return !isNaN(parseFloat(value)) && isFinite(value) && Math.floor(value) == value;
75
+ }
76
+
77
+ /**
78
+ * Check to see if the URL is a Vimeo url.
79
+ *
80
+ * @param {string} url The url string.
81
+ * @return {boolean}
82
+ */
83
+ function isVimeoUrl(url) {
84
+ return /^(https?:)?\/\/((((player|www)\.)?vimeo\.com)|((player\.)?[a-zA-Z0-9-]+\.(videoji\.(hk|cn)|vimeo\.work)))(?=$|\/)/.test(url);
85
+ }
86
+
87
+ /**
88
+ * Check to see if the URL is for a Vimeo embed.
89
+ *
90
+ * @param {string} url The url string.
91
+ * @return {boolean}
92
+ */
93
+ function isVimeoEmbed(url) {
94
+ const expr = /^https:\/\/player\.((vimeo\.com)|([a-zA-Z0-9-]+\.(videoji\.(hk|cn)|vimeo\.work)))\/video\/\d+/;
95
+ return expr.test(url);
96
+ }
97
+ function getOembedDomain(url) {
98
+ const match = (url || '').match(/^(?:https?:)?(?:\/\/)?([^/?]+)/);
99
+ const domain = (match && match[1] || '').replace('player.', '');
100
+ const customDomains = ['.videoji.hk', '.vimeo.work', '.videoji.cn'];
101
+ for (const customDomain of customDomains) {
102
+ if (domain.endsWith(customDomain)) {
103
+ return domain;
104
+ }
105
+ }
106
+ return 'vimeo.com';
107
+ }
108
+
109
+ /**
110
+ * Get the Vimeo URL from an element.
111
+ * The element must have either a data-vimeo-id or data-vimeo-url attribute.
112
+ *
113
+ * @param {object} oEmbedParameters The oEmbed parameters.
114
+ * @return {string}
115
+ */
116
+ function getVimeoUrl() {
117
+ let oEmbedParameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
118
+ const id = oEmbedParameters.id;
119
+ const url = oEmbedParameters.url;
120
+ const idOrUrl = id || url;
121
+ if (!idOrUrl) {
122
+ throw new Error('An id or url must be passed, either in an options object or as a data-vimeo-id or data-vimeo-url attribute.');
123
+ }
124
+ if (isInteger(idOrUrl)) {
125
+ return `https://vimeo.com/${idOrUrl}`;
126
+ }
127
+ if (isVimeoUrl(idOrUrl)) {
128
+ return idOrUrl.replace('http:', 'https:');
129
+ }
130
+ if (id) {
131
+ throw new TypeError(`“${id}” is not a valid video id.`);
132
+ }
133
+ throw new TypeError(`“${idOrUrl}” is not a vimeo.com url.`);
134
+ }
135
+
136
+ /* eslint-disable max-params */
137
+ /**
138
+ * A utility method for attaching and detaching event handlers
139
+ *
140
+ * @param {EventTarget} target
141
+ * @param {string | string[]} eventName
142
+ * @param {function} callback
143
+ * @param {'addEventListener' | 'on'} onName
144
+ * @param {'removeEventListener' | 'off'} offName
145
+ * @return {{cancel: (function(): void)}}
146
+ */
147
+ const subscribe = function (target, eventName, callback) {
148
+ let onName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'addEventListener';
149
+ let offName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'removeEventListener';
150
+ const eventNames = typeof eventName === 'string' ? [eventName] : eventName;
151
+ eventNames.forEach(evName => {
152
+ target[onName](evName, callback);
153
+ });
154
+ return {
155
+ cancel: () => eventNames.forEach(evName => target[offName](evName, callback))
156
+ };
157
+ };
158
+
159
+ /**
160
+ * Find the iframe element that contains a specific source window
161
+ *
162
+ * @param {Window} sourceWindow The source window to find the iframe for
163
+ * @param {Document} [doc=document] The document to search within
164
+ * @return {HTMLIFrameElement|null} The iframe element if found, otherwise null
165
+ */
166
+ function findIframeBySourceWindow(sourceWindow) {
167
+ let doc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
168
+ if (!sourceWindow || !doc || typeof doc.querySelectorAll !== 'function') {
169
+ return null;
170
+ }
171
+ const iframes = doc.querySelectorAll('iframe');
172
+ for (let i = 0; i < iframes.length; i++) {
173
+ if (iframes[i] && iframes[i].contentWindow === sourceWindow) {
174
+ return iframes[i];
175
+ }
176
+ }
177
+ return null;
178
+ }
179
+
180
+ const arrayIndexOfSupport = typeof Array.prototype.indexOf !== 'undefined';
181
+ const postMessageSupport = typeof window !== 'undefined' && typeof window.postMessage !== 'undefined';
182
+ if (!isServerRuntime && (!arrayIndexOfSupport || !postMessageSupport)) {
183
+ throw new Error('Sorry, the Vimeo Player API is not available in this browser.');
184
+ }
185
+
186
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
187
+
188
+ function createCommonjsModule(fn, module) {
189
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
190
+ }
191
+
192
+ /*!
193
+ * weakmap-polyfill v2.0.4 - ECMAScript6 WeakMap polyfill
194
+ * https://github.com/polygonplanet/weakmap-polyfill
195
+ * Copyright (c) 2015-2021 polygonplanet <polygon.planet.aqua@gmail.com>
196
+ * @license MIT
197
+ */
198
+
199
+ (function (self) {
200
+
201
+ if (self.WeakMap) {
202
+ return;
203
+ }
204
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
205
+ var hasDefine = Object.defineProperty && function () {
206
+ try {
207
+ // Avoid IE8's broken Object.defineProperty
208
+ return Object.defineProperty({}, 'x', {
209
+ value: 1
210
+ }).x === 1;
211
+ } catch (e) {}
212
+ }();
213
+ var defineProperty = function (object, name, value) {
214
+ if (hasDefine) {
215
+ Object.defineProperty(object, name, {
216
+ configurable: true,
217
+ writable: true,
218
+ value: value
219
+ });
220
+ } else {
221
+ object[name] = value;
222
+ }
223
+ };
224
+ self.WeakMap = function () {
225
+ // ECMA-262 23.3 WeakMap Objects
226
+ function WeakMap() {
227
+ if (this === void 0) {
228
+ throw new TypeError("Constructor WeakMap requires 'new'");
229
+ }
230
+ defineProperty(this, '_id', genId('_WeakMap'));
231
+
232
+ // ECMA-262 23.3.1.1 WeakMap([iterable])
233
+ if (arguments.length > 0) {
234
+ // Currently, WeakMap `iterable` argument is not supported
235
+ throw new TypeError('WeakMap iterable is not supported');
236
+ }
237
+ }
238
+
239
+ // ECMA-262 23.3.3.2 WeakMap.prototype.delete(key)
240
+ defineProperty(WeakMap.prototype, 'delete', function (key) {
241
+ checkInstance(this, 'delete');
242
+ if (!isObject(key)) {
243
+ return false;
244
+ }
245
+ var entry = key[this._id];
246
+ if (entry && entry[0] === key) {
247
+ delete key[this._id];
248
+ return true;
249
+ }
250
+ return false;
251
+ });
252
+
253
+ // ECMA-262 23.3.3.3 WeakMap.prototype.get(key)
254
+ defineProperty(WeakMap.prototype, 'get', function (key) {
255
+ checkInstance(this, 'get');
256
+ if (!isObject(key)) {
257
+ return void 0;
258
+ }
259
+ var entry = key[this._id];
260
+ if (entry && entry[0] === key) {
261
+ return entry[1];
262
+ }
263
+ return void 0;
264
+ });
265
+
266
+ // ECMA-262 23.3.3.4 WeakMap.prototype.has(key)
267
+ defineProperty(WeakMap.prototype, 'has', function (key) {
268
+ checkInstance(this, 'has');
269
+ if (!isObject(key)) {
270
+ return false;
271
+ }
272
+ var entry = key[this._id];
273
+ if (entry && entry[0] === key) {
274
+ return true;
275
+ }
276
+ return false;
277
+ });
278
+
279
+ // ECMA-262 23.3.3.5 WeakMap.prototype.set(key, value)
280
+ defineProperty(WeakMap.prototype, 'set', function (key, value) {
281
+ checkInstance(this, 'set');
282
+ if (!isObject(key)) {
283
+ throw new TypeError('Invalid value used as weak map key');
284
+ }
285
+ var entry = key[this._id];
286
+ if (entry && entry[0] === key) {
287
+ entry[1] = value;
288
+ return this;
289
+ }
290
+ defineProperty(key, this._id, [key, value]);
291
+ return this;
292
+ });
293
+ function checkInstance(x, methodName) {
294
+ if (!isObject(x) || !hasOwnProperty.call(x, '_id')) {
295
+ throw new TypeError(methodName + ' method called on incompatible receiver ' + typeof x);
296
+ }
297
+ }
298
+ function genId(prefix) {
299
+ return prefix + '_' + rand() + '.' + rand();
300
+ }
301
+ function rand() {
302
+ return Math.random().toString().substring(2);
303
+ }
304
+ defineProperty(WeakMap, '_polyfill', true);
305
+ return WeakMap;
306
+ }();
307
+ function isObject(x) {
308
+ return Object(x) === x;
309
+ }
310
+ })(typeof globalThis !== 'undefined' ? globalThis : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : typeof commonjsGlobal !== 'undefined' ? commonjsGlobal : commonjsGlobal);
311
+
312
+ var npo_src = createCommonjsModule(function (module) {
313
+ /*! Native Promise Only
314
+ v0.8.1 (c) Kyle Simpson
315
+ MIT License: http://getify.mit-license.org
316
+ */
317
+
318
+ (function UMD(name, context, definition) {
319
+ // special form of UMD for polyfilling across evironments
320
+ context[name] = context[name] || definition();
321
+ if (module.exports) {
322
+ module.exports = context[name];
323
+ }
324
+ })("Promise", typeof commonjsGlobal != "undefined" ? commonjsGlobal : commonjsGlobal, function DEF() {
325
+
326
+ var builtInProp,
327
+ cycle,
328
+ scheduling_queue,
329
+ ToString = Object.prototype.toString,
330
+ timer = typeof setImmediate != "undefined" ? function timer(fn) {
331
+ return setImmediate(fn);
332
+ } : setTimeout;
333
+
334
+ // dammit, IE8.
335
+ try {
336
+ builtInProp = function builtInProp(obj, name, val, config) {
337
+ return Object.defineProperty(obj, name, {
338
+ value: val,
339
+ writable: true,
340
+ configurable: config !== false
341
+ });
342
+ };
343
+ } catch (err) {
344
+ builtInProp = function builtInProp(obj, name, val) {
345
+ obj[name] = val;
346
+ return obj;
347
+ };
348
+ }
349
+
350
+ // Note: using a queue instead of array for efficiency
351
+ scheduling_queue = function Queue() {
352
+ var first, last, item;
353
+ function Item(fn, self) {
354
+ this.fn = fn;
355
+ this.self = self;
356
+ this.next = void 0;
357
+ }
358
+ return {
359
+ add: function add(fn, self) {
360
+ item = new Item(fn, self);
361
+ if (last) {
362
+ last.next = item;
363
+ } else {
364
+ first = item;
365
+ }
366
+ last = item;
367
+ item = void 0;
368
+ },
369
+ drain: function drain() {
370
+ var f = first;
371
+ first = last = cycle = void 0;
372
+ while (f) {
373
+ f.fn.call(f.self);
374
+ f = f.next;
375
+ }
376
+ }
377
+ };
378
+ }();
379
+ function schedule(fn, self) {
380
+ scheduling_queue.add(fn, self);
381
+ if (!cycle) {
382
+ cycle = timer(scheduling_queue.drain);
383
+ }
384
+ }
385
+
386
+ // promise duck typing
387
+ function isThenable(o) {
388
+ var _then,
389
+ o_type = typeof o;
390
+ if (o != null && (o_type == "object" || o_type == "function")) {
391
+ _then = o.then;
392
+ }
393
+ return typeof _then == "function" ? _then : false;
394
+ }
395
+ function notify() {
396
+ for (var i = 0; i < this.chain.length; i++) {
397
+ notifyIsolated(this, this.state === 1 ? this.chain[i].success : this.chain[i].failure, this.chain[i]);
398
+ }
399
+ this.chain.length = 0;
400
+ }
401
+
402
+ // NOTE: This is a separate function to isolate
403
+ // the `try..catch` so that other code can be
404
+ // optimized better
405
+ function notifyIsolated(self, cb, chain) {
406
+ var ret, _then;
407
+ try {
408
+ if (cb === false) {
409
+ chain.reject(self.msg);
410
+ } else {
411
+ if (cb === true) {
412
+ ret = self.msg;
413
+ } else {
414
+ ret = cb.call(void 0, self.msg);
415
+ }
416
+ if (ret === chain.promise) {
417
+ chain.reject(TypeError("Promise-chain cycle"));
418
+ } else if (_then = isThenable(ret)) {
419
+ _then.call(ret, chain.resolve, chain.reject);
420
+ } else {
421
+ chain.resolve(ret);
422
+ }
423
+ }
424
+ } catch (err) {
425
+ chain.reject(err);
426
+ }
427
+ }
428
+ function resolve(msg) {
429
+ var _then,
430
+ self = this;
431
+
432
+ // already triggered?
433
+ if (self.triggered) {
434
+ return;
435
+ }
436
+ self.triggered = true;
437
+
438
+ // unwrap
439
+ if (self.def) {
440
+ self = self.def;
441
+ }
442
+ try {
443
+ if (_then = isThenable(msg)) {
444
+ schedule(function () {
445
+ var def_wrapper = new MakeDefWrapper(self);
446
+ try {
447
+ _then.call(msg, function $resolve$() {
448
+ resolve.apply(def_wrapper, arguments);
449
+ }, function $reject$() {
450
+ reject.apply(def_wrapper, arguments);
451
+ });
452
+ } catch (err) {
453
+ reject.call(def_wrapper, err);
454
+ }
455
+ });
456
+ } else {
457
+ self.msg = msg;
458
+ self.state = 1;
459
+ if (self.chain.length > 0) {
460
+ schedule(notify, self);
461
+ }
462
+ }
463
+ } catch (err) {
464
+ reject.call(new MakeDefWrapper(self), err);
465
+ }
466
+ }
467
+ function reject(msg) {
468
+ var self = this;
469
+
470
+ // already triggered?
471
+ if (self.triggered) {
472
+ return;
473
+ }
474
+ self.triggered = true;
475
+
476
+ // unwrap
477
+ if (self.def) {
478
+ self = self.def;
479
+ }
480
+ self.msg = msg;
481
+ self.state = 2;
482
+ if (self.chain.length > 0) {
483
+ schedule(notify, self);
484
+ }
485
+ }
486
+ function iteratePromises(Constructor, arr, resolver, rejecter) {
487
+ for (var idx = 0; idx < arr.length; idx++) {
488
+ (function IIFE(idx) {
489
+ Constructor.resolve(arr[idx]).then(function $resolver$(msg) {
490
+ resolver(idx, msg);
491
+ }, rejecter);
492
+ })(idx);
493
+ }
494
+ }
495
+ function MakeDefWrapper(self) {
496
+ this.def = self;
497
+ this.triggered = false;
498
+ }
499
+ function MakeDef(self) {
500
+ this.promise = self;
501
+ this.state = 0;
502
+ this.triggered = false;
503
+ this.chain = [];
504
+ this.msg = void 0;
505
+ }
506
+ function Promise(executor) {
507
+ if (typeof executor != "function") {
508
+ throw TypeError("Not a function");
509
+ }
510
+ if (this.__NPO__ !== 0) {
511
+ throw TypeError("Not a promise");
512
+ }
513
+
514
+ // instance shadowing the inherited "brand"
515
+ // to signal an already "initialized" promise
516
+ this.__NPO__ = 1;
517
+ var def = new MakeDef(this);
518
+ this["then"] = function then(success, failure) {
519
+ var o = {
520
+ success: typeof success == "function" ? success : true,
521
+ failure: typeof failure == "function" ? failure : false
522
+ };
523
+ // Note: `then(..)` itself can be borrowed to be used against
524
+ // a different promise constructor for making the chained promise,
525
+ // by substituting a different `this` binding.
526
+ o.promise = new this.constructor(function extractChain(resolve, reject) {
527
+ if (typeof resolve != "function" || typeof reject != "function") {
528
+ throw TypeError("Not a function");
529
+ }
530
+ o.resolve = resolve;
531
+ o.reject = reject;
532
+ });
533
+ def.chain.push(o);
534
+ if (def.state !== 0) {
535
+ schedule(notify, def);
536
+ }
537
+ return o.promise;
538
+ };
539
+ this["catch"] = function $catch$(failure) {
540
+ return this.then(void 0, failure);
541
+ };
542
+ try {
543
+ executor.call(void 0, function publicResolve(msg) {
544
+ resolve.call(def, msg);
545
+ }, function publicReject(msg) {
546
+ reject.call(def, msg);
547
+ });
548
+ } catch (err) {
549
+ reject.call(def, err);
550
+ }
551
+ }
552
+ var PromisePrototype = builtInProp({}, "constructor", Promise, /*configurable=*/false);
553
+
554
+ // Note: Android 4 cannot use `Object.defineProperty(..)` here
555
+ Promise.prototype = PromisePrototype;
556
+
557
+ // built-in "brand" to signal an "uninitialized" promise
558
+ builtInProp(PromisePrototype, "__NPO__", 0, /*configurable=*/false);
559
+ builtInProp(Promise, "resolve", function Promise$resolve(msg) {
560
+ var Constructor = this;
561
+
562
+ // spec mandated checks
563
+ // note: best "isPromise" check that's practical for now
564
+ if (msg && typeof msg == "object" && msg.__NPO__ === 1) {
565
+ return msg;
566
+ }
567
+ return new Constructor(function executor(resolve, reject) {
568
+ if (typeof resolve != "function" || typeof reject != "function") {
569
+ throw TypeError("Not a function");
570
+ }
571
+ resolve(msg);
572
+ });
573
+ });
574
+ builtInProp(Promise, "reject", function Promise$reject(msg) {
575
+ return new this(function executor(resolve, reject) {
576
+ if (typeof resolve != "function" || typeof reject != "function") {
577
+ throw TypeError("Not a function");
578
+ }
579
+ reject(msg);
580
+ });
581
+ });
582
+ builtInProp(Promise, "all", function Promise$all(arr) {
583
+ var Constructor = this;
584
+
585
+ // spec mandated checks
586
+ if (ToString.call(arr) != "[object Array]") {
587
+ return Constructor.reject(TypeError("Not an array"));
588
+ }
589
+ if (arr.length === 0) {
590
+ return Constructor.resolve([]);
591
+ }
592
+ return new Constructor(function executor(resolve, reject) {
593
+ if (typeof resolve != "function" || typeof reject != "function") {
594
+ throw TypeError("Not a function");
595
+ }
596
+ var len = arr.length,
597
+ msgs = Array(len),
598
+ count = 0;
599
+ iteratePromises(Constructor, arr, function resolver(idx, msg) {
600
+ msgs[idx] = msg;
601
+ if (++count === len) {
602
+ resolve(msgs);
603
+ }
604
+ }, reject);
605
+ });
606
+ });
607
+ builtInProp(Promise, "race", function Promise$race(arr) {
608
+ var Constructor = this;
609
+
610
+ // spec mandated checks
611
+ if (ToString.call(arr) != "[object Array]") {
612
+ return Constructor.reject(TypeError("Not an array"));
613
+ }
614
+ return new Constructor(function executor(resolve, reject) {
615
+ if (typeof resolve != "function" || typeof reject != "function") {
616
+ throw TypeError("Not a function");
617
+ }
618
+ iteratePromises(Constructor, arr, function resolver(idx, msg) {
619
+ resolve(msg);
620
+ }, reject);
621
+ });
622
+ });
623
+ return Promise;
624
+ });
625
+ });
626
+
627
+ /**
628
+ * @module lib/callbacks
629
+ */
630
+
631
+ const callbackMap = new WeakMap();
632
+
633
+ /**
634
+ * Store a callback for a method or event for a player.
635
+ *
636
+ * @param {Player} player The player object.
637
+ * @param {string} name The method or event name.
638
+ * @param {(function(this:Player, *): void|{resolve: function, reject: function})} callback
639
+ * The callback to call or an object with resolve and reject functions for a promise.
640
+ * @return {void}
641
+ */
642
+ function storeCallback(player, name, callback) {
643
+ const playerCallbacks = callbackMap.get(player.element) || {};
644
+ if (!(name in playerCallbacks)) {
645
+ playerCallbacks[name] = [];
646
+ }
647
+ playerCallbacks[name].push(callback);
648
+ callbackMap.set(player.element, playerCallbacks);
649
+ }
650
+
651
+ /**
652
+ * Get the callbacks for a player and event or method.
653
+ *
654
+ * @param {Player} player The player object.
655
+ * @param {string} name The method or event name
656
+ * @return {function[]}
657
+ */
658
+ function getCallbacks(player, name) {
659
+ const playerCallbacks = callbackMap.get(player.element) || {};
660
+ return playerCallbacks[name] || [];
661
+ }
662
+
663
+ /**
664
+ * Remove a stored callback for a method or event for a player.
665
+ *
666
+ * @param {Player} player The player object.
667
+ * @param {string} name The method or event name
668
+ * @param {function} [callback] The specific callback to remove.
669
+ * @return {boolean} Was this the last callback?
670
+ */
671
+ function removeCallback(player, name, callback) {
672
+ const playerCallbacks = callbackMap.get(player.element) || {};
673
+ if (!playerCallbacks[name]) {
674
+ return true;
675
+ }
676
+
677
+ // If no callback is passed, remove all callbacks for the event
678
+ if (!callback) {
679
+ playerCallbacks[name] = [];
680
+ callbackMap.set(player.element, playerCallbacks);
681
+ return true;
682
+ }
683
+ const index = playerCallbacks[name].indexOf(callback);
684
+ if (index !== -1) {
685
+ playerCallbacks[name].splice(index, 1);
686
+ }
687
+ callbackMap.set(player.element, playerCallbacks);
688
+ return playerCallbacks[name] && playerCallbacks[name].length === 0;
689
+ }
690
+
691
+ /**
692
+ * Return the first stored callback for a player and event or method.
693
+ *
694
+ * @param {Player} player The player object.
695
+ * @param {string} name The method or event name.
696
+ * @return {function} The callback, or false if there were none
697
+ */
698
+ function shiftCallbacks(player, name) {
699
+ const playerCallbacks = getCallbacks(player, name);
700
+ if (playerCallbacks.length < 1) {
701
+ return false;
702
+ }
703
+ const callback = playerCallbacks.shift();
704
+ removeCallback(player, name, callback);
705
+ return callback;
706
+ }
707
+
708
+ /**
709
+ * Move callbacks associated with an element to another element.
710
+ *
711
+ * @param {HTMLElement} oldElement The old element.
712
+ * @param {HTMLElement} newElement The new element.
713
+ * @return {void}
714
+ */
715
+ function swapCallbacks(oldElement, newElement) {
716
+ const playerCallbacks = callbackMap.get(oldElement);
717
+ callbackMap.set(newElement, playerCallbacks);
718
+ callbackMap.delete(oldElement);
719
+ }
720
+
721
+ /**
722
+ * @module lib/postmessage
723
+ */
724
+
725
+ /**
726
+ * Parse a message received from postMessage.
727
+ *
728
+ * @param {*} data The data received from postMessage.
729
+ * @return {object}
730
+ */
731
+ function parseMessageData(data) {
732
+ if (typeof data === 'string') {
733
+ try {
734
+ data = JSON.parse(data);
735
+ } catch (error) {
736
+ // If the message cannot be parsed, throw the error as a warning
737
+ console.warn(error);
738
+ return {};
739
+ }
740
+ }
741
+ return data;
742
+ }
743
+
744
+ /**
745
+ * Post a message to the specified target.
746
+ *
747
+ * @param {Player} player The player object to use.
748
+ * @param {string} method The API method to call.
749
+ * @param {string|number|object|Array|undefined} params The parameters to send to the player.
750
+ * @return {void}
751
+ */
752
+ function postMessage(player, method, params) {
753
+ if (!player.element.contentWindow || !player.element.contentWindow.postMessage) {
754
+ return;
755
+ }
756
+ let message = {
757
+ method
758
+ };
759
+ if (params !== undefined) {
760
+ message.value = params;
761
+ }
762
+
763
+ // IE 8 and 9 do not support passing messages, so stringify them
764
+ const ieVersion = parseFloat(navigator.userAgent.toLowerCase().replace(/^.*msie (\d+).*$/, '$1'));
765
+ if (ieVersion >= 8 && ieVersion < 10) {
766
+ message = JSON.stringify(message);
767
+ }
768
+ player.element.contentWindow.postMessage(message, player.origin);
769
+ }
770
+
771
+ /**
772
+ * Parse the data received from a message event.
773
+ *
774
+ * @param {Player} player The player that received the message.
775
+ * @param {(Object|string)} data The message data. Strings will be parsed into JSON.
776
+ * @return {void}
777
+ */
778
+ function processData(player, data) {
779
+ data = parseMessageData(data);
780
+ let callbacks = [];
781
+ let param;
782
+ if (data.event) {
783
+ if (data.event === 'error') {
784
+ const promises = getCallbacks(player, data.data.method);
785
+ promises.forEach(promise => {
786
+ const error = new Error(data.data.message);
787
+ error.name = data.data.name;
788
+ promise.reject(error);
789
+ removeCallback(player, data.data.method, promise);
790
+ });
791
+ }
792
+ callbacks = getCallbacks(player, `event:${data.event}`);
793
+ param = data.data;
794
+ } else if (data.method) {
795
+ const callback = shiftCallbacks(player, data.method);
796
+ if (callback) {
797
+ callbacks.push(callback);
798
+ param = data.value;
799
+ }
800
+ }
801
+ callbacks.forEach(callback => {
802
+ try {
803
+ if (typeof callback === 'function') {
804
+ callback.call(player, param);
805
+ return;
806
+ }
807
+ callback.resolve(param);
808
+ } catch (e) {
809
+ // empty
810
+ }
811
+ });
812
+ }
813
+
814
+ /**
815
+ * @module lib/embed
816
+ */
817
+ const oEmbedParameters = ['airplay', 'audio_tracks', 'audiotrack', 'autopause', 'autoplay', 'background', 'byline', 'cc', 'chapter_id', 'chapters', 'chromecast', 'color', 'colors', 'controls', 'disable_context_menu', 'dnt', 'end_time', 'fullscreen', 'height', 'id', 'initial_quality', 'interactive_params', 'keyboard', 'loop', 'maxheight', 'max_quality', 'maxwidth', 'min_quality', 'muted', 'play_button_position', 'playsinline', 'portrait', 'preload', 'progress_bar', 'quality', 'quality_selector', 'responsive', 'skipping_forward', 'speed', 'start_time', 'texttrack', 'thumbnail_id', 'title', 'transcript', 'transparent', 'unmute_button', 'url', 'vimeo_logo', 'volume', 'watch_full_video', 'width'];
818
+
819
+ /**
820
+ * Get the 'data-vimeo'-prefixed attributes from an element as an object.
821
+ *
822
+ * @param {HTMLElement} element The element.
823
+ * @param {Object} [defaults={}] The default values to use.
824
+ * @return {Object<string, string>}
825
+ */
826
+ function getOEmbedParameters(element) {
827
+ let defaults = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
828
+ return oEmbedParameters.reduce((params, param) => {
829
+ const value = element.getAttribute(`data-vimeo-${param}`);
830
+ if (value || value === '') {
831
+ params[param] = value === '' ? 1 : value;
832
+ }
833
+ return params;
834
+ }, defaults);
835
+ }
836
+
837
+ /**
838
+ * Create an embed from oEmbed data inside an element.
839
+ *
840
+ * @param {object} data The oEmbed data.
841
+ * @param {HTMLElement} element The element to put the iframe in.
842
+ * @return {HTMLIFrameElement} The iframe embed.
843
+ */
844
+ function createEmbed(_ref, element) {
845
+ let {
846
+ html
847
+ } = _ref;
848
+ if (!element) {
849
+ throw new TypeError('An element must be provided');
850
+ }
851
+ if (element.getAttribute('data-vimeo-initialized') !== null) {
852
+ return element.querySelector('iframe');
853
+ }
854
+ const div = document.createElement('div');
855
+ div.innerHTML = html;
856
+ element.appendChild(div.firstChild);
857
+ element.setAttribute('data-vimeo-initialized', 'true');
858
+ return element.querySelector('iframe');
859
+ }
860
+
861
+ /**
862
+ * Make an oEmbed call for the specified URL.
863
+ *
864
+ * @param {string} videoUrl The vimeo.com url for the video.
865
+ * @param {Object} [params] Parameters to pass to oEmbed.
866
+ * @param {HTMLElement} element The element.
867
+ * @return {Promise}
868
+ */
869
+ function getOEmbedData(videoUrl) {
870
+ let params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
871
+ let element = arguments.length > 2 ? arguments[2] : undefined;
872
+ return new Promise((resolve, reject) => {
873
+ if (!isVimeoUrl(videoUrl)) {
874
+ throw new TypeError(`“${videoUrl}” is not a vimeo.com url.`);
875
+ }
876
+ const domain = getOembedDomain(videoUrl);
877
+ let url = `https://${domain}/api/oembed.json?url=${encodeURIComponent(videoUrl)}`;
878
+ for (const param in params) {
879
+ if (params.hasOwnProperty(param)) {
880
+ url += `&${param}=${encodeURIComponent(params[param])}`;
881
+ }
882
+ }
883
+ const xhr = 'XDomainRequest' in window ? new XDomainRequest() : new XMLHttpRequest();
884
+ xhr.open('GET', url, true);
885
+ xhr.onload = function () {
886
+ if (xhr.status === 404) {
887
+ reject(new Error(`“${videoUrl}” was not found.`));
888
+ return;
889
+ }
890
+ if (xhr.status === 403) {
891
+ reject(new Error(`“${videoUrl}” is not embeddable.`));
892
+ return;
893
+ }
894
+ try {
895
+ const json = JSON.parse(xhr.responseText);
896
+ // Check api response for 403 on oembed
897
+ if (json.domain_status_code === 403) {
898
+ // We still want to create the embed to give users visual feedback
899
+ createEmbed(json, element);
900
+ reject(new Error(`“${videoUrl}” is not embeddable.`));
901
+ return;
902
+ }
903
+ resolve(json);
904
+ } catch (error) {
905
+ reject(error);
906
+ }
907
+ };
908
+ xhr.onerror = function () {
909
+ const status = xhr.status ? ` (${xhr.status})` : '';
910
+ reject(new Error(`There was an error fetching the embed code from Vimeo${status}.`));
911
+ };
912
+ xhr.send();
913
+ });
914
+ }
915
+
916
+ /**
917
+ * Initialize all embeds within a specific element
918
+ *
919
+ * @param {HTMLElement} [parent=document] The parent element.
920
+ * @return {void}
921
+ */
922
+ function initializeEmbeds() {
923
+ let parent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
924
+ const elements = [].slice.call(parent.querySelectorAll('[data-vimeo-id], [data-vimeo-url]'));
925
+ const handleError = error => {
926
+ if ('console' in window && console.error) {
927
+ console.error(`There was an error creating an embed: ${error}`);
928
+ }
929
+ };
930
+ elements.forEach(element => {
931
+ try {
932
+ // Skip any that have data-vimeo-defer
933
+ if (element.getAttribute('data-vimeo-defer') !== null) {
934
+ return;
935
+ }
936
+ const params = getOEmbedParameters(element);
937
+ const url = getVimeoUrl(params);
938
+ getOEmbedData(url, params, element).then(data => {
939
+ return createEmbed(data, element);
940
+ }).catch(handleError);
941
+ } catch (error) {
942
+ handleError(error);
943
+ }
944
+ });
945
+ }
946
+
947
+ /**
948
+ * Resize embeds when messaged by the player.
949
+ *
950
+ * @param {HTMLElement} [parent=document] The parent element.
951
+ * @return {void}
952
+ */
953
+ function resizeEmbeds() {
954
+ let parent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
955
+ // Prevent execution if users include the player.js script multiple times.
956
+ if (window.VimeoPlayerResizeEmbeds_) {
957
+ return;
958
+ }
959
+ window.VimeoPlayerResizeEmbeds_ = true;
960
+ const onMessage = event => {
961
+ if (!isVimeoUrl(event.origin)) {
962
+ return;
963
+ }
964
+
965
+ // 'spacechange' is fired only on embeds with cards
966
+ if (!event.data || event.data.event !== 'spacechange') {
967
+ return;
968
+ }
969
+ const senderIFrame = event.source ? findIframeBySourceWindow(event.source, parent) : null;
970
+ if (senderIFrame) {
971
+ // Change padding-bottom of the enclosing div to accommodate
972
+ // card carousel without distorting aspect ratio
973
+ const space = senderIFrame.parentElement;
974
+ space.style.paddingBottom = `${event.data.data[0].bottom}px`;
975
+ }
976
+ };
977
+ window.addEventListener('message', onMessage);
978
+ }
979
+
980
+ /**
981
+ * Add chapters to existing metadata for Google SEO
982
+ *
983
+ * @param {HTMLElement} [parent=document] The parent element.
984
+ * @return {void}
985
+ */
986
+ function initAppendVideoMetadata() {
987
+ let parent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
988
+ // Prevent execution if users include the player.js script multiple times.
989
+ if (window.VimeoSeoMetadataAppended) {
990
+ return;
991
+ }
992
+ window.VimeoSeoMetadataAppended = true;
993
+ const onMessage = event => {
994
+ if (!isVimeoUrl(event.origin)) {
995
+ return;
996
+ }
997
+ const data = parseMessageData(event.data);
998
+ if (!data || data.event !== 'ready') {
999
+ return;
1000
+ }
1001
+ const senderIFrame = event.source ? findIframeBySourceWindow(event.source, parent) : null;
1002
+
1003
+ // Initiate appendVideoMetadata if iframe is a Vimeo embed
1004
+ if (senderIFrame && isVimeoEmbed(senderIFrame.src)) {
1005
+ const player = new Player(senderIFrame);
1006
+ player.callMethod('appendVideoMetadata', window.location.href);
1007
+ }
1008
+ };
1009
+ window.addEventListener('message', onMessage);
1010
+ }
1011
+
1012
+ /**
1013
+ * Seek to time indicated by vimeo_t query parameter if present in URL
1014
+ *
1015
+ * @param {HTMLElement} [parent=document] The parent element.
1016
+ * @return {void}
1017
+ */
1018
+ function checkUrlTimeParam() {
1019
+ let parent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
1020
+ // Prevent execution if users include the player.js script multiple times.
1021
+ if (window.VimeoCheckedUrlTimeParam) {
1022
+ return;
1023
+ }
1024
+ window.VimeoCheckedUrlTimeParam = true;
1025
+ const handleError = error => {
1026
+ if ('console' in window && console.error) {
1027
+ console.error(`There was an error getting video Id: ${error}`);
1028
+ }
1029
+ };
1030
+ const onMessage = event => {
1031
+ if (!isVimeoUrl(event.origin)) {
1032
+ return;
1033
+ }
1034
+ const data = parseMessageData(event.data);
1035
+ if (!data || data.event !== 'ready') {
1036
+ return;
1037
+ }
1038
+ const senderIFrame = event.source ? findIframeBySourceWindow(event.source, parent) : null;
1039
+ if (senderIFrame && isVimeoEmbed(senderIFrame.src)) {
1040
+ const player = new Player(senderIFrame);
1041
+ player.getVideoId().then(videoId => {
1042
+ const matches = new RegExp(`[?&]vimeo_t_${videoId}=([^&#]*)`).exec(window.location.href);
1043
+ if (matches && matches[1]) {
1044
+ const sec = decodeURI(matches[1]);
1045
+ player.setCurrentTime(sec);
1046
+ }
1047
+ return;
1048
+ }).catch(handleError);
1049
+ }
1050
+ };
1051
+ window.addEventListener('message', onMessage);
1052
+ }
1053
+
1054
+ /**
1055
+ * Updates iframe embeds to support DRM content playback by adding the 'encrypted-media' permission
1056
+ * to the iframe's allow attribute when DRM initialization fails. This function acts as a fallback
1057
+ * mechanism to enable playback of DRM-protected content in embeds that weren't properly configured.
1058
+ *
1059
+ * @return {void}
1060
+ */
1061
+ function updateDRMEmbeds() {
1062
+ if (window.VimeoDRMEmbedsUpdated) {
1063
+ return;
1064
+ }
1065
+ window.VimeoDRMEmbedsUpdated = true;
1066
+
1067
+ /**
1068
+ * Handle message events for DRM initialization failures
1069
+ * @param {MessageEvent} event - The message event from the iframe
1070
+ */
1071
+ const onMessage = event => {
1072
+ if (!isVimeoUrl(event.origin)) {
1073
+ return;
1074
+ }
1075
+ const data = parseMessageData(event.data);
1076
+ if (!data || data.event !== 'drminitfailed') {
1077
+ return;
1078
+ }
1079
+ const senderIFrame = event.source ? findIframeBySourceWindow(event.source) : null;
1080
+ if (!senderIFrame) {
1081
+ return;
1082
+ }
1083
+ const currentAllow = senderIFrame.getAttribute('allow') || '';
1084
+ const allowSupportsDRM = currentAllow.includes('encrypted-media');
1085
+ if (!allowSupportsDRM) {
1086
+ // For DRM playback to successfully occur, the iframe `allow` attribute must include 'encrypted-media'.
1087
+ // If the video requires DRM but doesn't have the attribute, we try to add on behalf of the embed owner
1088
+ // as a temporary measure to enable playback until they're able to update their embeds.
1089
+ senderIFrame.setAttribute('allow', `${currentAllow}; encrypted-media`);
1090
+ const currentUrl = new URL(senderIFrame.getAttribute('src'));
1091
+
1092
+ // Adding this forces the embed to reload once `allow` has been updated with `encrypted-media`.
1093
+ currentUrl.searchParams.set('forcereload', 'drm');
1094
+ senderIFrame.setAttribute('src', currentUrl.toString());
1095
+ return;
1096
+ }
1097
+ };
1098
+ window.addEventListener('message', onMessage);
1099
+ }
1100
+
1101
+ /* MIT License
1102
+
1103
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
1104
+
1105
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1106
+
1107
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1108
+
1109
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1110
+ Terms */
1111
+
1112
+ function initializeScreenfull() {
1113
+ const fn = function () {
1114
+ let val;
1115
+ const fnMap = [['requestFullscreen', 'exitFullscreen', 'fullscreenElement', 'fullscreenEnabled', 'fullscreenchange', 'fullscreenerror'],
1116
+ // New WebKit
1117
+ ['webkitRequestFullscreen', 'webkitExitFullscreen', 'webkitFullscreenElement', 'webkitFullscreenEnabled', 'webkitfullscreenchange', 'webkitfullscreenerror'],
1118
+ // Old WebKit
1119
+ ['webkitRequestFullScreen', 'webkitCancelFullScreen', 'webkitCurrentFullScreenElement', 'webkitCancelFullScreen', 'webkitfullscreenchange', 'webkitfullscreenerror'], ['mozRequestFullScreen', 'mozCancelFullScreen', 'mozFullScreenElement', 'mozFullScreenEnabled', 'mozfullscreenchange', 'mozfullscreenerror'], ['msRequestFullscreen', 'msExitFullscreen', 'msFullscreenElement', 'msFullscreenEnabled', 'MSFullscreenChange', 'MSFullscreenError']];
1120
+ let i = 0;
1121
+ const l = fnMap.length;
1122
+ const ret = {};
1123
+ for (; i < l; i++) {
1124
+ val = fnMap[i];
1125
+ if (val && val[1] in document) {
1126
+ for (i = 0; i < val.length; i++) {
1127
+ ret[fnMap[0][i]] = val[i];
1128
+ }
1129
+ return ret;
1130
+ }
1131
+ }
1132
+ return false;
1133
+ }();
1134
+ const eventNameMap = {
1135
+ fullscreenchange: fn.fullscreenchange,
1136
+ fullscreenerror: fn.fullscreenerror
1137
+ };
1138
+ const screenfull = {
1139
+ request(element) {
1140
+ return new Promise((resolve, reject) => {
1141
+ const onFullScreenEntered = function () {
1142
+ screenfull.off('fullscreenchange', onFullScreenEntered);
1143
+ resolve();
1144
+ };
1145
+ screenfull.on('fullscreenchange', onFullScreenEntered);
1146
+ element = element || document.documentElement;
1147
+ const returnPromise = element[fn.requestFullscreen]();
1148
+ if (returnPromise instanceof Promise) {
1149
+ returnPromise.then(onFullScreenEntered).catch(reject);
1150
+ }
1151
+ });
1152
+ },
1153
+ exit() {
1154
+ return new Promise((resolve, reject) => {
1155
+ if (!screenfull.isFullscreen) {
1156
+ resolve();
1157
+ return;
1158
+ }
1159
+ const onFullScreenExit = function () {
1160
+ screenfull.off('fullscreenchange', onFullScreenExit);
1161
+ resolve();
1162
+ };
1163
+ screenfull.on('fullscreenchange', onFullScreenExit);
1164
+ const returnPromise = document[fn.exitFullscreen]();
1165
+ if (returnPromise instanceof Promise) {
1166
+ returnPromise.then(onFullScreenExit).catch(reject);
1167
+ }
1168
+ });
1169
+ },
1170
+ on(event, callback) {
1171
+ const eventName = eventNameMap[event];
1172
+ if (eventName) {
1173
+ document.addEventListener(eventName, callback);
1174
+ }
1175
+ },
1176
+ off(event, callback) {
1177
+ const eventName = eventNameMap[event];
1178
+ if (eventName) {
1179
+ document.removeEventListener(eventName, callback);
1180
+ }
1181
+ }
1182
+ };
1183
+ Object.defineProperties(screenfull, {
1184
+ isFullscreen: {
1185
+ get() {
1186
+ return Boolean(document[fn.fullscreenElement]);
1187
+ }
1188
+ },
1189
+ element: {
1190
+ enumerable: true,
1191
+ get() {
1192
+ return document[fn.fullscreenElement];
1193
+ }
1194
+ },
1195
+ isEnabled: {
1196
+ enumerable: true,
1197
+ get() {
1198
+ // Coerce to boolean in case of old WebKit
1199
+ return Boolean(document[fn.fullscreenEnabled]);
1200
+ }
1201
+ }
1202
+ });
1203
+ return screenfull;
1204
+ }
1205
+
1206
+ /** @typedef {import('./timing-src-connector.types').PlayerControls} PlayerControls */
1207
+ /** @typedef {import('timing-object').ITimingObject} TimingObject */
1208
+ /** @typedef {import('./timing-src-connector.types').TimingSrcConnectorOptions} TimingSrcConnectorOptions */
1209
+ /** @typedef {(msg: string) => any} Logger */
1210
+ /** @typedef {import('timing-object').TConnectionState} TConnectionState */
1211
+
1212
+ /**
1213
+ * @type {TimingSrcConnectorOptions}
1214
+ *
1215
+ * For details on these properties and their effects, see the typescript definition referenced above.
1216
+ */
1217
+ const defaultOptions = {
1218
+ role: 'viewer',
1219
+ autoPlayMuted: true,
1220
+ allowedDrift: 0.3,
1221
+ maxAllowedDrift: 1,
1222
+ minCheckInterval: 0.1,
1223
+ maxRateAdjustment: 0.2,
1224
+ maxTimeToCatchUp: 1
1225
+ };
1226
+
1227
+ /**
1228
+ * There's a proposed W3C spec for the Timing Object which would introduce a new set of APIs that would simplify time-synchronization tasks for browser applications.
1229
+ *
1230
+ * Proposed spec: https://webtiming.github.io/timingobject/
1231
+ * V3 Spec: https://timingsrc.readthedocs.io/en/latest/
1232
+ * Demuxed talk: https://www.youtube.com/watch?v=cZSjDaGDmX8
1233
+ *
1234
+ * This class makes it easy to connect Vimeo.Player to a provided TimingObject via Vimeo.Player.setTimingSrc(myTimingObject, options) and the synchronization will be handled automatically.
1235
+ *
1236
+ * There are 5 general responsibilities in TimingSrcConnector:
1237
+ *
1238
+ * 1. `updatePlayer()` which sets the player's currentTime, playbackRate and pause/play state based on current state of the TimingObject.
1239
+ * 2. `updateTimingObject()` which sets the TimingObject's position and velocity from the player's state.
1240
+ * 3. `playerUpdater` which listens for change events on the TimingObject and will respond by calling updatePlayer.
1241
+ * 4. `timingObjectUpdater` which listens to the player events of seeked, play and pause and will respond by calling `updateTimingObject()`.
1242
+ * 5. `maintainPlaybackPosition` this is code that constantly monitors the player to make sure it's always in sync with the TimingObject. This is needed because videos will generally not play with precise time accuracy and there will be some drift which becomes more noticeable over longer periods (as noted in the timing-object spec). More details on this method below.
1243
+ */
1244
+ class TimingSrcConnector extends EventTarget {
1245
+ logger;
1246
+
1247
+ /**
1248
+ * @param {PlayerControls} player
1249
+ * @param {TimingObject} timingObject
1250
+ * @param {TimingSrcConnectorOptions} options
1251
+ * @param {Logger} logger
1252
+ */
1253
+ constructor(player, timingObject) {
1254
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1255
+ let logger = arguments.length > 3 ? arguments[3] : undefined;
1256
+ super();
1257
+ this.logger = logger;
1258
+ this.init(timingObject, player, {
1259
+ ...defaultOptions,
1260
+ ...options
1261
+ });
1262
+ }
1263
+ disconnect() {
1264
+ this.dispatchEvent(new Event('disconnect'));
1265
+ }
1266
+
1267
+ /**
1268
+ * @param {TimingObject} timingObject
1269
+ * @param {PlayerControls} player
1270
+ * @param {TimingSrcConnectorOptions} options
1271
+ * @return {Promise<void>}
1272
+ */
1273
+ async init(timingObject, player, options) {
1274
+ await this.waitForTOReadyState(timingObject, 'open');
1275
+ if (options.role === 'viewer') {
1276
+ await this.updatePlayer(timingObject, player, options);
1277
+ const playerUpdater = subscribe(timingObject, 'change', () => this.updatePlayer(timingObject, player, options));
1278
+ const positionSync = this.maintainPlaybackPosition(timingObject, player, options);
1279
+ this.addEventListener('disconnect', () => {
1280
+ positionSync.cancel();
1281
+ playerUpdater.cancel();
1282
+ });
1283
+ } else {
1284
+ await this.updateTimingObject(timingObject, player);
1285
+ const timingObjectUpdater = subscribe(player, ['seeked', 'play', 'pause', 'ratechange'], () => this.updateTimingObject(timingObject, player), 'on', 'off');
1286
+ this.addEventListener('disconnect', () => timingObjectUpdater.cancel());
1287
+ }
1288
+ }
1289
+
1290
+ /**
1291
+ * Sets the TimingObject's state to reflect that of the player
1292
+ *
1293
+ * @param {TimingObject} timingObject
1294
+ * @param {PlayerControls} player
1295
+ * @return {Promise<void>}
1296
+ */
1297
+ async updateTimingObject(timingObject, player) {
1298
+ const [position, isPaused, playbackRate] = await Promise.all([player.getCurrentTime(), player.getPaused(), player.getPlaybackRate()]);
1299
+ timingObject.update({
1300
+ position,
1301
+ velocity: isPaused ? 0 : playbackRate
1302
+ });
1303
+ }
1304
+
1305
+ /**
1306
+ * Sets the player's timing state to reflect that of the TimingObject
1307
+ *
1308
+ * @param {TimingObject} timingObject
1309
+ * @param {PlayerControls} player
1310
+ * @param {TimingSrcConnectorOptions} options
1311
+ * @return {Promise<void>}
1312
+ */
1313
+ async updatePlayer(timingObject, player, options) {
1314
+ const {
1315
+ position,
1316
+ velocity
1317
+ } = timingObject.query();
1318
+ if (typeof position === 'number') {
1319
+ player.setCurrentTime(position);
1320
+ }
1321
+ if (typeof velocity === 'number') {
1322
+ if (velocity === 0) {
1323
+ if ((await player.getPaused()) === false) {
1324
+ player.pause();
1325
+ }
1326
+ } else if (velocity > 0) {
1327
+ if ((await player.getPaused()) === true) {
1328
+ await player.play().catch(async err => {
1329
+ if (err.name === 'NotAllowedError' && options.autoPlayMuted) {
1330
+ await player.setMuted(true);
1331
+ await player.play().catch(err2 => console.error('Couldn\'t play the video from TimingSrcConnector. Error:', err2));
1332
+ }
1333
+ });
1334
+ this.updatePlayer(timingObject, player, options);
1335
+ }
1336
+ if ((await player.getPlaybackRate()) !== velocity) {
1337
+ player.setPlaybackRate(velocity);
1338
+ }
1339
+ }
1340
+ }
1341
+ }
1342
+
1343
+ /**
1344
+ * Since video players do not play with 100% time precision, we need to closely monitor
1345
+ * our player to be sure it remains in sync with the TimingObject.
1346
+ *
1347
+ * If out of sync, we use the current conditions and the options provided to determine
1348
+ * whether to re-sync via setting currentTime or adjusting the playbackRate
1349
+ *
1350
+ * @param {TimingObject} timingObject
1351
+ * @param {PlayerControls} player
1352
+ * @param {TimingSrcConnectorOptions} options
1353
+ * @return {{cancel: (function(): void)}}
1354
+ */
1355
+ maintainPlaybackPosition(timingObject, player, options) {
1356
+ const {
1357
+ allowedDrift,
1358
+ maxAllowedDrift,
1359
+ minCheckInterval,
1360
+ maxRateAdjustment,
1361
+ maxTimeToCatchUp
1362
+ } = options;
1363
+ const syncInterval = Math.min(maxTimeToCatchUp, Math.max(minCheckInterval, maxAllowedDrift)) * 1000;
1364
+ const check = async () => {
1365
+ if (timingObject.query().velocity === 0 || (await player.getPaused()) === true) {
1366
+ return;
1367
+ }
1368
+ const diff = timingObject.query().position - (await player.getCurrentTime());
1369
+ const diffAbs = Math.abs(diff);
1370
+ this.log(`Drift: ${diff}`);
1371
+ if (diffAbs > maxAllowedDrift) {
1372
+ await this.adjustSpeed(player, 0);
1373
+ player.setCurrentTime(timingObject.query().position);
1374
+ this.log('Resync by currentTime');
1375
+ } else if (diffAbs > allowedDrift) {
1376
+ const min = diffAbs / maxTimeToCatchUp;
1377
+ const max = maxRateAdjustment;
1378
+ const adjustment = min < max ? (max - min) / 2 : max;
1379
+ await this.adjustSpeed(player, adjustment * Math.sign(diff));
1380
+ this.log('Resync by playbackRate');
1381
+ }
1382
+ };
1383
+ const interval = setInterval(() => check(), syncInterval);
1384
+ return {
1385
+ cancel: () => clearInterval(interval)
1386
+ };
1387
+ }
1388
+
1389
+ /**
1390
+ * @param {string} msg
1391
+ */
1392
+ log(msg) {
1393
+ this.logger?.(`TimingSrcConnector: ${msg}`);
1394
+ }
1395
+ speedAdjustment = 0;
1396
+
1397
+ /**
1398
+ * @param {PlayerControls} player
1399
+ * @param {number} newAdjustment
1400
+ * @return {Promise<void>}
1401
+ */
1402
+ adjustSpeed = async (player, newAdjustment) => {
1403
+ if (this.speedAdjustment === newAdjustment) {
1404
+ return;
1405
+ }
1406
+ const newPlaybackRate = (await player.getPlaybackRate()) - this.speedAdjustment + newAdjustment;
1407
+ this.log(`New playbackRate: ${newPlaybackRate}`);
1408
+ await player.setPlaybackRate(newPlaybackRate);
1409
+ this.speedAdjustment = newAdjustment;
1410
+ };
1411
+
1412
+ /**
1413
+ * @param {TimingObject} timingObject
1414
+ * @param {TConnectionState} state
1415
+ * @return {Promise<void>}
1416
+ */
1417
+ waitForTOReadyState(timingObject, state) {
1418
+ return new Promise(resolve => {
1419
+ const check = () => {
1420
+ if (timingObject.readyState === state) {
1421
+ resolve();
1422
+ } else {
1423
+ timingObject.addEventListener('readystatechange', check, {
1424
+ once: true
1425
+ });
1426
+ }
1427
+ };
1428
+ check();
1429
+ });
1430
+ }
1431
+ }
1432
+
1433
+ const playerMap = new WeakMap();
1434
+ const readyMap = new WeakMap();
1435
+ let screenfull = {};
1436
+ class Player {
1437
+ /**
1438
+ * Create a Player.
1439
+ *
1440
+ * @param {(HTMLIFrameElement|HTMLElement|string|jQuery)} element A reference to the Vimeo
1441
+ * player iframe, and id, or a jQuery object.
1442
+ * @param {object} [options] oEmbed parameters to use when creating an embed in the element.
1443
+ * @return {Player}
1444
+ */
1445
+ constructor(element) {
1446
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1447
+ /* global jQuery */
1448
+ if (window.jQuery && element instanceof jQuery) {
1449
+ if (element.length > 1 && window.console && console.warn) {
1450
+ console.warn('A jQuery object with multiple elements was passed, using the first element.');
1451
+ }
1452
+ element = element[0];
1453
+ }
1454
+
1455
+ // Find an element by ID
1456
+ if (typeof document !== 'undefined' && typeof element === 'string') {
1457
+ element = document.getElementById(element);
1458
+ }
1459
+
1460
+ // Not an element!
1461
+ if (!isDomElement(element)) {
1462
+ throw new TypeError('You must pass either a valid element or a valid id.');
1463
+ }
1464
+
1465
+ // Already initialized an embed in this div, so grab the iframe
1466
+ if (element.nodeName !== 'IFRAME') {
1467
+ const iframe = element.querySelector('iframe');
1468
+ if (iframe) {
1469
+ element = iframe;
1470
+ }
1471
+ }
1472
+
1473
+ // iframe url is not a Vimeo url
1474
+ if (element.nodeName === 'IFRAME' && !isVimeoUrl(element.getAttribute('src') || '')) {
1475
+ throw new Error('The player element passed isn’t a Vimeo embed.');
1476
+ }
1477
+
1478
+ // If there is already a player object in the map, return that
1479
+ if (playerMap.has(element)) {
1480
+ return playerMap.get(element);
1481
+ }
1482
+ this._window = element.ownerDocument.defaultView;
1483
+ this.element = element;
1484
+ this.origin = '*';
1485
+ const readyPromise = new npo_src((resolve, reject) => {
1486
+ this._onMessage = event => {
1487
+ if (!isVimeoUrl(event.origin) || this.element.contentWindow !== event.source) {
1488
+ return;
1489
+ }
1490
+ if (this.origin === '*') {
1491
+ this.origin = event.origin;
1492
+ }
1493
+ const data = parseMessageData(event.data);
1494
+ const isError = data && data.event === 'error';
1495
+ const isReadyError = isError && data.data && data.data.method === 'ready';
1496
+ if (isReadyError) {
1497
+ const error = new Error(data.data.message);
1498
+ error.name = data.data.name;
1499
+ reject(error);
1500
+ return;
1501
+ }
1502
+ const isReadyEvent = data && data.event === 'ready';
1503
+ const isPingResponse = data && data.method === 'ping';
1504
+ if (isReadyEvent || isPingResponse) {
1505
+ this.element.setAttribute('data-ready', 'true');
1506
+ resolve();
1507
+ return;
1508
+ }
1509
+ processData(this, data);
1510
+ };
1511
+ this._window.addEventListener('message', this._onMessage);
1512
+ if (this.element.nodeName !== 'IFRAME') {
1513
+ const params = getOEmbedParameters(element, options);
1514
+ const url = getVimeoUrl(params);
1515
+ getOEmbedData(url, params, element).then(data => {
1516
+ const iframe = createEmbed(data, element);
1517
+ // Overwrite element with the new iframe,
1518
+ // but store reference to the original element
1519
+ this.element = iframe;
1520
+ this._originalElement = element;
1521
+ swapCallbacks(element, iframe);
1522
+ playerMap.set(this.element, this);
1523
+ return data;
1524
+ }).catch(reject);
1525
+ }
1526
+ });
1527
+
1528
+ // Store a copy of this Player in the map
1529
+ readyMap.set(this, readyPromise);
1530
+ playerMap.set(this.element, this);
1531
+
1532
+ // Send a ping to the iframe so the ready promise will be resolved if
1533
+ // the player is already ready.
1534
+ if (this.element.nodeName === 'IFRAME') {
1535
+ postMessage(this, 'ping');
1536
+ }
1537
+ if (screenfull.isEnabled) {
1538
+ const exitFullscreen = () => screenfull.exit();
1539
+ this.fullscreenchangeHandler = () => {
1540
+ if (screenfull.isFullscreen) {
1541
+ storeCallback(this, 'event:exitFullscreen', exitFullscreen);
1542
+ } else {
1543
+ removeCallback(this, 'event:exitFullscreen', exitFullscreen);
1544
+ }
1545
+ // eslint-disable-next-line
1546
+ this.ready().then(() => {
1547
+ postMessage(this, 'fullscreenchange', screenfull.isFullscreen);
1548
+ });
1549
+ };
1550
+ screenfull.on('fullscreenchange', this.fullscreenchangeHandler);
1551
+ }
1552
+ return this;
1553
+ }
1554
+
1555
+ /**
1556
+ * Check to see if the URL is a Vimeo URL.
1557
+ *
1558
+ * @param {string} url The URL string.
1559
+ * @return {boolean}
1560
+ */
1561
+ static isVimeoUrl(url) {
1562
+ return isVimeoUrl(url);
1563
+ }
1564
+
1565
+ /**
1566
+ * Get a promise for a method.
1567
+ *
1568
+ * @param {string} name The API method to call.
1569
+ * @param {...(string|number|object|Array)} args Arguments to send via postMessage.
1570
+ * @return {Promise}
1571
+ */
1572
+ callMethod(name) {
1573
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1574
+ args[_key - 1] = arguments[_key];
1575
+ }
1576
+ if (name === undefined || name === null) {
1577
+ throw new TypeError('You must pass a method name.');
1578
+ }
1579
+ return new npo_src((resolve, reject) => {
1580
+ // We are storing the resolve/reject handlers to call later, so we
1581
+ // can’t return here.
1582
+ return this.ready().then(() => {
1583
+ storeCallback(this, name, {
1584
+ resolve,
1585
+ reject
1586
+ });
1587
+ if (args.length === 0) {
1588
+ args = {};
1589
+ } else if (args.length === 1) {
1590
+ args = args[0];
1591
+ }
1592
+ postMessage(this, name, args);
1593
+ }).catch(reject);
1594
+ });
1595
+ }
1596
+ /**
1597
+ * Get a promise for the value of a player property.
1598
+ *
1599
+ * @param {string} name The property name
1600
+ * @return {Promise}
1601
+ */
1602
+ get(name) {
1603
+ return new npo_src((resolve, reject) => {
1604
+ name = getMethodName(name, 'get');
1605
+
1606
+ // We are storing the resolve/reject handlers to call later, so we
1607
+ // can’t return here.
1608
+ return this.ready().then(() => {
1609
+ storeCallback(this, name, {
1610
+ resolve,
1611
+ reject
1612
+ });
1613
+ postMessage(this, name);
1614
+ }).catch(reject);
1615
+ });
1616
+ }
1617
+
1618
+ /**
1619
+ * Get a promise for setting the value of a player property.
1620
+ *
1621
+ * @param {string} name The API method to call.
1622
+ * @param {mixed} value The value to set.
1623
+ * @return {Promise}
1624
+ */
1625
+ set(name, value) {
1626
+ return new npo_src((resolve, reject) => {
1627
+ name = getMethodName(name, 'set');
1628
+ if (value === undefined || value === null) {
1629
+ throw new TypeError('There must be a value to set.');
1630
+ }
1631
+
1632
+ // We are storing the resolve/reject handlers to call later, so we
1633
+ // can’t return here.
1634
+ return this.ready().then(() => {
1635
+ storeCallback(this, name, {
1636
+ resolve,
1637
+ reject
1638
+ });
1639
+ postMessage(this, name, value);
1640
+ }).catch(reject);
1641
+ });
1642
+ }
1643
+
1644
+ /**
1645
+ * Add an event listener for the specified event. Will call the
1646
+ * callback with a single parameter, `data`, that contains the data for
1647
+ * that event.
1648
+ *
1649
+ * @param {string} eventName The name of the event.
1650
+ * @param {function(*)} callback The function to call when the event fires.
1651
+ * @return {void}
1652
+ */
1653
+ on(eventName, callback) {
1654
+ if (!eventName) {
1655
+ throw new TypeError('You must pass an event name.');
1656
+ }
1657
+ if (!callback) {
1658
+ throw new TypeError('You must pass a callback function.');
1659
+ }
1660
+ if (typeof callback !== 'function') {
1661
+ throw new TypeError('The callback must be a function.');
1662
+ }
1663
+ const callbacks = getCallbacks(this, `event:${eventName}`);
1664
+ if (callbacks.length === 0) {
1665
+ this.callMethod('addEventListener', eventName).catch(() => {
1666
+ // Ignore the error. There will be an error event fired that
1667
+ // will trigger the error callback if they are listening.
1668
+ });
1669
+ }
1670
+ storeCallback(this, `event:${eventName}`, callback);
1671
+ }
1672
+
1673
+ /**
1674
+ * Remove an event listener for the specified event. Will remove all
1675
+ * listeners for that event if a `callback` isn’t passed, or only that
1676
+ * specific callback if it is passed.
1677
+ *
1678
+ * @param {string} eventName The name of the event.
1679
+ * @param {function} [callback] The specific callback to remove.
1680
+ * @return {void}
1681
+ */
1682
+ off(eventName, callback) {
1683
+ if (!eventName) {
1684
+ throw new TypeError('You must pass an event name.');
1685
+ }
1686
+ if (callback && typeof callback !== 'function') {
1687
+ throw new TypeError('The callback must be a function.');
1688
+ }
1689
+ const lastCallback = removeCallback(this, `event:${eventName}`, callback);
1690
+
1691
+ // If there are no callbacks left, remove the listener
1692
+ if (lastCallback) {
1693
+ this.callMethod('removeEventListener', eventName).catch(e => {
1694
+ // Ignore the error. There will be an error event fired that
1695
+ // will trigger the error callback if they are listening.
1696
+ });
1697
+ }
1698
+ }
1699
+
1700
+ /**
1701
+ * A promise to load a new video.
1702
+ *
1703
+ * @promise LoadVideoPromise
1704
+ * @fulfill {number} The video with this id or url successfully loaded.
1705
+ * @reject {TypeError} The id was not a number.
1706
+ */
1707
+ /**
1708
+ * Load a new video into this embed. The promise will be resolved if
1709
+ * the video is successfully loaded, or it will be rejected if it could
1710
+ * not be loaded.
1711
+ *
1712
+ * @param {number|string|object} options The id of the video, the url of the video, or an object with embed options.
1713
+ * @return {LoadVideoPromise}
1714
+ */
1715
+ loadVideo(options) {
1716
+ return this.callMethod('loadVideo', options);
1717
+ }
1718
+
1719
+ /**
1720
+ * A promise to perform an action when the Player is ready.
1721
+ *
1722
+ * @todo document errors
1723
+ * @promise LoadVideoPromise
1724
+ * @fulfill {void}
1725
+ */
1726
+ /**
1727
+ * Trigger a function when the player iframe has initialized. You do not
1728
+ * need to wait for `ready` to trigger to begin adding event listeners
1729
+ * or calling other methods.
1730
+ *
1731
+ * @return {ReadyPromise}
1732
+ */
1733
+ ready() {
1734
+ const readyPromise = readyMap.get(this) || new npo_src((resolve, reject) => {
1735
+ reject(new Error('Unknown player. Probably unloaded.'));
1736
+ });
1737
+ return npo_src.resolve(readyPromise);
1738
+ }
1739
+
1740
+ /**
1741
+ * A promise to add a cue point to the player.
1742
+ *
1743
+ * @promise AddCuePointPromise
1744
+ * @fulfill {string} The id of the cue point to use for removeCuePoint.
1745
+ * @reject {RangeError} the time was less than 0 or greater than the
1746
+ * video’s duration.
1747
+ * @reject {UnsupportedError} Cue points are not supported with the current
1748
+ * player or browser.
1749
+ */
1750
+ /**
1751
+ * Add a cue point to the player.
1752
+ *
1753
+ * @param {number} time The time for the cue point.
1754
+ * @param {object} [data] Arbitrary data to be returned with the cue point.
1755
+ * @return {AddCuePointPromise}
1756
+ */
1757
+ addCuePoint(time) {
1758
+ let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1759
+ return this.callMethod('addCuePoint', {
1760
+ time,
1761
+ data
1762
+ });
1763
+ }
1764
+
1765
+ /**
1766
+ * A promise to remove a cue point from the player.
1767
+ *
1768
+ * @promise AddCuePointPromise
1769
+ * @fulfill {string} The id of the cue point that was removed.
1770
+ * @reject {InvalidCuePoint} The cue point with the specified id was not
1771
+ * found.
1772
+ * @reject {UnsupportedError} Cue points are not supported with the current
1773
+ * player or browser.
1774
+ */
1775
+ /**
1776
+ * Remove a cue point from the video.
1777
+ *
1778
+ * @param {string} id The id of the cue point to remove.
1779
+ * @return {RemoveCuePointPromise}
1780
+ */
1781
+ removeCuePoint(id) {
1782
+ return this.callMethod('removeCuePoint', id);
1783
+ }
1784
+
1785
+ /**
1786
+ * A representation of a text track on a video.
1787
+ *
1788
+ * @typedef {Object} VimeoTextTrack
1789
+ * @property {string} language The ISO language code.
1790
+ * @property {string} kind The kind of track it is (captions or subtitles).
1791
+ * @property {string} label The human‐readable label for the track.
1792
+ */
1793
+ /**
1794
+ * A promise to enable a text track.
1795
+ *
1796
+ * @promise EnableTextTrackPromise
1797
+ * @fulfill {VimeoTextTrack} The text track that was enabled.
1798
+ * @reject {InvalidTrackLanguageError} No track was available with the
1799
+ * specified language.
1800
+ * @reject {InvalidTrackError} No track was available with the specified
1801
+ * language and kind.
1802
+ */
1803
+ /**
1804
+ * Enable the text track with the specified language, and optionally the
1805
+ * specified kind (captions or subtitles).
1806
+ *
1807
+ * When set via the API, the track language will not change the viewer’s
1808
+ * stored preference.
1809
+ *
1810
+ * @param {string} language The two‐letter language code.
1811
+ * @param {string} [kind] The kind of track to enable (captions or subtitles).
1812
+ * @param {boolean} [showing] Whether to enable display of closed captions for enabled text track within the player.
1813
+ * @return {EnableTextTrackPromise}
1814
+ */
1815
+ enableTextTrack(language) {
1816
+ let kind = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1817
+ let showing = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
1818
+ if (!language) {
1819
+ throw new TypeError('You must pass a language.');
1820
+ }
1821
+ return this.callMethod('enableTextTrack', {
1822
+ language,
1823
+ kind,
1824
+ showing
1825
+ });
1826
+ }
1827
+
1828
+ /**
1829
+ * A promise to disable the active text track.
1830
+ *
1831
+ * @promise DisableTextTrackPromise
1832
+ * @fulfill {void} The track was disabled.
1833
+ */
1834
+ /**
1835
+ * Disable the currently-active text track.
1836
+ *
1837
+ * @return {DisableTextTrackPromise}
1838
+ */
1839
+ disableTextTrack() {
1840
+ return this.callMethod('disableTextTrack');
1841
+ }
1842
+
1843
+ /** @typedef {import('../types/formats.js').VimeoAudioTrack} VimeoAudioTrack */
1844
+ /** @typedef {import('../types/formats.js').AudioLanguage} AudioLanguage */
1845
+ /** @typedef {import('../types/formats.js').AudioKind} AudioKind */
1846
+ /**
1847
+ * A promise to enable an audio track.
1848
+ *
1849
+ * @promise SelectAudioTrackPromise
1850
+ * @fulfill {VimeoAudioTrack} The audio track that was enabled.
1851
+ * @reject {NoAudioTracksError} No audio exists for the video.
1852
+ * @reject {NoAlternateAudioTracksError} No alternate audio tracks exist for the video.
1853
+ * @reject {NoMatchingAudioTrackError} No track was available with the specified
1854
+ * language and kind.
1855
+ */
1856
+ /**
1857
+ * Enable the audio track with the specified language, and optionally the
1858
+ * specified kind (main, translation, descriptions, or commentary).
1859
+ *
1860
+ * When set via the API, the track language will not change the viewer’s
1861
+ * stored preference.
1862
+ *
1863
+ * @param {AudioLanguage} language The two‐letter language code.
1864
+ * @param {AudioKind} [kind] The kind of track to enable (main, translation, descriptions, commentary).
1865
+ * @return {SelectAudioTrackPromise}
1866
+ */
1867
+ selectAudioTrack(language, kind) {
1868
+ if (!language) {
1869
+ throw new TypeError('You must pass a language.');
1870
+ }
1871
+ return this.callMethod('selectAudioTrack', {
1872
+ language,
1873
+ kind
1874
+ });
1875
+ }
1876
+
1877
+ /**
1878
+ * Enable the main audio track for the video.
1879
+ *
1880
+ * @return {SelectAudioTrackPromise}
1881
+ */
1882
+ selectDefaultAudioTrack() {
1883
+ return this.callMethod('selectDefaultAudioTrack');
1884
+ }
1885
+
1886
+ /**
1887
+ * A promise to pause the video.
1888
+ *
1889
+ * @promise PausePromise
1890
+ * @fulfill {void} The video was paused.
1891
+ */
1892
+ /**
1893
+ * Pause the video if it’s playing.
1894
+ *
1895
+ * @return {PausePromise}
1896
+ */
1897
+ pause() {
1898
+ return this.callMethod('pause');
1899
+ }
1900
+
1901
+ /**
1902
+ * A promise to play the video.
1903
+ *
1904
+ * @promise PlayPromise
1905
+ * @fulfill {void} The video was played.
1906
+ */
1907
+ /**
1908
+ * Play the video if it’s paused. **Note:** on iOS and some other
1909
+ * mobile devices, you cannot programmatically trigger play. Once the
1910
+ * viewer has tapped on the play button in the player, however, you
1911
+ * will be able to use this function.
1912
+ *
1913
+ * @return {PlayPromise}
1914
+ */
1915
+ play() {
1916
+ return this.callMethod('play');
1917
+ }
1918
+
1919
+ /**
1920
+ * Request that the player enters fullscreen.
1921
+ * @return {Promise}
1922
+ */
1923
+ requestFullscreen() {
1924
+ if (screenfull.isEnabled) {
1925
+ return screenfull.request(this.element);
1926
+ }
1927
+ return this.callMethod('requestFullscreen');
1928
+ }
1929
+
1930
+ /**
1931
+ * Request that the player exits fullscreen.
1932
+ * @return {Promise}
1933
+ */
1934
+ exitFullscreen() {
1935
+ if (screenfull.isEnabled) {
1936
+ return screenfull.exit();
1937
+ }
1938
+ return this.callMethod('exitFullscreen');
1939
+ }
1940
+
1941
+ /**
1942
+ * Returns true if the player is currently fullscreen.
1943
+ * @return {Promise}
1944
+ */
1945
+ getFullscreen() {
1946
+ if (screenfull.isEnabled) {
1947
+ return npo_src.resolve(screenfull.isFullscreen);
1948
+ }
1949
+ return this.get('fullscreen');
1950
+ }
1951
+
1952
+ /**
1953
+ * Request that the player enters picture-in-picture.
1954
+ * @return {Promise}
1955
+ */
1956
+ requestPictureInPicture() {
1957
+ return this.callMethod('requestPictureInPicture');
1958
+ }
1959
+
1960
+ /**
1961
+ * Request that the player exits picture-in-picture.
1962
+ * @return {Promise}
1963
+ */
1964
+ exitPictureInPicture() {
1965
+ return this.callMethod('exitPictureInPicture');
1966
+ }
1967
+
1968
+ /**
1969
+ * Returns true if the player is currently picture-in-picture.
1970
+ * @return {Promise}
1971
+ */
1972
+ getPictureInPicture() {
1973
+ return this.get('pictureInPicture');
1974
+ }
1975
+
1976
+ /**
1977
+ * A promise to prompt the viewer to initiate remote playback.
1978
+ *
1979
+ * @promise RemotePlaybackPromptPromise
1980
+ * @fulfill {void}
1981
+ * @reject {NotFoundError} No remote playback device is available.
1982
+ */
1983
+ /**
1984
+ * Request to prompt the user to initiate remote playback.
1985
+ *
1986
+ * @return {RemotePlaybackPromptPromise}
1987
+ */
1988
+ remotePlaybackPrompt() {
1989
+ return this.callMethod('remotePlaybackPrompt');
1990
+ }
1991
+
1992
+ /**
1993
+ * A promise to unload the video.
1994
+ *
1995
+ * @promise UnloadPromise
1996
+ * @fulfill {void} The video was unloaded.
1997
+ */
1998
+ /**
1999
+ * Return the player to its initial state.
2000
+ *
2001
+ * @return {UnloadPromise}
2002
+ */
2003
+ unload() {
2004
+ return this.callMethod('unload');
2005
+ }
2006
+
2007
+ /**
2008
+ * Cleanup the player and remove it from the DOM
2009
+ *
2010
+ * It won't be usable and a new one should be constructed
2011
+ * in order to do any operations.
2012
+ *
2013
+ * @return {Promise}
2014
+ */
2015
+ destroy() {
2016
+ return new npo_src(resolve => {
2017
+ readyMap.delete(this);
2018
+ playerMap.delete(this.element);
2019
+ if (this._originalElement) {
2020
+ playerMap.delete(this._originalElement);
2021
+ this._originalElement.removeAttribute('data-vimeo-initialized');
2022
+ }
2023
+ if (this.element && this.element.nodeName === 'IFRAME' && this.element.parentNode) {
2024
+ // If we've added an additional wrapper div, remove that from the DOM.
2025
+ // If not, just remove the iframe element.
2026
+ if (this.element.parentNode.parentNode && this._originalElement && this._originalElement !== this.element.parentNode) {
2027
+ this.element.parentNode.parentNode.removeChild(this.element.parentNode);
2028
+ } else {
2029
+ this.element.parentNode.removeChild(this.element);
2030
+ }
2031
+ }
2032
+
2033
+ // If the clip is private there is a case where the element stays the
2034
+ // div element. Destroy should reset the div and remove the iframe child.
2035
+ if (this.element && this.element.nodeName === 'DIV' && this.element.parentNode) {
2036
+ this.element.removeAttribute('data-vimeo-initialized');
2037
+ const iframe = this.element.querySelector('iframe');
2038
+ if (iframe && iframe.parentNode) {
2039
+ // If we've added an additional wrapper div, remove that from the DOM.
2040
+ // If not, just remove the iframe element.
2041
+ if (iframe.parentNode.parentNode && this._originalElement && this._originalElement !== iframe.parentNode) {
2042
+ iframe.parentNode.parentNode.removeChild(iframe.parentNode);
2043
+ } else {
2044
+ iframe.parentNode.removeChild(iframe);
2045
+ }
2046
+ }
2047
+ }
2048
+ this._window.removeEventListener('message', this._onMessage);
2049
+ if (screenfull.isEnabled) {
2050
+ screenfull.off('fullscreenchange', this.fullscreenchangeHandler);
2051
+ }
2052
+ resolve();
2053
+ });
2054
+ }
2055
+
2056
+ /**
2057
+ * A promise to get the autopause behavior of the video.
2058
+ *
2059
+ * @promise GetAutopausePromise
2060
+ * @fulfill {boolean} Whether autopause is turned on or off.
2061
+ * @reject {UnsupportedError} Autopause is not supported with the current
2062
+ * player or browser.
2063
+ */
2064
+ /**
2065
+ * Get the autopause behavior for this player.
2066
+ *
2067
+ * @return {GetAutopausePromise}
2068
+ */
2069
+ getAutopause() {
2070
+ return this.get('autopause');
2071
+ }
2072
+
2073
+ /**
2074
+ * A promise to set the autopause behavior of the video.
2075
+ *
2076
+ * @promise SetAutopausePromise
2077
+ * @fulfill {boolean} Whether autopause is turned on or off.
2078
+ * @reject {UnsupportedError} Autopause is not supported with the current
2079
+ * player or browser.
2080
+ */
2081
+ /**
2082
+ * Enable or disable the autopause behavior of this player.
2083
+ *
2084
+ * By default, when another video is played in the same browser, this
2085
+ * player will automatically pause. Unless you have a specific reason
2086
+ * for doing so, we recommend that you leave autopause set to the
2087
+ * default (`true`).
2088
+ *
2089
+ * @param {boolean} autopause
2090
+ * @return {SetAutopausePromise}
2091
+ */
2092
+ setAutopause(autopause) {
2093
+ return this.set('autopause', autopause);
2094
+ }
2095
+
2096
+ /**
2097
+ * A promise to get the buffered property of the video.
2098
+ *
2099
+ * @promise GetBufferedPromise
2100
+ * @fulfill {Array} Buffered Timeranges converted to an Array.
2101
+ */
2102
+ /**
2103
+ * Get the buffered property of the video.
2104
+ *
2105
+ * @return {GetBufferedPromise}
2106
+ */
2107
+ getBuffered() {
2108
+ return this.get('buffered');
2109
+ }
2110
+
2111
+ /**
2112
+ * @typedef {Object} CameraProperties
2113
+ * @prop {number} props.yaw - Number between 0 and 360.
2114
+ * @prop {number} props.pitch - Number between -90 and 90.
2115
+ * @prop {number} props.roll - Number between -180 and 180.
2116
+ * @prop {number} props.fov - The field of view in degrees.
2117
+ */
2118
+ /**
2119
+ * A promise to get the camera properties of the player.
2120
+ *
2121
+ * @promise GetCameraPromise
2122
+ * @fulfill {CameraProperties} The camera properties.
2123
+ */
2124
+ /**
2125
+ * For 360° videos get the camera properties for this player.
2126
+ *
2127
+ * @return {GetCameraPromise}
2128
+ */
2129
+ getCameraProps() {
2130
+ return this.get('cameraProps');
2131
+ }
2132
+
2133
+ /**
2134
+ * A promise to set the camera properties of the player.
2135
+ *
2136
+ * @promise SetCameraPromise
2137
+ * @fulfill {Object} The camera was successfully set.
2138
+ * @reject {RangeError} The range was out of bounds.
2139
+ */
2140
+ /**
2141
+ * For 360° videos set the camera properties for this player.
2142
+ *
2143
+ * @param {CameraProperties} camera The camera properties
2144
+ * @return {SetCameraPromise}
2145
+ */
2146
+ setCameraProps(camera) {
2147
+ return this.set('cameraProps', camera);
2148
+ }
2149
+
2150
+ /**
2151
+ * A representation of a chapter.
2152
+ *
2153
+ * @typedef {Object} VimeoChapter
2154
+ * @property {number} startTime The start time of the chapter.
2155
+ * @property {object} title The title of the chapter.
2156
+ * @property {number} index The place in the order of Chapters. Starts at 1.
2157
+ */
2158
+ /**
2159
+ * A promise to get chapters for the video.
2160
+ *
2161
+ * @promise GetChaptersPromise
2162
+ * @fulfill {VimeoChapter[]} The chapters for the video.
2163
+ */
2164
+ /**
2165
+ * Get an array of all the chapters for the video.
2166
+ *
2167
+ * @return {GetChaptersPromise}
2168
+ */
2169
+ getChapters() {
2170
+ return this.get('chapters');
2171
+ }
2172
+
2173
+ /**
2174
+ * A promise to get the currently active chapter.
2175
+ *
2176
+ * @promise GetCurrentChaptersPromise
2177
+ * @fulfill {VimeoChapter|undefined} The current chapter for the video.
2178
+ */
2179
+ /**
2180
+ * Get the currently active chapter for the video.
2181
+ *
2182
+ * @return {GetCurrentChaptersPromise}
2183
+ */
2184
+ getCurrentChapter() {
2185
+ return this.get('currentChapter');
2186
+ }
2187
+
2188
+ /**
2189
+ * A promise to get the accent color of the player.
2190
+ *
2191
+ * @promise GetColorPromise
2192
+ * @fulfill {string} The hex color of the player.
2193
+ */
2194
+ /**
2195
+ * Get the accent color for this player. Note this is deprecated in place of `getColorTwo`.
2196
+ *
2197
+ * @return {GetColorPromise}
2198
+ */
2199
+ getColor() {
2200
+ return this.get('color');
2201
+ }
2202
+
2203
+ /**
2204
+ * A promise to get all colors for the player in an array.
2205
+ *
2206
+ * @promise GetColorsPromise
2207
+ * @fulfill {string[]} The hex colors of the player.
2208
+ */
2209
+ /**
2210
+ * Get all the colors for this player in an array: [colorOne, colorTwo, colorThree, colorFour]
2211
+ *
2212
+ * @return {GetColorPromise}
2213
+ */
2214
+ getColors() {
2215
+ return npo_src.all([this.get('colorOne'), this.get('colorTwo'), this.get('colorThree'), this.get('colorFour')]);
2216
+ }
2217
+
2218
+ /**
2219
+ * A promise to set the accent color of the player.
2220
+ *
2221
+ * @promise SetColorPromise
2222
+ * @fulfill {string} The color was successfully set.
2223
+ * @reject {TypeError} The string was not a valid hex or rgb color.
2224
+ * @reject {ContrastError} The color was set, but the contrast is
2225
+ * outside of the acceptable range.
2226
+ * @reject {EmbedSettingsError} The owner of the player has chosen to
2227
+ * use a specific color.
2228
+ */
2229
+ /**
2230
+ * Set the accent color of this player to a hex or rgb string. Setting the
2231
+ * color may fail if the owner of the video has set their embed
2232
+ * preferences to force a specific color.
2233
+ * Note this is deprecated in place of `setColorTwo`.
2234
+ *
2235
+ * @param {string} color The hex or rgb color string to set.
2236
+ * @return {SetColorPromise}
2237
+ */
2238
+ setColor(color) {
2239
+ return this.set('color', color);
2240
+ }
2241
+
2242
+ /**
2243
+ * A promise to set all colors for the player.
2244
+ *
2245
+ * @promise SetColorsPromise
2246
+ * @fulfill {string[]} The colors were successfully set.
2247
+ * @reject {TypeError} The string was not a valid hex or rgb color.
2248
+ * @reject {ContrastError} The color was set, but the contrast is
2249
+ * outside of the acceptable range.
2250
+ * @reject {EmbedSettingsError} The owner of the player has chosen to
2251
+ * use a specific color.
2252
+ */
2253
+ /**
2254
+ * Set the colors of this player to a hex or rgb string. Setting the
2255
+ * color may fail if the owner of the video has set their embed
2256
+ * preferences to force a specific color.
2257
+ * The colors should be passed in as an array: [colorOne, colorTwo, colorThree, colorFour].
2258
+ * If a color should not be set, the index in the array can be left as null.
2259
+ *
2260
+ * @param {string[]} colors Array of the hex or rgb color strings to set.
2261
+ * @return {SetColorsPromise}
2262
+ */
2263
+ setColors(colors) {
2264
+ if (!Array.isArray(colors)) {
2265
+ return new npo_src((resolve, reject) => reject(new TypeError('Argument must be an array.')));
2266
+ }
2267
+ const nullPromise = new npo_src(resolve => resolve(null));
2268
+ const colorPromises = [colors[0] ? this.set('colorOne', colors[0]) : nullPromise, colors[1] ? this.set('colorTwo', colors[1]) : nullPromise, colors[2] ? this.set('colorThree', colors[2]) : nullPromise, colors[3] ? this.set('colorFour', colors[3]) : nullPromise];
2269
+ return npo_src.all(colorPromises);
2270
+ }
2271
+
2272
+ /**
2273
+ * A representation of a cue point.
2274
+ *
2275
+ * @typedef {Object} VimeoCuePoint
2276
+ * @property {number} time The time of the cue point.
2277
+ * @property {object} data The data passed when adding the cue point.
2278
+ * @property {string} id The unique id for use with removeCuePoint.
2279
+ */
2280
+ /**
2281
+ * A promise to get the cue points of a video.
2282
+ *
2283
+ * @promise GetCuePointsPromise
2284
+ * @fulfill {VimeoCuePoint[]} The cue points added to the video.
2285
+ * @reject {UnsupportedError} Cue points are not supported with the current
2286
+ * player or browser.
2287
+ */
2288
+ /**
2289
+ * Get an array of the cue points added to the video.
2290
+ *
2291
+ * @return {GetCuePointsPromise}
2292
+ */
2293
+ getCuePoints() {
2294
+ return this.get('cuePoints');
2295
+ }
2296
+
2297
+ /**
2298
+ * A promise to get the current time of the video.
2299
+ *
2300
+ * @promise GetCurrentTimePromise
2301
+ * @fulfill {number} The current time in seconds.
2302
+ */
2303
+ /**
2304
+ * Get the current playback position in seconds.
2305
+ *
2306
+ * @return {GetCurrentTimePromise}
2307
+ */
2308
+ getCurrentTime() {
2309
+ return this.get('currentTime');
2310
+ }
2311
+
2312
+ /**
2313
+ * A promise to set the current time of the video.
2314
+ *
2315
+ * @promise SetCurrentTimePromise
2316
+ * @fulfill {number} The actual current time that was set.
2317
+ * @reject {RangeError} the time was less than 0 or greater than the
2318
+ * video’s duration.
2319
+ */
2320
+ /**
2321
+ * Set the current playback position in seconds. If the player was
2322
+ * paused, it will remain paused. Likewise, if the player was playing,
2323
+ * it will resume playing once the video has buffered.
2324
+ *
2325
+ * You can provide an accurate time and the player will attempt to seek
2326
+ * to as close to that time as possible. The exact time will be the
2327
+ * fulfilled value of the promise.
2328
+ *
2329
+ * @param {number} currentTime
2330
+ * @return {SetCurrentTimePromise}
2331
+ */
2332
+ setCurrentTime(currentTime) {
2333
+ return this.set('currentTime', currentTime);
2334
+ }
2335
+
2336
+ /**
2337
+ * A promise to get the duration of the video.
2338
+ *
2339
+ * @promise GetDurationPromise
2340
+ * @fulfill {number} The duration in seconds.
2341
+ */
2342
+ /**
2343
+ * Get the duration of the video in seconds. It will be rounded to the
2344
+ * nearest second before playback begins, and to the nearest thousandth
2345
+ * of a second after playback begins.
2346
+ *
2347
+ * @return {GetDurationPromise}
2348
+ */
2349
+ getDuration() {
2350
+ return this.get('duration');
2351
+ }
2352
+
2353
+ /**
2354
+ * A promise to get the ended state of the video.
2355
+ *
2356
+ * @promise GetEndedPromise
2357
+ * @fulfill {boolean} Whether or not the video has ended.
2358
+ */
2359
+ /**
2360
+ * Get the ended state of the video. The video has ended if
2361
+ * `currentTime === duration`.
2362
+ *
2363
+ * @return {GetEndedPromise}
2364
+ */
2365
+ getEnded() {
2366
+ return this.get('ended');
2367
+ }
2368
+
2369
+ /**
2370
+ * A promise to get the loop state of the player.
2371
+ *
2372
+ * @promise GetLoopPromise
2373
+ * @fulfill {boolean} Whether or not the player is set to loop.
2374
+ */
2375
+ /**
2376
+ * Get the loop state of the player.
2377
+ *
2378
+ * @return {GetLoopPromise}
2379
+ */
2380
+ getLoop() {
2381
+ return this.get('loop');
2382
+ }
2383
+
2384
+ /**
2385
+ * A promise to set the loop state of the player.
2386
+ *
2387
+ * @promise SetLoopPromise
2388
+ * @fulfill {boolean} The loop state that was set.
2389
+ */
2390
+ /**
2391
+ * Set the loop state of the player. When set to `true`, the player
2392
+ * will start over immediately once playback ends.
2393
+ *
2394
+ * @param {boolean} loop
2395
+ * @return {SetLoopPromise}
2396
+ */
2397
+ setLoop(loop) {
2398
+ return this.set('loop', loop);
2399
+ }
2400
+
2401
+ /**
2402
+ * A promise to set the muted state of the player.
2403
+ *
2404
+ * @promise SetMutedPromise
2405
+ * @fulfill {boolean} The muted state that was set.
2406
+ */
2407
+ /**
2408
+ * Set the muted state of the player. When set to `true`, the player
2409
+ * volume will be muted.
2410
+ *
2411
+ * @param {boolean} muted
2412
+ * @return {SetMutedPromise}
2413
+ */
2414
+ setMuted(muted) {
2415
+ return this.set('muted', muted);
2416
+ }
2417
+
2418
+ /**
2419
+ * A promise to get the muted state of the player.
2420
+ *
2421
+ * @promise GetMutedPromise
2422
+ * @fulfill {boolean} Whether or not the player is muted.
2423
+ */
2424
+ /**
2425
+ * Get the muted state of the player.
2426
+ *
2427
+ * @return {GetMutedPromise}
2428
+ */
2429
+ getMuted() {
2430
+ return this.get('muted');
2431
+ }
2432
+
2433
+ /**
2434
+ * A promise to get the paused state of the player.
2435
+ *
2436
+ * @promise GetLoopPromise
2437
+ * @fulfill {boolean} Whether or not the video is paused.
2438
+ */
2439
+ /**
2440
+ * Get the paused state of the player.
2441
+ *
2442
+ * @return {GetLoopPromise}
2443
+ */
2444
+ getPaused() {
2445
+ return this.get('paused');
2446
+ }
2447
+
2448
+ /**
2449
+ * A promise to get the playback rate of the player.
2450
+ *
2451
+ * @promise GetPlaybackRatePromise
2452
+ * @fulfill {number} The playback rate of the player on a scale from 0 to 2.
2453
+ */
2454
+ /**
2455
+ * Get the playback rate of the player on a scale from `0` to `2`.
2456
+ *
2457
+ * @return {GetPlaybackRatePromise}
2458
+ */
2459
+ getPlaybackRate() {
2460
+ return this.get('playbackRate');
2461
+ }
2462
+
2463
+ /**
2464
+ * A promise to set the playbackrate of the player.
2465
+ *
2466
+ * @promise SetPlaybackRatePromise
2467
+ * @fulfill {number} The playback rate was set.
2468
+ * @reject {RangeError} The playback rate was less than 0 or greater than 2.
2469
+ */
2470
+ /**
2471
+ * Set the playback rate of the player on a scale from `0` to `2`. When set
2472
+ * via the API, the playback rate will not be synchronized to other
2473
+ * players or stored as the viewer's preference.
2474
+ *
2475
+ * @param {number} playbackRate
2476
+ * @return {SetPlaybackRatePromise}
2477
+ */
2478
+ setPlaybackRate(playbackRate) {
2479
+ return this.set('playbackRate', playbackRate);
2480
+ }
2481
+
2482
+ /**
2483
+ * A promise to get the played property of the video.
2484
+ *
2485
+ * @promise GetPlayedPromise
2486
+ * @fulfill {Array} Played Timeranges converted to an Array.
2487
+ */
2488
+ /**
2489
+ * Get the played property of the video.
2490
+ *
2491
+ * @return {GetPlayedPromise}
2492
+ */
2493
+ getPlayed() {
2494
+ return this.get('played');
2495
+ }
2496
+
2497
+ /**
2498
+ * A promise to get the qualities available of the current video.
2499
+ *
2500
+ * @promise GetQualitiesPromise
2501
+ * @fulfill {Array} The qualities of the video.
2502
+ */
2503
+ /**
2504
+ * Get the qualities of the current video.
2505
+ *
2506
+ * @return {GetQualitiesPromise}
2507
+ */
2508
+ getQualities() {
2509
+ return this.get('qualities');
2510
+ }
2511
+
2512
+ /**
2513
+ * A promise to get the current set quality of the video.
2514
+ *
2515
+ * @promise GetQualityPromise
2516
+ * @fulfill {string} The current set quality.
2517
+ */
2518
+ /**
2519
+ * Get the current set quality of the video.
2520
+ *
2521
+ * @return {GetQualityPromise}
2522
+ */
2523
+ getQuality() {
2524
+ return this.get('quality');
2525
+ }
2526
+
2527
+ /**
2528
+ * A promise to set the video quality.
2529
+ *
2530
+ * @promise SetQualityPromise
2531
+ * @fulfill {number} The quality was set.
2532
+ * @reject {RangeError} The quality is not available.
2533
+ */
2534
+ /**
2535
+ * Set a video quality.
2536
+ *
2537
+ * @param {string} quality
2538
+ * @return {SetQualityPromise}
2539
+ */
2540
+ setQuality(quality) {
2541
+ return this.set('quality', quality);
2542
+ }
2543
+
2544
+ /**
2545
+ * A promise to get the remote playback availability.
2546
+ *
2547
+ * @promise RemotePlaybackAvailabilityPromise
2548
+ * @fulfill {boolean} Whether remote playback is available.
2549
+ */
2550
+ /**
2551
+ * Get the availability of remote playback.
2552
+ *
2553
+ * @return {RemotePlaybackAvailabilityPromise}
2554
+ */
2555
+ getRemotePlaybackAvailability() {
2556
+ return this.get('remotePlaybackAvailability');
2557
+ }
2558
+
2559
+ /**
2560
+ * A promise to get the current remote playback state.
2561
+ *
2562
+ * @promise RemotePlaybackStatePromise
2563
+ * @fulfill {string} The state of the remote playback: connecting, connected, or disconnected.
2564
+ */
2565
+ /**
2566
+ * Get the current remote playback state.
2567
+ *
2568
+ * @return {RemotePlaybackStatePromise}
2569
+ */
2570
+ getRemotePlaybackState() {
2571
+ return this.get('remotePlaybackState');
2572
+ }
2573
+
2574
+ /**
2575
+ * A promise to get the seekable property of the video.
2576
+ *
2577
+ * @promise GetSeekablePromise
2578
+ * @fulfill {Array} Seekable Timeranges converted to an Array.
2579
+ */
2580
+ /**
2581
+ * Get the seekable property of the video.
2582
+ *
2583
+ * @return {GetSeekablePromise}
2584
+ */
2585
+ getSeekable() {
2586
+ return this.get('seekable');
2587
+ }
2588
+
2589
+ /**
2590
+ * A promise to get the seeking property of the player.
2591
+ *
2592
+ * @promise GetSeekingPromise
2593
+ * @fulfill {boolean} Whether or not the player is currently seeking.
2594
+ */
2595
+ /**
2596
+ * Get if the player is currently seeking.
2597
+ *
2598
+ * @return {GetSeekingPromise}
2599
+ */
2600
+ getSeeking() {
2601
+ return this.get('seeking');
2602
+ }
2603
+
2604
+ /**
2605
+ * A promise to get the text tracks of a video.
2606
+ *
2607
+ * @promise GetTextTracksPromise
2608
+ * @fulfill {VimeoTextTrack[]} The text tracks associated with the video.
2609
+ */
2610
+ /**
2611
+ * Get an array of the text tracks that exist for the video.
2612
+ *
2613
+ * @return {GetTextTracksPromise}
2614
+ */
2615
+ getTextTracks() {
2616
+ return this.get('textTracks');
2617
+ }
2618
+
2619
+ /**
2620
+ * A promise to get the audio tracks of a video.
2621
+ *
2622
+ * @promise GetAudioTracksPromise
2623
+ * @fulfill {VimeoAudioTrack[]} The audio tracks associated with the video.
2624
+ */
2625
+ /**
2626
+ * Get an array of the audio tracks that exist for the video.
2627
+ *
2628
+ * @return {GetAudioTracksPromise}
2629
+ */
2630
+ getAudioTracks() {
2631
+ return this.get('audioTracks');
2632
+ }
2633
+
2634
+ /**
2635
+ * A promise to get the enabled audio track of a video.
2636
+ *
2637
+ * @promise GetAudioTrackPromise
2638
+ * @fulfill {VimeoAudioTrack} The enabled audio track.
2639
+ */
2640
+ /**
2641
+ * Get the enabled audio track for a video.
2642
+ *
2643
+ * @return {GetAudioTrackPromise}
2644
+ */
2645
+ getEnabledAudioTrack() {
2646
+ return this.get('enabledAudioTrack');
2647
+ }
2648
+
2649
+ /**
2650
+ * Get the main audio track for a video.
2651
+ *
2652
+ * @return {GetAudioTrackPromise}
2653
+ */
2654
+ getDefaultAudioTrack() {
2655
+ return this.get('defaultAudioTrack');
2656
+ }
2657
+
2658
+ /**
2659
+ * A promise to get the embed code for the video.
2660
+ *
2661
+ * @promise GetVideoEmbedCodePromise
2662
+ * @fulfill {string} The `<iframe>` embed code for the video.
2663
+ */
2664
+ /**
2665
+ * Get the `<iframe>` embed code for the video.
2666
+ *
2667
+ * @return {GetVideoEmbedCodePromise}
2668
+ */
2669
+ getVideoEmbedCode() {
2670
+ return this.get('videoEmbedCode');
2671
+ }
2672
+
2673
+ /**
2674
+ * A promise to get the id of the video.
2675
+ *
2676
+ * @promise GetVideoIdPromise
2677
+ * @fulfill {number} The id of the video.
2678
+ */
2679
+ /**
2680
+ * Get the id of the video.
2681
+ *
2682
+ * @return {GetVideoIdPromise}
2683
+ */
2684
+ getVideoId() {
2685
+ return this.get('videoId');
2686
+ }
2687
+
2688
+ /**
2689
+ * A promise to get the title of the video.
2690
+ *
2691
+ * @promise GetVideoTitlePromise
2692
+ * @fulfill {number} The title of the video.
2693
+ */
2694
+ /**
2695
+ * Get the title of the video.
2696
+ *
2697
+ * @return {GetVideoTitlePromise}
2698
+ */
2699
+ getVideoTitle() {
2700
+ return this.get('videoTitle');
2701
+ }
2702
+
2703
+ /**
2704
+ * A promise to get the native width of the video.
2705
+ *
2706
+ * @promise GetVideoWidthPromise
2707
+ * @fulfill {number} The native width of the video.
2708
+ */
2709
+ /**
2710
+ * Get the native width of the currently‐playing video. The width of
2711
+ * the highest‐resolution available will be used before playback begins.
2712
+ *
2713
+ * @return {GetVideoWidthPromise}
2714
+ */
2715
+ getVideoWidth() {
2716
+ return this.get('videoWidth');
2717
+ }
2718
+
2719
+ /**
2720
+ * A promise to get the native height of the video.
2721
+ *
2722
+ * @promise GetVideoHeightPromise
2723
+ * @fulfill {number} The native height of the video.
2724
+ */
2725
+ /**
2726
+ * Get the native height of the currently‐playing video. The height of
2727
+ * the highest‐resolution available will be used before playback begins.
2728
+ *
2729
+ * @return {GetVideoHeightPromise}
2730
+ */
2731
+ getVideoHeight() {
2732
+ return this.get('videoHeight');
2733
+ }
2734
+
2735
+ /**
2736
+ * A promise to get the vimeo.com url for the video.
2737
+ *
2738
+ * @promise GetVideoUrlPromise
2739
+ * @fulfill {number} The vimeo.com url for the video.
2740
+ * @reject {PrivacyError} The url isn’t available because of the video’s privacy setting.
2741
+ */
2742
+ /**
2743
+ * Get the vimeo.com url for the video.
2744
+ *
2745
+ * @return {GetVideoUrlPromise}
2746
+ */
2747
+ getVideoUrl() {
2748
+ return this.get('videoUrl');
2749
+ }
2750
+
2751
+ /**
2752
+ * A promise to get the volume level of the player.
2753
+ *
2754
+ * @promise GetVolumePromise
2755
+ * @fulfill {number} The volume level of the player on a scale from 0 to 1.
2756
+ */
2757
+ /**
2758
+ * Get the current volume level of the player on a scale from `0` to `1`.
2759
+ *
2760
+ * Most mobile devices do not support an independent volume from the
2761
+ * system volume. In those cases, this method will always return `1`.
2762
+ *
2763
+ * @return {GetVolumePromise}
2764
+ */
2765
+ getVolume() {
2766
+ return this.get('volume');
2767
+ }
2768
+
2769
+ /**
2770
+ * A promise to set the volume level of the player.
2771
+ *
2772
+ * @promise SetVolumePromise
2773
+ * @fulfill {number} The volume was set.
2774
+ * @reject {RangeError} The volume was less than 0 or greater than 1.
2775
+ */
2776
+ /**
2777
+ * Set the volume of the player on a scale from `0` to `1`. When set
2778
+ * via the API, the volume level will not be synchronized to other
2779
+ * players or stored as the viewer’s preference.
2780
+ *
2781
+ * Most mobile devices do not support setting the volume. An error will
2782
+ * *not* be triggered in that situation.
2783
+ *
2784
+ * @param {number} volume
2785
+ * @return {SetVolumePromise}
2786
+ */
2787
+ setVolume(volume) {
2788
+ return this.set('volume', volume);
2789
+ }
2790
+
2791
+ /** @typedef {import('timing-object').ITimingObject} TimingObject */
2792
+ /** @typedef {import('./lib/timing-src-connector.types').TimingSrcConnectorOptions} TimingSrcConnectorOptions */
2793
+ /** @typedef {import('./lib/timing-src-connector').TimingSrcConnector} TimingSrcConnector */
2794
+
2795
+ /**
2796
+ * Connects a TimingObject to the video player (https://webtiming.github.io/timingobject/)
2797
+ *
2798
+ * @param {TimingObject} timingObject
2799
+ * @param {TimingSrcConnectorOptions} options
2800
+ *
2801
+ * @return {Promise<TimingSrcConnector>}
2802
+ */
2803
+ async setTimingSrc(timingObject, options) {
2804
+ if (!timingObject) {
2805
+ throw new TypeError('A Timing Object must be provided.');
2806
+ }
2807
+ await this.ready();
2808
+ const connector = new TimingSrcConnector(this, timingObject, options);
2809
+ postMessage(this, 'notifyTimingObjectConnect');
2810
+ connector.addEventListener('disconnect', () => postMessage(this, 'notifyTimingObjectDisconnect'));
2811
+ return connector;
2812
+ }
2813
+ }
2814
+
2815
+ // Setup embed only if this is not a server runtime
2816
+ if (!isServerRuntime) {
2817
+ screenfull = initializeScreenfull();
2818
+ initializeEmbeds();
2819
+ resizeEmbeds();
2820
+ initAppendVideoMetadata();
2821
+ checkUrlTimeParam();
2822
+ updateDRMEmbeds();
2823
+ }
2824
+
2825
+ export { Player as default };