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