stormcloud-video-player 0.2.34 → 0.2.36

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
@@ -695,19 +695,10 @@ function createImaController(video, options) {
695
695
  adsManager.addEventListener(
696
696
  AdEvent.CONTENT_PAUSE_REQUESTED,
697
697
  () => {
698
- console.log("[DEBUG-FLOW] \u{1F3AF} CONTENT_PAUSE_REQUESTED - Ad starting");
698
+ console.log("[DEBUG-FLOW] \u{1F3AF} CONTENT_PAUSE_REQUESTED - Ad request accepted");
699
699
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
700
700
  video.pause();
701
701
  }
702
- hideContentVideo();
703
- if (adContainerEl) {
704
- adContainerEl.style.pointerEvents = "auto";
705
- adContainerEl.style.display = "flex";
706
- adContainerEl.style.backgroundColor = "#000";
707
- adContainerEl.offsetHeight;
708
- adContainerEl.style.opacity = "1";
709
- console.log("[DEBUG-LAYER] \u{1F7E1} Ad container VISIBLE");
710
- }
711
702
  adPlaying = true;
712
703
  setAdPlayingFlag(true);
713
704
  emit("content_pause");
@@ -738,7 +729,7 @@ function createImaController(video, options) {
738
729
  console.log("[DEBUG-FLOW] \u23F8\uFE0F CONTENT_RESUME - Single ad done");
739
730
  adPlaying = false;
740
731
  setAdPlayingFlag(false);
741
- console.log("[DEBUG-LAYER] \u26A0\uFE0F Waiting for pod manager decision (more ads or done)");
732
+ console.log("[DEBUG-LAYER] \u26A0\uFE0F Waiting for pod manager (more ads, placeholder, or done)");
742
733
  emit("content_resume");
743
734
  }
744
735
  );
@@ -2506,44 +2497,31 @@ var StormcloudVideoPlayer = class {
2506
2497
  }
2507
2498
  });
2508
2499
  this.ima.on("ad_error", () => {
2509
- if (this.config.debugAdTiming) {
2510
- console.log("[StormcloudVideoPlayer] IMA ad_error event received", {
2511
- showAds: this.showAds,
2512
- inAdBreak: this.inAdBreak,
2513
- remainingAds: this.adPodQueue.length
2514
- });
2515
- }
2500
+ const remaining = this.getRemainingAdMs();
2501
+ console.log(
2502
+ `[DEBUG-POD] \u274C ad_error event | inBreak=${this.inAdBreak}, queue=${this.adPodQueue.length}, remaining=${remaining}ms`
2503
+ );
2516
2504
  if (this.inAdBreak) {
2517
- const remaining = this.getRemainingAdMs();
2518
2505
  if (remaining > 500 && this.adPodQueue.length > 0) {
2519
2506
  const nextPreloaded = this.findNextPreloadedAd();
2520
2507
  if (nextPreloaded) {
2521
2508
  this.currentAdIndex++;
2522
- if (this.config.debugAdTiming) {
2523
- console.log(
2524
- `[StormcloudVideoPlayer] Skipping to next preloaded ad after error`
2525
- );
2526
- }
2509
+ console.log(
2510
+ `[DEBUG-POD] \u27A1\uFE0F Trying next ad after error (${this.currentAdIndex}/${this.totalAdsInBreak})`
2511
+ );
2527
2512
  this.playSingleAd(nextPreloaded).catch(() => {
2528
2513
  this.handleAdFailure();
2529
2514
  });
2530
2515
  } else {
2531
- if (this.config.debugAdTiming) {
2532
- console.log(
2533
- "[StormcloudVideoPlayer] No preloaded ads available, ending ad break"
2534
- );
2535
- }
2516
+ console.log("[DEBUG-POD] \u26A0\uFE0F No more preloaded ads - calling handleAdFailure");
2536
2517
  this.handleAdFailure();
2537
2518
  }
2538
2519
  } else {
2520
+ console.log("[DEBUG-POD] \u26A0\uFE0F No more ads or time - calling handleAdFailure");
2539
2521
  this.handleAdFailure();
2540
2522
  }
2541
2523
  } else {
2542
- if (this.config.debugAdTiming) {
2543
- console.log(
2544
- "[StormcloudVideoPlayer] Ad error before ad break established - cleaning up"
2545
- );
2546
- }
2524
+ console.log("[DEBUG-POD] \u26A0\uFE0F Error before ad break established");
2547
2525
  this.handleAdFailure();
2548
2526
  }
2549
2527
  });
@@ -2553,7 +2531,7 @@ var StormcloudVideoPlayer = class {
2553
2531
  this.clearAdRequestWatchdog();
2554
2532
  this.activeAdRequestToken = null;
2555
2533
  this.showAds = true;
2556
- this.enforceAdHoldState();
2534
+ console.log("[DEBUG-LAYER] \u{1F3AC} Layers: Main=hidden, Ad=visible, Placeholder=no");
2557
2535
  });
2558
2536
  this.ima.on("content_resume", () => {
2559
2537
  console.log(`[DEBUG-POD] \u23F8\uFE0F content_resume | ad ${this.currentAdIndex}/${this.totalAdsInBreak}, queue=${this.adPodQueue.length}, remaining=${this.getRemainingAdMs()}ms`);
@@ -2733,6 +2711,12 @@ var StormcloudVideoPlayer = class {
2733
2711
  });
2734
2712
  }
2735
2713
  if (marker.type === "start") {
2714
+ if (this.inAdBreak) {
2715
+ console.log(
2716
+ `[DEBUG-POD] \u26A0\uFE0F SCTE-35 start marker ignored - already in ad break (currentTime: ${this.video.currentTime})`
2717
+ );
2718
+ return;
2719
+ }
2736
2720
  this.inAdBreak = true;
2737
2721
  const durationMs = marker.durationSeconds != null ? marker.durationSeconds * 1e3 : void 0;
2738
2722
  this.expectedAdBreakDurationMs = durationMs;
@@ -2799,6 +2783,9 @@ var StormcloudVideoPlayer = class {
2799
2783
  return;
2800
2784
  }
2801
2785
  if (marker.type === "progress" && this.inAdBreak) {
2786
+ console.log(
2787
+ `[DEBUG-POD] \u{1F4CA} SCTE-35 progress marker (currentTime: ${this.video.currentTime})`
2788
+ );
2802
2789
  if (marker.durationSeconds != null) {
2803
2790
  this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
2804
2791
  }
@@ -2810,7 +2797,8 @@ var StormcloudVideoPlayer = class {
2810
2797
  );
2811
2798
  this.scheduleAdStopCountdown(remainingMs);
2812
2799
  }
2813
- if (!this.ima.isAdPlaying()) {
2800
+ if (!this.ima.isAdPlaying() && this.activeAdRequestToken === null) {
2801
+ console.log("[DEBUG-POD] \u{1F4CA} Progress marker: no ad playing, attempting to start");
2814
2802
  const scheduled = this.findCurrentOrNextBreak(
2815
2803
  this.video.currentTime * 1e3
2816
2804
  );
@@ -2819,25 +2807,31 @@ var StormcloudVideoPlayer = class {
2819
2807
  const first = tags[0];
2820
2808
  const rest = tags.slice(1);
2821
2809
  this.adPodQueue = rest;
2822
- if (!this.showAds) {
2823
- this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
2824
- }
2825
2810
  this.playSingleAd(first).catch(() => {
2826
2811
  });
2827
2812
  }
2813
+ } else {
2814
+ console.log(
2815
+ `[DEBUG-POD] \u{1F4CA} Progress marker: ad playing or request active (playing=${this.ima.isAdPlaying()}, token=${this.activeAdRequestToken})`
2816
+ );
2828
2817
  }
2829
2818
  return;
2830
2819
  }
2831
2820
  if (marker.type === "end") {
2821
+ console.log(
2822
+ `[DEBUG-POD] \u{1F3C1} SCTE-35 end marker received (currentTime: ${this.video.currentTime})`
2823
+ );
2832
2824
  this.inAdBreak = false;
2833
2825
  this.expectedAdBreakDurationMs = void 0;
2834
2826
  this.currentAdBreakStartWallClockMs = void 0;
2835
2827
  this.clearAdStartTimer();
2836
2828
  this.clearAdStopTimer();
2837
2829
  if (this.ima.isAdPlaying()) {
2830
+ console.log("[DEBUG-POD] \u{1F6D1} Stopping ad due to SCTE-35 end marker");
2838
2831
  this.ima.stop().catch(() => {
2839
2832
  });
2840
2833
  }
2834
+ this.handleAdPodComplete();
2841
2835
  return;
2842
2836
  }
2843
2837
  }
@@ -3168,10 +3162,12 @@ var StormcloudVideoPlayer = class {
3168
3162
  this.vastToMediaUrlMap.clear();
3169
3163
  this.preloadedMediaUrls.clear();
3170
3164
  this.preloadingMediaUrls.clear();
3165
+ const currentMuted = this.video.muted;
3166
+ const currentVolume = this.video.volume;
3171
3167
  console.log(
3172
- `[DEBUG-AUDIO] \u{1F4BE} Capturing original state | muted=${this.video.muted}, volume=${this.video.volume}`
3168
+ `[DEBUG-AUDIO] \u{1F4BE} Capturing ORIGINAL state (once) | muted=${currentMuted}, volume=${currentVolume}`
3173
3169
  );
3174
- this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3170
+ this.ima.updateOriginalMutedState(currentMuted, currentVolume);
3175
3171
  this.inAdBreak = true;
3176
3172
  this.currentAdIndex = 0;
3177
3173
  this.totalAdsInBreak = vastTagUrls.length;
@@ -3294,31 +3290,15 @@ var StormcloudVideoPlayer = class {
3294
3290
  const overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
3295
3291
  const shouldExtendAdBreak = (adPlaying || pendingAds || this.showAds) && overrunMs < maxExtensionMs;
3296
3292
  if (shouldExtendAdBreak) {
3297
- if (this.config.debugAdTiming) {
3298
- console.log(
3299
- "[StormcloudVideoPlayer] Extending ad break beyond scheduled duration",
3300
- {
3301
- adPlaying,
3302
- pendingAds,
3303
- showAds: this.showAds,
3304
- overrunMs,
3305
- checkIntervalMs,
3306
- maxExtensionMs
3307
- }
3308
- );
3309
- }
3293
+ console.log(
3294
+ `[DEBUG-POD] \u23F3 Extending ad break | elapsed=${elapsedSinceStartMs}ms, expected=${expectedDurationMs}ms, overrun=${overrunMs}ms`
3295
+ );
3310
3296
  this.scheduleAdStopCountdown(checkIntervalMs);
3311
3297
  return;
3312
3298
  }
3313
- if (this.config.debugAdTiming) {
3314
- console.log("[StormcloudVideoPlayer] Ending ad break via timer", {
3315
- adPlaying,
3316
- pendingAds,
3317
- showAds: this.showAds,
3318
- overrunMs,
3319
- maxExtensionMs
3320
- });
3321
- }
3299
+ console.log(
3300
+ `[DEBUG-POD] \u23F1\uFE0F Ad break duration expired | elapsed=${elapsedSinceStartMs}ms, expected=${expectedDurationMs}ms`
3301
+ );
3322
3302
  if (adPlaying) {
3323
3303
  this.ima.stop().catch(() => {
3324
3304
  });
@@ -3401,7 +3381,6 @@ var StormcloudVideoPlayer = class {
3401
3381
  this.clearAdRequestWatchdog();
3402
3382
  this.clearAdFailsafeTimer();
3403
3383
  this.activeAdRequestToken = null;
3404
- this.releaseAdHoldState();
3405
3384
  this.preloadingAdUrls.clear();
3406
3385
  this.vastToMediaUrlMap.clear();
3407
3386
  this.preloadedMediaUrls.clear();
@@ -3418,13 +3397,18 @@ var StormcloudVideoPlayer = class {
3418
3397
  this.totalAdsInBreak = 0;
3419
3398
  this.ima.stop().catch(() => {
3420
3399
  });
3421
- const originalMutedState = this.ima.getOriginalMutedState();
3422
- const originalVolume = typeof this.ima.getOriginalVolume === "function" ? this.ima.getOriginalVolume() : this.video.volume;
3423
- this.video.muted = originalMutedState;
3424
- this.video.volume = originalVolume;
3400
+ const restoredMuted = this.ima.getOriginalMutedState();
3401
+ const restoredVolume = this.ima.getOriginalVolume();
3425
3402
  console.log(
3426
- `[DEBUG-AUDIO] \u{1F50A} Main video restored | muted=${originalMutedState}, volume=${originalVolume}`
3403
+ `[DEBUG-AUDIO] \u{1F50A} Audio restored by IMA | muted=${restoredMuted}, volume=${restoredVolume}`
3427
3404
  );
3405
+ console.log("[DEBUG-LAYER] \u{1F3AC} Layers: Main=visible, Ad=hidden, Placeholder=no");
3406
+ if (this.video.muted !== restoredMuted) {
3407
+ this.video.muted = restoredMuted;
3408
+ }
3409
+ if (Math.abs(this.video.volume - restoredVolume) > 0.01) {
3410
+ this.video.volume = restoredVolume;
3411
+ }
3428
3412
  if (!this.shouldContinueLiveStreamDuringAds() && this.video.paused) {
3429
3413
  console.log("[DEBUG-FLOW] \u25B6\uFE0F Resuming main video playback");
3430
3414
  (_a = this.video.play()) == null ? void 0 : _a.catch((error) => {
@@ -3433,9 +3417,20 @@ var StormcloudVideoPlayer = class {
3433
3417
  }
3434
3418
  }
3435
3419
  handleAdFailure() {
3436
- console.log(
3437
- `[DEBUG-POD] \u274C handleAdFailure | inBreak=${this.inAdBreak}, showAds=${this.showAds}, paused=${this.video.paused}`
3438
- );
3420
+ console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
3421
+ const remaining = this.getRemainingAdMs();
3422
+ if (remaining > 500 && this.adPodQueue.length > 0) {
3423
+ const nextPreloaded = this.findNextPreloadedAd();
3424
+ if (nextPreloaded) {
3425
+ this.currentAdIndex++;
3426
+ console.log(`[DEBUG-POD] \u27A1\uFE0F Trying next ad after failure (${this.currentAdIndex}/${this.totalAdsInBreak})`);
3427
+ this.playSingleAd(nextPreloaded).catch(() => {
3428
+ this.handleAdPodComplete();
3429
+ });
3430
+ return;
3431
+ }
3432
+ }
3433
+ console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
3439
3434
  this.handleAdPodComplete();
3440
3435
  }
3441
3436
  startAdRequestWatchdog(token) {
@@ -3508,12 +3503,6 @@ var StormcloudVideoPlayer = class {
3508
3503
  }
3509
3504
  return [b.vastTagUrl];
3510
3505
  }
3511
- logQueuedAdUrls(urls) {
3512
- if (!this.config.debugAdTiming) {
3513
- return;
3514
- }
3515
- console.log("[StormcloudVideoPlayer] ALL ad URLs queued:", urls);
3516
- }
3517
3506
  logAdState(event, extra = {}) {
3518
3507
  if (!this.config.debugAdTiming) {
3519
3508
  return;
@@ -3528,22 +3517,6 @@ var StormcloudVideoPlayer = class {
3528
3517
  ...extra
3529
3518
  });
3530
3519
  }
3531
- enforceAdHoldState() {
3532
- this.video.dataset.stormcloudAdPlaying = "true";
3533
- this.video.muted = true;
3534
- this.video.volume = 0;
3535
- console.log("[DEBUG-LAYER] \u{1F512} Enforced ad hold state (main video muted)");
3536
- if (typeof this.ima.showPlaceholder === "function") {
3537
- this.ima.showPlaceholder();
3538
- }
3539
- }
3540
- releaseAdHoldState() {
3541
- delete this.video.dataset.stormcloudAdPlaying;
3542
- console.log("[DEBUG-LAYER] \u{1F513} Released ad hold state");
3543
- if (typeof this.ima.hidePlaceholder === "function") {
3544
- this.ima.hidePlaceholder();
3545
- }
3546
- }
3547
3520
  async fetchAndParseVastXml(vastTagUrl) {
3548
3521
  try {
3549
3522
  const response = await fetch(vastTagUrl, { mode: "cors" });
@@ -3908,7 +3881,6 @@ var StormcloudVideoPlayer = class {
3908
3881
  }
3909
3882
  (_a = this.hls) == null ? void 0 : _a.destroy();
3910
3883
  (_b = this.ima) == null ? void 0 : _b.destroy();
3911
- this.releaseAdHoldState();
3912
3884
  this.preloadingAdUrls.clear();
3913
3885
  this.vastToMediaUrlMap.clear();
3914
3886
  this.preloadedMediaUrls.clear();