@openplayerjs/hls 3.4.1 → 3.4.3

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/index.js CHANGED
@@ -663,7 +663,7 @@ var hasRequiredUrlToolkit;
663
663
  function requireUrlToolkit () {
664
664
  if (hasRequiredUrlToolkit) return urlToolkit.exports;
665
665
  hasRequiredUrlToolkit = 1;
666
- (function (module, exports$1) {
666
+ (function (module, exports) {
667
667
  // see https://tools.ietf.org/html/rfc1808
668
668
 
669
669
  (function (root) {
@@ -36621,6 +36621,7 @@ class Hls {
36621
36621
  }
36622
36622
  Hls.defaultConfig = void 0;
36623
36623
 
36624
+ const ERROR_RECOVERY_THROTTLE_MS = 3000;
36624
36625
  class HlsMediaEngine extends BaseMediaEngine {
36625
36626
  constructor(config = {}) {
36626
36627
  super();
@@ -36660,7 +36661,7 @@ class HlsMediaEngine extends BaseMediaEngine {
36660
36661
  writable: true,
36661
36662
  value: null
36662
36663
  });
36663
- Object.defineProperty(this, "recoverSwapAudioCodecDate", {
36664
+ Object.defineProperty(this, "recoverSwapAudioCodecTimestamp", {
36664
36665
  enumerable: true,
36665
36666
  configurable: true,
36666
36667
  writable: true,
@@ -36748,24 +36749,9 @@ class HlsMediaEngine extends BaseMediaEngine {
36748
36749
  }, EVENT_OPTIONS);
36749
36750
  }
36750
36751
  const onPlay = () => {
36751
- if (!this.canHandlePlayback(ctx)) {
36752
- // If another surface owns playback (ads/cast/etc), force content back to paused.
36753
- try {
36754
- ctx.surface.pause();
36755
- }
36756
- catch {
36757
- //
36758
- }
36759
- return;
36760
- }
36761
- if (!this.adapter)
36762
- return;
36763
- if (autoStartLoad)
36752
+ if (!this.ensurePlaybackOwnership(ctx))
36764
36753
  return;
36765
- if (this.startedLoad)
36766
- return;
36767
- this.startedLoad = true;
36768
- this.adapter.startLoad();
36754
+ this.maybeStartLoad(autoStartLoad);
36769
36755
  };
36770
36756
  const onPause = () => {
36771
36757
  if (!autoStartLoad && this.adapter) {
@@ -36776,14 +36762,7 @@ class HlsMediaEngine extends BaseMediaEngine {
36776
36762
  this.addMediaListener(ctx.media, 'play', onPlay);
36777
36763
  this.addMediaListener(ctx.media, 'pause', onPause);
36778
36764
  this.commands.push(ctx.events.on('cmd:startLoad', () => {
36779
- if (!this.adapter)
36780
- return;
36781
- if (autoStartLoad)
36782
- return;
36783
- if (this.startedLoad)
36784
- return;
36785
- this.startedLoad = true;
36786
- this.adapter.startLoad();
36765
+ this.maybeStartLoad(autoStartLoad);
36787
36766
  }));
36788
36767
  this.onAdapterEvent(this.HlsClass.Events.MANIFEST_PARSED, () => ctx.events.emit('loadedmetadata'), EVENT_OPTIONS);
36789
36768
  this.onAdapterEvent(this.HlsClass.Events.MEDIA_ATTACHED, () => {
@@ -36829,13 +36808,14 @@ class HlsMediaEngine extends BaseMediaEngine {
36829
36808
  switch (data.type) {
36830
36809
  case this.HlsClass.ErrorTypes.MEDIA_ERROR: {
36831
36810
  const now = Date.now();
36832
- if (!this.attemptedErrorRecovery || now - this.attemptedErrorRecovery > 3000) {
36811
+ if (!this.attemptedErrorRecovery || now - this.attemptedErrorRecovery > ERROR_RECOVERY_THROTTLE_MS) {
36833
36812
  this.attemptedErrorRecovery = now;
36834
36813
  this.adapter?.recoverMediaError();
36835
36814
  }
36836
36815
  else {
36837
- if (!this.recoverSwapAudioCodecDate || now - this.recoverSwapAudioCodecDate > 3000) {
36838
- this.recoverSwapAudioCodecDate = now;
36816
+ if (!this.recoverSwapAudioCodecTimestamp ||
36817
+ now - this.recoverSwapAudioCodecTimestamp > ERROR_RECOVERY_THROTTLE_MS) {
36818
+ this.recoverSwapAudioCodecTimestamp = now;
36839
36819
  this.adapter?.swapAudioCodec();
36840
36820
  this.adapter?.recoverMediaError();
36841
36821
  }
@@ -36857,6 +36837,29 @@ class HlsMediaEngine extends BaseMediaEngine {
36857
36837
  ctx.events.emit('playback:error', data);
36858
36838
  }, EVENT_OPTIONS);
36859
36839
  }
36840
+ ensurePlaybackOwnership(ctx) {
36841
+ if (this.canHandlePlayback(ctx)) {
36842
+ return true;
36843
+ }
36844
+ // If another surface owns playback (ads/cast/etc), force content back to paused.
36845
+ try {
36846
+ ctx.surface.pause();
36847
+ }
36848
+ catch {
36849
+ //
36850
+ }
36851
+ return false;
36852
+ }
36853
+ maybeStartLoad(autoStartLoad) {
36854
+ if (!this.adapter)
36855
+ return;
36856
+ if (autoStartLoad)
36857
+ return;
36858
+ if (this.startedLoad)
36859
+ return;
36860
+ this.startedLoad = true;
36861
+ this.adapter.startLoad();
36862
+ }
36860
36863
  /**
36861
36864
  * Attach a separate hls.js instance to an arbitrary video element without
36862
36865
  * touching the main engine state. Intended for ad creatives that are HLS
@@ -36878,7 +36881,7 @@ class HlsMediaEngine extends BaseMediaEngine {
36878
36881
  hls.destroy();
36879
36882
  };
36880
36883
  }
36881
- detach() {
36884
+ detach(_ctx) {
36882
36885
  this.unbindCommands();
36883
36886
  this.unbindMediaEvents();
36884
36887
  this.unbindAdapterEvents();