hls.js 1.6.3-0.canary.11253 → 1.6.3-0.canary.11255

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/hls.js CHANGED
@@ -1165,7 +1165,7 @@
1165
1165
  // Some browsers don't allow to use bind on console object anyway
1166
1166
  // fallback to default if needed
1167
1167
  try {
1168
- newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.6.3-0.canary.11253");
1168
+ newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.6.3-0.canary.11255");
1169
1169
  } catch (e) {
1170
1170
  /* log fn threw an exception. All logger methods are no-ops. */
1171
1171
  return createLogger();
@@ -4695,7 +4695,6 @@
4695
4695
  if (PDTValue >= (endPDT || 0)) {
4696
4696
  return null;
4697
4697
  }
4698
- maxFragLookUpTolerance = maxFragLookUpTolerance || 0;
4699
4698
  for (var seg = 0; seg < fragments.length; ++seg) {
4700
4699
  var frag = fragments[seg];
4701
4700
  if (pdtWithinToleranceTest(PDTValue, maxFragLookUpTolerance, frag)) {
@@ -4821,38 +4820,32 @@
4821
4820
  var endProgramDateTime = candidate.endProgramDateTime || 0;
4822
4821
  return endProgramDateTime - candidateLookupTolerance > pdtBufferEnd;
4823
4822
  }
4824
- function findFragWithCC(fragments, cc) {
4825
- return BinarySearch.search(fragments, function (candidate) {
4826
- if (candidate.cc < cc) {
4827
- return 1;
4828
- } else if (candidate.cc > cc) {
4829
- return -1;
4830
- } else {
4831
- return 0;
4832
- }
4833
- });
4834
- }
4835
- function findNearestWithCC(details, cc, fragment) {
4823
+ function findNearestWithCC(details, cc, pos) {
4836
4824
  if (details) {
4837
4825
  if (details.startCC <= cc && details.endCC >= cc) {
4838
- var start = fragment.start;
4839
- var end = fragment.end;
4840
4826
  var fragments = details.fragments;
4841
- if (!fragment.relurl) {
4842
- var fragmentHint = details.fragmentHint;
4843
- if (fragmentHint) {
4844
- fragments = fragments.concat(fragmentHint);
4845
- }
4827
+ var fragmentHint = details.fragmentHint;
4828
+ if (fragmentHint) {
4829
+ fragments = fragments.concat(fragmentHint);
4846
4830
  }
4847
- return BinarySearch.search(fragments, function (candidate) {
4848
- if (candidate.cc < cc || candidate.end <= start) {
4831
+ var closest;
4832
+ BinarySearch.search(fragments, function (candidate) {
4833
+ if (candidate.cc < cc) {
4849
4834
  return 1;
4850
- } else if (candidate.cc > cc || candidate.start >= end) {
4835
+ }
4836
+ if (candidate.cc > cc) {
4851
4837
  return -1;
4852
- } else {
4853
- return 0;
4854
4838
  }
4839
+ closest = candidate;
4840
+ if (candidate.end <= pos) {
4841
+ return 1;
4842
+ }
4843
+ if (candidate.start > pos) {
4844
+ return -1;
4845
+ }
4846
+ return 0;
4855
4847
  });
4848
+ return closest || null;
4856
4849
  }
4857
4850
  }
4858
4851
  return null;
@@ -9612,8 +9605,11 @@
9612
9605
  if (this.fragCurrent === null) {
9613
9606
  keyLoadingPromise = Promise.reject(new Error("frag load aborted, context changed in KEY_LOADING"));
9614
9607
  }
9615
- } else if (!frag.encrypted && details.encryptedFragments.length) {
9616
- this.keyLoader.loadClear(frag, details.encryptedFragments);
9608
+ } else if (!frag.encrypted) {
9609
+ keyLoadingPromise = this.keyLoader.loadClear(frag, details.encryptedFragments);
9610
+ if (keyLoadingPromise) {
9611
+ this.log("[eme] blocking frag load until media-keys acquired");
9612
+ }
9617
9613
  }
9618
9614
  var fragPrevious = this.fragPrevious;
9619
9615
  if (isMediaFragment(frag) && (!fragPrevious || frag.sn !== fragPrevious.sn)) {
@@ -9969,7 +9965,7 @@
9969
9965
  this.log("LL-Part loading ON for initial live fragment");
9970
9966
  this.loadingParts = true;
9971
9967
  }
9972
- frag = this.getInitialLiveFragment(levelDetails, fragments);
9968
+ frag = this.getInitialLiveFragment(levelDetails);
9973
9969
  var mainStart = this.hls.startPosition;
9974
9970
  var liveSyncPosition = this.hls.liveSyncPosition;
9975
9971
  var startPosition = frag ? (mainStart !== -1 && mainStart >= start ? mainStart : liveSyncPosition) || frag.start : pos;
@@ -10099,7 +10095,8 @@
10099
10095
  "sliding" of the playlist, which is its offset from the start of playback. After sliding we can compute the real
10100
10096
  start and end times for each fragment in the playlist (after which this method will not need to be called).
10101
10097
  */;
10102
- _proto.getInitialLiveFragment = function getInitialLiveFragment(levelDetails, fragments) {
10098
+ _proto.getInitialLiveFragment = function getInitialLiveFragment(levelDetails) {
10099
+ var fragments = levelDetails.fragments;
10103
10100
  var fragPrevious = this.fragPrevious;
10104
10101
  var frag = null;
10105
10102
  if (fragPrevious) {
@@ -10122,7 +10119,7 @@
10122
10119
  // It's important to stay within the continuity range if available; otherwise the fragments in the playlist
10123
10120
  // will have the wrong start times
10124
10121
  if (!frag) {
10125
- frag = findFragWithCC(fragments, fragPrevious.cc);
10122
+ frag = findNearestWithCC(levelDetails, fragPrevious.cc, fragPrevious.end);
10126
10123
  if (frag) {
10127
10124
  this.log("Live playlist, switching playlist, load frag with same CC: " + frag.sn);
10128
10125
  }
@@ -16677,7 +16674,7 @@
16677
16674
  return !remuxResult.audio && !remuxResult.video && !remuxResult.text && !remuxResult.id3 && !remuxResult.initSegment;
16678
16675
  }
16679
16676
 
16680
- var version = "1.6.3-0.canary.11253";
16677
+ var version = "1.6.3-0.canary.11255";
16681
16678
 
16682
16679
  // ensure the worker ends up in the bundle
16683
16680
  // If the worker should not be included this gets aliased to empty.js
@@ -17133,23 +17130,46 @@
17133
17130
  if (this.state === State.WAITING_INIT_PTS) {
17134
17131
  var waitingData = this.waitingData;
17135
17132
  if (!waitingData && !this.loadingParts || waitingData && waitingData.frag.cc !== cc) {
17136
- this.nextLoadPosition = this.findSyncFrag(frag).start;
17133
+ this.syncWithAnchor(frag, waitingData == null ? void 0 : waitingData.frag);
17137
17134
  }
17138
- this.tick();
17139
17135
  } else if (!this.hls.hasEnoughToStart && inFlightFrag && inFlightFrag.cc !== cc) {
17140
- this.startFragRequested = false;
17141
- this.nextLoadPosition = this.findSyncFrag(frag).start;
17142
17136
  inFlightFrag.abortRequests();
17143
- this.resetLoadingState();
17137
+ this.syncWithAnchor(frag, inFlightFrag);
17144
17138
  } else if (this.state === State.IDLE) {
17145
17139
  this.tick();
17146
17140
  }
17147
17141
  }
17148
17142
  };
17149
- _proto.findSyncFrag = function findSyncFrag(mainFrag) {
17143
+ _proto.getLoadPosition = function getLoadPosition() {
17144
+ if (!this.startFragRequested && this.nextLoadPosition >= 0) {
17145
+ return this.nextLoadPosition;
17146
+ }
17147
+ return _BaseStreamController.prototype.getLoadPosition.call(this);
17148
+ };
17149
+ _proto.syncWithAnchor = function syncWithAnchor(mainAnchor, waitingToAppend) {
17150
+ var _this$mainFragLoading;
17151
+ // Drop waiting fragment if videoTrackCC has changed since waitingFragment was set and initPTS was not found
17152
+ var mainFragLoading = ((_this$mainFragLoading = this.mainFragLoading) == null ? void 0 : _this$mainFragLoading.frag) || null;
17153
+ if (waitingToAppend) {
17154
+ if ((mainFragLoading == null ? void 0 : mainFragLoading.cc) === waitingToAppend.cc) {
17155
+ // Wait for loading frag to complete and INIT_PTS_FOUND
17156
+ return;
17157
+ }
17158
+ }
17159
+ var targetDiscontinuity = (mainFragLoading || mainAnchor).cc;
17150
17160
  var trackDetails = this.getLevelDetails();
17151
- var cc = mainFrag.cc;
17152
- return findNearestWithCC(trackDetails, cc, mainFrag) || trackDetails && findFragWithCC(trackDetails.fragments, cc) || mainFrag;
17161
+ var pos = this.getLoadPosition();
17162
+ var syncFrag = findNearestWithCC(trackDetails, targetDiscontinuity, pos);
17163
+ // Only stop waiting for audioFrag.cc if an audio segment of the same discontinuity domain (cc) is found
17164
+ if (syncFrag) {
17165
+ this.log("Waiting fragment cc (" + (waitingToAppend == null ? void 0 : waitingToAppend.cc) + ") cancelled because video is at cc " + mainAnchor.cc);
17166
+ this.startFragRequested = false;
17167
+ this.nextLoadPosition = syncFrag.start;
17168
+ this.resetLoadingState();
17169
+ if (this.state === State.IDLE) {
17170
+ this.doTickIdle();
17171
+ }
17172
+ }
17153
17173
  };
17154
17174
  _proto.startLoad = function startLoad(startPosition, skipSeekToStartPosition) {
17155
17175
  if (!this.levels) {
@@ -17230,10 +17250,7 @@
17230
17250
  _BaseStreamController.prototype._handleFragmentLoadComplete.call(this, data);
17231
17251
  }
17232
17252
  } else if (mainAnchor && mainAnchor.cc !== waitingData.frag.cc) {
17233
- // Drop waiting fragment if videoTrackCC has changed since waitingFragment was set and initPTS was not found
17234
- this.log("Waiting fragment cc (" + frag.cc + ") cancelled because video is at cc " + mainAnchor.cc);
17235
- this.nextLoadPosition = this.findSyncFrag(mainAnchor).start;
17236
- this.clearWaitingFragment();
17253
+ this.syncWithAnchor(mainAnchor, waitingData.frag);
17237
17254
  }
17238
17255
  } else {
17239
17256
  this.state = State.IDLE;
@@ -17242,22 +17259,12 @@
17242
17259
  }
17243
17260
  this.onTickEnd();
17244
17261
  };
17245
- _proto.clearWaitingFragment = function clearWaitingFragment() {
17262
+ _proto.resetLoadingState = function resetLoadingState() {
17246
17263
  var waitingData = this.waitingData;
17247
17264
  if (waitingData) {
17248
- if (!this.hls.hasEnoughToStart) {
17249
- // Load overlapping fragment on start when discontinuity start times are not aligned
17250
- this.startFragRequested = false;
17251
- }
17252
17265
  this.fragmentTracker.removeFragment(waitingData.frag);
17253
17266
  this.waitingData = null;
17254
- if (this.state !== State.STOPPED) {
17255
- this.state = State.IDLE;
17256
- }
17257
17267
  }
17258
- };
17259
- _proto.resetLoadingState = function resetLoadingState() {
17260
- this.clearWaitingFragment();
17261
17268
  _BaseStreamController.prototype.resetLoadingState.call(this);
17262
17269
  };
17263
17270
  _proto.onTickEnd = function onTickEnd() {
@@ -17269,7 +17276,7 @@
17269
17276
  this.lastCurrentTime = media.currentTime;
17270
17277
  };
17271
17278
  _proto.doTickIdle = function doTickIdle() {
17272
- var _this$mainFragLoading;
17279
+ var _this$mainFragLoading2;
17273
17280
  var hls = this.hls,
17274
17281
  levels = this.levels,
17275
17282
  media = this.media,
@@ -17341,7 +17348,7 @@
17341
17348
  }
17342
17349
 
17343
17350
  // Request audio segments up to one fragment ahead of main stream-controller
17344
- var mainFragLoading = ((_this$mainFragLoading = this.mainFragLoading) == null ? void 0 : _this$mainFragLoading.frag) || null;
17351
+ var mainFragLoading = ((_this$mainFragLoading2 = this.mainFragLoading) == null ? void 0 : _this$mainFragLoading2.frag) || null;
17345
17352
  if (!this.audioOnly && this.startFragRequested && mainFragLoading && isMediaFragment(frag) && !frag.endList && (!trackDetails.live || !this.loadingParts && targetBufferTime < this.hls.liveSyncPosition)) {
17346
17353
  if (this.fragmentTracker.getState(mainFragLoading) === FragmentState.OK) {
17347
17354
  this.mainFragLoading = mainFragLoading = null;
@@ -22534,6 +22541,7 @@
22534
22541
  _this4.log("Create media-keys for \"" + keySystem + "\"");
22535
22542
  _keySystemAccessPromises.mediaKeys = mediaKeySystemAccess.createMediaKeys().then(function (mediaKeys) {
22536
22543
  _this4.log("Media-keys created for \"" + keySystem + "\"");
22544
+ _keySystemAccessPromises.hasMediaKeys = true;
22537
22545
  return certificateRequest.then(function (certificate) {
22538
22546
  if (certificate) {
22539
22547
  return _this4.setMediaKeysServerCertificate(mediaKeys, keySystem, certificate);
@@ -22594,23 +22602,36 @@
22594
22602
  this.log("Updating key-session \"" + keySession.sessionId + "\" for keyID " + Hex.hexDump(((_mediaKeySessionConte = mediaKeySessionContext.decryptdata) == null ? void 0 : _mediaKeySessionConte.keyId) || []) + "\n } (data length: " + (data ? data.byteLength : data) + ")");
22595
22603
  return keySession.update(data);
22596
22604
  };
22597
- _proto.selectKeySystemFormat = function selectKeySystemFormat(frag) {
22598
- var keyFormats = Object.keys(frag.levelkeys || {});
22599
- if (!this.keyFormatPromise) {
22600
- this.log("Selecting key-system from fragment (sn: " + frag.sn + " " + frag.type + ": " + frag.level + ") key formats " + keyFormats.join(', '));
22601
- this.keyFormatPromise = this.getKeyFormatPromise(keyFormats);
22602
- }
22603
- return this.keyFormatPromise;
22604
- };
22605
- _proto.getKeyFormatPromise = function getKeyFormatPromise(keyFormats) {
22605
+ _proto.getSelectedKeySystemFormats = function getSelectedKeySystemFormats() {
22606
22606
  var _this5 = this;
22607
+ return Object.keys(this.keySystemAccessPromises).map(function (keySystem) {
22608
+ return {
22609
+ keySystem: keySystem,
22610
+ hasMediaKeys: _this5.keySystemAccessPromises[keySystem].hasMediaKeys
22611
+ };
22612
+ }).filter(function (_ref3) {
22613
+ var hasMediaKeys = _ref3.hasMediaKeys;
22614
+ return !!hasMediaKeys;
22615
+ }).map(function (_ref4) {
22616
+ var keySystem = _ref4.keySystem;
22617
+ return keySystemDomainToKeySystemFormat(keySystem);
22618
+ }).filter(function (keySystem) {
22619
+ return !!keySystem;
22620
+ });
22621
+ };
22622
+ _proto.getKeySystemAccess = function getKeySystemAccess(keySystemsToAttempt) {
22623
+ var _this6 = this;
22624
+ return this.getKeySystemSelectionPromise(keySystemsToAttempt).then(function (_ref5) {
22625
+ var keySystem = _ref5.keySystem,
22626
+ mediaKeys = _ref5.mediaKeys;
22627
+ return _this6.attemptSetMediaKeys(keySystem, mediaKeys);
22628
+ });
22629
+ };
22630
+ _proto.selectKeySystem = function selectKeySystem(keySystemsToAttempt) {
22631
+ var _this7 = this;
22607
22632
  return new Promise(function (resolve, reject) {
22608
- var keySystemsInConfig = getKeySystemsForConfig(_this5.config);
22609
- var keySystemsToAttempt = keyFormats.map(keySystemFormatToKeySystemDomain).filter(function (value) {
22610
- return !!value && keySystemsInConfig.indexOf(value) !== -1;
22611
- });
22612
- return _this5.getKeySystemSelectionPromise(keySystemsToAttempt).then(function (_ref3) {
22613
- var keySystem = _ref3.keySystem;
22633
+ return _this7.getKeySystemSelectionPromise(keySystemsToAttempt).then(function (_ref6) {
22634
+ var keySystem = _ref6.keySystem;
22614
22635
  var keySystemFormat = keySystemDomainToKeySystemFormat(keySystem);
22615
22636
  if (keySystemFormat) {
22616
22637
  resolve(keySystemFormat);
@@ -22620,22 +22641,37 @@
22620
22641
  }).catch(reject);
22621
22642
  });
22622
22643
  };
22644
+ _proto.selectKeySystemFormat = function selectKeySystemFormat(frag) {
22645
+ var keyFormats = Object.keys(frag.levelkeys || {});
22646
+ if (!this.keyFormatPromise) {
22647
+ this.log("Selecting key-system from fragment (sn: " + frag.sn + " " + frag.type + ": " + frag.level + ") key formats " + keyFormats.join(', '));
22648
+ this.keyFormatPromise = this.getKeyFormatPromise(keyFormats);
22649
+ }
22650
+ return this.keyFormatPromise;
22651
+ };
22652
+ _proto.getKeyFormatPromise = function getKeyFormatPromise(keyFormats) {
22653
+ var keySystemsInConfig = getKeySystemsForConfig(this.config);
22654
+ var keySystemsToAttempt = keyFormats.map(keySystemFormatToKeySystemDomain).filter(function (value) {
22655
+ return !!value && keySystemsInConfig.indexOf(value) !== -1;
22656
+ });
22657
+ return this.selectKeySystem(keySystemsToAttempt);
22658
+ };
22623
22659
  _proto.loadKey = function loadKey(data) {
22624
- var _this6 = this;
22660
+ var _this8 = this;
22625
22661
  var decryptdata = data.keyInfo.decryptdata;
22626
22662
  var keyId = this.getKeyIdString(decryptdata);
22627
22663
  var keyDetails = "(keyId: " + keyId + " format: \"" + decryptdata.keyFormat + "\" method: " + decryptdata.method + " uri: " + decryptdata.uri + ")";
22628
22664
  this.log("Starting session for key " + keyDetails);
22629
22665
  var keyContextPromise = this.keyIdToKeySessionPromise[keyId];
22630
22666
  if (!keyContextPromise) {
22631
- keyContextPromise = this.getKeySystemForKeyPromise(decryptdata).then(function (_ref4) {
22632
- var keySystem = _ref4.keySystem,
22633
- mediaKeys = _ref4.mediaKeys;
22634
- _this6.throwIfDestroyed();
22635
- _this6.log("Handle encrypted media sn: " + data.frag.sn + " " + data.frag.type + ": " + data.frag.level + " using key " + keyDetails);
22636
- return _this6.attemptSetMediaKeys(keySystem, mediaKeys).then(function () {
22637
- _this6.throwIfDestroyed();
22638
- return _this6.createMediaKeySessionContext({
22667
+ keyContextPromise = this.getKeySystemForKeyPromise(decryptdata).then(function (_ref7) {
22668
+ var keySystem = _ref7.keySystem,
22669
+ mediaKeys = _ref7.mediaKeys;
22670
+ _this8.throwIfDestroyed();
22671
+ _this8.log("Handle encrypted media sn: " + data.frag.sn + " " + data.frag.type + ": " + data.frag.level + " using key " + keyDetails);
22672
+ return _this8.attemptSetMediaKeys(keySystem, mediaKeys).then(function () {
22673
+ _this8.throwIfDestroyed();
22674
+ return _this8.createMediaKeySessionContext({
22639
22675
  keySystem: keySystem,
22640
22676
  mediaKeys: mediaKeys,
22641
22677
  decryptdata: decryptdata
@@ -22645,10 +22681,10 @@
22645
22681
  var keySessionContextPromise = this.keyIdToKeySessionPromise[keyId] = keyContextPromise.then(function (keySessionContext) {
22646
22682
  var scheme = 'cenc';
22647
22683
  var initData = decryptdata.pssh ? decryptdata.pssh.buffer : null;
22648
- return _this6.generateRequestWithPreferredKeySession(keySessionContext, scheme, initData, 'playlist-key');
22684
+ return _this8.generateRequestWithPreferredKeySession(keySessionContext, scheme, initData, 'playlist-key');
22649
22685
  });
22650
22686
  keySessionContextPromise.catch(function (error) {
22651
- return _this6.handleError(error);
22687
+ return _this8.handleError(error);
22652
22688
  });
22653
22689
  }
22654
22690
  return keyContextPromise;
@@ -22700,22 +22736,22 @@
22700
22736
  return this.attemptKeySystemAccess(keySystemsToAttempt);
22701
22737
  };
22702
22738
  _proto.attemptSetMediaKeys = function attemptSetMediaKeys(keySystem, mediaKeys) {
22703
- var _this7 = this;
22739
+ var _this9 = this;
22704
22740
  var queue = this.setMediaKeysQueue.slice();
22705
22741
  this.log("Setting media-keys for \"" + keySystem + "\"");
22706
22742
  // Only one setMediaKeys() can run at one time, and multiple setMediaKeys() operations
22707
22743
  // can be queued for execution for multiple key sessions.
22708
22744
  var setMediaKeysPromise = Promise.all(queue).then(function () {
22709
- if (!_this7.media) {
22745
+ if (!_this9.media) {
22710
22746
  throw new Error('Attempted to set mediaKeys without media element attached');
22711
22747
  }
22712
- return _this7.media.setMediaKeys(mediaKeys);
22748
+ return _this9.media.setMediaKeys(mediaKeys);
22713
22749
  });
22714
22750
  this.setMediaKeysQueue.push(setMediaKeysPromise);
22715
22751
  return setMediaKeysPromise.then(function () {
22716
- _this7.log("Media-keys set for \"" + keySystem + "\"");
22752
+ _this9.log("Media-keys set for \"" + keySystem + "\"");
22717
22753
  queue.push(setMediaKeysPromise);
22718
- _this7.setMediaKeysQueue = _this7.setMediaKeysQueue.filter(function (p) {
22754
+ _this9.setMediaKeysQueue = _this9.setMediaKeysQueue.filter(function (p) {
22719
22755
  return queue.indexOf(p) === -1;
22720
22756
  });
22721
22757
  });
@@ -22723,7 +22759,7 @@
22723
22759
  _proto.generateRequestWithPreferredKeySession = function generateRequestWithPreferredKeySession(context, initDataType, initData, reason) {
22724
22760
  var _this$config$drmSyste,
22725
22761
  _this$config$drmSyste2,
22726
- _this8 = this;
22762
+ _this0 = this;
22727
22763
  var generateRequestFilter = (_this$config$drmSyste = this.config.drmSystems) == null ? void 0 : (_this$config$drmSyste2 = _this$config$drmSyste[context.keySystem]) == null ? void 0 : _this$config$drmSyste2.generateRequest;
22728
22764
  if (generateRequestFilter) {
22729
22765
  try {
@@ -22757,22 +22793,22 @@
22757
22793
  }
22758
22794
  var messageType = event.messageType,
22759
22795
  message = event.message;
22760
- _this8.log("\"" + messageType + "\" message event for session \"" + keySession.sessionId + "\" message size: " + message.byteLength);
22796
+ _this0.log("\"" + messageType + "\" message event for session \"" + keySession.sessionId + "\" message size: " + message.byteLength);
22761
22797
  if (messageType === 'license-request' || messageType === 'license-renewal') {
22762
- _this8.renewLicense(context, message).catch(function (error) {
22798
+ _this0.renewLicense(context, message).catch(function (error) {
22763
22799
  if (licenseStatus.eventNames().length) {
22764
22800
  licenseStatus.emit('error', error);
22765
22801
  } else {
22766
- _this8.handleError(error);
22802
+ _this0.handleError(error);
22767
22803
  }
22768
22804
  });
22769
22805
  } else if (messageType === 'license-release') {
22770
22806
  if (context.keySystem === KeySystems.FAIRPLAY) {
22771
- _this8.updateKeySession(context, strToUtf8array('acknowledged'));
22772
- _this8.removeSession(context);
22807
+ _this0.updateKeySession(context, strToUtf8array('acknowledged'));
22808
+ _this0.removeSession(context);
22773
22809
  }
22774
22810
  } else {
22775
- _this8.warn("unhandled media key message type \"" + messageType + "\"");
22811
+ _this0.warn("unhandled media key message type \"" + messageType + "\"");
22776
22812
  }
22777
22813
  };
22778
22814
  var onkeystatuseschange = context._onkeystatuseschange = function (event) {
@@ -22781,12 +22817,12 @@
22781
22817
  licenseStatus.emit('error', new Error('invalid state'));
22782
22818
  return;
22783
22819
  }
22784
- _this8.onKeyStatusChange(context);
22820
+ _this0.onKeyStatusChange(context);
22785
22821
  var keyStatus = context.keyStatus;
22786
22822
  licenseStatus.emit('keyStatus', keyStatus);
22787
22823
  if (keyStatus === 'expired') {
22788
- _this8.warn(context.keySystem + " expired for key " + keyId);
22789
- _this8.renewKeySession(context);
22824
+ _this0.warn(context.keySystem + " expired for key " + keyId);
22825
+ _this0.renewKeySession(context);
22790
22826
  }
22791
22827
  };
22792
22828
  context.mediaKeysSession.addEventListener('message', onmessage);
@@ -22811,13 +22847,13 @@
22811
22847
  } else if (keyStatus === 'expired') {
22812
22848
  reject(new Error('key expired while generating request'));
22813
22849
  } else {
22814
- _this8.warn("unhandled key status change \"" + keyStatus + "\"");
22850
+ _this0.warn("unhandled key status change \"" + keyStatus + "\"");
22815
22851
  }
22816
22852
  });
22817
22853
  });
22818
22854
  return context.mediaKeysSession.generateRequest(initDataType, initData).then(function () {
22819
22855
  var _context$mediaKeysSes;
22820
- _this8.log("Request generated for key-session \"" + ((_context$mediaKeysSes = context.mediaKeysSession) == null ? void 0 : _context$mediaKeysSes.sessionId) + "\" keyId: " + keyId);
22856
+ _this0.log("Request generated for key-session \"" + ((_context$mediaKeysSes = context.mediaKeysSession) == null ? void 0 : _context$mediaKeysSes.sessionId) + "\" keyId: " + keyId);
22821
22857
  }).catch(function (error) {
22822
22858
  throw new EMEKeyError({
22823
22859
  type: ErrorTypes.KEY_SYSTEM_ERROR,
@@ -22829,7 +22865,7 @@
22829
22865
  return keyUsablePromise;
22830
22866
  }).catch(function (error) {
22831
22867
  licenseStatus.removeAllListeners();
22832
- _this8.removeSession(context);
22868
+ _this0.removeSession(context);
22833
22869
  throw error;
22834
22870
  }).then(function () {
22835
22871
  licenseStatus.removeAllListeners();
@@ -22837,7 +22873,7 @@
22837
22873
  });
22838
22874
  };
22839
22875
  _proto.onKeyStatusChange = function onKeyStatusChange(mediaKeySessionContext) {
22840
- var _this9 = this;
22876
+ var _this1 = this;
22841
22877
  mediaKeySessionContext.mediaKeysSession.keyStatuses.forEach(function (status, keyId) {
22842
22878
  // keyStatuses.forEach is not standard API so the callback value looks weird on xboxone
22843
22879
  // xboxone callback(keyId, status) so we need to exchange them
@@ -22846,7 +22882,7 @@
22846
22882
  keyId = status;
22847
22883
  status = temp;
22848
22884
  }
22849
- _this9.log("key status change \"" + status + "\" for keyStatuses keyId: " + Hex.hexDump('buffer' in keyId ? new Uint8Array(keyId.buffer, keyId.byteOffset, keyId.byteLength) : new Uint8Array(keyId)) + " session keyId: " + Hex.hexDump(new Uint8Array(mediaKeySessionContext.decryptdata.keyId || [])) + " uri: " + mediaKeySessionContext.decryptdata.uri);
22885
+ _this1.log("key status change \"" + status + "\" for keyStatuses keyId: " + Hex.hexDump('buffer' in keyId ? new Uint8Array(keyId.buffer, keyId.byteOffset, keyId.byteLength) : new Uint8Array(keyId)) + " session keyId: " + Hex.hexDump(new Uint8Array(mediaKeySessionContext.decryptdata.keyId || [])) + " uri: " + mediaKeySessionContext.decryptdata.uri);
22850
22886
  mediaKeySessionContext.keyStatus = status;
22851
22887
  });
22852
22888
  };
@@ -22908,10 +22944,10 @@
22908
22944
  });
22909
22945
  };
22910
22946
  _proto.setMediaKeysServerCertificate = function setMediaKeysServerCertificate(mediaKeys, keySystem, cert) {
22911
- var _this0 = this;
22947
+ var _this10 = this;
22912
22948
  return new Promise(function (resolve, reject) {
22913
22949
  mediaKeys.setServerCertificate(cert).then(function (success) {
22914
- _this0.log("setServerCertificate " + (success ? 'success' : 'not supported by CDM') + " (" + (cert == null ? void 0 : cert.byteLength) + ") on \"" + keySystem + "\"");
22950
+ _this10.log("setServerCertificate " + (success ? 'success' : 'not supported by CDM') + " (" + (cert == null ? void 0 : cert.byteLength) + ") on \"" + keySystem + "\"");
22915
22951
  resolve(mediaKeys);
22916
22952
  }).catch(function (error) {
22917
22953
  reject(new EMEKeyError({
@@ -22924,9 +22960,9 @@
22924
22960
  });
22925
22961
  };
22926
22962
  _proto.renewLicense = function renewLicense(context, keyMessage) {
22927
- var _this1 = this;
22963
+ var _this11 = this;
22928
22964
  return this.requestLicense(context, new Uint8Array(keyMessage)).then(function (data) {
22929
- return _this1.updateKeySession(context, new Uint8Array(data)).catch(function (error) {
22965
+ return _this11.updateKeySession(context, new Uint8Array(data)).catch(function (error) {
22930
22966
  throw new EMEKeyError({
22931
22967
  type: ErrorTypes.KEY_SYSTEM_ERROR,
22932
22968
  details: ErrorDetails.KEY_SYSTEM_SESSION_UPDATE_FAILED,
@@ -22974,7 +23010,7 @@
22974
23010
  return strToUtf8array(atob(challengeText));
22975
23011
  };
22976
23012
  _proto.setupLicenseXHR = function setupLicenseXHR(xhr, url, keysListItem, licenseChallenge) {
22977
- var _this10 = this;
23013
+ var _this12 = this;
22978
23014
  var licenseXhrSetup = this.config.licenseXhrSetup;
22979
23015
  if (!licenseXhrSetup) {
22980
23016
  xhr.open('POST', url, true);
@@ -22987,7 +23023,7 @@
22987
23023
  if (!keysListItem.decryptdata) {
22988
23024
  throw new Error('Key removed');
22989
23025
  }
22990
- return licenseXhrSetup.call(_this10.hls, xhr, url, keysListItem, licenseChallenge);
23026
+ return licenseXhrSetup.call(_this12.hls, xhr, url, keysListItem, licenseChallenge);
22991
23027
  }).catch(function (error) {
22992
23028
  if (!keysListItem.decryptdata) {
22993
23029
  // Key session removed. Cancel license request.
@@ -22995,7 +23031,7 @@
22995
23031
  }
22996
23032
  // let's try to open before running setup
22997
23033
  xhr.open('POST', url, true);
22998
- return licenseXhrSetup.call(_this10.hls, xhr, url, keysListItem, licenseChallenge);
23034
+ return licenseXhrSetup.call(_this12.hls, xhr, url, keysListItem, licenseChallenge);
22999
23035
  }).then(function (licenseXhrSetupResult) {
23000
23036
  // if licenseXhrSetup did not yet call open, let's do it now
23001
23037
  if (!xhr.readyState) {
@@ -23009,36 +23045,36 @@
23009
23045
  });
23010
23046
  };
23011
23047
  _proto.requestLicense = function requestLicense(keySessionContext, licenseChallenge) {
23012
- var _this11 = this;
23048
+ var _this13 = this;
23013
23049
  var keyLoadPolicy = this.config.keyLoadPolicy.default;
23014
23050
  return new Promise(function (resolve, reject) {
23015
- var url = _this11.getLicenseServerUrlOrThrow(keySessionContext.keySystem);
23016
- _this11.log("Sending license request to URL: " + url);
23051
+ var url = _this13.getLicenseServerUrlOrThrow(keySessionContext.keySystem);
23052
+ _this13.log("Sending license request to URL: " + url);
23017
23053
  var xhr = new XMLHttpRequest();
23018
23054
  xhr.responseType = 'arraybuffer';
23019
23055
  xhr.onreadystatechange = function () {
23020
- if (!_this11.hls || !keySessionContext.mediaKeysSession) {
23056
+ if (!_this13.hls || !keySessionContext.mediaKeysSession) {
23021
23057
  return reject(new Error('invalid state'));
23022
23058
  }
23023
23059
  if (xhr.readyState === 4) {
23024
23060
  if (xhr.status === 200) {
23025
- _this11._requestLicenseFailureCount = 0;
23061
+ _this13._requestLicenseFailureCount = 0;
23026
23062
  var data = xhr.response;
23027
- _this11.log("License received " + (data instanceof ArrayBuffer ? data.byteLength : data));
23028
- var licenseResponseCallback = _this11.config.licenseResponseCallback;
23063
+ _this13.log("License received " + (data instanceof ArrayBuffer ? data.byteLength : data));
23064
+ var licenseResponseCallback = _this13.config.licenseResponseCallback;
23029
23065
  if (licenseResponseCallback) {
23030
23066
  try {
23031
- data = licenseResponseCallback.call(_this11.hls, xhr, url, keySessionContext);
23067
+ data = licenseResponseCallback.call(_this13.hls, xhr, url, keySessionContext);
23032
23068
  } catch (error) {
23033
- _this11.error(error);
23069
+ _this13.error(error);
23034
23070
  }
23035
23071
  }
23036
23072
  resolve(data);
23037
23073
  } else {
23038
23074
  var retryConfig = keyLoadPolicy.errorRetry;
23039
23075
  var maxNumRetry = retryConfig ? retryConfig.maxNumRetry : 0;
23040
- _this11._requestLicenseFailureCount++;
23041
- if (_this11._requestLicenseFailureCount > maxNumRetry || xhr.status >= 400 && xhr.status < 500) {
23076
+ _this13._requestLicenseFailureCount++;
23077
+ if (_this13._requestLicenseFailureCount > maxNumRetry || xhr.status >= 400 && xhr.status < 500) {
23042
23078
  reject(new EMEKeyError({
23043
23079
  type: ErrorTypes.KEY_SYSTEM_ERROR,
23044
23080
  details: ErrorDetails.KEY_SYSTEM_LICENSE_REQUEST_FAILED,
@@ -23052,9 +23088,9 @@
23052
23088
  }
23053
23089
  }, "License Request XHR failed (" + url + "). Status: " + xhr.status + " (" + xhr.statusText + ")"));
23054
23090
  } else {
23055
- var attemptsLeft = maxNumRetry - _this11._requestLicenseFailureCount + 1;
23056
- _this11.warn("Retrying license request, " + attemptsLeft + " attempts left");
23057
- _this11.requestLicense(keySessionContext, licenseChallenge).then(resolve, reject);
23091
+ var attemptsLeft = maxNumRetry - _this13._requestLicenseFailureCount + 1;
23092
+ _this13.warn("Retrying license request, " + attemptsLeft + " attempts left");
23093
+ _this13.requestLicense(keySessionContext, licenseChallenge).then(resolve, reject);
23058
23094
  }
23059
23095
  }
23060
23096
  }
@@ -23063,11 +23099,11 @@
23063
23099
  keySessionContext.licenseXhr.abort();
23064
23100
  }
23065
23101
  keySessionContext.licenseXhr = xhr;
23066
- _this11.setupLicenseXHR(xhr, url, keySessionContext, licenseChallenge).then(function (_ref5) {
23067
- var xhr = _ref5.xhr,
23068
- licenseChallenge = _ref5.licenseChallenge;
23102
+ _this13.setupLicenseXHR(xhr, url, keySessionContext, licenseChallenge).then(function (_ref8) {
23103
+ var xhr = _ref8.xhr,
23104
+ licenseChallenge = _ref8.licenseChallenge;
23069
23105
  if (keySessionContext.keySystem == KeySystems.PLAYREADY) {
23070
- licenseChallenge = _this11.unpackPlayReadyKeyMessage(xhr, licenseChallenge);
23106
+ licenseChallenge = _this13.unpackPlayReadyKeyMessage(xhr, licenseChallenge);
23071
23107
  }
23072
23108
  xhr.send(licenseChallenge);
23073
23109
  });
@@ -23095,7 +23131,7 @@
23095
23131
  }
23096
23132
  };
23097
23133
  _proto._clear = function _clear(media) {
23098
- var _this12 = this,
23134
+ var _this14 = this,
23099
23135
  _media$setMediaKeys;
23100
23136
  var mediaKeysList = this.mediaKeySessions;
23101
23137
  this._requestLicenseFailureCount = 0;
@@ -23107,11 +23143,11 @@
23107
23143
  // Close all sessions and remove media keys from the video element.
23108
23144
  var keySessionCount = mediaKeysList.length;
23109
23145
  EMEController.CDMCleanupPromise = Promise.all(mediaKeysList.map(function (mediaKeySessionContext) {
23110
- return _this12.removeSession(mediaKeySessionContext);
23146
+ return _this14.removeSession(mediaKeySessionContext);
23111
23147
  }).concat(media == null ? void 0 : (_media$setMediaKeys = media.setMediaKeys(null)) == null ? void 0 : _media$setMediaKeys.catch(function (error) {
23112
- var _this12$hls;
23113
- _this12.log("Could not clear media keys: " + error);
23114
- (_this12$hls = _this12.hls) == null ? void 0 : _this12$hls.trigger(Events.ERROR, {
23148
+ var _this14$hls;
23149
+ _this14.log("Could not clear media keys: " + error);
23150
+ (_this14$hls = _this14.hls) == null ? void 0 : _this14$hls.trigger(Events.ERROR, {
23115
23151
  type: ErrorTypes.OTHER_ERROR,
23116
23152
  details: ErrorDetails.KEY_SYSTEM_DESTROY_MEDIA_KEYS_ERROR,
23117
23153
  fatal: false,
@@ -23119,13 +23155,13 @@
23119
23155
  });
23120
23156
  }))).then(function () {
23121
23157
  if (keySessionCount) {
23122
- _this12.log('finished closing key sessions and clearing media keys');
23158
+ _this14.log('finished closing key sessions and clearing media keys');
23123
23159
  mediaKeysList.length = 0;
23124
23160
  }
23125
23161
  }).catch(function (error) {
23126
- var _this12$hls2;
23127
- _this12.log("Could not close sessions and clear media keys: " + error);
23128
- (_this12$hls2 = _this12.hls) == null ? void 0 : _this12$hls2.trigger(Events.ERROR, {
23162
+ var _this14$hls2;
23163
+ _this14.log("Could not close sessions and clear media keys: " + error);
23164
+ (_this14$hls2 = _this14.hls) == null ? void 0 : _this14$hls2.trigger(Events.ERROR, {
23129
23165
  type: ErrorTypes.OTHER_ERROR,
23130
23166
  details: ErrorDetails.KEY_SYSTEM_DESTROY_CLOSE_SESSION_ERROR,
23131
23167
  fatal: false,
@@ -23136,8 +23172,8 @@
23136
23172
  _proto.onManifestLoading = function onManifestLoading() {
23137
23173
  this.keyFormatPromise = null;
23138
23174
  };
23139
- _proto.onManifestLoaded = function onManifestLoaded(event, _ref6) {
23140
- var sessionKeys = _ref6.sessionKeys;
23175
+ _proto.onManifestLoaded = function onManifestLoaded(event, _ref9) {
23176
+ var sessionKeys = _ref9.sessionKeys;
23141
23177
  if (!sessionKeys || !this.config.emeEnabled) {
23142
23178
  return;
23143
23179
  }
@@ -23153,7 +23189,7 @@
23153
23189
  }
23154
23190
  };
23155
23191
  _proto.removeSession = function removeSession(mediaKeySessionContext) {
23156
- var _this13 = this;
23192
+ var _this15 = this;
23157
23193
  var mediaKeysSession = mediaKeySessionContext.mediaKeysSession,
23158
23194
  licenseXhr = mediaKeySessionContext.licenseXhr;
23159
23195
  if (mediaKeysSession) {
@@ -23182,9 +23218,9 @@
23182
23218
  mediaKeysSession.remove().then(resolve);
23183
23219
  }) : Promise.resolve();
23184
23220
  return removePromise.catch(function (error) {
23185
- var _this13$hls;
23186
- _this13.log("Could not remove session: " + error);
23187
- (_this13$hls = _this13.hls) == null ? void 0 : _this13$hls.trigger(Events.ERROR, {
23221
+ var _this15$hls;
23222
+ _this15.log("Could not remove session: " + error);
23223
+ (_this15$hls = _this15.hls) == null ? void 0 : _this15$hls.trigger(Events.ERROR, {
23188
23224
  type: ErrorTypes.OTHER_ERROR,
23189
23225
  details: ErrorDetails.KEY_SYSTEM_DESTROY_REMOVE_SESSION_ERROR,
23190
23226
  fatal: false,
@@ -23193,9 +23229,9 @@
23193
23229
  }).then(function () {
23194
23230
  return mediaKeysSession.close();
23195
23231
  }).catch(function (error) {
23196
- var _this13$hls2;
23197
- _this13.log("Could not close session: " + error);
23198
- (_this13$hls2 = _this13.hls) == null ? void 0 : _this13$hls2.trigger(Events.ERROR, {
23232
+ var _this15$hls2;
23233
+ _this15.log("Could not close session: " + error);
23234
+ (_this15$hls2 = _this15.hls) == null ? void 0 : _this15$hls2.trigger(Events.ERROR, {
23199
23235
  type: ErrorTypes.OTHER_ERROR,
23200
23236
  details: ErrorDetails.KEY_SYSTEM_DESTROY_CLOSE_SESSION_ERROR,
23201
23237
  fatal: false,
@@ -23209,13 +23245,13 @@
23209
23245
  EMEController.CDMCleanupPromise = void 0;
23210
23246
  var EMEKeyError = /*#__PURE__*/function (_Error) {
23211
23247
  function EMEKeyError(data, message) {
23212
- var _this14;
23213
- _this14 = _Error.call(this, message) || this;
23214
- _this14.data = void 0;
23248
+ var _this16;
23249
+ _this16 = _Error.call(this, message) || this;
23250
+ _this16.data = void 0;
23215
23251
  data.error || (data.error = new Error(message));
23216
- _this14.data = data;
23252
+ _this16.data = data;
23217
23253
  data.err = data.error;
23218
- return _this14;
23254
+ return _this16;
23219
23255
  }
23220
23256
  _inheritsLoose(EMEKeyError, _Error);
23221
23257
  return EMEKeyError;
@@ -25959,7 +25995,6 @@
25959
25995
  var _this$schedule$items2, _this$detachedData4;
25960
25996
  var interstitial = player.interstitial,
25961
25997
  assetItem = player.assetItem;
25962
- player.assetId;
25963
25998
  var scheduleIndex = this.schedule.findEventIndex(interstitial.identifier);
25964
25999
  var item = (_this$schedule$items2 = this.schedule.items) == null ? void 0 : _this$schedule$items2[scheduleIndex];
25965
26000
  if (!item) {
@@ -31205,6 +31240,8 @@
31205
31240
  // used by eme-controller
31206
31241
  requestMediaKeySystemAccessFunc: requestMediaKeySystemAccess ,
31207
31242
  // used by eme-controller
31243
+ requireKeySystemAccessOnStart: false,
31244
+ // used by eme-controller
31208
31245
  testBandwidth: true,
31209
31246
  progressive: false,
31210
31247
  lowLatencyMode: true,
@@ -34589,23 +34626,40 @@
34589
34626
  };
34590
34627
  _proto.loadClear = function loadClear(loadingFrag, encryptedFragments) {
34591
34628
  var _this = this;
34592
- if (this.emeController && this.config.emeEnabled) {
34593
- // access key-system with nearest key on start (loaidng frag is unencrypted)
34594
- var sn = loadingFrag.sn,
34595
- cc = loadingFrag.cc;
34596
- var _loop = function _loop() {
34597
- var frag = encryptedFragments[i];
34598
- if (cc <= frag.cc && (sn === 'initSegment' || frag.sn === 'initSegment' || sn < frag.sn)) {
34599
- _this.emeController.selectKeySystemFormat(frag).then(function (keySystemFormat) {
34600
- frag.setKeyFormat(keySystemFormat);
34601
- });
34602
- return 1; // break
34629
+ if (this.emeController && this.config.emeEnabled && !this.emeController.getSelectedKeySystemFormats().length) {
34630
+ // access key-system with nearest key on start (loading frag is unencrypted)
34631
+ if (encryptedFragments.length) {
34632
+ var sn = loadingFrag.sn,
34633
+ cc = loadingFrag.cc;
34634
+ var _loop = function _loop() {
34635
+ var frag = encryptedFragments[i];
34636
+ if (cc <= frag.cc && (sn === 'initSegment' || frag.sn === 'initSegment' || sn < frag.sn)) {
34637
+ return {
34638
+ v: _this.emeController.selectKeySystemFormat(frag).then(function (keySystemFormat) {
34639
+ frag.setKeyFormat(keySystemFormat);
34640
+ if (_this.emeController && _this.config.requireKeySystemAccessOnStart) {
34641
+ var keySystem = keySystemFormatToKeySystemDomain(keySystemFormat);
34642
+ if (keySystem) {
34643
+ return _this.emeController.getKeySystemAccess([keySystem]);
34644
+ }
34645
+ }
34646
+ })
34647
+ };
34648
+ }
34649
+ },
34650
+ _ret;
34651
+ for (var i = 0; i < encryptedFragments.length; i++) {
34652
+ _ret = _loop();
34653
+ if (_ret) return _ret.v;
34654
+ }
34655
+ } else if (this.config.requireKeySystemAccessOnStart) {
34656
+ var keySystemsInConfig = getKeySystemsForConfig(this.config);
34657
+ if (keySystemsInConfig.length) {
34658
+ return this.emeController.getKeySystemAccess(keySystemsInConfig);
34603
34659
  }
34604
- };
34605
- for (var i = 0; i < encryptedFragments.length; i++) {
34606
- if (_loop()) break;
34607
34660
  }
34608
34661
  }
34662
+ return null;
34609
34663
  };
34610
34664
  _proto.load = function load(frag) {
34611
34665
  var _this2 = this;