@kkcompany/player 2.25.0-canary.2 → 2.25.0-canary.20

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/core.mjs CHANGED
@@ -4,14 +4,6 @@ import UAParser from 'ua-parser-js';
4
4
  new UAParser();
5
5
 
6
6
  const isSafari = () => /^((?!chrome|android|X11|Linux).)*(safari|iPad|iPhone|Version)/i.test(navigator.userAgent);
7
-
8
- function needNativeHls() {
9
- // Don't let Android phones play HLS, even if some of them report supported
10
- // This covers Samsung & OPPO special cases
11
- const isAndroid = /android|X11|Linux/i.test(navigator.userAgent);
12
- return isAndroid || /firefox/i.test(navigator.userAgent) ? '' : // canPlayType isn't reliable across all iOS verion / device combinations, so also check user agent
13
- isSafari() ? 'maybe' : document.createElement('video').canPlayType('application/vnd.apple.mpegURL');
14
- }
15
7
  // navigator.maxTouchPoints() is not supported in Safari 11, iOS Safari 11.0-11.2 compat/compat
16
8
 
17
9
 
@@ -45,7 +37,7 @@ const waitFor = (check, handler) => {
45
37
  function getVersion() {
46
38
  try {
47
39
  // eslint-disable-next-line no-undef
48
- return "2.25.0-canary.2";
40
+ return "2.25.0-canary.20";
49
41
  } catch (e) {
50
42
  return undefined;
51
43
  }
@@ -138,7 +130,7 @@ const makeResponse = (headers, data, status, uri, responseURL, requestType) => {
138
130
  throw new shaka$1.util.Error(severity, shaka$1.util.Error.Category.NETWORK, shaka$1.util.Error.Code.BAD_HTTP_STATUS, uri, status, responseText, headers, requestType);
139
131
  };
140
132
 
141
- const goog$1 = {
133
+ const goog$2 = {
142
134
  asserts: {
143
135
  assert: () => {}
144
136
  }
@@ -284,7 +276,7 @@ class HttpFetchPlugin {
284
276
  }
285
277
 
286
278
  if (readObj.done) {
287
- goog$1.asserts.assert(!readObj.value, 'readObj should be unset when "done" is true.');
279
+ goog$2.asserts.assert(!readObj.value, 'readObj should be unset when "done" is true.');
288
280
  controller.close();
289
281
  } else {
290
282
  controller.enqueue(readObj.value);
@@ -523,6 +515,664 @@ const fixDashManifest = (data, {
523
515
  return new XMLSerializer().serializeToString(doc);
524
516
  };
525
517
 
518
+ /* eslint-disable no-cond-assign */
519
+
520
+ /* eslint-disable prefer-destructuring */
521
+
522
+ /*! @license
523
+ * Shaka Player
524
+ * Copyright 2016 Google LLC
525
+ * SPDX-License-Identifier: Apache-2.0
526
+ */
527
+ const goog$1 = {
528
+ asserts: {
529
+ assert: (condition, message) => {
530
+ if (!condition) {
531
+ console.warn('GOOG Assert!', message);
532
+ }
533
+ }
534
+ }
535
+ };
536
+
537
+ const addDefaultTextColor = styles => {
538
+ const textColor = shaka.text.Cue.defaultTextColor;
539
+
540
+ for (const [key, value] of Object.entries(textColor)) {
541
+ const cue = new shaka.text.Cue(0, 0, '');
542
+ cue.color = value;
543
+ styles.set(`.${key}`, cue);
544
+ }
545
+
546
+ const bgColor = shaka.text.Cue.defaultTextBackgroundColor;
547
+
548
+ for (const [key, value] of Object.entries(bgColor)) {
549
+ const cue = new shaka.text.Cue(0, 0, '');
550
+ cue.backgroundColor = value;
551
+ styles.set(`.${key}`, cue);
552
+ }
553
+ };
554
+
555
+ const parseTime = text => {
556
+ var _Array$from;
557
+
558
+ const timeFormat = /(?:(\d{1,}):)?(\d{2}):(\d{2})((\.(\d{1,3})))?/g;
559
+ const results = (_Array$from = Array.from(text.matchAll(timeFormat))) === null || _Array$from === void 0 ? void 0 : _Array$from[0];
560
+
561
+ if (results == null) {
562
+ return null;
563
+ } // This capture is optional, but will still be in the array as undefined,
564
+ // in which case it is 0.
565
+
566
+
567
+ const hours = Number(results[1]) || 0;
568
+ const minutes = Number(results[2]);
569
+ const seconds = Number(results[3]);
570
+ const milliseconds = Number(results[6]) || 0;
571
+
572
+ if (minutes > 59 || seconds > 59) {
573
+ return null;
574
+ }
575
+
576
+ return milliseconds / 1000 + seconds + minutes * 60 + hours * 3600;
577
+ };
578
+
579
+ const parseRegion = block => {
580
+ if (block[0].trim() !== 'REGION') {
581
+ return [];
582
+ }
583
+
584
+ const region = new shaka.text.CueRegion();
585
+ block.slice(1).forEach(word => {
586
+ let results = null;
587
+
588
+ if (results = /^id:(.*)$/.exec(word)) {
589
+ region.id = results[1];
590
+ } else if (results = /^width:(\d{1,2}|100)%$/.exec(word)) {
591
+ region.width = Number(results[1]);
592
+ } else if (results = /^lines:(\d+)$/.exec(word)) {
593
+ region.height = Number(results[1]);
594
+ region.heightUnits = shaka.text.CueRegion.units.LINES;
595
+ } else if (results = /^regionanchor:(\d{1,2}|100)%,(\d{1,2}|100)%$/.exec(word)) {
596
+ region.regionAnchorX = Number(results[1]);
597
+ region.regionAnchorY = Number(results[2]);
598
+ } else if (results = /^viewportanchor:(\d{1,2}|100)%,(\d{1,2}|100)%$/.exec(word)) {
599
+ region.viewportAnchorX = Number(results[1]);
600
+ region.viewportAnchorY = Number(results[2]);
601
+ } else if (results = /^scroll:up$/.exec(word)) {
602
+ region.scroll = shaka.text.CueRegion.scrollMode.UP;
603
+ } else {
604
+ shaka.log.warning('VTT parser encountered an invalid VTTRegion setting: ', word, ' The setting will be ignored.');
605
+ }
606
+ });
607
+ return [region];
608
+ };
609
+ /**
610
+ * @implements {shaka.extern.TextParser}
611
+ * @export
612
+ */
613
+
614
+
615
+ class VttTextParser {
616
+ /** Constructs a VTT parser. */
617
+ constructor() {
618
+ /** @private {boolean} */
619
+ this.sequenceMode_ = false;
620
+ /** @private {string} */
621
+
622
+ this.manifestType_ = shaka.media.ManifestParser.UNKNOWN;
623
+ }
624
+ /**
625
+ * @override
626
+ * @export
627
+ */
628
+
629
+
630
+ parseInit() {
631
+ goog$1.asserts.assert(false, 'VTT does not have init segments');
632
+ }
633
+ /**
634
+ * @override
635
+ * @export
636
+ */
637
+
638
+
639
+ setSequenceMode(sequenceMode) {
640
+ this.sequenceMode_ = sequenceMode;
641
+ }
642
+ /**
643
+ * @override
644
+ * @export
645
+ */
646
+
647
+
648
+ setManifestType(manifestType) {
649
+ this.manifestType_ = manifestType;
650
+ }
651
+ /**
652
+ * @override
653
+ * @export
654
+ */
655
+
656
+
657
+ parseMedia(data, time) {
658
+ // Get the input as a string. Normalize newlines to \n.
659
+ let str = shaka.util.StringUtils.fromUTF8(data);
660
+ str = str.replace(/\r\n|\r(?=[^\n]|$)/gm, '\n');
661
+ const blocks = str.split(/\n{2,}/m);
662
+
663
+ if (!/^WEBVTT($|[ \t\n])/m.test(blocks[0])) {
664
+ throw new shaka.util.Error(shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.TEXT, shaka.util.Error.Code.INVALID_TEXT_HEADER);
665
+ } // Depending on "segmentRelativeVttTiming" configuration,
666
+ // "vttOffset" will correspond to either "periodStart" (default)
667
+ // or "segmentStart", for segmented VTT where timings are relative
668
+ // to the beginning of each segment.
669
+ // NOTE: "periodStart" is the timestamp offset applied via TextEngine.
670
+ // It is no longer closely tied to periods, but the name stuck around.
671
+ // NOTE: This offset and the flag choosing its meaning have no effect on
672
+ // HLS content, which should use X-TIMESTAMP-MAP and periodStart instead.
673
+
674
+
675
+ let offset = time.vttOffset;
676
+
677
+ if (this.manifestType_ == shaka.media.ManifestParser.HLS) {
678
+ // Only use 'X-TIMESTAMP-MAP' with HLS.
679
+ if (blocks[0].includes('X-TIMESTAMP-MAP')) {
680
+ offset = this.computeHlsOffset_(blocks[0], time);
681
+ } else if (time.periodStart && time.vttOffset == time.periodStart) {
682
+ // In the case where X-TIMESTAMP-MAP is not used and it is HLS, we
683
+ // should not use offset unless segment-relative times are used.
684
+ offset = 0;
685
+ }
686
+ }
687
+
688
+ const regions = [];
689
+ /** @type {!Map<string, !shaka.text.Cue>} */
690
+
691
+ const styles = new Map();
692
+ addDefaultTextColor(styles); // Parse cues.
693
+
694
+ const ret = [];
695
+
696
+ for (const block of blocks.slice(1)) {
697
+ const lines = block.split('\n');
698
+ VttTextParser.parseStyle_(lines, styles);
699
+ regions.push(...parseRegion(lines));
700
+ const cue = VttTextParser.parseCue_(lines, offset, regions, styles);
701
+
702
+ if (cue) {
703
+ ret.push(cue);
704
+ }
705
+ }
706
+
707
+ return ret;
708
+ }
709
+ /**
710
+ * @param {string} headerBlock Contains X-TIMESTAMP-MAP.
711
+ * @param {shaka.extern.TextParser.TimeContext} time
712
+ * @return {number}
713
+ * @private
714
+ */
715
+
716
+
717
+ computeHlsOffset_(headerBlock, time) {
718
+ // https://bit.ly/2K92l7y
719
+ // The 'X-TIMESTAMP-MAP' header is used in HLS to align text with
720
+ // the rest of the media.
721
+ // The header format is 'X-TIMESTAMP-MAP=MPEGTS:n,LOCAL:m'
722
+ // (the attributes can go in any order)
723
+ // where n is MPEG-2 time and m is cue time it maps to.
724
+ // For example 'X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000'
725
+ // means an offset of 10 seconds
726
+ // 900000/MPEG_TIMESCALE - cue time.
727
+ const cueTimeMatch = headerBlock.match(/LOCAL:((?:(\d{1,}):)?(\d{2}):(\d{2})\.(\d{3}))/m);
728
+ const mpegTimeMatch = headerBlock.match(/MPEGTS:(\d+)/m);
729
+
730
+ if (!cueTimeMatch || !mpegTimeMatch) {
731
+ throw new shaka.util.Error(shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.TEXT, shaka.util.Error.Code.INVALID_TEXT_HEADER);
732
+ }
733
+
734
+ const cueTime = parseTime(cueTimeMatch[1]);
735
+
736
+ if (cueTime == null) {
737
+ throw new shaka.util.Error(shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.TEXT, shaka.util.Error.Code.INVALID_TEXT_HEADER);
738
+ }
739
+
740
+ let mpegTime = Number(mpegTimeMatch[1]);
741
+ const mpegTimescale = VttTextParser.MPEG_TIMESCALE_;
742
+ const rolloverSeconds = VttTextParser.TS_ROLLOVER_ / mpegTimescale;
743
+ let segmentStart = time.segmentStart - time.periodStart;
744
+
745
+ while (segmentStart >= rolloverSeconds) {
746
+ segmentStart -= rolloverSeconds;
747
+ mpegTime += VttTextParser.TS_ROLLOVER_;
748
+ }
749
+
750
+ return time.periodStart + mpegTime / mpegTimescale - cueTime;
751
+ }
752
+ /**
753
+ * Parses a style block into a Cue object.
754
+ *
755
+ * @param {!Array<string>} text
756
+ * @param {!Map<string, !shaka.text.Cue>} styles
757
+ * @private
758
+ */
759
+
760
+
761
+ static parseStyle_(text, styles) {
762
+ // Skip empty blocks.
763
+ if (text.length == 1 && !text[0]) {
764
+ return;
765
+ } // Skip comment blocks.
766
+
767
+
768
+ if (/^NOTE($|[ \t])/.test(text[0])) {
769
+ return;
770
+ } // Only style block are allowed.
771
+
772
+
773
+ if (text[0] != 'STYLE') {
774
+ return;
775
+ }
776
+ /** @type {!Array<!Array<string>>} */
777
+
778
+
779
+ const styleBlocks = [];
780
+ let lastBlockIndex = -1;
781
+
782
+ for (let i = 1; i < text.length; i++) {
783
+ if (text[i].includes('::cue')) {
784
+ styleBlocks.push([]);
785
+ lastBlockIndex = styleBlocks.length - 1;
786
+ }
787
+
788
+ if (lastBlockIndex == -1) {
789
+ continue;
790
+ }
791
+
792
+ styleBlocks[lastBlockIndex].push(text[i]);
793
+
794
+ if (text[i].includes('}')) {
795
+ lastBlockIndex = -1;
796
+ }
797
+ }
798
+
799
+ for (const styleBlock of styleBlocks) {
800
+ let styleSelector = 'global'; // Look for what is within parentheses. For example:
801
+ // <code>:: cue (b) {</code>, what we are looking for is <code>b</code>
802
+
803
+ const selector = styleBlock[0].match(/\((.*)\)/);
804
+
805
+ if (selector) {
806
+ styleSelector = selector.pop();
807
+ } // We start at 1 to avoid '::cue' and end earlier to avoid '}'
808
+
809
+
810
+ let propertyLines = styleBlock.slice(1, -1);
811
+
812
+ if (styleBlock[0].includes('}')) {
813
+ const payload = /\{(.*?)\}/.exec(styleBlock[0]);
814
+
815
+ if (payload) {
816
+ propertyLines = payload[1].split(';');
817
+ }
818
+ } // Continue styles over multiple selectors if necessary.
819
+ // For example,
820
+ // ::cue(b) { background: white; } ::cue(b) { color: blue; }
821
+ // should set both the background and foreground of bold tags.
822
+
823
+
824
+ let cue = styles.get(styleSelector);
825
+
826
+ if (!cue) {
827
+ cue = new shaka.text.Cue(0, 0, '');
828
+ }
829
+
830
+ let validStyle = false;
831
+
832
+ for (let i = 0; i < propertyLines.length; i++) {
833
+ // We look for CSS properties. As a general rule they are separated by
834
+ // <code>:</code>. Eg: <code>color: red;</code>
835
+ const lineParts = /^\s*([^:]+):\s*(.*)/.exec(propertyLines[i]);
836
+
837
+ if (lineParts) {
838
+ const name = lineParts[1].trim();
839
+ const value = lineParts[2].trim().replace(';', '');
840
+
841
+ switch (name) {
842
+ case 'background-color':
843
+ case 'background':
844
+ validStyle = true;
845
+ cue.backgroundColor = value;
846
+ break;
847
+
848
+ case 'color':
849
+ validStyle = true;
850
+ cue.color = value;
851
+ break;
852
+
853
+ case 'font-family':
854
+ validStyle = true;
855
+ cue.fontFamily = value;
856
+ break;
857
+
858
+ case 'font-size':
859
+ validStyle = true;
860
+ cue.fontSize = value;
861
+ break;
862
+
863
+ case 'font-weight':
864
+ if (parseInt(value, 10) >= 700 || value == 'bold') {
865
+ validStyle = true;
866
+ cue.fontWeight = shaka.text.Cue.fontWeight.BOLD;
867
+ }
868
+
869
+ break;
870
+
871
+ case 'font-style':
872
+ switch (value) {
873
+ case 'normal':
874
+ validStyle = true;
875
+ cue.fontStyle = shaka.text.Cue.fontStyle.NORMAL;
876
+ break;
877
+
878
+ case 'italic':
879
+ validStyle = true;
880
+ cue.fontStyle = shaka.text.Cue.fontStyle.ITALIC;
881
+ break;
882
+
883
+ case 'oblique':
884
+ validStyle = true;
885
+ cue.fontStyle = shaka.text.Cue.fontStyle.OBLIQUE;
886
+ break;
887
+ }
888
+
889
+ break;
890
+
891
+ case 'opacity':
892
+ validStyle = true;
893
+ cue.opacity = parseFloat(value);
894
+ break;
895
+
896
+ case 'text-combine-upright':
897
+ validStyle = true;
898
+ cue.textCombineUpright = value;
899
+ break;
900
+
901
+ case 'text-shadow':
902
+ validStyle = true;
903
+ cue.textShadow = value;
904
+ break;
905
+
906
+ case 'white-space':
907
+ validStyle = true;
908
+ cue.wrapLine = value != 'noWrap';
909
+ break;
910
+
911
+ default:
912
+ shaka.log.warning('VTT parser encountered an unsupported style: ', lineParts);
913
+ break;
914
+ }
915
+ }
916
+ }
917
+
918
+ if (validStyle) {
919
+ styles.set(styleSelector, cue);
920
+ }
921
+ }
922
+ }
923
+ /**
924
+ * Parses a text block into a Cue object.
925
+ *
926
+ * @param {!Array<string>} text
927
+ * @param {number} timeOffset
928
+ * @param {!Array<!shaka.text.CueRegion>} regions
929
+ * @param {!Map<string, !shaka.text.Cue>} styles
930
+ * @return {shaka.text.Cue}
931
+ * @private
932
+ */
933
+
934
+
935
+ static parseCue_(text, timeOffset, regions, styles) {
936
+ // Skip empty blocks.
937
+ if (text.length == 1 && !text[0]) {
938
+ return null;
939
+ } // Skip comment blocks.
940
+
941
+
942
+ if (/^NOTE($|[ \t])/.test(text[0])) {
943
+ return null;
944
+ } // Skip style and region blocks.
945
+
946
+
947
+ if (text[0] == 'STYLE' || text[0] == 'REGION') {
948
+ return null;
949
+ }
950
+
951
+ const skipIndex = text.findIndex(line => /^#/.test(line.trim()));
952
+
953
+ if (skipIndex > 0) {
954
+ text = text.slice(skipIndex);
955
+ }
956
+
957
+ if (text.length < 2) {
958
+ return;
959
+ }
960
+
961
+ let id = null;
962
+
963
+ if (!text[0].includes('-->')) {
964
+ id = text[0];
965
+ text.splice(0, 1);
966
+ } // Parse the times.
967
+
968
+
969
+ let [start, end] = text[0].split('-->').map(part => parseTime(part.trim()));
970
+
971
+ if (start == null || end == null) {
972
+ shaka.log.alwaysWarn('Failed to parse VTT time code. Cue skipped:', id, text);
973
+ return null;
974
+ }
975
+
976
+ start += timeOffset;
977
+ end += timeOffset; // Get the payload.
978
+
979
+ const payload = text.slice(1).join('\n').trim();
980
+ let cue = null;
981
+
982
+ if (styles.has('global')) {
983
+ cue = styles.get('global').clone();
984
+ cue.startTime = start;
985
+ cue.endTime = end;
986
+ cue.payload = payload;
987
+ } else {
988
+ cue = new shaka.text.Cue(start, end, payload);
989
+ } // Parse optional settings.
990
+
991
+
992
+ text[0].split(/\s+/g).slice(3).forEach(word => {
993
+ if (!word.trim()) {
994
+ return;
995
+ }
996
+
997
+ if (!VttTextParser.parseCueSetting(cue, word, regions)) {
998
+ shaka.log.warning('VTT parser encountered an invalid VTT setting: ', word, ' The setting will be ignored.');
999
+ }
1000
+ });
1001
+ shaka.text.Cue.parseCuePayload(cue, styles);
1002
+
1003
+ if (id != null) {
1004
+ cue.id = id;
1005
+ }
1006
+
1007
+ return cue;
1008
+ }
1009
+ /**
1010
+ * Parses a WebVTT setting from the given word.
1011
+ *
1012
+ * @param {!shaka.text.Cue} cue
1013
+ * @param {string} word
1014
+ * @param {!Array<!shaka.text.CueRegion>} regions
1015
+ * @return {boolean} True on success.
1016
+ */
1017
+
1018
+
1019
+ static parseCueSetting(cue, word, regions) {
1020
+ let results = null;
1021
+
1022
+ if (results = /^align:(start|middle|center|end|left|right)$/.exec(word)) {
1023
+ VttTextParser.setTextAlign_(cue, results[1]);
1024
+ } else if (results = /^vertical:(lr|rl)$/.exec(word)) {
1025
+ VttTextParser.setVerticalWritingMode_(cue, results[1]);
1026
+ } else if (results = /^size:([\d.]+)%$/.exec(word)) {
1027
+ cue.size = Number(results[1]);
1028
+ } else if (results = /^position:([\d.]+)%(?:,(line-left|line-right|middle|center|start|end|auto))?$/.exec(word)) {
1029
+ cue.position = Number(results[1]);
1030
+
1031
+ if (results[2]) {
1032
+ VttTextParser.setPositionAlign_(cue, results[2]);
1033
+ }
1034
+ } else if (results = /^region:(.*)$/.exec(word)) {
1035
+ const region = VttTextParser.getRegionById_(regions, results[1]);
1036
+
1037
+ if (region) {
1038
+ cue.region = region;
1039
+ }
1040
+ } else {
1041
+ return VttTextParser.parsedLineValueAndInterpretation_(cue, word);
1042
+ }
1043
+
1044
+ return true;
1045
+ }
1046
+ /**
1047
+ *
1048
+ * @param {!Array<!shaka.text.CueRegion>} regions
1049
+ * @param {string} id
1050
+ * @return {?shaka.text.CueRegion}
1051
+ * @private
1052
+ */
1053
+
1054
+
1055
+ static getRegionById_(regions, id) {
1056
+ const regionsWithId = regions.filter(region => region.id == id);
1057
+
1058
+ if (!regionsWithId.length) {
1059
+ shaka.log.warning('VTT parser could not find a region with id: ', id, ' The region will be ignored.');
1060
+ return null;
1061
+ }
1062
+
1063
+ goog$1.asserts.assert(regionsWithId.length == 1, 'VTTRegion ids should be unique!');
1064
+ return regionsWithId[0];
1065
+ }
1066
+ /**
1067
+ * @param {!shaka.text.Cue} cue
1068
+ * @param {string} align
1069
+ * @private
1070
+ */
1071
+
1072
+
1073
+ static setTextAlign_(cue, align) {
1074
+ const Cue = shaka.text.Cue;
1075
+
1076
+ if (align == 'middle') {
1077
+ cue.textAlign = Cue.textAlign.CENTER;
1078
+ } else {
1079
+ goog$1.asserts.assert(align.toUpperCase() in Cue.textAlign, `${align.toUpperCase()} Should be in Cue.textAlign values!`);
1080
+ cue.textAlign = Cue.textAlign[align.toUpperCase()];
1081
+ }
1082
+ }
1083
+ /**
1084
+ * @param {!shaka.text.Cue} cue
1085
+ * @param {string} align
1086
+ * @private
1087
+ */
1088
+
1089
+
1090
+ static setPositionAlign_(cue, align) {
1091
+ const Cue = shaka.text.Cue;
1092
+
1093
+ if (align == 'line-left' || align == 'start') {
1094
+ cue.positionAlign = Cue.positionAlign.LEFT;
1095
+ } else if (align == 'line-right' || align == 'end') {
1096
+ cue.positionAlign = Cue.positionAlign.RIGHT;
1097
+ } else if (align == 'center' || align == 'middle') {
1098
+ cue.positionAlign = Cue.positionAlign.CENTER;
1099
+ } else {
1100
+ cue.positionAlign = Cue.positionAlign.AUTO;
1101
+ }
1102
+ }
1103
+ /**
1104
+ * @param {!shaka.text.Cue} cue
1105
+ * @param {string} value
1106
+ * @private
1107
+ */
1108
+
1109
+
1110
+ static setVerticalWritingMode_(cue, value) {
1111
+ const Cue = shaka.text.Cue;
1112
+
1113
+ if (value == 'lr') {
1114
+ cue.writingMode = Cue.writingMode.VERTICAL_LEFT_TO_RIGHT;
1115
+ } else {
1116
+ cue.writingMode = Cue.writingMode.VERTICAL_RIGHT_TO_LEFT;
1117
+ }
1118
+ }
1119
+ /**
1120
+ * @param {!shaka.text.Cue} cue
1121
+ * @param {string} word
1122
+ * @return {boolean}
1123
+ * @private
1124
+ */
1125
+
1126
+
1127
+ static parsedLineValueAndInterpretation_(cue, word) {
1128
+ const Cue = shaka.text.Cue;
1129
+ let results = null;
1130
+
1131
+ if (results = /^line:([\d.]+)%(?:,(start|end|center))?$/.exec(word)) {
1132
+ cue.lineInterpretation = Cue.lineInterpretation.PERCENTAGE;
1133
+ cue.line = Number(results[1]);
1134
+
1135
+ if (results[2]) {
1136
+ goog$1.asserts.assert(results[2].toUpperCase() in Cue.lineAlign, `${results[2].toUpperCase()} Should be in Cue.lineAlign values!`);
1137
+ cue.lineAlign = Cue.lineAlign[results[2].toUpperCase()];
1138
+ }
1139
+ } else if (results = /^line:(-?\d+)(?:,(start|end|center))?$/.exec(word)) {
1140
+ cue.lineInterpretation = Cue.lineInterpretation.LINE_NUMBER;
1141
+ cue.line = Number(results[1]);
1142
+
1143
+ if (results[2]) {
1144
+ goog$1.asserts.assert(results[2].toUpperCase() in Cue.lineAlign, `${results[2].toUpperCase()} Should be in Cue.lineAlign values!`);
1145
+ cue.lineAlign = Cue.lineAlign[results[2].toUpperCase()];
1146
+ }
1147
+ } else {
1148
+ return false;
1149
+ }
1150
+
1151
+ return true;
1152
+ }
1153
+
1154
+ }
1155
+ /**
1156
+ * @const {number}
1157
+ * @private
1158
+ */
1159
+
1160
+
1161
+ VttTextParser.MPEG_TIMESCALE_ = 90000;
1162
+ /**
1163
+ * At this value, timestamps roll over in TS content.
1164
+ * @const {number}
1165
+ * @private
1166
+ */
1167
+
1168
+ VttTextParser.TS_ROLLOVER_ = 0x200000000;
1169
+
1170
+ VttTextParser.register = shakaNameSpace => {
1171
+ shakaNameSpace.text.TextEngine.registerParser('text/vtt', () => new VttTextParser());
1172
+ shakaNameSpace.text.TextEngine.registerParser('text/vtt; codecs="vtt"', () => new VttTextParser());
1173
+ shakaNameSpace.text.TextEngine.registerParser('text/vtt; codecs="wvtt"', () => new VttTextParser());
1174
+ };
1175
+
526
1176
  /*! @license
527
1177
  * Shaka Player
528
1178
  * Copyright 2016 Google LLC
@@ -1412,9 +2062,13 @@ class UITextDisplayer {
1412
2062
  } else if (cue.textAlign == Cue.textAlign.RIGHT || cue.textAlign == Cue.textAlign.END) {
1413
2063
  style.width = '100%';
1414
2064
  style.alignItems = 'end';
1415
- }
2065
+ } // in VTT displayAlign can't be set, it defaults to 'after',
2066
+ // but for vertical, it should be 'before'
2067
+
1416
2068
 
1417
- if (cue.displayAlign == Cue.displayAlign.BEFORE) {
2069
+ if (/vertical/.test(cue.writingMode)) {
2070
+ style.justifyContent = 'flex-start';
2071
+ } else if (cue.displayAlign == Cue.displayAlign.BEFORE) {
1418
2072
  style.justifyContent = 'flex-start';
1419
2073
  } else if (cue.displayAlign == Cue.displayAlign.CENTER) {
1420
2074
  style.justifyContent = 'center';
@@ -1787,6 +2441,7 @@ const loadShaka = async (videoElement, config = {}, options = {}) => {
1787
2441
  return getQualityItem(activeTrack);
1788
2442
  };
1789
2443
 
2444
+ VttTextParser.register(shaka);
1790
2445
  HttpFetchPlugin.register(shaka);
1791
2446
  const networkEngine = player.getNetworkingEngine();
1792
2447
  networkEngine.registerRequestFilter((type, request) => extensionOptions.requestHandlers.reduce((merged, handler) => handler(type, merged, player, extensionOptions), request));
@@ -1837,38 +2492,6 @@ const loadShaka = async (videoElement, config = {}, options = {}) => {
1837
2492
  return player;
1838
2493
  };
1839
2494
 
1840
- const timeoutError = () => new Error('request timeout');
1841
- /**
1842
- * @param {URL|RequestInfo} url
1843
- * @param {RequestInit} options
1844
- * @param {{responseType: 'json'|'text'}}
1845
- */
1846
-
1847
-
1848
- const retryRequest = (url, options = {}, {
1849
- responseType = 'json',
1850
- timeout = 6,
1851
- retryTimes = 6
1852
- } = {}) => new Promise((resolve, reject) => {
1853
- setTimeout(() => reject(timeoutError()), timeout * 1000);
1854
- fetch(url, options).then(response => {
1855
- var _response$responseTyp;
1856
-
1857
- return resolve(((_response$responseTyp = response[responseType]) === null || _response$responseTyp === void 0 ? void 0 : _response$responseTyp.call(response)) || response);
1858
- }).catch(reject);
1859
- }).catch(error => {
1860
- console.log(error);
1861
-
1862
- if (retryTimes > 0) {
1863
- return retryRequest(url, options, {
1864
- timeout,
1865
- retryTimes: retryTimes - 1
1866
- });
1867
- }
1868
-
1869
- return error;
1870
- });
1871
-
1872
2495
  const protocolExtensions = {
1873
2496
  hls: 'm3u8',
1874
2497
  dash: 'mpd'
@@ -2021,34 +2644,6 @@ const getDrmOptions = source => {
2021
2644
  }];
2022
2645
  };
2023
2646
 
2024
- /* eslint-disable no-param-reassign */
2025
-
2026
- const matchAll = (input, pattern) => {
2027
- const flags = [pattern.global && 'g', pattern.ignoreCase && 'i', pattern.multiline && 'm'].filter(Boolean).join('');
2028
- const clone = new RegExp(pattern, flags);
2029
- return Array.from(function* () {
2030
- let matched = true;
2031
-
2032
- while (1) {
2033
- matched = clone.exec(input);
2034
-
2035
- if (!matched) {
2036
- return;
2037
- }
2038
-
2039
- yield matched;
2040
- }
2041
- }());
2042
- };
2043
-
2044
- const getHlsQualityOptions = manifest => {
2045
- const resolutionList = matchAll(manifest, /RESOLUTION=\d+x(\d+)/g);
2046
- return Array.from(new Set(resolutionList.map(([, height]) => ({
2047
- height: +height
2048
- })))).sort((a, b) => b.height - a.height);
2049
- };
2050
- // for unit test
2051
-
2052
2647
  /* eslint-disable no-param-reassign */
2053
2648
  // when the gap is small enough, we consider it is on edge.
2054
2649
  // The magic number 10s comes from observation of YouTube
@@ -2062,7 +2657,7 @@ const isLiveDuration = duration => duration >= SHAKA_LIVE_DURATION;
2062
2657
  const isEnded = media => !isLiveDuration(media.initialDuration) && media.initialDuration - media.currentTime < 1; // When donwload bandwidth is low, Safari may report time update while buffering, ignore it.
2063
2658
 
2064
2659
 
2065
- const isBuffered = media => needNativeHls() || Array.from({
2660
+ const isBuffered = media => isSafari() || Array.from({
2066
2661
  length: media.buffered.length
2067
2662
  }, (_, index) => ({
2068
2663
  start: media.buffered.start(index),
@@ -2218,22 +2813,6 @@ const subscribePlaybackState = (media, updateState, {
2218
2813
  return () => registered.forEach(off => off());
2219
2814
  };
2220
2815
 
2221
- const tryPatchHlsVideoQualities = async (player, hlsUrl) => {
2222
- if (/(^data)|(mp4$)/.test(hlsUrl)) {
2223
- return;
2224
- } // filtered manifest comes with data URI and should be ignored
2225
-
2226
-
2227
- const manifest = await retryRequest(hlsUrl, {}, {
2228
- responseType: 'text'
2229
- }).catch(e => console.warn('Failed to get HLS video qualities', e));
2230
- const videoQualities = getHlsQualityOptions(manifest);
2231
-
2232
- if (videoQualities) {
2233
- player.getVariantTracks = () => videoQualities;
2234
- }
2235
- };
2236
-
2237
2816
  const seek = async (media, {
2238
2817
  player,
2239
2818
  plugins = []
@@ -2383,10 +2962,6 @@ const load = async (media, {
2383
2962
  loadStartTime = merged.startTime;
2384
2963
  }
2385
2964
 
2386
- if (needNativeHls() && merged.type === 'application/x-mpegurl') {
2387
- await tryPatchHlsVideoQualities(player, merged.src);
2388
- }
2389
-
2390
2965
  return player.unload().then(() => player.load(merged.src, loadStartTime, merged.type)).then(loadResult => {
2391
2966
  getSourceText(source).forEach(({
2392
2967
  src,
@@ -2458,7 +3033,7 @@ const loadPlayer = async (videoElement, {
2458
3033
  // TODO unsubscribe to release the video element
2459
3034
  // when resuming from background, video may play without no media events
2460
3035
  // on some iOS devices, pause again to workaround
2461
- if (!isIOS()) {
3036
+ if (isIOS()) {
2462
3037
  on(document, 'visibilitychange', () => setTimeout(() => videoElement.pause(), 50));
2463
3038
  }
2464
3039