stormcloud-video-player 0.2.35 → 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");
@@ -2540,7 +2531,7 @@ var StormcloudVideoPlayer = class {
2540
2531
  this.clearAdRequestWatchdog();
2541
2532
  this.activeAdRequestToken = null;
2542
2533
  this.showAds = true;
2543
- this.enforceAdHoldState();
2534
+ console.log("[DEBUG-LAYER] \u{1F3AC} Layers: Main=hidden, Ad=visible, Placeholder=no");
2544
2535
  });
2545
2536
  this.ima.on("content_resume", () => {
2546
2537
  console.log(`[DEBUG-POD] \u23F8\uFE0F content_resume | ad ${this.currentAdIndex}/${this.totalAdsInBreak}, queue=${this.adPodQueue.length}, remaining=${this.getRemainingAdMs()}ms`);
@@ -2720,6 +2711,12 @@ var StormcloudVideoPlayer = class {
2720
2711
  });
2721
2712
  }
2722
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
+ }
2723
2720
  this.inAdBreak = true;
2724
2721
  const durationMs = marker.durationSeconds != null ? marker.durationSeconds * 1e3 : void 0;
2725
2722
  this.expectedAdBreakDurationMs = durationMs;
@@ -2786,6 +2783,9 @@ var StormcloudVideoPlayer = class {
2786
2783
  return;
2787
2784
  }
2788
2785
  if (marker.type === "progress" && this.inAdBreak) {
2786
+ console.log(
2787
+ `[DEBUG-POD] \u{1F4CA} SCTE-35 progress marker (currentTime: ${this.video.currentTime})`
2788
+ );
2789
2789
  if (marker.durationSeconds != null) {
2790
2790
  this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
2791
2791
  }
@@ -2797,7 +2797,8 @@ var StormcloudVideoPlayer = class {
2797
2797
  );
2798
2798
  this.scheduleAdStopCountdown(remainingMs);
2799
2799
  }
2800
- 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");
2801
2802
  const scheduled = this.findCurrentOrNextBreak(
2802
2803
  this.video.currentTime * 1e3
2803
2804
  );
@@ -2806,25 +2807,31 @@ var StormcloudVideoPlayer = class {
2806
2807
  const first = tags[0];
2807
2808
  const rest = tags.slice(1);
2808
2809
  this.adPodQueue = rest;
2809
- if (!this.showAds) {
2810
- this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
2811
- }
2812
2810
  this.playSingleAd(first).catch(() => {
2813
2811
  });
2814
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
+ );
2815
2817
  }
2816
2818
  return;
2817
2819
  }
2818
2820
  if (marker.type === "end") {
2821
+ console.log(
2822
+ `[DEBUG-POD] \u{1F3C1} SCTE-35 end marker received (currentTime: ${this.video.currentTime})`
2823
+ );
2819
2824
  this.inAdBreak = false;
2820
2825
  this.expectedAdBreakDurationMs = void 0;
2821
2826
  this.currentAdBreakStartWallClockMs = void 0;
2822
2827
  this.clearAdStartTimer();
2823
2828
  this.clearAdStopTimer();
2824
2829
  if (this.ima.isAdPlaying()) {
2830
+ console.log("[DEBUG-POD] \u{1F6D1} Stopping ad due to SCTE-35 end marker");
2825
2831
  this.ima.stop().catch(() => {
2826
2832
  });
2827
2833
  }
2834
+ this.handleAdPodComplete();
2828
2835
  return;
2829
2836
  }
2830
2837
  }
@@ -3155,10 +3162,12 @@ var StormcloudVideoPlayer = class {
3155
3162
  this.vastToMediaUrlMap.clear();
3156
3163
  this.preloadedMediaUrls.clear();
3157
3164
  this.preloadingMediaUrls.clear();
3165
+ const currentMuted = this.video.muted;
3166
+ const currentVolume = this.video.volume;
3158
3167
  console.log(
3159
- `[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}`
3160
3169
  );
3161
- this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3170
+ this.ima.updateOriginalMutedState(currentMuted, currentVolume);
3162
3171
  this.inAdBreak = true;
3163
3172
  this.currentAdIndex = 0;
3164
3173
  this.totalAdsInBreak = vastTagUrls.length;
@@ -3372,7 +3381,6 @@ var StormcloudVideoPlayer = class {
3372
3381
  this.clearAdRequestWatchdog();
3373
3382
  this.clearAdFailsafeTimer();
3374
3383
  this.activeAdRequestToken = null;
3375
- this.releaseAdHoldState();
3376
3384
  this.preloadingAdUrls.clear();
3377
3385
  this.vastToMediaUrlMap.clear();
3378
3386
  this.preloadedMediaUrls.clear();
@@ -3389,13 +3397,18 @@ var StormcloudVideoPlayer = class {
3389
3397
  this.totalAdsInBreak = 0;
3390
3398
  this.ima.stop().catch(() => {
3391
3399
  });
3392
- const originalMutedState = this.ima.getOriginalMutedState();
3393
- const originalVolume = typeof this.ima.getOriginalVolume === "function" ? this.ima.getOriginalVolume() : this.video.volume;
3394
- this.video.muted = originalMutedState;
3395
- this.video.volume = originalVolume;
3400
+ const restoredMuted = this.ima.getOriginalMutedState();
3401
+ const restoredVolume = this.ima.getOriginalVolume();
3396
3402
  console.log(
3397
- `[DEBUG-AUDIO] \u{1F50A} Main video restored | muted=${originalMutedState}, volume=${originalVolume}`
3403
+ `[DEBUG-AUDIO] \u{1F50A} Audio restored by IMA | muted=${restoredMuted}, volume=${restoredVolume}`
3398
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
+ }
3399
3412
  if (!this.shouldContinueLiveStreamDuringAds() && this.video.paused) {
3400
3413
  console.log("[DEBUG-FLOW] \u25B6\uFE0F Resuming main video playback");
3401
3414
  (_a = this.video.play()) == null ? void 0 : _a.catch((error) => {
@@ -3404,20 +3417,20 @@ var StormcloudVideoPlayer = class {
3404
3417
  }
3405
3418
  }
3406
3419
  handleAdFailure() {
3420
+ console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
3407
3421
  const remaining = this.getRemainingAdMs();
3408
- console.log(
3409
- `[DEBUG-POD] \u274C handleAdFailure | inBreak=${this.inAdBreak}, showAds=${this.showAds}, remaining=${remaining}ms`
3410
- );
3411
- if (remaining > 500 && this.inAdBreak) {
3412
- console.log(
3413
- `[DEBUG-POD] \u23F3 Ad failed but ${remaining}ms remaining - showing placeholder until duration expires`
3414
- );
3415
- this.showAds = true;
3416
- this.ima.showPlaceholder();
3417
- this.enforceAdHoldState();
3418
- return;
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
+ }
3419
3432
  }
3420
- console.log("[DEBUG-POD] \u23F9\uFE0F No remaining time - ending ad break now");
3433
+ console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
3421
3434
  this.handleAdPodComplete();
3422
3435
  }
3423
3436
  startAdRequestWatchdog(token) {
@@ -3490,12 +3503,6 @@ var StormcloudVideoPlayer = class {
3490
3503
  }
3491
3504
  return [b.vastTagUrl];
3492
3505
  }
3493
- logQueuedAdUrls(urls) {
3494
- if (!this.config.debugAdTiming) {
3495
- return;
3496
- }
3497
- console.log("[StormcloudVideoPlayer] ALL ad URLs queued:", urls);
3498
- }
3499
3506
  logAdState(event, extra = {}) {
3500
3507
  if (!this.config.debugAdTiming) {
3501
3508
  return;
@@ -3510,22 +3517,6 @@ var StormcloudVideoPlayer = class {
3510
3517
  ...extra
3511
3518
  });
3512
3519
  }
3513
- enforceAdHoldState() {
3514
- this.video.dataset.stormcloudAdPlaying = "true";
3515
- this.video.muted = true;
3516
- this.video.volume = 0;
3517
- console.log("[DEBUG-LAYER] \u{1F512} Enforced ad hold state (main video muted)");
3518
- if (typeof this.ima.showPlaceholder === "function") {
3519
- this.ima.showPlaceholder();
3520
- }
3521
- }
3522
- releaseAdHoldState() {
3523
- delete this.video.dataset.stormcloudAdPlaying;
3524
- console.log("[DEBUG-LAYER] \u{1F513} Released ad hold state");
3525
- if (typeof this.ima.hidePlaceholder === "function") {
3526
- this.ima.hidePlaceholder();
3527
- }
3528
- }
3529
3520
  async fetchAndParseVastXml(vastTagUrl) {
3530
3521
  try {
3531
3522
  const response = await fetch(vastTagUrl, { mode: "cors" });
@@ -3890,7 +3881,6 @@ var StormcloudVideoPlayer = class {
3890
3881
  }
3891
3882
  (_a = this.hls) == null ? void 0 : _a.destroy();
3892
3883
  (_b = this.ima) == null ? void 0 : _b.destroy();
3893
- this.releaseAdHoldState();
3894
3884
  this.preloadingAdUrls.clear();
3895
3885
  this.vastToMediaUrlMap.clear();
3896
3886
  this.preloadedMediaUrls.clear();