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.
@@ -390,15 +390,17 @@ function createImaController(video, options) {
390
390
  let adsLoadedResolve;
391
391
  let adsLoadedReject;
392
392
  function makeAdsRequest(google, vastTagUrl) {
393
+ console.log("[IMA] \u{1F4CB} === makeAdsRequest() - Building IMA request ===");
393
394
  const adsRequest = new google.ima.AdsRequest();
394
395
  const preloadedResponse = preloadedVast.get(vastTagUrl);
395
396
  if (preloadedResponse) {
396
397
  adsRequest.adsResponse = preloadedResponse;
397
398
  console.log(
398
- "[IMA] Using preloaded VAST response for immediate ad request"
399
+ "[IMA] \u26A1 Using preloaded VAST response for immediate ad request"
399
400
  );
400
401
  } else {
401
402
  adsRequest.adTagUrl = vastTagUrl;
403
+ console.log("[IMA] \u{1F310} Will fetch VAST from URL:", vastTagUrl);
402
404
  }
403
405
  const videoWidth = video.offsetWidth || video.clientWidth || 640;
404
406
  const videoHeight = video.offsetHeight || video.clientHeight || 360;
@@ -410,6 +412,7 @@ function createImaController(video, options) {
410
412
  try {
411
413
  const willAutoPlay = !video.paused || video.autoplay;
412
414
  adsRequest.setAdWillAutoPlay(willAutoPlay);
415
+ console.log(`[IMA] Ad will autoplay: ${willAutoPlay}`);
413
416
  } catch (error) {
414
417
  console.warn("[IMA] Failed to call setAdWillAutoPlay:", error);
415
418
  }
@@ -418,13 +421,17 @@ function createImaController(video, options) {
418
421
  try {
419
422
  const willPlayMuted = video.muted || video.volume === 0;
420
423
  adsRequest.setAdWillPlayMuted(willPlayMuted);
424
+ console.log(`[IMA] Ad will play muted: ${willPlayMuted}`);
421
425
  } catch (error) {
422
426
  console.warn("[IMA] Failed to call setAdWillPlayMuted:", error);
423
427
  }
424
428
  }
425
429
  adsRequest.vastLoadTimeout = 5e3;
426
- console.log(`[IMA] Ads request dimensions: ${videoWidth}x${videoHeight}`);
430
+ console.log(`[IMA] \u{1F4D0} Ads request dimensions: ${videoWidth}x${videoHeight}`);
431
+ console.log("[IMA] \u23F1\uFE0F VAST load timeout: 5000ms");
432
+ console.log("[IMA] \u{1F680} Calling adsLoader.requestAds()...");
427
433
  adsLoader.requestAds(adsRequest);
434
+ console.log("[IMA] \u23F3 Waiting for ADS_MANAGER_LOADED or AD_ERROR event...");
428
435
  if (preloadedResponse) {
429
436
  preloadedVast.delete(vastTagUrl);
430
437
  }
@@ -502,22 +509,24 @@ function createImaController(video, options) {
502
509
  });
503
510
  },
504
511
  async requestAds(vastTagUrl) {
505
- console.log("[IMA] Requesting ads:", vastTagUrl);
512
+ console.log("[IMA] \u{1F4E1} === requestAds() called ===");
513
+ console.log("[IMA] VAST URL:", vastTagUrl);
514
+ console.log("[IMA] This will fetch the ad from the server - no visual change yet");
506
515
  if (!vastTagUrl || vastTagUrl.trim() === "") {
507
516
  const error = new Error("VAST tag URL is empty or undefined");
508
- console.warn("[IMA]", error.message);
517
+ console.warn("[IMA] \u274C", error.message);
509
518
  return Promise.reject(error);
510
519
  }
511
520
  try {
512
521
  new URL(vastTagUrl);
513
522
  } catch (e) {
514
523
  const error = new Error(`Invalid VAST tag URL format: ${vastTagUrl}`);
515
- console.warn("[IMA]", error.message);
524
+ console.warn("[IMA] \u274C", error.message);
516
525
  return Promise.reject(error);
517
526
  }
518
527
  if (adPlaying) {
519
528
  console.warn(
520
- "[IMA] Cannot request new ads while an ad is playing. Call stop() first."
529
+ "[IMA] \u26A0\uFE0F Cannot request new ads while an ad is playing. Call stop() first."
521
530
  );
522
531
  return Promise.reject(
523
532
  new Error("Ad already playing - cannot request new ads")
@@ -607,20 +616,85 @@ function createImaController(video, options) {
607
616
  adsLoader.addEventListener(
608
617
  google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
609
618
  (evt) => {
610
- console.log(
611
- "[IMA] Ads manager loaded - enabling preloading for continuous playback"
612
- );
619
+ console.log("[IMA] \u2705 ADS_MANAGER_LOADED - Ads fetched successfully!");
620
+ console.log("[IMA] Setting up ads manager with preloading enabled");
621
+ console.log("[IMA] ========================================");
622
+ console.log("[IMA] EXPECTED EVENT FLOW:");
623
+ console.log("[IMA] 1. requestAds() \u2192 fetch VAST");
624
+ console.log("[IMA] 2. ADS_MANAGER_LOADED \u2192 ads ready");
625
+ console.log("[IMA] 3. play() \u2192 start playback");
626
+ console.log("[IMA] 4. CONTENT_PAUSE_REQUESTED \u2192 show ad layer \u2728");
627
+ console.log("[IMA] 5. STARTED \u2192 ad is playing");
628
+ console.log("[IMA] 6. CONTENT_RESUME_REQUESTED \u2192 ad done");
629
+ console.log("[IMA] 7. ALL_ADS_COMPLETED \u2192 hide ad layer");
630
+ console.log("[IMA] ========================================");
613
631
  try {
614
632
  const adsRenderingSettings = new google.ima.AdsRenderingSettings();
615
633
  adsRenderingSettings.enablePreloading = true;
616
634
  adsManager = evt.getAdsManager(video, adsRenderingSettings);
617
635
  const AdEvent = google.ima.AdEvent.Type;
618
636
  const AdErrorEvent = google.ima.AdErrorEvent.Type;
637
+ console.log("[IMA] ========== IMA EVENT LOGGING ENABLED ==========");
638
+ console.log("[IMA] All IMA SDK events will be logged below");
639
+ const allAdEvents = [
640
+ "AD_BREAK_READY",
641
+ "AD_METADATA",
642
+ "ALL_ADS_COMPLETED",
643
+ "CLICK",
644
+ "COMPLETE",
645
+ "CONTENT_PAUSE_REQUESTED",
646
+ "CONTENT_RESUME_REQUESTED",
647
+ "DURATION_CHANGE",
648
+ "FIRST_QUARTILE",
649
+ "IMPRESSION",
650
+ "INTERACTION",
651
+ "LINEAR_CHANGED",
652
+ "LOADED",
653
+ "LOG",
654
+ "MIDPOINT",
655
+ "PAUSED",
656
+ "RESUMED",
657
+ "SKIPPABLE_STATE_CHANGED",
658
+ "SKIPPED",
659
+ "STARTED",
660
+ "THIRD_QUARTILE",
661
+ "USER_CLOSE",
662
+ "VOLUME_CHANGED",
663
+ "VOLUME_MUTED"
664
+ ];
665
+ allAdEvents.forEach((eventType) => {
666
+ if (AdEvent[eventType]) {
667
+ adsManager.addEventListener(AdEvent[eventType], (e) => {
668
+ var _a, _b, _c, _d, _e, _f;
669
+ const ad = (_a = e.getAd) == null ? void 0 : _a.call(e);
670
+ const adData = ad ? {
671
+ adId: (_b = ad.getAdId) == null ? void 0 : _b.call(ad),
672
+ title: (_c = ad.getTitle) == null ? void 0 : _c.call(ad),
673
+ duration: (_d = ad.getDuration) == null ? void 0 : _d.call(ad),
674
+ isLinear: (_e = ad.isLinear) == null ? void 0 : _e.call(ad),
675
+ contentType: (_f = ad.getContentType) == null ? void 0 : _f.call(ad)
676
+ } : null;
677
+ console.log(`[IMA EVENT] ${eventType}`, {
678
+ eventType,
679
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
680
+ adData
681
+ });
682
+ });
683
+ }
684
+ });
685
+ console.log("[IMA] ========== EVENT LISTENERS ATTACHED ==========");
619
686
  adsManager.addEventListener(
620
687
  AdErrorEvent.AD_ERROR,
621
688
  (errorEvent) => {
622
- var _a;
623
- console.error("[IMA] Ad error:", errorEvent.getError());
689
+ var _a, _b, _c, _d, _e, _f;
690
+ const error = errorEvent.getError();
691
+ console.error("[IMA] \u274C AD_ERROR Event:", {
692
+ message: (_a = error.getMessage) == null ? void 0 : _a.call(error),
693
+ errorCode: (_b = error.getErrorCode) == null ? void 0 : _b.call(error),
694
+ type: (_c = error.getType) == null ? void 0 : _c.call(error),
695
+ vastErrorCode: (_d = error.getVastErrorCode) == null ? void 0 : _d.call(error),
696
+ innerError: (_e = error.getInnerError) == null ? void 0 : _e.call(error)
697
+ });
624
698
  destroyAdsManager();
625
699
  adPlaying = false;
626
700
  setAdPlayingFlag(false);
@@ -662,7 +736,7 @@ function createImaController(video, options) {
662
736
  console.log(
663
737
  "[IMA] Resuming paused video after ad error"
664
738
  );
665
- (_a = video.play()) == null ? void 0 : _a.catch(() => {
739
+ (_f = video.play()) == null ? void 0 : _f.catch(() => {
666
740
  });
667
741
  }
668
742
  }
@@ -672,7 +746,8 @@ function createImaController(video, options) {
672
746
  adsManager.addEventListener(
673
747
  AdEvent.CONTENT_PAUSE_REQUESTED,
674
748
  () => {
675
- console.log("[IMA] Content pause requested");
749
+ console.log("[IMA] \u2705 CONTENT_PAUSE_REQUESTED - Ad is ready to play!");
750
+ console.log("[IMA] This is the event that triggers the ad layer to appear");
676
751
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
677
752
  video.pause();
678
753
  console.log("[IMA] Content video paused (VOD mode)");
@@ -688,15 +763,16 @@ function createImaController(video, options) {
688
763
  adContainerEl.style.backgroundColor = "#000";
689
764
  adContainerEl.offsetHeight;
690
765
  adContainerEl.style.opacity = "1";
691
- console.log("[IMA] Ad container shown on content pause");
766
+ console.log("[IMA] \u2728 Ad container NOW VISIBLE (after content pause)");
692
767
  }
693
768
  adPlaying = true;
694
769
  setAdPlayingFlag(true);
770
+ console.log("[IMA] Emitting 'content_pause' event to player");
695
771
  emit("content_pause");
696
772
  }
697
773
  );
698
774
  adsManager.addEventListener(AdEvent.STARTED, () => {
699
- console.log("[IMA] Ad started - showing ad video");
775
+ console.log("[IMA] \u25B6\uFE0F STARTED - Ad playback has begun");
700
776
  setAdPlayingFlag(true);
701
777
  hideContentVideo();
702
778
  if (adVideoElement) {
@@ -712,20 +788,21 @@ function createImaController(video, options) {
712
788
  adContainerEl.style.backgroundColor = "#000";
713
789
  adContainerEl.offsetHeight;
714
790
  adContainerEl.style.opacity = "1";
715
- console.log("[IMA] Ad container now visible");
791
+ console.log("[IMA] Ad container now visible (STARTED event)");
716
792
  }
717
793
  });
718
794
  adsManager.addEventListener(
719
795
  AdEvent.CONTENT_RESUME_REQUESTED,
720
796
  () => {
721
- console.log("[IMA] Content resume requested");
797
+ console.log("[IMA] \u23F8\uFE0F CONTENT_RESUME_REQUESTED - Single ad completed");
722
798
  adPlaying = false;
723
799
  setAdPlayingFlag(false);
800
+ console.log("[IMA] Emitting 'content_resume' event to player");
724
801
  emit("content_resume");
725
802
  }
726
803
  );
727
804
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
728
- console.log("[IMA] All ads completed - restoring content");
805
+ console.log("[IMA] \u{1F3C1} ALL_ADS_COMPLETED - All ads in break finished");
729
806
  adPlaying = false;
730
807
  setAdPlayingFlag(false);
731
808
  if (adContainerEl) {
@@ -735,7 +812,7 @@ function createImaController(video, options) {
735
812
  if (adContainerEl) {
736
813
  adContainerEl.style.pointerEvents = "none";
737
814
  adContainerEl.style.display = "none";
738
- console.log("[IMA] Ad container hidden");
815
+ console.log("[IMA] \u{1F648} Ad container hidden (ALL_ADS_COMPLETED)");
739
816
  }
740
817
  }, 300);
741
818
  }
@@ -746,6 +823,7 @@ function createImaController(video, options) {
746
823
  console.warn("[IMA] Failed to resume content video:", e);
747
824
  });
748
825
  }
826
+ console.log("[IMA] Emitting 'all_ads_completed' event to player");
749
827
  emit("all_ads_completed");
750
828
  });
751
829
  console.log("[IMA] Ads manager event listeners attached");
@@ -794,7 +872,17 @@ function createImaController(video, options) {
794
872
  adsLoader.addEventListener(
795
873
  google.ima.AdErrorEvent.Type.AD_ERROR,
796
874
  (adErrorEvent) => {
797
- console.error("[IMA] Ads loader error:", adErrorEvent.getError());
875
+ var _a, _b, _c, _d;
876
+ const error = adErrorEvent.getError();
877
+ console.error("[IMA] \u274C ADS_LOADER ERROR - Ad request failed!", {
878
+ message: (_a = error.getMessage) == null ? void 0 : _a.call(error),
879
+ errorCode: (_b = error.getErrorCode) == null ? void 0 : _b.call(error),
880
+ type: (_c = error.getType) == null ? void 0 : _c.call(error),
881
+ vastErrorCode: (_d = error.getVastErrorCode) == null ? void 0 : _d.call(error)
882
+ });
883
+ console.error("[IMA] This means the ad server didn't return valid ads");
884
+ console.error("[IMA] Ad layer will NOT appear (no flicker)");
885
+ console.error("[IMA] Full error object:", adErrorEvent.getError());
798
886
  adPlaying = false;
799
887
  setAdPlayingFlag(false);
800
888
  if (adContainerEl) {
@@ -826,8 +914,10 @@ function createImaController(video, options) {
826
914
  false
827
915
  );
828
916
  }
829
- console.log("[IMA] Making ads request");
917
+ console.log("[IMA] \u{1F680} Making ads request to IMA SDK");
918
+ console.log("[IMA] Waiting for IMA SDK response (LOADED or ERROR event)...");
830
919
  makeAdsRequest(google, vastTagUrl);
920
+ console.log("[IMA] \u23F3 Returning promise that will resolve when ads are loaded");
831
921
  return adsLoadedPromise;
832
922
  } catch (error) {
833
923
  console.error("[IMA] Failed to request ads:", error);
@@ -865,20 +955,23 @@ function createImaController(video, options) {
865
955
  },
866
956
  async play() {
867
957
  var _a, _b;
958
+ console.log("[IMA] \u25B6\uFE0F === play() called ===");
959
+ console.log("[IMA] This initializes and starts the ad");
960
+ console.log("[IMA] Ad layer will appear when CONTENT_PAUSE_REQUESTED fires");
868
961
  if (!((_a = window.google) == null ? void 0 : _a.ima) || !adDisplayContainer) {
869
962
  console.warn(
870
- "[IMA] Cannot play ad: IMA SDK or ad container not available"
963
+ "[IMA] \u274C Cannot play ad: IMA SDK or ad container not available"
871
964
  );
872
965
  return Promise.reject(new Error("IMA SDK not available"));
873
966
  }
874
967
  if (!adsManager) {
875
- console.warn("[IMA] Cannot play ad: No ads manager available");
968
+ console.warn("[IMA] \u274C Cannot play ad: No ads manager available");
876
969
  return Promise.reject(new Error("No ads manager"));
877
970
  }
878
971
  try {
879
972
  const width = video.clientWidth || 640;
880
973
  const height = video.clientHeight || 360;
881
- console.log(`[IMA] Initializing ads manager (${width}x${height})`);
974
+ console.log(`[IMA] \u{1F3AC} Initializing ads manager (${width}x${height})`);
882
975
  adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
883
976
  adPlaying = true;
884
977
  const adVolume = originalMutedState ? 0 : originalVolume;
@@ -886,7 +979,7 @@ function createImaController(video, options) {
886
979
  adVideoElement.volume = adVolume;
887
980
  adVideoElement.muted = originalMutedState;
888
981
  console.log(
889
- `[IMA] Set dedicated ad video volume to ${adVolume}, muted: ${originalMutedState}`
982
+ `[IMA] \u{1F50A} Set dedicated ad video volume to ${adVolume}, muted: ${originalMutedState}`
890
983
  );
891
984
  }
892
985
  try {
@@ -895,11 +988,13 @@ function createImaController(video, options) {
895
988
  } catch (error) {
896
989
  console.warn("[IMA] Failed to set IMA manager volume:", error);
897
990
  }
898
- console.log("[IMA] Starting ad playback");
991
+ console.log("[IMA] \u{1F3AF} Calling adsManager.start()");
992
+ console.log("[IMA] If successful, IMA will fire CONTENT_PAUSE_REQUESTED");
899
993
  adsManager.start();
994
+ console.log("[IMA] \u2705 play() completed successfully");
900
995
  return Promise.resolve();
901
996
  } catch (error) {
902
- console.error("[IMA] Error starting ad playback:", error);
997
+ console.error("[IMA] \u274C Error starting ad playback:", error);
903
998
  adPlaying = false;
904
999
  setAdPlayingFlag(false);
905
1000
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
@@ -2570,10 +2665,9 @@ var StormcloudVideoPlayer = class {
2570
2665
  const nextPreloaded = this.findNextPreloadedAd();
2571
2666
  if (nextPreloaded) {
2572
2667
  this.currentAdIndex++;
2573
- this.enforceAdHoldState();
2574
2668
  if (this.config.debugAdTiming) {
2575
2669
  console.log(
2576
- `[StormcloudVideoPlayer] Playing next preloaded ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak})`
2670
+ `[StormcloudVideoPlayer] Playing next preloaded ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - layer will stay visible if ad loads`
2577
2671
  );
2578
2672
  }
2579
2673
  this.playSingleAd(nextPreloaded).catch(() => {
@@ -3213,10 +3307,9 @@ var StormcloudVideoPlayer = class {
3213
3307
  this.currentAdIndex = 0;
3214
3308
  this.totalAdsInBreak = vastTagUrls.length;
3215
3309
  this.adPodQueue = [...vastTagUrls];
3216
- this.enforceAdHoldState();
3217
3310
  if (this.config.debugAdTiming) {
3218
3311
  console.log(
3219
- `[StormcloudVideoPlayer] Starting ad pod with ${vastTagUrls.length} ads - preloading all ads in parallel`
3312
+ `[StormcloudVideoPlayer] Starting ad pod with ${vastTagUrls.length} ads - preloading all ads in parallel (ad layer will show after ad loads)`
3220
3313
  );
3221
3314
  }
3222
3315
  this.preloadAllAdsInBackground().catch((error) => {
@@ -3307,7 +3400,6 @@ var StormcloudVideoPlayer = class {
3307
3400
  const rest = tags.slice(1);
3308
3401
  this.adPodQueue = rest;
3309
3402
  this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3310
- this.enforceAdHoldState();
3311
3403
  await this.playSingleAd(first);
3312
3404
  this.inAdBreak = true;
3313
3405
  this.expectedAdBreakDurationMs = remainingMs;
@@ -3433,10 +3525,9 @@ var StormcloudVideoPlayer = class {
3433
3525
  try {
3434
3526
  if (this.config.debugAdTiming) {
3435
3527
  console.log(
3436
- "[StormcloudVideoPlayer] Ad request completed, attempting playback"
3528
+ "[StormcloudVideoPlayer] Ad request completed, attempting playback (ad layer will show when IMA triggers content pause)"
3437
3529
  );
3438
3530
  }
3439
- this.enforceAdHoldState();
3440
3531
  await this.ima.play();
3441
3532
  this.showAds = true;
3442
3533
  if (this.config.debugAdTiming) {