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.
@@ -80,10 +80,7 @@ declare class StormcloudVideoPlayer {
80
80
  private startAdFailsafeTimer;
81
81
  private clearAdFailsafeTimer;
82
82
  private selectVastTagsForBreak;
83
- private logQueuedAdUrls;
84
83
  private logAdState;
85
- private enforceAdHoldState;
86
- private releaseAdHoldState;
87
84
  private fetchAndParseVastXml;
88
85
  private extractMediaUrlsFromVast;
89
86
  private preloadMediaFile;
@@ -631,19 +631,10 @@ function createImaController(video, options) {
631
631
  adsManager.addEventListener(
632
632
  AdEvent.CONTENT_PAUSE_REQUESTED,
633
633
  () => {
634
- console.log("[DEBUG-FLOW] \u{1F3AF} CONTENT_PAUSE_REQUESTED - Ad starting");
634
+ console.log("[DEBUG-FLOW] \u{1F3AF} CONTENT_PAUSE_REQUESTED - Ad request accepted");
635
635
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
636
636
  video.pause();
637
637
  }
638
- hideContentVideo();
639
- if (adContainerEl) {
640
- adContainerEl.style.pointerEvents = "auto";
641
- adContainerEl.style.display = "flex";
642
- adContainerEl.style.backgroundColor = "#000";
643
- adContainerEl.offsetHeight;
644
- adContainerEl.style.opacity = "1";
645
- console.log("[DEBUG-LAYER] \u{1F7E1} Ad container VISIBLE");
646
- }
647
638
  adPlaying = true;
648
639
  setAdPlayingFlag(true);
649
640
  emit("content_pause");
@@ -674,7 +665,7 @@ function createImaController(video, options) {
674
665
  console.log("[DEBUG-FLOW] \u23F8\uFE0F CONTENT_RESUME - Single ad done");
675
666
  adPlaying = false;
676
667
  setAdPlayingFlag(false);
677
- console.log("[DEBUG-LAYER] \u26A0\uFE0F Waiting for pod manager decision (more ads or done)");
668
+ console.log("[DEBUG-LAYER] \u26A0\uFE0F Waiting for pod manager (more ads, placeholder, or done)");
678
669
  emit("content_resume");
679
670
  }
680
671
  );
@@ -2442,44 +2433,31 @@ var StormcloudVideoPlayer = class {
2442
2433
  }
2443
2434
  });
2444
2435
  this.ima.on("ad_error", () => {
2445
- if (this.config.debugAdTiming) {
2446
- console.log("[StormcloudVideoPlayer] IMA ad_error event received", {
2447
- showAds: this.showAds,
2448
- inAdBreak: this.inAdBreak,
2449
- remainingAds: this.adPodQueue.length
2450
- });
2451
- }
2436
+ const remaining = this.getRemainingAdMs();
2437
+ console.log(
2438
+ `[DEBUG-POD] \u274C ad_error event | inBreak=${this.inAdBreak}, queue=${this.adPodQueue.length}, remaining=${remaining}ms`
2439
+ );
2452
2440
  if (this.inAdBreak) {
2453
- const remaining = this.getRemainingAdMs();
2454
2441
  if (remaining > 500 && this.adPodQueue.length > 0) {
2455
2442
  const nextPreloaded = this.findNextPreloadedAd();
2456
2443
  if (nextPreloaded) {
2457
2444
  this.currentAdIndex++;
2458
- if (this.config.debugAdTiming) {
2459
- console.log(
2460
- `[StormcloudVideoPlayer] Skipping to next preloaded ad after error`
2461
- );
2462
- }
2445
+ console.log(
2446
+ `[DEBUG-POD] \u27A1\uFE0F Trying next ad after error (${this.currentAdIndex}/${this.totalAdsInBreak})`
2447
+ );
2463
2448
  this.playSingleAd(nextPreloaded).catch(() => {
2464
2449
  this.handleAdFailure();
2465
2450
  });
2466
2451
  } else {
2467
- if (this.config.debugAdTiming) {
2468
- console.log(
2469
- "[StormcloudVideoPlayer] No preloaded ads available, ending ad break"
2470
- );
2471
- }
2452
+ console.log("[DEBUG-POD] \u26A0\uFE0F No more preloaded ads - calling handleAdFailure");
2472
2453
  this.handleAdFailure();
2473
2454
  }
2474
2455
  } else {
2456
+ console.log("[DEBUG-POD] \u26A0\uFE0F No more ads or time - calling handleAdFailure");
2475
2457
  this.handleAdFailure();
2476
2458
  }
2477
2459
  } else {
2478
- if (this.config.debugAdTiming) {
2479
- console.log(
2480
- "[StormcloudVideoPlayer] Ad error before ad break established - cleaning up"
2481
- );
2482
- }
2460
+ console.log("[DEBUG-POD] \u26A0\uFE0F Error before ad break established");
2483
2461
  this.handleAdFailure();
2484
2462
  }
2485
2463
  });
@@ -2489,7 +2467,7 @@ var StormcloudVideoPlayer = class {
2489
2467
  this.clearAdRequestWatchdog();
2490
2468
  this.activeAdRequestToken = null;
2491
2469
  this.showAds = true;
2492
- this.enforceAdHoldState();
2470
+ console.log("[DEBUG-LAYER] \u{1F3AC} Layers: Main=hidden, Ad=visible, Placeholder=no");
2493
2471
  });
2494
2472
  this.ima.on("content_resume", () => {
2495
2473
  console.log(`[DEBUG-POD] \u23F8\uFE0F content_resume | ad ${this.currentAdIndex}/${this.totalAdsInBreak}, queue=${this.adPodQueue.length}, remaining=${this.getRemainingAdMs()}ms`);
@@ -2669,6 +2647,12 @@ var StormcloudVideoPlayer = class {
2669
2647
  });
2670
2648
  }
2671
2649
  if (marker.type === "start") {
2650
+ if (this.inAdBreak) {
2651
+ console.log(
2652
+ `[DEBUG-POD] \u26A0\uFE0F SCTE-35 start marker ignored - already in ad break (currentTime: ${this.video.currentTime})`
2653
+ );
2654
+ return;
2655
+ }
2672
2656
  this.inAdBreak = true;
2673
2657
  const durationMs = marker.durationSeconds != null ? marker.durationSeconds * 1e3 : void 0;
2674
2658
  this.expectedAdBreakDurationMs = durationMs;
@@ -2735,6 +2719,9 @@ var StormcloudVideoPlayer = class {
2735
2719
  return;
2736
2720
  }
2737
2721
  if (marker.type === "progress" && this.inAdBreak) {
2722
+ console.log(
2723
+ `[DEBUG-POD] \u{1F4CA} SCTE-35 progress marker (currentTime: ${this.video.currentTime})`
2724
+ );
2738
2725
  if (marker.durationSeconds != null) {
2739
2726
  this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
2740
2727
  }
@@ -2746,7 +2733,8 @@ var StormcloudVideoPlayer = class {
2746
2733
  );
2747
2734
  this.scheduleAdStopCountdown(remainingMs);
2748
2735
  }
2749
- if (!this.ima.isAdPlaying()) {
2736
+ if (!this.ima.isAdPlaying() && this.activeAdRequestToken === null) {
2737
+ console.log("[DEBUG-POD] \u{1F4CA} Progress marker: no ad playing, attempting to start");
2750
2738
  const scheduled = this.findCurrentOrNextBreak(
2751
2739
  this.video.currentTime * 1e3
2752
2740
  );
@@ -2755,25 +2743,31 @@ var StormcloudVideoPlayer = class {
2755
2743
  const first = tags[0];
2756
2744
  const rest = tags.slice(1);
2757
2745
  this.adPodQueue = rest;
2758
- if (!this.showAds) {
2759
- this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
2760
- }
2761
2746
  this.playSingleAd(first).catch(() => {
2762
2747
  });
2763
2748
  }
2749
+ } else {
2750
+ console.log(
2751
+ `[DEBUG-POD] \u{1F4CA} Progress marker: ad playing or request active (playing=${this.ima.isAdPlaying()}, token=${this.activeAdRequestToken})`
2752
+ );
2764
2753
  }
2765
2754
  return;
2766
2755
  }
2767
2756
  if (marker.type === "end") {
2757
+ console.log(
2758
+ `[DEBUG-POD] \u{1F3C1} SCTE-35 end marker received (currentTime: ${this.video.currentTime})`
2759
+ );
2768
2760
  this.inAdBreak = false;
2769
2761
  this.expectedAdBreakDurationMs = void 0;
2770
2762
  this.currentAdBreakStartWallClockMs = void 0;
2771
2763
  this.clearAdStartTimer();
2772
2764
  this.clearAdStopTimer();
2773
2765
  if (this.ima.isAdPlaying()) {
2766
+ console.log("[DEBUG-POD] \u{1F6D1} Stopping ad due to SCTE-35 end marker");
2774
2767
  this.ima.stop().catch(() => {
2775
2768
  });
2776
2769
  }
2770
+ this.handleAdPodComplete();
2777
2771
  return;
2778
2772
  }
2779
2773
  }
@@ -3104,10 +3098,12 @@ var StormcloudVideoPlayer = class {
3104
3098
  this.vastToMediaUrlMap.clear();
3105
3099
  this.preloadedMediaUrls.clear();
3106
3100
  this.preloadingMediaUrls.clear();
3101
+ const currentMuted = this.video.muted;
3102
+ const currentVolume = this.video.volume;
3107
3103
  console.log(
3108
- `[DEBUG-AUDIO] \u{1F4BE} Capturing original state | muted=${this.video.muted}, volume=${this.video.volume}`
3104
+ `[DEBUG-AUDIO] \u{1F4BE} Capturing ORIGINAL state (once) | muted=${currentMuted}, volume=${currentVolume}`
3109
3105
  );
3110
- this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3106
+ this.ima.updateOriginalMutedState(currentMuted, currentVolume);
3111
3107
  this.inAdBreak = true;
3112
3108
  this.currentAdIndex = 0;
3113
3109
  this.totalAdsInBreak = vastTagUrls.length;
@@ -3230,31 +3226,15 @@ var StormcloudVideoPlayer = class {
3230
3226
  const overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
3231
3227
  const shouldExtendAdBreak = (adPlaying || pendingAds || this.showAds) && overrunMs < maxExtensionMs;
3232
3228
  if (shouldExtendAdBreak) {
3233
- if (this.config.debugAdTiming) {
3234
- console.log(
3235
- "[StormcloudVideoPlayer] Extending ad break beyond scheduled duration",
3236
- {
3237
- adPlaying,
3238
- pendingAds,
3239
- showAds: this.showAds,
3240
- overrunMs,
3241
- checkIntervalMs,
3242
- maxExtensionMs
3243
- }
3244
- );
3245
- }
3229
+ console.log(
3230
+ `[DEBUG-POD] \u23F3 Extending ad break | elapsed=${elapsedSinceStartMs}ms, expected=${expectedDurationMs}ms, overrun=${overrunMs}ms`
3231
+ );
3246
3232
  this.scheduleAdStopCountdown(checkIntervalMs);
3247
3233
  return;
3248
3234
  }
3249
- if (this.config.debugAdTiming) {
3250
- console.log("[StormcloudVideoPlayer] Ending ad break via timer", {
3251
- adPlaying,
3252
- pendingAds,
3253
- showAds: this.showAds,
3254
- overrunMs,
3255
- maxExtensionMs
3256
- });
3257
- }
3235
+ console.log(
3236
+ `[DEBUG-POD] \u23F1\uFE0F Ad break duration expired | elapsed=${elapsedSinceStartMs}ms, expected=${expectedDurationMs}ms`
3237
+ );
3258
3238
  if (adPlaying) {
3259
3239
  this.ima.stop().catch(() => {
3260
3240
  });
@@ -3337,7 +3317,6 @@ var StormcloudVideoPlayer = class {
3337
3317
  this.clearAdRequestWatchdog();
3338
3318
  this.clearAdFailsafeTimer();
3339
3319
  this.activeAdRequestToken = null;
3340
- this.releaseAdHoldState();
3341
3320
  this.preloadingAdUrls.clear();
3342
3321
  this.vastToMediaUrlMap.clear();
3343
3322
  this.preloadedMediaUrls.clear();
@@ -3354,13 +3333,18 @@ var StormcloudVideoPlayer = class {
3354
3333
  this.totalAdsInBreak = 0;
3355
3334
  this.ima.stop().catch(() => {
3356
3335
  });
3357
- const originalMutedState = this.ima.getOriginalMutedState();
3358
- const originalVolume = typeof this.ima.getOriginalVolume === "function" ? this.ima.getOriginalVolume() : this.video.volume;
3359
- this.video.muted = originalMutedState;
3360
- this.video.volume = originalVolume;
3336
+ const restoredMuted = this.ima.getOriginalMutedState();
3337
+ const restoredVolume = this.ima.getOriginalVolume();
3361
3338
  console.log(
3362
- `[DEBUG-AUDIO] \u{1F50A} Main video restored | muted=${originalMutedState}, volume=${originalVolume}`
3339
+ `[DEBUG-AUDIO] \u{1F50A} Audio restored by IMA | muted=${restoredMuted}, volume=${restoredVolume}`
3363
3340
  );
3341
+ console.log("[DEBUG-LAYER] \u{1F3AC} Layers: Main=visible, Ad=hidden, Placeholder=no");
3342
+ if (this.video.muted !== restoredMuted) {
3343
+ this.video.muted = restoredMuted;
3344
+ }
3345
+ if (Math.abs(this.video.volume - restoredVolume) > 0.01) {
3346
+ this.video.volume = restoredVolume;
3347
+ }
3364
3348
  if (!this.shouldContinueLiveStreamDuringAds() && this.video.paused) {
3365
3349
  console.log("[DEBUG-FLOW] \u25B6\uFE0F Resuming main video playback");
3366
3350
  (_a = this.video.play()) == null ? void 0 : _a.catch((error) => {
@@ -3369,9 +3353,20 @@ var StormcloudVideoPlayer = class {
3369
3353
  }
3370
3354
  }
3371
3355
  handleAdFailure() {
3372
- console.log(
3373
- `[DEBUG-POD] \u274C handleAdFailure | inBreak=${this.inAdBreak}, showAds=${this.showAds}, paused=${this.video.paused}`
3374
- );
3356
+ console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
3357
+ const remaining = this.getRemainingAdMs();
3358
+ if (remaining > 500 && this.adPodQueue.length > 0) {
3359
+ const nextPreloaded = this.findNextPreloadedAd();
3360
+ if (nextPreloaded) {
3361
+ this.currentAdIndex++;
3362
+ console.log(`[DEBUG-POD] \u27A1\uFE0F Trying next ad after failure (${this.currentAdIndex}/${this.totalAdsInBreak})`);
3363
+ this.playSingleAd(nextPreloaded).catch(() => {
3364
+ this.handleAdPodComplete();
3365
+ });
3366
+ return;
3367
+ }
3368
+ }
3369
+ console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
3375
3370
  this.handleAdPodComplete();
3376
3371
  }
3377
3372
  startAdRequestWatchdog(token) {
@@ -3444,12 +3439,6 @@ var StormcloudVideoPlayer = class {
3444
3439
  }
3445
3440
  return [b.vastTagUrl];
3446
3441
  }
3447
- logQueuedAdUrls(urls) {
3448
- if (!this.config.debugAdTiming) {
3449
- return;
3450
- }
3451
- console.log("[StormcloudVideoPlayer] ALL ad URLs queued:", urls);
3452
- }
3453
3442
  logAdState(event, extra = {}) {
3454
3443
  if (!this.config.debugAdTiming) {
3455
3444
  return;
@@ -3464,22 +3453,6 @@ var StormcloudVideoPlayer = class {
3464
3453
  ...extra
3465
3454
  });
3466
3455
  }
3467
- enforceAdHoldState() {
3468
- this.video.dataset.stormcloudAdPlaying = "true";
3469
- this.video.muted = true;
3470
- this.video.volume = 0;
3471
- console.log("[DEBUG-LAYER] \u{1F512} Enforced ad hold state (main video muted)");
3472
- if (typeof this.ima.showPlaceholder === "function") {
3473
- this.ima.showPlaceholder();
3474
- }
3475
- }
3476
- releaseAdHoldState() {
3477
- delete this.video.dataset.stormcloudAdPlaying;
3478
- console.log("[DEBUG-LAYER] \u{1F513} Released ad hold state");
3479
- if (typeof this.ima.hidePlaceholder === "function") {
3480
- this.ima.hidePlaceholder();
3481
- }
3482
- }
3483
3456
  async fetchAndParseVastXml(vastTagUrl) {
3484
3457
  try {
3485
3458
  const response = await fetch(vastTagUrl, { mode: "cors" });
@@ -3844,7 +3817,6 @@ var StormcloudVideoPlayer = class {
3844
3817
  }
3845
3818
  (_a = this.hls) == null ? void 0 : _a.destroy();
3846
3819
  (_b = this.ima) == null ? void 0 : _b.destroy();
3847
- this.releaseAdHoldState();
3848
3820
  this.preloadingAdUrls.clear();
3849
3821
  this.vastToMediaUrlMap.clear();
3850
3822
  this.preloadedMediaUrls.clear();