hls.js 1.6.3-0.canary.11254 → 1.6.3-0.canary.11257

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.d.mts CHANGED
@@ -975,6 +975,9 @@ export declare class EMEController extends Logger implements ComponentAPI {
975
975
  private renewKeySession;
976
976
  private getKeyIdString;
977
977
  private updateKeySession;
978
+ getSelectedKeySystemFormats(): KeySystemFormats[];
979
+ getKeySystemAccess(keySystemsToAttempt: KeySystems[]): Promise<void>;
980
+ selectKeySystem(keySystemsToAttempt: KeySystems[]): Promise<KeySystemFormats>;
978
981
  selectKeySystemFormat(frag: Fragment): Promise<KeySystemFormats>;
979
982
  private getKeyFormatPromise;
980
983
  loadKey(data: KeyLoadedData): Promise<MediaKeySessionContext>;
@@ -1009,6 +1012,7 @@ export declare type EMEControllerConfig = {
1009
1012
  drmSystems: DRMSystemsConfiguration;
1010
1013
  drmSystemOptions: DRMSystemOptions;
1011
1014
  requestMediaKeySystemAccessFunc: MediaKeyFunc | null;
1015
+ requireKeySystemAccessOnStart: boolean;
1012
1016
  };
1013
1017
 
1014
1018
  export declare const enum ErrorActionFlags {
@@ -2536,7 +2540,7 @@ export declare class KeyLoader implements ComponentAPI {
2536
2540
  code: number;
2537
2541
  text: string;
2538
2542
  }): LoadError;
2539
- loadClear(loadingFrag: Fragment, encryptedFragments: Fragment[]): void | Promise<void>;
2543
+ loadClear(loadingFrag: Fragment, encryptedFragments: Fragment[]): null | Promise<void>;
2540
2544
  load(frag: Fragment): Promise<KeyLoadedData>;
2541
2545
  loadInternal(frag: Fragment, keySystemFormat?: KeySystemFormats): Promise<KeyLoadedData>;
2542
2546
  loadKeyEME(keyInfo: KeyLoaderInfo, frag: Fragment): Promise<KeyLoadedData>;
package/dist/hls.d.ts CHANGED
@@ -975,6 +975,9 @@ export declare class EMEController extends Logger implements ComponentAPI {
975
975
  private renewKeySession;
976
976
  private getKeyIdString;
977
977
  private updateKeySession;
978
+ getSelectedKeySystemFormats(): KeySystemFormats[];
979
+ getKeySystemAccess(keySystemsToAttempt: KeySystems[]): Promise<void>;
980
+ selectKeySystem(keySystemsToAttempt: KeySystems[]): Promise<KeySystemFormats>;
978
981
  selectKeySystemFormat(frag: Fragment): Promise<KeySystemFormats>;
979
982
  private getKeyFormatPromise;
980
983
  loadKey(data: KeyLoadedData): Promise<MediaKeySessionContext>;
@@ -1009,6 +1012,7 @@ export declare type EMEControllerConfig = {
1009
1012
  drmSystems: DRMSystemsConfiguration;
1010
1013
  drmSystemOptions: DRMSystemOptions;
1011
1014
  requestMediaKeySystemAccessFunc: MediaKeyFunc | null;
1015
+ requireKeySystemAccessOnStart: boolean;
1012
1016
  };
1013
1017
 
1014
1018
  export declare const enum ErrorActionFlags {
@@ -2536,7 +2540,7 @@ export declare class KeyLoader implements ComponentAPI {
2536
2540
  code: number;
2537
2541
  text: string;
2538
2542
  }): LoadError;
2539
- loadClear(loadingFrag: Fragment, encryptedFragments: Fragment[]): void | Promise<void>;
2543
+ loadClear(loadingFrag: Fragment, encryptedFragments: Fragment[]): null | Promise<void>;
2540
2544
  load(frag: Fragment): Promise<KeyLoadedData>;
2541
2545
  loadInternal(frag: Fragment, keySystemFormat?: KeySystemFormats): Promise<KeyLoadedData>;
2542
2546
  loadKeyEME(keyInfo: KeyLoaderInfo, frag: Fragment): Promise<KeyLoadedData>;
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.11254");
1168
+ newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.6.3-0.canary.11257");
1169
1169
  } catch (e) {
1170
1170
  /* log fn threw an exception. All logger methods are no-ops. */
1171
1171
  return createLogger();
@@ -9605,8 +9605,11 @@
9605
9605
  if (this.fragCurrent === null) {
9606
9606
  keyLoadingPromise = Promise.reject(new Error("frag load aborted, context changed in KEY_LOADING"));
9607
9607
  }
9608
- } else if (!frag.encrypted && details.encryptedFragments.length) {
9609
- 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
+ }
9610
9613
  }
9611
9614
  var fragPrevious = this.fragPrevious;
9612
9615
  if (isMediaFragment(frag) && (!fragPrevious || frag.sn !== fragPrevious.sn)) {
@@ -16671,7 +16674,7 @@
16671
16674
  return !remuxResult.audio && !remuxResult.video && !remuxResult.text && !remuxResult.id3 && !remuxResult.initSegment;
16672
16675
  }
16673
16676
 
16674
- var version = "1.6.3-0.canary.11254";
16677
+ var version = "1.6.3-0.canary.11257";
16675
16678
 
16676
16679
  // ensure the worker ends up in the bundle
16677
16680
  // If the worker should not be included this gets aliased to empty.js
@@ -22538,6 +22541,7 @@
22538
22541
  _this4.log("Create media-keys for \"" + keySystem + "\"");
22539
22542
  _keySystemAccessPromises.mediaKeys = mediaKeySystemAccess.createMediaKeys().then(function (mediaKeys) {
22540
22543
  _this4.log("Media-keys created for \"" + keySystem + "\"");
22544
+ _keySystemAccessPromises.hasMediaKeys = true;
22541
22545
  return certificateRequest.then(function (certificate) {
22542
22546
  if (certificate) {
22543
22547
  return _this4.setMediaKeysServerCertificate(mediaKeys, keySystem, certificate);
@@ -22598,23 +22602,36 @@
22598
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) + ")");
22599
22603
  return keySession.update(data);
22600
22604
  };
22601
- _proto.selectKeySystemFormat = function selectKeySystemFormat(frag) {
22602
- var keyFormats = Object.keys(frag.levelkeys || {});
22603
- if (!this.keyFormatPromise) {
22604
- this.log("Selecting key-system from fragment (sn: " + frag.sn + " " + frag.type + ": " + frag.level + ") key formats " + keyFormats.join(', '));
22605
- this.keyFormatPromise = this.getKeyFormatPromise(keyFormats);
22606
- }
22607
- return this.keyFormatPromise;
22608
- };
22609
- _proto.getKeyFormatPromise = function getKeyFormatPromise(keyFormats) {
22605
+ _proto.getSelectedKeySystemFormats = function getSelectedKeySystemFormats() {
22610
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;
22611
22632
  return new Promise(function (resolve, reject) {
22612
- var keySystemsInConfig = getKeySystemsForConfig(_this5.config);
22613
- var keySystemsToAttempt = keyFormats.map(keySystemFormatToKeySystemDomain).filter(function (value) {
22614
- return !!value && keySystemsInConfig.indexOf(value) !== -1;
22615
- });
22616
- return _this5.getKeySystemSelectionPromise(keySystemsToAttempt).then(function (_ref3) {
22617
- var keySystem = _ref3.keySystem;
22633
+ return _this7.getKeySystemSelectionPromise(keySystemsToAttempt).then(function (_ref6) {
22634
+ var keySystem = _ref6.keySystem;
22618
22635
  var keySystemFormat = keySystemDomainToKeySystemFormat(keySystem);
22619
22636
  if (keySystemFormat) {
22620
22637
  resolve(keySystemFormat);
@@ -22624,22 +22641,37 @@
22624
22641
  }).catch(reject);
22625
22642
  });
22626
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
+ };
22627
22659
  _proto.loadKey = function loadKey(data) {
22628
- var _this6 = this;
22660
+ var _this8 = this;
22629
22661
  var decryptdata = data.keyInfo.decryptdata;
22630
22662
  var keyId = this.getKeyIdString(decryptdata);
22631
22663
  var keyDetails = "(keyId: " + keyId + " format: \"" + decryptdata.keyFormat + "\" method: " + decryptdata.method + " uri: " + decryptdata.uri + ")";
22632
22664
  this.log("Starting session for key " + keyDetails);
22633
22665
  var keyContextPromise = this.keyIdToKeySessionPromise[keyId];
22634
22666
  if (!keyContextPromise) {
22635
- keyContextPromise = this.getKeySystemForKeyPromise(decryptdata).then(function (_ref4) {
22636
- var keySystem = _ref4.keySystem,
22637
- mediaKeys = _ref4.mediaKeys;
22638
- _this6.throwIfDestroyed();
22639
- _this6.log("Handle encrypted media sn: " + data.frag.sn + " " + data.frag.type + ": " + data.frag.level + " using key " + keyDetails);
22640
- return _this6.attemptSetMediaKeys(keySystem, mediaKeys).then(function () {
22641
- _this6.throwIfDestroyed();
22642
- 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({
22643
22675
  keySystem: keySystem,
22644
22676
  mediaKeys: mediaKeys,
22645
22677
  decryptdata: decryptdata
@@ -22649,10 +22681,10 @@
22649
22681
  var keySessionContextPromise = this.keyIdToKeySessionPromise[keyId] = keyContextPromise.then(function (keySessionContext) {
22650
22682
  var scheme = 'cenc';
22651
22683
  var initData = decryptdata.pssh ? decryptdata.pssh.buffer : null;
22652
- return _this6.generateRequestWithPreferredKeySession(keySessionContext, scheme, initData, 'playlist-key');
22684
+ return _this8.generateRequestWithPreferredKeySession(keySessionContext, scheme, initData, 'playlist-key');
22653
22685
  });
22654
22686
  keySessionContextPromise.catch(function (error) {
22655
- return _this6.handleError(error);
22687
+ return _this8.handleError(error);
22656
22688
  });
22657
22689
  }
22658
22690
  return keyContextPromise;
@@ -22704,22 +22736,22 @@
22704
22736
  return this.attemptKeySystemAccess(keySystemsToAttempt);
22705
22737
  };
22706
22738
  _proto.attemptSetMediaKeys = function attemptSetMediaKeys(keySystem, mediaKeys) {
22707
- var _this7 = this;
22739
+ var _this9 = this;
22708
22740
  var queue = this.setMediaKeysQueue.slice();
22709
22741
  this.log("Setting media-keys for \"" + keySystem + "\"");
22710
22742
  // Only one setMediaKeys() can run at one time, and multiple setMediaKeys() operations
22711
22743
  // can be queued for execution for multiple key sessions.
22712
22744
  var setMediaKeysPromise = Promise.all(queue).then(function () {
22713
- if (!_this7.media) {
22745
+ if (!_this9.media) {
22714
22746
  throw new Error('Attempted to set mediaKeys without media element attached');
22715
22747
  }
22716
- return _this7.media.setMediaKeys(mediaKeys);
22748
+ return _this9.media.setMediaKeys(mediaKeys);
22717
22749
  });
22718
22750
  this.setMediaKeysQueue.push(setMediaKeysPromise);
22719
22751
  return setMediaKeysPromise.then(function () {
22720
- _this7.log("Media-keys set for \"" + keySystem + "\"");
22752
+ _this9.log("Media-keys set for \"" + keySystem + "\"");
22721
22753
  queue.push(setMediaKeysPromise);
22722
- _this7.setMediaKeysQueue = _this7.setMediaKeysQueue.filter(function (p) {
22754
+ _this9.setMediaKeysQueue = _this9.setMediaKeysQueue.filter(function (p) {
22723
22755
  return queue.indexOf(p) === -1;
22724
22756
  });
22725
22757
  });
@@ -22727,7 +22759,7 @@
22727
22759
  _proto.generateRequestWithPreferredKeySession = function generateRequestWithPreferredKeySession(context, initDataType, initData, reason) {
22728
22760
  var _this$config$drmSyste,
22729
22761
  _this$config$drmSyste2,
22730
- _this8 = this;
22762
+ _this0 = this;
22731
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;
22732
22764
  if (generateRequestFilter) {
22733
22765
  try {
@@ -22761,22 +22793,22 @@
22761
22793
  }
22762
22794
  var messageType = event.messageType,
22763
22795
  message = event.message;
22764
- _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);
22765
22797
  if (messageType === 'license-request' || messageType === 'license-renewal') {
22766
- _this8.renewLicense(context, message).catch(function (error) {
22798
+ _this0.renewLicense(context, message).catch(function (error) {
22767
22799
  if (licenseStatus.eventNames().length) {
22768
22800
  licenseStatus.emit('error', error);
22769
22801
  } else {
22770
- _this8.handleError(error);
22802
+ _this0.handleError(error);
22771
22803
  }
22772
22804
  });
22773
22805
  } else if (messageType === 'license-release') {
22774
22806
  if (context.keySystem === KeySystems.FAIRPLAY) {
22775
- _this8.updateKeySession(context, strToUtf8array('acknowledged'));
22776
- _this8.removeSession(context);
22807
+ _this0.updateKeySession(context, strToUtf8array('acknowledged'));
22808
+ _this0.removeSession(context);
22777
22809
  }
22778
22810
  } else {
22779
- _this8.warn("unhandled media key message type \"" + messageType + "\"");
22811
+ _this0.warn("unhandled media key message type \"" + messageType + "\"");
22780
22812
  }
22781
22813
  };
22782
22814
  var onkeystatuseschange = context._onkeystatuseschange = function (event) {
@@ -22785,12 +22817,12 @@
22785
22817
  licenseStatus.emit('error', new Error('invalid state'));
22786
22818
  return;
22787
22819
  }
22788
- _this8.onKeyStatusChange(context);
22820
+ _this0.onKeyStatusChange(context);
22789
22821
  var keyStatus = context.keyStatus;
22790
22822
  licenseStatus.emit('keyStatus', keyStatus);
22791
22823
  if (keyStatus === 'expired') {
22792
- _this8.warn(context.keySystem + " expired for key " + keyId);
22793
- _this8.renewKeySession(context);
22824
+ _this0.warn(context.keySystem + " expired for key " + keyId);
22825
+ _this0.renewKeySession(context);
22794
22826
  }
22795
22827
  };
22796
22828
  context.mediaKeysSession.addEventListener('message', onmessage);
@@ -22815,13 +22847,13 @@
22815
22847
  } else if (keyStatus === 'expired') {
22816
22848
  reject(new Error('key expired while generating request'));
22817
22849
  } else {
22818
- _this8.warn("unhandled key status change \"" + keyStatus + "\"");
22850
+ _this0.warn("unhandled key status change \"" + keyStatus + "\"");
22819
22851
  }
22820
22852
  });
22821
22853
  });
22822
22854
  return context.mediaKeysSession.generateRequest(initDataType, initData).then(function () {
22823
22855
  var _context$mediaKeysSes;
22824
- _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);
22825
22857
  }).catch(function (error) {
22826
22858
  throw new EMEKeyError({
22827
22859
  type: ErrorTypes.KEY_SYSTEM_ERROR,
@@ -22833,7 +22865,7 @@
22833
22865
  return keyUsablePromise;
22834
22866
  }).catch(function (error) {
22835
22867
  licenseStatus.removeAllListeners();
22836
- _this8.removeSession(context);
22868
+ _this0.removeSession(context);
22837
22869
  throw error;
22838
22870
  }).then(function () {
22839
22871
  licenseStatus.removeAllListeners();
@@ -22841,7 +22873,7 @@
22841
22873
  });
22842
22874
  };
22843
22875
  _proto.onKeyStatusChange = function onKeyStatusChange(mediaKeySessionContext) {
22844
- var _this9 = this;
22876
+ var _this1 = this;
22845
22877
  mediaKeySessionContext.mediaKeysSession.keyStatuses.forEach(function (status, keyId) {
22846
22878
  // keyStatuses.forEach is not standard API so the callback value looks weird on xboxone
22847
22879
  // xboxone callback(keyId, status) so we need to exchange them
@@ -22850,7 +22882,7 @@
22850
22882
  keyId = status;
22851
22883
  status = temp;
22852
22884
  }
22853
- _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);
22854
22886
  mediaKeySessionContext.keyStatus = status;
22855
22887
  });
22856
22888
  };
@@ -22912,10 +22944,10 @@
22912
22944
  });
22913
22945
  };
22914
22946
  _proto.setMediaKeysServerCertificate = function setMediaKeysServerCertificate(mediaKeys, keySystem, cert) {
22915
- var _this0 = this;
22947
+ var _this10 = this;
22916
22948
  return new Promise(function (resolve, reject) {
22917
22949
  mediaKeys.setServerCertificate(cert).then(function (success) {
22918
- _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 + "\"");
22919
22951
  resolve(mediaKeys);
22920
22952
  }).catch(function (error) {
22921
22953
  reject(new EMEKeyError({
@@ -22928,9 +22960,9 @@
22928
22960
  });
22929
22961
  };
22930
22962
  _proto.renewLicense = function renewLicense(context, keyMessage) {
22931
- var _this1 = this;
22963
+ var _this11 = this;
22932
22964
  return this.requestLicense(context, new Uint8Array(keyMessage)).then(function (data) {
22933
- return _this1.updateKeySession(context, new Uint8Array(data)).catch(function (error) {
22965
+ return _this11.updateKeySession(context, new Uint8Array(data)).catch(function (error) {
22934
22966
  throw new EMEKeyError({
22935
22967
  type: ErrorTypes.KEY_SYSTEM_ERROR,
22936
22968
  details: ErrorDetails.KEY_SYSTEM_SESSION_UPDATE_FAILED,
@@ -22978,7 +23010,7 @@
22978
23010
  return strToUtf8array(atob(challengeText));
22979
23011
  };
22980
23012
  _proto.setupLicenseXHR = function setupLicenseXHR(xhr, url, keysListItem, licenseChallenge) {
22981
- var _this10 = this;
23013
+ var _this12 = this;
22982
23014
  var licenseXhrSetup = this.config.licenseXhrSetup;
22983
23015
  if (!licenseXhrSetup) {
22984
23016
  xhr.open('POST', url, true);
@@ -22991,7 +23023,7 @@
22991
23023
  if (!keysListItem.decryptdata) {
22992
23024
  throw new Error('Key removed');
22993
23025
  }
22994
- return licenseXhrSetup.call(_this10.hls, xhr, url, keysListItem, licenseChallenge);
23026
+ return licenseXhrSetup.call(_this12.hls, xhr, url, keysListItem, licenseChallenge);
22995
23027
  }).catch(function (error) {
22996
23028
  if (!keysListItem.decryptdata) {
22997
23029
  // Key session removed. Cancel license request.
@@ -22999,7 +23031,7 @@
22999
23031
  }
23000
23032
  // let's try to open before running setup
23001
23033
  xhr.open('POST', url, true);
23002
- return licenseXhrSetup.call(_this10.hls, xhr, url, keysListItem, licenseChallenge);
23034
+ return licenseXhrSetup.call(_this12.hls, xhr, url, keysListItem, licenseChallenge);
23003
23035
  }).then(function (licenseXhrSetupResult) {
23004
23036
  // if licenseXhrSetup did not yet call open, let's do it now
23005
23037
  if (!xhr.readyState) {
@@ -23013,36 +23045,36 @@
23013
23045
  });
23014
23046
  };
23015
23047
  _proto.requestLicense = function requestLicense(keySessionContext, licenseChallenge) {
23016
- var _this11 = this;
23048
+ var _this13 = this;
23017
23049
  var keyLoadPolicy = this.config.keyLoadPolicy.default;
23018
23050
  return new Promise(function (resolve, reject) {
23019
- var url = _this11.getLicenseServerUrlOrThrow(keySessionContext.keySystem);
23020
- _this11.log("Sending license request to URL: " + url);
23051
+ var url = _this13.getLicenseServerUrlOrThrow(keySessionContext.keySystem);
23052
+ _this13.log("Sending license request to URL: " + url);
23021
23053
  var xhr = new XMLHttpRequest();
23022
23054
  xhr.responseType = 'arraybuffer';
23023
23055
  xhr.onreadystatechange = function () {
23024
- if (!_this11.hls || !keySessionContext.mediaKeysSession) {
23056
+ if (!_this13.hls || !keySessionContext.mediaKeysSession) {
23025
23057
  return reject(new Error('invalid state'));
23026
23058
  }
23027
23059
  if (xhr.readyState === 4) {
23028
23060
  if (xhr.status === 200) {
23029
- _this11._requestLicenseFailureCount = 0;
23061
+ _this13._requestLicenseFailureCount = 0;
23030
23062
  var data = xhr.response;
23031
- _this11.log("License received " + (data instanceof ArrayBuffer ? data.byteLength : data));
23032
- var licenseResponseCallback = _this11.config.licenseResponseCallback;
23063
+ _this13.log("License received " + (data instanceof ArrayBuffer ? data.byteLength : data));
23064
+ var licenseResponseCallback = _this13.config.licenseResponseCallback;
23033
23065
  if (licenseResponseCallback) {
23034
23066
  try {
23035
- data = licenseResponseCallback.call(_this11.hls, xhr, url, keySessionContext);
23067
+ data = licenseResponseCallback.call(_this13.hls, xhr, url, keySessionContext);
23036
23068
  } catch (error) {
23037
- _this11.error(error);
23069
+ _this13.error(error);
23038
23070
  }
23039
23071
  }
23040
23072
  resolve(data);
23041
23073
  } else {
23042
23074
  var retryConfig = keyLoadPolicy.errorRetry;
23043
23075
  var maxNumRetry = retryConfig ? retryConfig.maxNumRetry : 0;
23044
- _this11._requestLicenseFailureCount++;
23045
- if (_this11._requestLicenseFailureCount > maxNumRetry || xhr.status >= 400 && xhr.status < 500) {
23076
+ _this13._requestLicenseFailureCount++;
23077
+ if (_this13._requestLicenseFailureCount > maxNumRetry || xhr.status >= 400 && xhr.status < 500) {
23046
23078
  reject(new EMEKeyError({
23047
23079
  type: ErrorTypes.KEY_SYSTEM_ERROR,
23048
23080
  details: ErrorDetails.KEY_SYSTEM_LICENSE_REQUEST_FAILED,
@@ -23056,9 +23088,9 @@
23056
23088
  }
23057
23089
  }, "License Request XHR failed (" + url + "). Status: " + xhr.status + " (" + xhr.statusText + ")"));
23058
23090
  } else {
23059
- var attemptsLeft = maxNumRetry - _this11._requestLicenseFailureCount + 1;
23060
- _this11.warn("Retrying license request, " + attemptsLeft + " attempts left");
23061
- _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);
23062
23094
  }
23063
23095
  }
23064
23096
  }
@@ -23067,11 +23099,11 @@
23067
23099
  keySessionContext.licenseXhr.abort();
23068
23100
  }
23069
23101
  keySessionContext.licenseXhr = xhr;
23070
- _this11.setupLicenseXHR(xhr, url, keySessionContext, licenseChallenge).then(function (_ref5) {
23071
- var xhr = _ref5.xhr,
23072
- licenseChallenge = _ref5.licenseChallenge;
23102
+ _this13.setupLicenseXHR(xhr, url, keySessionContext, licenseChallenge).then(function (_ref8) {
23103
+ var xhr = _ref8.xhr,
23104
+ licenseChallenge = _ref8.licenseChallenge;
23073
23105
  if (keySessionContext.keySystem == KeySystems.PLAYREADY) {
23074
- licenseChallenge = _this11.unpackPlayReadyKeyMessage(xhr, licenseChallenge);
23106
+ licenseChallenge = _this13.unpackPlayReadyKeyMessage(xhr, licenseChallenge);
23075
23107
  }
23076
23108
  xhr.send(licenseChallenge);
23077
23109
  });
@@ -23099,7 +23131,7 @@
23099
23131
  }
23100
23132
  };
23101
23133
  _proto._clear = function _clear(media) {
23102
- var _this12 = this,
23134
+ var _this14 = this,
23103
23135
  _media$setMediaKeys;
23104
23136
  var mediaKeysList = this.mediaKeySessions;
23105
23137
  this._requestLicenseFailureCount = 0;
@@ -23111,11 +23143,11 @@
23111
23143
  // Close all sessions and remove media keys from the video element.
23112
23144
  var keySessionCount = mediaKeysList.length;
23113
23145
  EMEController.CDMCleanupPromise = Promise.all(mediaKeysList.map(function (mediaKeySessionContext) {
23114
- return _this12.removeSession(mediaKeySessionContext);
23146
+ return _this14.removeSession(mediaKeySessionContext);
23115
23147
  }).concat(media == null ? void 0 : (_media$setMediaKeys = media.setMediaKeys(null)) == null ? void 0 : _media$setMediaKeys.catch(function (error) {
23116
- var _this12$hls;
23117
- _this12.log("Could not clear media keys: " + error);
23118
- (_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, {
23119
23151
  type: ErrorTypes.OTHER_ERROR,
23120
23152
  details: ErrorDetails.KEY_SYSTEM_DESTROY_MEDIA_KEYS_ERROR,
23121
23153
  fatal: false,
@@ -23123,13 +23155,13 @@
23123
23155
  });
23124
23156
  }))).then(function () {
23125
23157
  if (keySessionCount) {
23126
- _this12.log('finished closing key sessions and clearing media keys');
23158
+ _this14.log('finished closing key sessions and clearing media keys');
23127
23159
  mediaKeysList.length = 0;
23128
23160
  }
23129
23161
  }).catch(function (error) {
23130
- var _this12$hls2;
23131
- _this12.log("Could not close sessions and clear media keys: " + error);
23132
- (_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, {
23133
23165
  type: ErrorTypes.OTHER_ERROR,
23134
23166
  details: ErrorDetails.KEY_SYSTEM_DESTROY_CLOSE_SESSION_ERROR,
23135
23167
  fatal: false,
@@ -23140,8 +23172,8 @@
23140
23172
  _proto.onManifestLoading = function onManifestLoading() {
23141
23173
  this.keyFormatPromise = null;
23142
23174
  };
23143
- _proto.onManifestLoaded = function onManifestLoaded(event, _ref6) {
23144
- var sessionKeys = _ref6.sessionKeys;
23175
+ _proto.onManifestLoaded = function onManifestLoaded(event, _ref9) {
23176
+ var sessionKeys = _ref9.sessionKeys;
23145
23177
  if (!sessionKeys || !this.config.emeEnabled) {
23146
23178
  return;
23147
23179
  }
@@ -23157,7 +23189,7 @@
23157
23189
  }
23158
23190
  };
23159
23191
  _proto.removeSession = function removeSession(mediaKeySessionContext) {
23160
- var _this13 = this;
23192
+ var _this15 = this;
23161
23193
  var mediaKeysSession = mediaKeySessionContext.mediaKeysSession,
23162
23194
  licenseXhr = mediaKeySessionContext.licenseXhr;
23163
23195
  if (mediaKeysSession) {
@@ -23186,9 +23218,9 @@
23186
23218
  mediaKeysSession.remove().then(resolve);
23187
23219
  }) : Promise.resolve();
23188
23220
  return removePromise.catch(function (error) {
23189
- var _this13$hls;
23190
- _this13.log("Could not remove session: " + error);
23191
- (_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, {
23192
23224
  type: ErrorTypes.OTHER_ERROR,
23193
23225
  details: ErrorDetails.KEY_SYSTEM_DESTROY_REMOVE_SESSION_ERROR,
23194
23226
  fatal: false,
@@ -23197,9 +23229,9 @@
23197
23229
  }).then(function () {
23198
23230
  return mediaKeysSession.close();
23199
23231
  }).catch(function (error) {
23200
- var _this13$hls2;
23201
- _this13.log("Could not close session: " + error);
23202
- (_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, {
23203
23235
  type: ErrorTypes.OTHER_ERROR,
23204
23236
  details: ErrorDetails.KEY_SYSTEM_DESTROY_CLOSE_SESSION_ERROR,
23205
23237
  fatal: false,
@@ -23213,13 +23245,13 @@
23213
23245
  EMEController.CDMCleanupPromise = void 0;
23214
23246
  var EMEKeyError = /*#__PURE__*/function (_Error) {
23215
23247
  function EMEKeyError(data, message) {
23216
- var _this14;
23217
- _this14 = _Error.call(this, message) || this;
23218
- _this14.data = void 0;
23248
+ var _this16;
23249
+ _this16 = _Error.call(this, message) || this;
23250
+ _this16.data = void 0;
23219
23251
  data.error || (data.error = new Error(message));
23220
- _this14.data = data;
23252
+ _this16.data = data;
23221
23253
  data.err = data.error;
23222
- return _this14;
23254
+ return _this16;
23223
23255
  }
23224
23256
  _inheritsLoose(EMEKeyError, _Error);
23225
23257
  return EMEKeyError;
@@ -31208,6 +31240,8 @@
31208
31240
  // used by eme-controller
31209
31241
  requestMediaKeySystemAccessFunc: requestMediaKeySystemAccess ,
31210
31242
  // used by eme-controller
31243
+ requireKeySystemAccessOnStart: false,
31244
+ // used by eme-controller
31211
31245
  testBandwidth: true,
31212
31246
  progressive: false,
31213
31247
  lowLatencyMode: true,
@@ -34592,23 +34626,40 @@
34592
34626
  };
34593
34627
  _proto.loadClear = function loadClear(loadingFrag, encryptedFragments) {
34594
34628
  var _this = this;
34595
- if (this.emeController && this.config.emeEnabled) {
34596
- // access key-system with nearest key on start (loaidng frag is unencrypted)
34597
- var sn = loadingFrag.sn,
34598
- cc = loadingFrag.cc;
34599
- var _loop = function _loop() {
34600
- var frag = encryptedFragments[i];
34601
- if (cc <= frag.cc && (sn === 'initSegment' || frag.sn === 'initSegment' || sn < frag.sn)) {
34602
- _this.emeController.selectKeySystemFormat(frag).then(function (keySystemFormat) {
34603
- frag.setKeyFormat(keySystemFormat);
34604
- });
34605
- 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);
34606
34659
  }
34607
- };
34608
- for (var i = 0; i < encryptedFragments.length; i++) {
34609
- if (_loop()) break;
34610
34660
  }
34611
34661
  }
34662
+ return null;
34612
34663
  };
34613
34664
  _proto.load = function load(frag) {
34614
34665
  var _this2 = this;
package/dist/hls.js.d.ts CHANGED
@@ -975,6 +975,9 @@ export declare class EMEController extends Logger implements ComponentAPI {
975
975
  private renewKeySession;
976
976
  private getKeyIdString;
977
977
  private updateKeySession;
978
+ getSelectedKeySystemFormats(): KeySystemFormats[];
979
+ getKeySystemAccess(keySystemsToAttempt: KeySystems[]): Promise<void>;
980
+ selectKeySystem(keySystemsToAttempt: KeySystems[]): Promise<KeySystemFormats>;
978
981
  selectKeySystemFormat(frag: Fragment): Promise<KeySystemFormats>;
979
982
  private getKeyFormatPromise;
980
983
  loadKey(data: KeyLoadedData): Promise<MediaKeySessionContext>;
@@ -1009,6 +1012,7 @@ export declare type EMEControllerConfig = {
1009
1012
  drmSystems: DRMSystemsConfiguration;
1010
1013
  drmSystemOptions: DRMSystemOptions;
1011
1014
  requestMediaKeySystemAccessFunc: MediaKeyFunc | null;
1015
+ requireKeySystemAccessOnStart: boolean;
1012
1016
  };
1013
1017
 
1014
1018
  export declare const enum ErrorActionFlags {
@@ -2536,7 +2540,7 @@ export declare class KeyLoader implements ComponentAPI {
2536
2540
  code: number;
2537
2541
  text: string;
2538
2542
  }): LoadError;
2539
- loadClear(loadingFrag: Fragment, encryptedFragments: Fragment[]): void | Promise<void>;
2543
+ loadClear(loadingFrag: Fragment, encryptedFragments: Fragment[]): null | Promise<void>;
2540
2544
  load(frag: Fragment): Promise<KeyLoadedData>;
2541
2545
  loadInternal(frag: Fragment, keySystemFormat?: KeySystemFormats): Promise<KeyLoadedData>;
2542
2546
  loadKeyEME(keyInfo: KeyLoaderInfo, frag: Fragment): Promise<KeyLoadedData>;