stormcloud-video-player 0.2.18 → 0.2.19

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/lib/index.cjs CHANGED
@@ -2940,14 +2940,66 @@ var StormcloudVideoPlayer = class {
2940
2940
  }
2941
2941
  }
2942
2942
  ensureAdStoppedByTimer() {
2943
+ var _a, _b;
2943
2944
  if (!this.inAdBreak) return;
2945
+ this.adStopTimerId = void 0;
2946
+ const adPlaying = this.ima.isAdPlaying();
2947
+ const pendingAds = this.adPodQueue.length > 0;
2948
+ const checkIntervalMs = Math.max(
2949
+ 250,
2950
+ Math.floor((_a = this.config.adBreakCheckIntervalMs) != null ? _a : 1e3)
2951
+ );
2952
+ const maxExtensionMsConfig = this.config.maxAdBreakExtensionMs;
2953
+ const maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 6e4;
2954
+ let elapsedSinceStartMs = 0;
2955
+ if (this.currentAdBreakStartWallClockMs != null) {
2956
+ elapsedSinceStartMs = Date.now() - this.currentAdBreakStartWallClockMs;
2957
+ }
2958
+ const expectedDurationMs = (_b = this.expectedAdBreakDurationMs) != null ? _b : 0;
2959
+ const overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
2960
+ const shouldExtendAdBreak = (adPlaying || pendingAds || this.showAds) && overrunMs < maxExtensionMs;
2961
+ if (shouldExtendAdBreak) {
2962
+ if (this.config.debugAdTiming) {
2963
+ console.log(
2964
+ "[StormcloudVideoPlayer] Extending ad break beyond scheduled duration",
2965
+ {
2966
+ adPlaying,
2967
+ pendingAds,
2968
+ showAds: this.showAds,
2969
+ overrunMs,
2970
+ checkIntervalMs,
2971
+ maxExtensionMs
2972
+ }
2973
+ );
2974
+ }
2975
+ this.scheduleAdStopCountdown(checkIntervalMs);
2976
+ return;
2977
+ }
2978
+ if (this.config.debugAdTiming) {
2979
+ console.log("[StormcloudVideoPlayer] Ending ad break via timer", {
2980
+ adPlaying,
2981
+ pendingAds,
2982
+ showAds: this.showAds,
2983
+ overrunMs,
2984
+ maxExtensionMs
2985
+ });
2986
+ }
2944
2987
  this.inAdBreak = false;
2945
2988
  this.expectedAdBreakDurationMs = void 0;
2946
2989
  this.currentAdBreakStartWallClockMs = void 0;
2947
- this.adStopTimerId = void 0;
2948
- if (this.ima.isAdPlaying()) {
2990
+ this.showAds = false;
2991
+ this.adPodQueue = [];
2992
+ this.currentAdIndex = 0;
2993
+ this.totalAdsInBreak = 0;
2994
+ this.clearAdFailsafeTimer();
2995
+ if (adPlaying) {
2949
2996
  this.ima.stop().catch(() => {
2950
2997
  });
2998
+ return;
2999
+ }
3000
+ const originalMutedState = this.ima.getOriginalMutedState();
3001
+ if (this.video.muted !== originalMutedState) {
3002
+ this.video.muted = originalMutedState;
2951
3003
  }
2952
3004
  }
2953
3005
  scheduleAdStartIn(delayMs) {