stormcloud-video-player 0.3.5 → 0.3.7

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.
@@ -225,7 +225,6 @@ function createImaController(video, options) {
225
225
  video.muted = true;
226
226
  video.volume = 0;
227
227
  contentVideoHidden = true;
228
- console.log("[DEBUG-LAYER] \u{1F534} Content video HIDDEN | muted=true, volume=0");
229
228
  }
230
229
  }
231
230
  function showContentVideo() {
@@ -237,9 +236,6 @@ function createImaController(video, options) {
237
236
  video.muted = originalMutedState;
238
237
  video.volume = originalVolume;
239
238
  contentVideoHidden = false;
240
- console.log(
241
- `[DEBUG-LAYER] \u{1F7E2} Content video RESTORED | muted=${originalMutedState}, volume=${originalVolume}`
242
- );
243
239
  }
244
240
  }
245
241
  function createAdVideoElement() {
@@ -260,13 +256,9 @@ function createImaController(video, options) {
260
256
  "canplay",
261
257
  () => {
262
258
  adVideo.style.opacity = "1";
263
- console.log("[DEBUG-LAYER] \u{1F4FA} Ad video element ready (canplay fired)");
264
259
  },
265
260
  { once: true }
266
261
  );
267
- console.log(
268
- `[DEBUG-AUDIO] \u{1F50A} Ad video created | volume=${adVideo.volume}, muted=${adVideo.muted}`
269
- );
270
262
  return adVideo;
271
263
  }
272
264
  function emit(event, payload) {
@@ -418,10 +410,8 @@ function createImaController(video, options) {
418
410
  function destroyAdsManager() {
419
411
  if (adsManager) {
420
412
  try {
421
- console.log("[IMA] Destroying existing ads manager");
422
413
  adsManager.destroy();
423
- } catch (error) {
424
- console.warn("[IMA] Error destroying ads manager:", error);
414
+ } catch {
425
415
  }
426
416
  adsManager = void 0;
427
417
  }
@@ -439,9 +429,6 @@ function createImaController(video, options) {
439
429
  if (!adVideoElement) {
440
430
  adVideoElement = createAdVideoElement();
441
431
  adContainerEl.appendChild(adVideoElement);
442
- console.log(
443
- "[IMA] Dedicated ad video element added to container"
444
- );
445
432
  }
446
433
  adDisplayContainer = new google.ima.AdDisplayContainer(
447
434
  adContainerEl,
@@ -449,9 +436,6 @@ function createImaController(video, options) {
449
436
  );
450
437
  try {
451
438
  (_a = adDisplayContainer.initialize) == null ? void 0 : _a.call(adDisplayContainer);
452
- console.log(
453
- "[IMA] AdDisplayContainer initialized with dedicated ad video"
454
- );
455
439
  } catch {
456
440
  }
457
441
  }
@@ -459,9 +443,6 @@ function createImaController(video, options) {
459
443
  });
460
444
  },
461
445
  async requestAds(vastTagUrl) {
462
- console.log("[IMA] \u{1F4E1} === requestAds() called ===");
463
- console.log("[IMA] VAST URL:", vastTagUrl);
464
- console.log("[IMA] This will fetch the ad from the server - no visual change yet");
465
446
  if (!vastTagUrl || vastTagUrl.trim() === "") {
466
447
  const error = new Error("VAST tag URL is empty or undefined");
467
448
  console.warn("[IMA] \u274C", error.message);
@@ -504,7 +485,6 @@ function createImaController(video, options) {
504
485
  lastAdTagUrl = vastTagUrl;
505
486
  retryAttempts = 0;
506
487
  if (!adDisplayContainer) {
507
- console.log("[IMA] Creating ad display container");
508
488
  const container = document.createElement("div");
509
489
  container.style.position = "absolute";
510
490
  container.style.left = "0";
@@ -527,25 +507,11 @@ function createImaController(video, options) {
527
507
  if (!adVideoElement) {
528
508
  adVideoElement = createAdVideoElement();
529
509
  adContainerEl.appendChild(adVideoElement);
530
- console.log(
531
- "[IMA] Dedicated ad video element created and added to container"
532
- );
533
510
  }
534
511
  adDisplayContainer = new google.ima.AdDisplayContainer(
535
512
  container,
536
513
  adVideoElement
537
514
  );
538
- try {
539
- adDisplayContainer.initialize();
540
- console.log(
541
- "[IMA] Ad display container initialized with dedicated ad video"
542
- );
543
- } catch (error) {
544
- console.warn(
545
- "[IMA] Failed to initialize ad display container:",
546
- error
547
- );
548
- }
549
515
  }
550
516
  const videoWidth = video.offsetWidth || video.clientWidth;
551
517
  const videoHeight = video.offsetHeight || video.clientHeight;
@@ -560,29 +526,17 @@ function createImaController(video, options) {
560
526
  return Promise.reject(error);
561
527
  }
562
528
  if (!adsLoader) {
563
- console.log("[IMA] Creating ads loader");
564
529
  const adsLoaderCls = new google.ima.AdsLoader(adDisplayContainer);
565
530
  adsLoader = adsLoaderCls;
566
531
  adsLoader.addEventListener(
567
532
  google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
568
533
  (evt) => {
569
- console.log("[DEBUG-FLOW] \u2705 ADS_MANAGER_LOADED - Setting up manager");
570
534
  try {
571
535
  const adsRenderingSettings = new google.ima.AdsRenderingSettings();
572
536
  adsRenderingSettings.enablePreloading = true;
573
537
  adsManager = evt.getAdsManager(video, adsRenderingSettings);
574
538
  const AdEvent = google.ima.AdEvent.Type;
575
539
  const AdErrorEvent = google.ima.AdErrorEvent.Type;
576
- const keyEvents = ["STARTED", "COMPLETE", "CONTENT_PAUSE_REQUESTED", "CONTENT_RESUME_REQUESTED", "ALL_ADS_COMPLETED"];
577
- keyEvents.forEach((eventType) => {
578
- if (AdEvent[eventType]) {
579
- adsManager.addEventListener(AdEvent[eventType], (e) => {
580
- var _a, _b;
581
- const ad = (_a = e.getAd) == null ? void 0 : _a.call(e);
582
- console.log(`[DEBUG-FLOW] \u{1F3AC} ${eventType} | title=${((_b = ad == null ? void 0 : ad.getTitle) == null ? void 0 : _b.call(ad)) || "N/A"}`);
583
- });
584
- }
585
- });
586
540
  adsManager.addEventListener(
587
541
  AdErrorEvent.AD_ERROR,
588
542
  (errorEvent) => {
@@ -599,7 +553,6 @@ function createImaController(video, options) {
599
553
  if (adContainerEl) {
600
554
  adContainerEl.style.pointerEvents = "none";
601
555
  adContainerEl.style.display = "none";
602
- console.log("[DEBUG-LAYER] \u274C Ad container HIDDEN (error)");
603
556
  }
604
557
  }, 300);
605
558
  }
@@ -631,7 +584,6 @@ function createImaController(video, options) {
631
584
  adsManager.addEventListener(
632
585
  AdEvent.CONTENT_PAUSE_REQUESTED,
633
586
  () => {
634
- console.log("[DEBUG-FLOW] \u{1F3AF} CONTENT_PAUSE_REQUESTED - Ad request accepted");
635
587
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
636
588
  video.pause();
637
589
  }
@@ -641,15 +593,11 @@ function createImaController(video, options) {
641
593
  }
642
594
  );
643
595
  adsManager.addEventListener(AdEvent.STARTED, () => {
644
- console.log("[DEBUG-FLOW] \u25B6\uFE0F STARTED - Ad playing now");
645
596
  setAdPlayingFlag(true);
646
597
  hideContentVideo();
647
598
  if (adVideoElement) {
648
599
  adVideoElement.volume = originalMutedState ? 0 : originalVolume;
649
600
  adVideoElement.muted = originalMutedState;
650
- console.log(
651
- `[DEBUG-AUDIO] \u{1F50A} Ad audio set | volume=${adVideoElement.volume}, muted=${adVideoElement.muted}`
652
- );
653
601
  }
654
602
  if (adContainerEl) {
655
603
  adContainerEl.style.pointerEvents = "auto";
@@ -662,15 +610,12 @@ function createImaController(video, options) {
662
610
  adsManager.addEventListener(
663
611
  AdEvent.CONTENT_RESUME_REQUESTED,
664
612
  () => {
665
- console.log("[DEBUG-FLOW] \u23F8\uFE0F CONTENT_RESUME - Single ad done");
666
613
  adPlaying = false;
667
614
  setAdPlayingFlag(false);
668
- console.log("[DEBUG-LAYER] \u26A0\uFE0F Waiting for pod manager (more ads, placeholder, or done)");
669
615
  emit("content_resume");
670
616
  }
671
617
  );
672
618
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
673
- console.log("[DEBUG-FLOW] \u{1F3C1} ALL_ADS_COMPLETED - Pod finished");
674
619
  adPlaying = false;
675
620
  setAdPlayingFlag(false);
676
621
  if (adContainerEl) {
@@ -680,19 +625,16 @@ function createImaController(video, options) {
680
625
  if (adContainerEl) {
681
626
  adContainerEl.style.pointerEvents = "none";
682
627
  adContainerEl.style.display = "none";
683
- console.log("[DEBUG-LAYER] \u26AB Ad container HIDDEN (pod done)");
684
628
  }
685
629
  }, 300);
686
630
  }
687
631
  showContentVideo();
688
632
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds) && video.paused) {
689
- video.play().catch((e) => {
690
- console.warn("[DEBUG-ERROR] Failed to resume video:", e);
633
+ video.play().catch(() => {
691
634
  });
692
635
  }
693
636
  emit("all_ads_completed");
694
637
  });
695
- console.log("[IMA] Ads manager event listeners attached");
696
638
  if (adsLoadedResolve) {
697
639
  adsLoadedResolve();
698
640
  adsLoadedResolve = void 0;
@@ -787,9 +729,7 @@ function createImaController(video, options) {
787
729
  }
788
730
  const preloadPromise = fetchVastDocument(vastTagUrl).then((xml) => {
789
731
  preloadedVast.set(vastTagUrl, xml);
790
- console.log("[IMA] Cached VAST response for preloading:", vastTagUrl);
791
- }).catch((error) => {
792
- console.warn("[IMA] Failed to preload VAST response:", error);
732
+ }).catch(() => {
793
733
  preloadedVast.delete(vastTagUrl);
794
734
  }).finally(() => {
795
735
  preloadingVast.delete(vastTagUrl);
@@ -802,7 +742,6 @@ function createImaController(video, options) {
802
742
  },
803
743
  async play() {
804
744
  var _a, _b;
805
- console.log("[DEBUG-FLOW] \u25B6\uFE0F play() - Starting ad playback");
806
745
  if (!((_a = window.google) == null ? void 0 : _a.ima) || !adDisplayContainer) {
807
746
  return Promise.reject(new Error("IMA SDK not available"));
808
747
  }
@@ -818,19 +757,15 @@ function createImaController(video, options) {
818
757
  if (adVideoElement) {
819
758
  adVideoElement.volume = adVolume;
820
759
  adVideoElement.muted = originalMutedState;
821
- console.log(
822
- `[DEBUG-AUDIO] \u{1F50A} Pre-start ad audio | volume=${adVolume}, muted=${originalMutedState}`
823
- );
824
760
  }
825
761
  try {
826
762
  adsManager.setVolume(adVolume);
827
- } catch (error) {
828
- console.warn("[DEBUG-ERROR] Failed to set IMA manager volume:", error);
763
+ } catch {
829
764
  }
830
765
  adsManager.start();
831
766
  return Promise.resolve();
832
767
  } catch (error) {
833
- console.error("[DEBUG-ERROR] \u274C Error starting ad:", error);
768
+ console.error("[IMA] \u274C Error starting ad:", error);
834
769
  adPlaying = false;
835
770
  setAdPlayingFlag(false);
836
771
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
@@ -842,7 +777,6 @@ function createImaController(video, options) {
842
777
  },
843
778
  async stop() {
844
779
  var _a;
845
- console.log("[DEBUG-FLOW] \u23F9\uFE0F stop() - Stopping ad playback");
846
780
  adPlaying = false;
847
781
  setAdPlayingFlag(false);
848
782
  if (adContainerEl) {
@@ -852,7 +786,6 @@ function createImaController(video, options) {
852
786
  if (adContainerEl) {
853
787
  adContainerEl.style.pointerEvents = "none";
854
788
  adContainerEl.style.display = "none";
855
- console.log("[DEBUG-LAYER] \u26AB Ad container HIDDEN (stop)");
856
789
  }
857
790
  }, 300);
858
791
  }
@@ -922,9 +855,6 @@ function createImaController(video, options) {
922
855
  },
923
856
  updateOriginalMutedState(muted, volume) {
924
857
  const nextVolume = typeof volume === "number" && !Number.isNaN(volume) ? Math.max(0, Math.min(1, volume)) : originalVolume;
925
- console.log(
926
- `[DEBUG-AUDIO] \u{1F4BE} Saved original state | muted: ${originalMutedState}->${muted}, volume: ${originalVolume}->${nextVolume}`
927
- );
928
858
  originalMutedState = muted;
929
859
  originalVolume = nextVolume;
930
860
  },
@@ -939,15 +869,11 @@ function createImaController(video, options) {
939
869
  if (adVideoElement && adPlaying) {
940
870
  adVideoElement.volume = clampedVolume;
941
871
  adVideoElement.muted = clampedVolume === 0;
942
- console.log(
943
- `[DEBUG-AUDIO] \u{1F50A} Ad volume changed | volume=${clampedVolume}, muted=${clampedVolume === 0}`
944
- );
945
872
  }
946
873
  if (adsManager && adPlaying) {
947
874
  try {
948
875
  adsManager.setVolume(clampedVolume);
949
- } catch (error) {
950
- console.warn("[DEBUG-ERROR] Failed to set IMA manager volume:", error);
876
+ } catch {
951
877
  }
952
878
  }
953
879
  },
@@ -2437,51 +2363,37 @@ var StormcloudVideoPlayer = class {
2437
2363
  });
2438
2364
  this.ima.on("ad_error", (errorPayload) => {
2439
2365
  const remaining = this.getRemainingAdMs();
2440
- console.error(
2441
- `[DEBUG-POD] \u274C ad_error event | inBreak=${this.inAdBreak}, queue=${this.adPodQueue.length}, remaining=${remaining}ms`,
2442
- errorPayload ? `
2443
- Error details: ${JSON.stringify(errorPayload)}` : ""
2444
- );
2366
+ console.error("[AD-ERROR] Ad playback failed", errorPayload || "");
2445
2367
  if (this.inAdBreak) {
2446
2368
  if (remaining > 500 && this.adPodQueue.length > 0) {
2447
2369
  const nextPreloaded = this.findNextPreloadedAd();
2448
2370
  if (nextPreloaded) {
2449
2371
  this.currentAdIndex++;
2450
- console.log(
2451
- `[DEBUG-POD] \u27A1\uFE0F Trying next ad after error (${this.currentAdIndex}/${this.totalAdsInBreak})`
2452
- );
2453
2372
  this.playSingleAd(nextPreloaded).catch(() => {
2454
2373
  this.handleAdFailure();
2455
2374
  });
2456
2375
  } else {
2457
- console.log("[DEBUG-POD] \u26A0\uFE0F No more preloaded ads - calling handleAdFailure");
2458
2376
  this.handleAdFailure();
2459
2377
  }
2460
2378
  } else {
2461
- console.log("[DEBUG-POD] \u26A0\uFE0F No more ads or time - calling handleAdFailure");
2462
2379
  this.handleAdFailure();
2463
2380
  }
2464
2381
  } else {
2465
- console.log("[DEBUG-POD] \u26A0\uFE0F Error before ad break established");
2466
2382
  this.handleAdFailure();
2467
2383
  }
2468
2384
  });
2469
2385
  this.ima.on("content_pause", () => {
2470
- console.log(`[DEBUG-POD] \u{1F3AF} content_pause (AD STARTING!) | ad ${this.currentAdIndex}/${this.totalAdsInBreak}, queue=${this.adPodQueue.length}`);
2471
2386
  this.clearAdFailsafeTimer();
2472
2387
  this.clearAdRequestWatchdog();
2473
2388
  this.activeAdRequestToken = null;
2474
2389
  this.showAds = true;
2475
- console.log("[DEBUG-LAYER] \u{1F3AC} Layers: Main=hidden, Ad=visible, Placeholder=no");
2476
2390
  });
2477
2391
  this.ima.on("content_resume", () => {
2478
- console.log(`[DEBUG-POD] \u23F8\uFE0F content_resume | ad ${this.currentAdIndex}/${this.totalAdsInBreak}, queue=${this.adPodQueue.length}, remaining=${this.getRemainingAdMs()}ms`);
2479
2392
  this.clearAdFailsafeTimer();
2480
2393
  this.clearAdRequestWatchdog();
2481
2394
  this.activeAdRequestToken = null;
2482
2395
  this.showAds = false;
2483
2396
  if (!this.inAdBreak) {
2484
- console.warn("[DEBUG-POD] \u26A0\uFE0F Not in ad break - shouldn't happen");
2485
2397
  return;
2486
2398
  }
2487
2399
  const remaining = this.getRemainingAdMs();
@@ -2489,17 +2401,13 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
2489
2401
  const nextPreloaded = this.findNextPreloadedAd();
2490
2402
  if (nextPreloaded) {
2491
2403
  this.currentAdIndex++;
2492
- console.log(`[DEBUG-POD] \u27A1\uFE0F Playing next ad ${this.currentAdIndex}/${this.totalAdsInBreak} (preloaded)`);
2493
2404
  this.playSingleAd(nextPreloaded).catch(() => {
2494
- console.error("[DEBUG-POD] \u274C Failed to play next ad");
2495
2405
  this.handleAdPodComplete();
2496
2406
  });
2497
2407
  } else {
2498
- console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads - ending pod");
2499
2408
  this.handleAdPodComplete();
2500
2409
  }
2501
2410
  } else {
2502
- console.log("[DEBUG-POD] \u2705 Pod complete (no more ads or time expired)");
2503
2411
  this.handleAdPodComplete();
2504
2412
  }
2505
2413
  });
@@ -2653,9 +2561,6 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
2653
2561
  }
2654
2562
  if (marker.type === "start") {
2655
2563
  if (this.inAdBreak) {
2656
- console.log(
2657
- `[DEBUG-POD] \u26A0\uFE0F SCTE-35 start marker ignored - already in ad break (currentTime: ${this.video.currentTime})`
2658
- );
2659
2564
  return;
2660
2565
  }
2661
2566
  this.inAdBreak = true;
@@ -2724,9 +2629,6 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
2724
2629
  return;
2725
2630
  }
2726
2631
  if (marker.type === "progress" && this.inAdBreak) {
2727
- console.log(
2728
- `[DEBUG-POD] \u{1F4CA} SCTE-35 progress marker (currentTime: ${this.video.currentTime})`
2729
- );
2730
2632
  if (marker.durationSeconds != null) {
2731
2633
  this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
2732
2634
  }
@@ -2739,7 +2641,6 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
2739
2641
  this.scheduleAdStopCountdown(remainingMs);
2740
2642
  }
2741
2643
  if (!this.ima.isAdPlaying() && this.activeAdRequestToken === null) {
2742
- console.log("[DEBUG-POD] \u{1F4CA} Progress marker: no ad playing, attempting to start");
2743
2644
  const scheduled = this.findCurrentOrNextBreak(
2744
2645
  this.video.currentTime * 1e3
2745
2646
  );
@@ -2751,24 +2652,16 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
2751
2652
  this.playSingleAd(first).catch(() => {
2752
2653
  });
2753
2654
  }
2754
- } else {
2755
- console.log(
2756
- `[DEBUG-POD] \u{1F4CA} Progress marker: ad playing or request active (playing=${this.ima.isAdPlaying()}, token=${this.activeAdRequestToken})`
2757
- );
2758
2655
  }
2759
2656
  return;
2760
2657
  }
2761
2658
  if (marker.type === "end") {
2762
- console.log(
2763
- `[DEBUG-POD] \u{1F3C1} SCTE-35 end marker received (currentTime: ${this.video.currentTime})`
2764
- );
2765
2659
  this.inAdBreak = false;
2766
2660
  this.expectedAdBreakDurationMs = void 0;
2767
2661
  this.currentAdBreakStartWallClockMs = void 0;
2768
2662
  this.clearAdStartTimer();
2769
2663
  this.clearAdStopTimer();
2770
2664
  if (this.ima.isAdPlaying()) {
2771
- console.log("[DEBUG-POD] \u{1F6D1} Stopping ad due to SCTE-35 end marker");
2772
2665
  this.ima.stop().catch(() => {
2773
2666
  });
2774
2667
  }
@@ -3169,11 +3062,9 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3169
3062
  } else if (tags && tags.length > 0) {
3170
3063
  vastTagUrls = tags;
3171
3064
  } else {
3172
- console.log("[DEBUG-POD] \u26A0\uFE0F No VAST tag available");
3173
3065
  return;
3174
3066
  }
3175
3067
  if (vastTagUrls.length > 0) {
3176
- console.log(`[DEBUG-POD] \u{1F3AF} Starting ad break with ${vastTagUrls.length} ads`);
3177
3068
  this.adPodAllUrls = [...vastTagUrls];
3178
3069
  this.preloadingAdUrls.clear();
3179
3070
  this.vastToMediaUrlMap.clear();
@@ -3181,9 +3072,6 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3181
3072
  this.preloadingMediaUrls.clear();
3182
3073
  const currentMuted = this.video.muted;
3183
3074
  const currentVolume = this.video.volume;
3184
- console.log(
3185
- `[DEBUG-AUDIO] \u{1F4BE} Capturing ORIGINAL state (once) | muted=${currentMuted}, volume=${currentVolume}`
3186
- );
3187
3075
  this.ima.updateOriginalMutedState(currentMuted, currentVolume);
3188
3076
  this.inAdBreak = true;
3189
3077
  this.currentAdIndex = 0;
@@ -3191,21 +3079,38 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3191
3079
  this.adPodQueue = [...vastTagUrls];
3192
3080
  if (this.isAdaptiveMode) {
3193
3081
  if (this.config.debugAdTiming) {
3194
- console.log("[ADAPTIVE-POD] Waiting for sequential preloading to complete...");
3082
+ console.log("[ADAPTIVE-POD] \u{1F680} Preloading first 2 ads before starting playback...");
3195
3083
  }
3196
3084
  try {
3197
- await this.preloadAllAdsInBackground();
3085
+ const adsToPreloadBeforeStart = Math.min(2, this.adPodAllUrls.length);
3086
+ for (let i = 0; i < adsToPreloadBeforeStart; i++) {
3087
+ const url = this.adPodAllUrls[i];
3088
+ if (url) {
3089
+ await this.preloadSingleAd(url);
3090
+ if (this.config.debugAdTiming) {
3091
+ console.log(`[ADAPTIVE-POD] \u2705 Preloaded ad ${i + 1}/${adsToPreloadBeforeStart}`);
3092
+ }
3093
+ }
3094
+ }
3198
3095
  if (this.config.debugAdTiming) {
3199
- console.log("[ADAPTIVE-POD] Preloading complete, starting playback");
3096
+ console.log("[ADAPTIVE-POD] \u{1F3AC} First ads preloaded, starting playback immediately");
3200
3097
  }
3201
3098
  } catch (error) {
3202
3099
  if (this.config.debugAdTiming) {
3203
3100
  console.warn(
3204
- "[ADAPTIVE-POD] Error in preloading:",
3101
+ "[ADAPTIVE-POD] \u26A0\uFE0F Error preloading initial ads:",
3205
3102
  error
3206
3103
  );
3207
3104
  }
3208
3105
  }
3106
+ this.preloadAllAdsInBackground().catch((error) => {
3107
+ if (this.config.debugAdTiming) {
3108
+ console.warn(
3109
+ "[ADAPTIVE-POD] Error in background preloading:",
3110
+ error
3111
+ );
3112
+ }
3113
+ });
3209
3114
  await this.playAdPod();
3210
3115
  } else {
3211
3116
  this.preloadAllAdsInBackground().catch((error) => {
@@ -3227,40 +3132,27 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3227
3132
  }
3228
3133
  async playAdPod() {
3229
3134
  if (this.adPodQueue.length === 0) {
3230
- console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
3231
3135
  return;
3232
3136
  }
3233
- const waitTime = this.isAdaptiveMode ? 100 : 500;
3137
+ const waitTime = this.isAdaptiveMode ? 50 : 500;
3234
3138
  await new Promise((resolve) => setTimeout(resolve, waitTime));
3235
- if (this.config.debugAdTiming) {
3236
- console.log(
3237
- `[DEBUG-POD] \u{1F50D} Looking for preloaded ad in queue of ${this.adPodQueue.length} URLs`
3238
- );
3239
- }
3240
3139
  const firstPreloaded = this.findNextPreloadedAd();
3241
3140
  if (!firstPreloaded) {
3242
- console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads found, trying first ad from queue");
3243
3141
  const firstAd = this.adPodQueue.shift();
3244
3142
  if (firstAd) {
3245
3143
  this.currentAdIndex++;
3246
- console.log(`[DEBUG-POD] \u{1F3AC} Attempting to play first ad (not preloaded): ${firstAd.substring(0, 60)}...`);
3247
3144
  try {
3248
3145
  await this.playSingleAd(firstAd);
3249
3146
  } catch (error) {
3250
- console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
3251
3147
  return;
3252
3148
  }
3253
- } else {
3254
- console.log("[DEBUG-POD] \u274C No ads available in queue");
3255
3149
  }
3256
3150
  return;
3257
3151
  }
3258
3152
  this.currentAdIndex++;
3259
- console.log(`[DEBUG-POD] \u{1F680} Starting pod with ad ${this.currentAdIndex}/${this.totalAdsInBreak}`);
3260
3153
  try {
3261
3154
  await this.playSingleAd(firstPreloaded);
3262
3155
  } catch (error) {
3263
- console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
3264
3156
  }
3265
3157
  }
3266
3158
  findCurrentOrNextBreak(nowMs) {
@@ -3340,15 +3232,9 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3340
3232
  const overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
3341
3233
  const shouldExtendAdBreak = (adPlaying || pendingAds || this.showAds) && overrunMs < maxExtensionMs;
3342
3234
  if (shouldExtendAdBreak) {
3343
- console.log(
3344
- `[DEBUG-POD] \u23F3 Extending ad break | elapsed=${elapsedSinceStartMs}ms, expected=${expectedDurationMs}ms, overrun=${overrunMs}ms`
3345
- );
3346
3235
  this.scheduleAdStopCountdown(checkIntervalMs);
3347
3236
  return;
3348
3237
  }
3349
- console.log(
3350
- `[DEBUG-POD] \u23F1\uFE0F Ad break duration expired | elapsed=${elapsedSinceStartMs}ms, expected=${expectedDurationMs}ms`
3351
- );
3352
3238
  if (adPlaying) {
3353
3239
  this.ima.stop().catch(() => {
3354
3240
  });
@@ -3381,42 +3267,23 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3381
3267
  this.ptsDriftEmaMs = this.ptsDriftEmaMs * (1 - alpha) + sampleMs * alpha;
3382
3268
  }
3383
3269
  async playSingleAd(vastTagUrl) {
3384
- console.log(`[DEBUG-POD] \u{1F3AC} playSingleAd | url=${vastTagUrl.substring(0, 60)}...`);
3385
3270
  if (this.ima.isAdPlaying()) {
3386
- console.warn("[DEBUG-POD] \u26A0\uFE0F Ad already playing - skipping request");
3387
3271
  return;
3388
3272
  }
3389
3273
  const requestToken = ++this.adRequestTokenCounter;
3390
- const wasPreloaded = this.ima.hasPreloadedAd(vastTagUrl);
3391
3274
  this.activeAdRequestToken = requestToken;
3392
- console.log(`[DEBUG-POD] \u{1F4DD} Request token=${requestToken}, preloaded=${wasPreloaded}`);
3393
3275
  this.startAdRequestWatchdog(requestToken);
3394
3276
  try {
3395
- console.log(`[DEBUG-POD] \u{1F4E1} Calling ima.requestAds() for token=${requestToken}...`);
3396
3277
  await this.ima.requestAds(vastTagUrl);
3397
- console.log(`[DEBUG-POD] \u2705 ima.requestAds() completed successfully`);
3398
3278
  this.clearAdRequestWatchdog();
3399
3279
  if (this.activeAdRequestToken !== requestToken) {
3400
- console.warn(`[DEBUG-POD] \u26A0\uFE0F Token mismatch after requestAds (stale request)`);
3401
3280
  return;
3402
3281
  }
3403
- console.log(`[DEBUG-POD] \u{1F4FA} Calling ima.play() to start ad playback...`);
3404
- console.log(`[DEBUG-POD] \u{1F4CA} Video element state: paused=${this.video.paused}, muted=${this.video.muted}, readyState=${this.video.readyState}`);
3405
3282
  try {
3406
3283
  this.startAdFailsafeTimer(requestToken);
3407
3284
  await this.ima.play();
3408
- if (this.activeAdRequestToken === requestToken) {
3409
- console.log(`[DEBUG-POD] \u2705 Ad play initiated successfully (token=${requestToken})`);
3410
- } else {
3411
- console.warn(`[DEBUG-POD] \u26A0\uFE0F Token mismatch after play (stale request)`);
3412
- }
3413
3285
  } catch (playError) {
3414
- console.error(
3415
- "[DEBUG-POD] \u274C Failed to play ad:",
3416
- playError instanceof Error ? playError.message : playError,
3417
- "\nFull error:",
3418
- playError
3419
- );
3286
+ console.error("[AD-ERROR] Failed to play ad:", playError);
3420
3287
  this.clearAdFailsafeTimer();
3421
3288
  if (this.activeAdRequestToken === requestToken) {
3422
3289
  this.activeAdRequestToken = null;
@@ -3425,7 +3292,7 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3425
3292
  return;
3426
3293
  }
3427
3294
  } catch (error) {
3428
- console.error("[DEBUG-POD] \u274C Ad request failed:", error == null ? void 0 : error.message);
3295
+ console.error("[AD-ERROR] Ad request failed:", error == null ? void 0 : error.message);
3429
3296
  this.clearAdRequestWatchdog();
3430
3297
  this.clearAdFailsafeTimer();
3431
3298
  if (this.activeAdRequestToken === requestToken) {
@@ -3436,7 +3303,6 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3436
3303
  }
3437
3304
  handleAdPodComplete() {
3438
3305
  var _a;
3439
- console.log("[DEBUG-POD] \u{1F3C1} handleAdPodComplete - Ending ad break, restoring content");
3440
3306
  this.clearAdRequestWatchdog();
3441
3307
  this.clearAdFailsafeTimer();
3442
3308
  this.activeAdRequestToken = null;
@@ -3458,10 +3324,6 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3458
3324
  });
3459
3325
  const restoredMuted = this.ima.getOriginalMutedState();
3460
3326
  const restoredVolume = this.ima.getOriginalVolume();
3461
- console.log(
3462
- `[DEBUG-AUDIO] \u{1F50A} Audio restored by IMA | muted=${restoredMuted}, volume=${restoredVolume}`
3463
- );
3464
- console.log("[DEBUG-LAYER] \u{1F3AC} Layers: Main=visible, Ad=hidden, Placeholder=no");
3465
3327
  if (this.video.muted !== restoredMuted) {
3466
3328
  this.video.muted = restoredMuted;
3467
3329
  }
@@ -3469,14 +3331,11 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3469
3331
  this.video.volume = restoredVolume;
3470
3332
  }
3471
3333
  if (!this.shouldContinueLiveStreamDuringAds() && this.video.paused) {
3472
- console.log("[DEBUG-FLOW] \u25B6\uFE0F Resuming main video playback");
3473
- (_a = this.video.play()) == null ? void 0 : _a.catch((error) => {
3474
- console.error("[DEBUG-ERROR] Failed to resume video:", error);
3334
+ (_a = this.video.play()) == null ? void 0 : _a.catch(() => {
3475
3335
  });
3476
3336
  }
3477
3337
  }
3478
3338
  handleAdFailure() {
3479
- console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
3480
3339
  const remaining = this.getRemainingAdMs();
3481
3340
  if (remaining > 500 && this.adPodQueue.length > 0) {
3482
3341
  if (this.isAdaptiveMode && this.currentAdIndex <= 1) {
@@ -3489,14 +3348,12 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3489
3348
  const nextPreloaded = this.findNextPreloadedAd();
3490
3349
  if (nextPreloaded) {
3491
3350
  this.currentAdIndex++;
3492
- console.log(`[DEBUG-POD] \u27A1\uFE0F Trying next ad after failure (${this.currentAdIndex}/${this.totalAdsInBreak})`);
3493
3351
  this.playSingleAd(nextPreloaded).catch(() => {
3494
3352
  this.handleAdPodComplete();
3495
3353
  });
3496
3354
  return;
3497
3355
  }
3498
3356
  }
3499
- console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
3500
3357
  this.handleAdPodComplete();
3501
3358
  }
3502
3359
  tryNextAdWithRetry(retryCount) {
@@ -3796,16 +3653,27 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3796
3653
  }
3797
3654
  }
3798
3655
  async preloadAllAdsInBackground() {
3656
+ var _a, _b;
3799
3657
  if (this.adPodAllUrls.length === 0) {
3800
3658
  return;
3801
3659
  }
3802
3660
  if (this.isAdaptiveMode) {
3803
3661
  if (this.config.debugAdTiming) {
3804
3662
  console.log(
3805
- `[ADAPTIVE-POD] \u{1F504} Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
3663
+ `[ADAPTIVE-POD] \u{1F504} Starting sequential preload of remaining ads`
3806
3664
  );
3807
3665
  }
3808
3666
  const processedUrls = /* @__PURE__ */ new Set();
3667
+ for (const url of this.adPodAllUrls) {
3668
+ if (((_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, url)) || this.fetchedAdDurations.has(url)) {
3669
+ processedUrls.add(url);
3670
+ }
3671
+ }
3672
+ if (this.config.debugAdTiming && processedUrls.size > 0) {
3673
+ console.log(
3674
+ `[ADAPTIVE-POD] \u{1F4E6} Skipping ${processedUrls.size} already-preloaded ads`
3675
+ );
3676
+ }
3809
3677
  while (true) {
3810
3678
  const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
3811
3679
  if (!nextUrl) {
@@ -3938,37 +3806,17 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3938
3806
  }
3939
3807
  findNextPreloadedAd() {
3940
3808
  var _a, _b, _c;
3941
- if (this.config.debugAdTiming) {
3942
- console.log(
3943
- `[DEBUG-POD] \u{1F50E} Searching for preloaded ad in queue (${this.adPodQueue.length} URLs, ${this.preloadedMediaUrls.size} media preloaded, ${this.vastToMediaUrlMap.size} VAST mappings)`
3944
- );
3945
- }
3946
3809
  for (let i = 0; i < this.adPodQueue.length; i++) {
3947
3810
  const vastTagUrl = this.adPodQueue[i];
3948
3811
  if (!vastTagUrl) continue;
3949
3812
  const hasImaPreload = (_c = (_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, vastTagUrl)) != null ? _c : false;
3950
3813
  const mediaUrls = this.vastToMediaUrlMap.get(vastTagUrl);
3951
3814
  const hasMediaPreload = mediaUrls && mediaUrls.length > 0 ? this.preloadedMediaUrls.has(mediaUrls[0]) : false;
3952
- if (this.config.debugAdTiming) {
3953
- console.log(
3954
- `[DEBUG-POD] Ad ${i}: IMA=${hasImaPreload}, Media=${hasMediaPreload}, MediaURLs=${(mediaUrls == null ? void 0 : mediaUrls.length) || 0}, URL=${vastTagUrl.substring(0, 60)}...`
3955
- );
3956
- }
3957
3815
  if (hasImaPreload || hasMediaPreload) {
3958
- if (this.config.debugAdTiming) {
3959
- console.log(
3960
- `[DEBUG-POD] \u2705 Found preloaded ad at index ${i}`
3961
- );
3962
- }
3963
3816
  this.adPodQueue.splice(0, i + 1);
3964
3817
  return vastTagUrl;
3965
3818
  }
3966
3819
  }
3967
- if (this.config.debugAdTiming) {
3968
- console.log(
3969
- `[DEBUG-POD] \u274C No preloaded ads found in queue`
3970
- );
3971
- }
3972
3820
  return void 0;
3973
3821
  }
3974
3822
  getRemainingAdMs() {