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