@kkcompany/player 2.25.0-canary.7 → 2.25.0-canary.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/modules.mjs CHANGED
@@ -390,38 +390,6 @@ const validateEnvironment = (supportEnvironmentList = []) => {
390
390
  }
391
391
  }; // Some touch devices with a mouse can't be distinguished, assume no mouse
392
392
 
393
- const timeoutError = () => new Error('request timeout');
394
- /**
395
- * @param {URL|RequestInfo} url
396
- * @param {RequestInit} options
397
- * @param {{responseType: 'json'|'text'}}
398
- */
399
-
400
-
401
- const retryRequest = (url, options = {}, {
402
- responseType = 'json',
403
- timeout = 6,
404
- retryTimes = 6
405
- } = {}) => new Promise((resolve, reject) => {
406
- setTimeout(() => reject(timeoutError()), timeout * 1000);
407
- fetch(url, options).then(response => {
408
- var _response$responseTyp;
409
-
410
- return resolve(((_response$responseTyp = response[responseType]) === null || _response$responseTyp === void 0 ? void 0 : _response$responseTyp.call(response)) || response);
411
- }).catch(reject);
412
- }).catch(error => {
413
- console.log(error);
414
-
415
- if (retryTimes > 0) {
416
- return retryRequest(url, options, {
417
- timeout,
418
- retryTimes: retryTimes - 1
419
- });
420
- }
421
-
422
- return error;
423
- });
424
-
425
393
  const protocolExtensions = {
426
394
  hls: 'm3u8',
427
395
  dash: 'mpd'
@@ -519,90 +487,6 @@ const getSource = (sourceOptions, {
519
487
  };
520
488
  };
521
489
 
522
- function getVersion() {
523
- try {
524
- // eslint-disable-next-line no-undef
525
- return "2.25.0-canary.7";
526
- } catch (e) {
527
- return undefined;
528
- }
529
- }
530
-
531
- /* eslint-disable no-param-reassign */
532
-
533
- const matchAll = (input, pattern) => {
534
- const flags = [pattern.global && 'g', pattern.ignoreCase && 'i', pattern.multiline && 'm'].filter(Boolean).join('');
535
- const clone = new RegExp(pattern, flags);
536
- return Array.from(function* () {
537
- let matched = true;
538
-
539
- while (1) {
540
- matched = clone.exec(input);
541
-
542
- if (!matched) {
543
- return;
544
- }
545
-
546
- yield matched;
547
- }
548
- }());
549
- };
550
-
551
- const rewriteUrls = (manifest, sourceUrl) => manifest.replace(/((#EXT-X-MEDIA:.*URI=")([^"]*))|((#EXT-X-STREAM-INF.*\n)(.*)(?=\n))/g, (...matches) => [matches[2], matches[5], new URL(matches[3] || matches[6], sourceUrl)].filter(Boolean).join(''));
552
-
553
- const filterHlsManifestQualities = (originalManifest, filter) => {
554
- if (!filter) {
555
- return;
556
- }
557
-
558
- const manifest = `${originalManifest}\n`;
559
- const profiles = matchAll(manifest, /RESOLUTION=(\d+)x(\d+)/g).map(([, width, height]) => ({
560
- width: +width,
561
- height: +height
562
- }));
563
- const allowed = filter(profiles) || profiles;
564
- const newManifest = manifest.replace(/#EXT-X-STREAM-INF.*RESOLUTION=(\d+)x(\d+).*\n.*\n/g, (item, width, height) => allowed.some(p => p.width === +width && p.height === +height) ? item : '');
565
- return newManifest !== manifest && newManifest;
566
- };
567
-
568
- const meetRestriction = (quality, {
569
- minHeight,
570
- maxHeight
571
- } = {}) => !(quality.height < minHeight || quality.height > maxHeight);
572
-
573
- const selectHlsQualities = async (source, restrictions = {}) => {
574
- if (!isSafari() || !(restrictions.minHeight || restrictions.maxHeight)) {
575
- return source;
576
- }
577
-
578
- const selected = getSource(source, {
579
- preferManifestType: 'hls'
580
- });
581
-
582
- if (!((selected === null || selected === void 0 ? void 0 : selected.type.toLowerCase()) === mimeTypes.hls)) {
583
- return source;
584
- }
585
-
586
- const filtered = filterHlsManifestQualities(await retryRequest(selected.src, {}, {
587
- responseType: 'text'
588
- }), items => items.filter(item => meetRestriction(item, restrictions)));
589
-
590
- if (filtered) {
591
- return { ...selected,
592
-
593
- /*
594
- Native Safari couldn't support blob .m3u8. and will throw MediaError: 4
595
- We find the hacky method: dataURI.
596
- By the way, bitmovin also use this form even user gives the blob URI.
597
- */
598
- src: `data:application/x-mpegURL,${encodeURI(rewriteUrls(filtered, selected.src))}`
599
- };
600
- }
601
-
602
- return source;
603
- };
604
- // for unit test
605
-
606
490
  /* eslint-disable no-param-reassign */
607
491
 
608
492
  const SHAKA_LIVE_DURATION = 4294967296;
@@ -1104,6 +988,15 @@ const mapLogEvents$1 = ({
1104
988
  };
1105
989
  };
1106
990
 
991
+ function getVersion() {
992
+ try {
993
+ // eslint-disable-next-line no-undef
994
+ return "2.25.0-canary.9";
995
+ } catch (e) {
996
+ return undefined;
997
+ }
998
+ }
999
+
1107
1000
  const logEventNames = {
1108
1001
  playbackBeganLoading: 'playback_began_player_loading',
1109
1002
  playbackBeganPlayerStartupTime: 'playback_began_player_startup_time',
@@ -1520,7 +1413,7 @@ const createAnalytics = ({
1520
1413
  const logTarget = mapLogEvents({
1521
1414
  video,
1522
1415
  playerName: 'shaka',
1523
- version: "2.25.0-canary.7"
1416
+ version: "2.25.0-canary.9"
1524
1417
  });
1525
1418
  logTarget.all((type, data) => {
1526
1419
  const payload = {
@@ -1577,6 +1470,113 @@ const createAnalytics = ({
1577
1470
  };
1578
1471
  };
1579
1472
 
1473
+ const timeoutError = () => new Error('request timeout');
1474
+ /**
1475
+ * @param {URL|RequestInfo} url
1476
+ * @param {RequestInit} options
1477
+ * @param {{responseType: 'json'|'text'}}
1478
+ */
1479
+
1480
+
1481
+ const retryRequest = (url, options = {}, {
1482
+ responseType = 'json',
1483
+ timeout = 6,
1484
+ retryTimes = 6
1485
+ } = {}) => new Promise((resolve, reject) => {
1486
+ setTimeout(() => reject(timeoutError()), timeout * 1000);
1487
+ fetch(url, options).then(response => {
1488
+ var _response$responseTyp;
1489
+
1490
+ return resolve(((_response$responseTyp = response[responseType]) === null || _response$responseTyp === void 0 ? void 0 : _response$responseTyp.call(response)) || response);
1491
+ }).catch(reject);
1492
+ }).catch(error => {
1493
+ console.log(error);
1494
+
1495
+ if (retryTimes > 0) {
1496
+ return retryRequest(url, options, {
1497
+ timeout,
1498
+ retryTimes: retryTimes - 1
1499
+ });
1500
+ }
1501
+
1502
+ return error;
1503
+ });
1504
+
1505
+ /* eslint-disable no-param-reassign */
1506
+
1507
+ const matchAll = (input, pattern) => {
1508
+ const flags = [pattern.global && 'g', pattern.ignoreCase && 'i', pattern.multiline && 'm'].filter(Boolean).join('');
1509
+ const clone = new RegExp(pattern, flags);
1510
+ return Array.from(function* () {
1511
+ let matched = true;
1512
+
1513
+ while (1) {
1514
+ matched = clone.exec(input);
1515
+
1516
+ if (!matched) {
1517
+ return;
1518
+ }
1519
+
1520
+ yield matched;
1521
+ }
1522
+ }());
1523
+ };
1524
+
1525
+ const rewriteUrls = (manifest, sourceUrl) => manifest.replace(/((#EXT-X-MEDIA:.*URI=")([^"]*))|((#EXT-X-STREAM-INF.*\n)(.*)(?=\n))/g, (...matches) => [matches[2], matches[5], new URL(matches[3] || matches[6], sourceUrl)].filter(Boolean).join(''));
1526
+
1527
+ const filterHlsManifestQualities = (originalManifest, filter) => {
1528
+ if (!filter) {
1529
+ return;
1530
+ }
1531
+
1532
+ const manifest = `${originalManifest}\n`;
1533
+ const profiles = matchAll(manifest, /RESOLUTION=(\d+)x(\d+)/g).map(([, width, height]) => ({
1534
+ width: +width,
1535
+ height: +height
1536
+ }));
1537
+ const allowed = filter(profiles) || profiles;
1538
+ const newManifest = manifest.replace(/#EXT-X-STREAM-INF.*RESOLUTION=(\d+)x(\d+).*\n.*\n/g, (item, width, height) => allowed.some(p => p.width === +width && p.height === +height) ? item : '');
1539
+ return newManifest !== manifest && newManifest;
1540
+ };
1541
+
1542
+ const meetRestriction = (quality, {
1543
+ minHeight,
1544
+ maxHeight
1545
+ } = {}) => !(quality.height < minHeight || quality.height > maxHeight);
1546
+
1547
+ const selectHlsQualities = async (source, restrictions = {}) => {
1548
+ if (!isSafari() || !(restrictions.minHeight || restrictions.maxHeight)) {
1549
+ return source;
1550
+ }
1551
+
1552
+ const selected = getSource(source, {
1553
+ preferManifestType: 'hls'
1554
+ });
1555
+
1556
+ if (!((selected === null || selected === void 0 ? void 0 : selected.type.toLowerCase()) === mimeTypes.hls)) {
1557
+ return source;
1558
+ }
1559
+
1560
+ const filtered = filterHlsManifestQualities(await retryRequest(selected.src, {}, {
1561
+ responseType: 'text'
1562
+ }), items => items.filter(item => meetRestriction(item, restrictions)));
1563
+
1564
+ if (filtered) {
1565
+ return { ...selected,
1566
+
1567
+ /*
1568
+ Native Safari couldn't support blob .m3u8. and will throw MediaError: 4
1569
+ We find the hacky method: dataURI.
1570
+ By the way, bitmovin also use this form even user gives the blob URI.
1571
+ */
1572
+ src: `data:application/x-mpegURL,${encodeURI(rewriteUrls(filtered, selected.src))}`
1573
+ };
1574
+ }
1575
+
1576
+ return source;
1577
+ };
1578
+ // for unit test
1579
+
1580
1580
  /* eslint-disable no-empty */
1581
1581
  const storageKey = 'playcraft-tab-lock';
1582
1582
  const lockRenewTime = 3000;