stormcloud-video-player 0.2.32 → 0.2.33

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.
@@ -351,15 +351,17 @@ function createImaController(video, options) {
351
351
  let adsLoadedResolve;
352
352
  let adsLoadedReject;
353
353
  function makeAdsRequest(google, vastTagUrl) {
354
+ console.log("[IMA] \u{1F4CB} === makeAdsRequest() - Building IMA request ===");
354
355
  const adsRequest = new google.ima.AdsRequest();
355
356
  const preloadedResponse = preloadedVast.get(vastTagUrl);
356
357
  if (preloadedResponse) {
357
358
  adsRequest.adsResponse = preloadedResponse;
358
359
  console.log(
359
- "[IMA] Using preloaded VAST response for immediate ad request"
360
+ "[IMA] \u26A1 Using preloaded VAST response for immediate ad request"
360
361
  );
361
362
  } else {
362
363
  adsRequest.adTagUrl = vastTagUrl;
364
+ console.log("[IMA] \u{1F310} Will fetch VAST from URL:", vastTagUrl);
363
365
  }
364
366
  const videoWidth = video.offsetWidth || video.clientWidth || 640;
365
367
  const videoHeight = video.offsetHeight || video.clientHeight || 360;
@@ -371,6 +373,7 @@ function createImaController(video, options) {
371
373
  try {
372
374
  const willAutoPlay = !video.paused || video.autoplay;
373
375
  adsRequest.setAdWillAutoPlay(willAutoPlay);
376
+ console.log(`[IMA] Ad will autoplay: ${willAutoPlay}`);
374
377
  } catch (error) {
375
378
  console.warn("[IMA] Failed to call setAdWillAutoPlay:", error);
376
379
  }
@@ -379,13 +382,17 @@ function createImaController(video, options) {
379
382
  try {
380
383
  const willPlayMuted = video.muted || video.volume === 0;
381
384
  adsRequest.setAdWillPlayMuted(willPlayMuted);
385
+ console.log(`[IMA] Ad will play muted: ${willPlayMuted}`);
382
386
  } catch (error) {
383
387
  console.warn("[IMA] Failed to call setAdWillPlayMuted:", error);
384
388
  }
385
389
  }
386
390
  adsRequest.vastLoadTimeout = 5e3;
387
- console.log(`[IMA] Ads request dimensions: ${videoWidth}x${videoHeight}`);
391
+ console.log(`[IMA] \u{1F4D0} Ads request dimensions: ${videoWidth}x${videoHeight}`);
392
+ console.log("[IMA] \u23F1\uFE0F VAST load timeout: 5000ms");
393
+ console.log("[IMA] \u{1F680} Calling adsLoader.requestAds()...");
388
394
  adsLoader.requestAds(adsRequest);
395
+ console.log("[IMA] \u23F3 Waiting for ADS_MANAGER_LOADED or AD_ERROR event...");
389
396
  if (preloadedResponse) {
390
397
  preloadedVast.delete(vastTagUrl);
391
398
  }
@@ -463,22 +470,24 @@ function createImaController(video, options) {
463
470
  });
464
471
  },
465
472
  async requestAds(vastTagUrl) {
466
- console.log("[IMA] Requesting ads:", vastTagUrl);
473
+ console.log("[IMA] \u{1F4E1} === requestAds() called ===");
474
+ console.log("[IMA] VAST URL:", vastTagUrl);
475
+ console.log("[IMA] This will fetch the ad from the server - no visual change yet");
467
476
  if (!vastTagUrl || vastTagUrl.trim() === "") {
468
477
  const error = new Error("VAST tag URL is empty or undefined");
469
- console.warn("[IMA]", error.message);
478
+ console.warn("[IMA] \u274C", error.message);
470
479
  return Promise.reject(error);
471
480
  }
472
481
  try {
473
482
  new URL(vastTagUrl);
474
483
  } catch (e) {
475
484
  const error = new Error(`Invalid VAST tag URL format: ${vastTagUrl}`);
476
- console.warn("[IMA]", error.message);
485
+ console.warn("[IMA] \u274C", error.message);
477
486
  return Promise.reject(error);
478
487
  }
479
488
  if (adPlaying) {
480
489
  console.warn(
481
- "[IMA] Cannot request new ads while an ad is playing. Call stop() first."
490
+ "[IMA] \u26A0\uFE0F Cannot request new ads while an ad is playing. Call stop() first."
482
491
  );
483
492
  return Promise.reject(
484
493
  new Error("Ad already playing - cannot request new ads")
@@ -568,20 +577,85 @@ function createImaController(video, options) {
568
577
  adsLoader.addEventListener(
569
578
  google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
570
579
  (evt) => {
571
- console.log(
572
- "[IMA] Ads manager loaded - enabling preloading for continuous playback"
573
- );
580
+ console.log("[IMA] \u2705 ADS_MANAGER_LOADED - Ads fetched successfully!");
581
+ console.log("[IMA] Setting up ads manager with preloading enabled");
582
+ console.log("[IMA] ========================================");
583
+ console.log("[IMA] EXPECTED EVENT FLOW:");
584
+ console.log("[IMA] 1. requestAds() \u2192 fetch VAST");
585
+ console.log("[IMA] 2. ADS_MANAGER_LOADED \u2192 ads ready");
586
+ console.log("[IMA] 3. play() \u2192 start playback");
587
+ console.log("[IMA] 4. CONTENT_PAUSE_REQUESTED \u2192 show ad layer \u2728");
588
+ console.log("[IMA] 5. STARTED \u2192 ad is playing");
589
+ console.log("[IMA] 6. CONTENT_RESUME_REQUESTED \u2192 ad done");
590
+ console.log("[IMA] 7. ALL_ADS_COMPLETED \u2192 hide ad layer");
591
+ console.log("[IMA] ========================================");
574
592
  try {
575
593
  const adsRenderingSettings = new google.ima.AdsRenderingSettings();
576
594
  adsRenderingSettings.enablePreloading = true;
577
595
  adsManager = evt.getAdsManager(video, adsRenderingSettings);
578
596
  const AdEvent = google.ima.AdEvent.Type;
579
597
  const AdErrorEvent = google.ima.AdErrorEvent.Type;
598
+ console.log("[IMA] ========== IMA EVENT LOGGING ENABLED ==========");
599
+ console.log("[IMA] All IMA SDK events will be logged below");
600
+ const allAdEvents = [
601
+ "AD_BREAK_READY",
602
+ "AD_METADATA",
603
+ "ALL_ADS_COMPLETED",
604
+ "CLICK",
605
+ "COMPLETE",
606
+ "CONTENT_PAUSE_REQUESTED",
607
+ "CONTENT_RESUME_REQUESTED",
608
+ "DURATION_CHANGE",
609
+ "FIRST_QUARTILE",
610
+ "IMPRESSION",
611
+ "INTERACTION",
612
+ "LINEAR_CHANGED",
613
+ "LOADED",
614
+ "LOG",
615
+ "MIDPOINT",
616
+ "PAUSED",
617
+ "RESUMED",
618
+ "SKIPPABLE_STATE_CHANGED",
619
+ "SKIPPED",
620
+ "STARTED",
621
+ "THIRD_QUARTILE",
622
+ "USER_CLOSE",
623
+ "VOLUME_CHANGED",
624
+ "VOLUME_MUTED"
625
+ ];
626
+ allAdEvents.forEach((eventType) => {
627
+ if (AdEvent[eventType]) {
628
+ adsManager.addEventListener(AdEvent[eventType], (e) => {
629
+ var _a, _b, _c, _d, _e, _f;
630
+ const ad = (_a = e.getAd) == null ? void 0 : _a.call(e);
631
+ const adData = ad ? {
632
+ adId: (_b = ad.getAdId) == null ? void 0 : _b.call(ad),
633
+ title: (_c = ad.getTitle) == null ? void 0 : _c.call(ad),
634
+ duration: (_d = ad.getDuration) == null ? void 0 : _d.call(ad),
635
+ isLinear: (_e = ad.isLinear) == null ? void 0 : _e.call(ad),
636
+ contentType: (_f = ad.getContentType) == null ? void 0 : _f.call(ad)
637
+ } : null;
638
+ console.log(`[IMA EVENT] ${eventType}`, {
639
+ eventType,
640
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
641
+ adData
642
+ });
643
+ });
644
+ }
645
+ });
646
+ console.log("[IMA] ========== EVENT LISTENERS ATTACHED ==========");
580
647
  adsManager.addEventListener(
581
648
  AdErrorEvent.AD_ERROR,
582
649
  (errorEvent) => {
583
- var _a;
584
- console.error("[IMA] Ad error:", errorEvent.getError());
650
+ var _a, _b, _c, _d, _e, _f;
651
+ const error = errorEvent.getError();
652
+ console.error("[IMA] \u274C AD_ERROR Event:", {
653
+ message: (_a = error.getMessage) == null ? void 0 : _a.call(error),
654
+ errorCode: (_b = error.getErrorCode) == null ? void 0 : _b.call(error),
655
+ type: (_c = error.getType) == null ? void 0 : _c.call(error),
656
+ vastErrorCode: (_d = error.getVastErrorCode) == null ? void 0 : _d.call(error),
657
+ innerError: (_e = error.getInnerError) == null ? void 0 : _e.call(error)
658
+ });
585
659
  destroyAdsManager();
586
660
  adPlaying = false;
587
661
  setAdPlayingFlag(false);
@@ -623,7 +697,7 @@ function createImaController(video, options) {
623
697
  console.log(
624
698
  "[IMA] Resuming paused video after ad error"
625
699
  );
626
- (_a = video.play()) == null ? void 0 : _a.catch(() => {
700
+ (_f = video.play()) == null ? void 0 : _f.catch(() => {
627
701
  });
628
702
  }
629
703
  }
@@ -633,7 +707,8 @@ function createImaController(video, options) {
633
707
  adsManager.addEventListener(
634
708
  AdEvent.CONTENT_PAUSE_REQUESTED,
635
709
  () => {
636
- console.log("[IMA] Content pause requested");
710
+ console.log("[IMA] \u2705 CONTENT_PAUSE_REQUESTED - Ad is ready to play!");
711
+ console.log("[IMA] This is the event that triggers the ad layer to appear");
637
712
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
638
713
  video.pause();
639
714
  console.log("[IMA] Content video paused (VOD mode)");
@@ -649,15 +724,16 @@ function createImaController(video, options) {
649
724
  adContainerEl.style.backgroundColor = "#000";
650
725
  adContainerEl.offsetHeight;
651
726
  adContainerEl.style.opacity = "1";
652
- console.log("[IMA] Ad container shown on content pause");
727
+ console.log("[IMA] \u2728 Ad container NOW VISIBLE (after content pause)");
653
728
  }
654
729
  adPlaying = true;
655
730
  setAdPlayingFlag(true);
731
+ console.log("[IMA] Emitting 'content_pause' event to player");
656
732
  emit("content_pause");
657
733
  }
658
734
  );
659
735
  adsManager.addEventListener(AdEvent.STARTED, () => {
660
- console.log("[IMA] Ad started - showing ad video");
736
+ console.log("[IMA] \u25B6\uFE0F STARTED - Ad playback has begun");
661
737
  setAdPlayingFlag(true);
662
738
  hideContentVideo();
663
739
  if (adVideoElement) {
@@ -673,20 +749,21 @@ function createImaController(video, options) {
673
749
  adContainerEl.style.backgroundColor = "#000";
674
750
  adContainerEl.offsetHeight;
675
751
  adContainerEl.style.opacity = "1";
676
- console.log("[IMA] Ad container now visible");
752
+ console.log("[IMA] Ad container now visible (STARTED event)");
677
753
  }
678
754
  });
679
755
  adsManager.addEventListener(
680
756
  AdEvent.CONTENT_RESUME_REQUESTED,
681
757
  () => {
682
- console.log("[IMA] Content resume requested");
758
+ console.log("[IMA] \u23F8\uFE0F CONTENT_RESUME_REQUESTED - Single ad completed");
683
759
  adPlaying = false;
684
760
  setAdPlayingFlag(false);
761
+ console.log("[IMA] Emitting 'content_resume' event to player");
685
762
  emit("content_resume");
686
763
  }
687
764
  );
688
765
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
689
- console.log("[IMA] All ads completed - restoring content");
766
+ console.log("[IMA] \u{1F3C1} ALL_ADS_COMPLETED - All ads in break finished");
690
767
  adPlaying = false;
691
768
  setAdPlayingFlag(false);
692
769
  if (adContainerEl) {
@@ -696,7 +773,7 @@ function createImaController(video, options) {
696
773
  if (adContainerEl) {
697
774
  adContainerEl.style.pointerEvents = "none";
698
775
  adContainerEl.style.display = "none";
699
- console.log("[IMA] Ad container hidden");
776
+ console.log("[IMA] \u{1F648} Ad container hidden (ALL_ADS_COMPLETED)");
700
777
  }
701
778
  }, 300);
702
779
  }
@@ -707,6 +784,7 @@ function createImaController(video, options) {
707
784
  console.warn("[IMA] Failed to resume content video:", e);
708
785
  });
709
786
  }
787
+ console.log("[IMA] Emitting 'all_ads_completed' event to player");
710
788
  emit("all_ads_completed");
711
789
  });
712
790
  console.log("[IMA] Ads manager event listeners attached");
@@ -755,7 +833,17 @@ function createImaController(video, options) {
755
833
  adsLoader.addEventListener(
756
834
  google.ima.AdErrorEvent.Type.AD_ERROR,
757
835
  (adErrorEvent) => {
758
- console.error("[IMA] Ads loader error:", adErrorEvent.getError());
836
+ var _a, _b, _c, _d;
837
+ const error = adErrorEvent.getError();
838
+ console.error("[IMA] \u274C ADS_LOADER ERROR - Ad request failed!", {
839
+ message: (_a = error.getMessage) == null ? void 0 : _a.call(error),
840
+ errorCode: (_b = error.getErrorCode) == null ? void 0 : _b.call(error),
841
+ type: (_c = error.getType) == null ? void 0 : _c.call(error),
842
+ vastErrorCode: (_d = error.getVastErrorCode) == null ? void 0 : _d.call(error)
843
+ });
844
+ console.error("[IMA] This means the ad server didn't return valid ads");
845
+ console.error("[IMA] Ad layer will NOT appear (no flicker)");
846
+ console.error("[IMA] Full error object:", adErrorEvent.getError());
759
847
  adPlaying = false;
760
848
  setAdPlayingFlag(false);
761
849
  if (adContainerEl) {
@@ -787,8 +875,10 @@ function createImaController(video, options) {
787
875
  false
788
876
  );
789
877
  }
790
- console.log("[IMA] Making ads request");
878
+ console.log("[IMA] \u{1F680} Making ads request to IMA SDK");
879
+ console.log("[IMA] Waiting for IMA SDK response (LOADED or ERROR event)...");
791
880
  makeAdsRequest(google, vastTagUrl);
881
+ console.log("[IMA] \u23F3 Returning promise that will resolve when ads are loaded");
792
882
  return adsLoadedPromise;
793
883
  } catch (error) {
794
884
  console.error("[IMA] Failed to request ads:", error);
@@ -826,20 +916,23 @@ function createImaController(video, options) {
826
916
  },
827
917
  async play() {
828
918
  var _a, _b;
919
+ console.log("[IMA] \u25B6\uFE0F === play() called ===");
920
+ console.log("[IMA] This initializes and starts the ad");
921
+ console.log("[IMA] Ad layer will appear when CONTENT_PAUSE_REQUESTED fires");
829
922
  if (!((_a = window.google) == null ? void 0 : _a.ima) || !adDisplayContainer) {
830
923
  console.warn(
831
- "[IMA] Cannot play ad: IMA SDK or ad container not available"
924
+ "[IMA] \u274C Cannot play ad: IMA SDK or ad container not available"
832
925
  );
833
926
  return Promise.reject(new Error("IMA SDK not available"));
834
927
  }
835
928
  if (!adsManager) {
836
- console.warn("[IMA] Cannot play ad: No ads manager available");
929
+ console.warn("[IMA] \u274C Cannot play ad: No ads manager available");
837
930
  return Promise.reject(new Error("No ads manager"));
838
931
  }
839
932
  try {
840
933
  const width = video.clientWidth || 640;
841
934
  const height = video.clientHeight || 360;
842
- console.log(`[IMA] Initializing ads manager (${width}x${height})`);
935
+ console.log(`[IMA] \u{1F3AC} Initializing ads manager (${width}x${height})`);
843
936
  adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
844
937
  adPlaying = true;
845
938
  const adVolume = originalMutedState ? 0 : originalVolume;
@@ -847,7 +940,7 @@ function createImaController(video, options) {
847
940
  adVideoElement.volume = adVolume;
848
941
  adVideoElement.muted = originalMutedState;
849
942
  console.log(
850
- `[IMA] Set dedicated ad video volume to ${adVolume}, muted: ${originalMutedState}`
943
+ `[IMA] \u{1F50A} Set dedicated ad video volume to ${adVolume}, muted: ${originalMutedState}`
851
944
  );
852
945
  }
853
946
  try {
@@ -856,11 +949,13 @@ function createImaController(video, options) {
856
949
  } catch (error) {
857
950
  console.warn("[IMA] Failed to set IMA manager volume:", error);
858
951
  }
859
- console.log("[IMA] Starting ad playback");
952
+ console.log("[IMA] \u{1F3AF} Calling adsManager.start()");
953
+ console.log("[IMA] If successful, IMA will fire CONTENT_PAUSE_REQUESTED");
860
954
  adsManager.start();
955
+ console.log("[IMA] \u2705 play() completed successfully");
861
956
  return Promise.resolve();
862
957
  } catch (error) {
863
- console.error("[IMA] Error starting ad playback:", error);
958
+ console.error("[IMA] \u274C Error starting ad playback:", error);
864
959
  adPlaying = false;
865
960
  setAdPlayingFlag(false);
866
961
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
@@ -2531,10 +2626,9 @@ var StormcloudVideoPlayer = class {
2531
2626
  const nextPreloaded = this.findNextPreloadedAd();
2532
2627
  if (nextPreloaded) {
2533
2628
  this.currentAdIndex++;
2534
- this.enforceAdHoldState();
2535
2629
  if (this.config.debugAdTiming) {
2536
2630
  console.log(
2537
- `[StormcloudVideoPlayer] Playing next preloaded ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak})`
2631
+ `[StormcloudVideoPlayer] Playing next preloaded ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - layer will stay visible if ad loads`
2538
2632
  );
2539
2633
  }
2540
2634
  this.playSingleAd(nextPreloaded).catch(() => {
@@ -3174,10 +3268,9 @@ var StormcloudVideoPlayer = class {
3174
3268
  this.currentAdIndex = 0;
3175
3269
  this.totalAdsInBreak = vastTagUrls.length;
3176
3270
  this.adPodQueue = [...vastTagUrls];
3177
- this.enforceAdHoldState();
3178
3271
  if (this.config.debugAdTiming) {
3179
3272
  console.log(
3180
- `[StormcloudVideoPlayer] Starting ad pod with ${vastTagUrls.length} ads - preloading all ads in parallel`
3273
+ `[StormcloudVideoPlayer] Starting ad pod with ${vastTagUrls.length} ads - preloading all ads in parallel (ad layer will show after ad loads)`
3181
3274
  );
3182
3275
  }
3183
3276
  this.preloadAllAdsInBackground().catch((error) => {
@@ -3268,7 +3361,6 @@ var StormcloudVideoPlayer = class {
3268
3361
  const rest = tags.slice(1);
3269
3362
  this.adPodQueue = rest;
3270
3363
  this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3271
- this.enforceAdHoldState();
3272
3364
  await this.playSingleAd(first);
3273
3365
  this.inAdBreak = true;
3274
3366
  this.expectedAdBreakDurationMs = remainingMs;
@@ -3394,10 +3486,9 @@ var StormcloudVideoPlayer = class {
3394
3486
  try {
3395
3487
  if (this.config.debugAdTiming) {
3396
3488
  console.log(
3397
- "[StormcloudVideoPlayer] Ad request completed, attempting playback"
3489
+ "[StormcloudVideoPlayer] Ad request completed, attempting playback (ad layer will show when IMA triggers content pause)"
3398
3490
  );
3399
3491
  }
3400
- this.enforceAdHoldState();
3401
3492
  await this.ima.play();
3402
3493
  this.showAds = true;
3403
3494
  if (this.config.debugAdTiming) {