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.
package/lib/index.cjs CHANGED
@@ -415,15 +415,17 @@ function createImaController(video, options) {
415
415
  let adsLoadedResolve;
416
416
  let adsLoadedReject;
417
417
  function makeAdsRequest(google, vastTagUrl) {
418
+ console.log("[IMA] \u{1F4CB} === makeAdsRequest() - Building IMA request ===");
418
419
  const adsRequest = new google.ima.AdsRequest();
419
420
  const preloadedResponse = preloadedVast.get(vastTagUrl);
420
421
  if (preloadedResponse) {
421
422
  adsRequest.adsResponse = preloadedResponse;
422
423
  console.log(
423
- "[IMA] Using preloaded VAST response for immediate ad request"
424
+ "[IMA] \u26A1 Using preloaded VAST response for immediate ad request"
424
425
  );
425
426
  } else {
426
427
  adsRequest.adTagUrl = vastTagUrl;
428
+ console.log("[IMA] \u{1F310} Will fetch VAST from URL:", vastTagUrl);
427
429
  }
428
430
  const videoWidth = video.offsetWidth || video.clientWidth || 640;
429
431
  const videoHeight = video.offsetHeight || video.clientHeight || 360;
@@ -435,6 +437,7 @@ function createImaController(video, options) {
435
437
  try {
436
438
  const willAutoPlay = !video.paused || video.autoplay;
437
439
  adsRequest.setAdWillAutoPlay(willAutoPlay);
440
+ console.log(`[IMA] Ad will autoplay: ${willAutoPlay}`);
438
441
  } catch (error) {
439
442
  console.warn("[IMA] Failed to call setAdWillAutoPlay:", error);
440
443
  }
@@ -443,13 +446,17 @@ function createImaController(video, options) {
443
446
  try {
444
447
  const willPlayMuted = video.muted || video.volume === 0;
445
448
  adsRequest.setAdWillPlayMuted(willPlayMuted);
449
+ console.log(`[IMA] Ad will play muted: ${willPlayMuted}`);
446
450
  } catch (error) {
447
451
  console.warn("[IMA] Failed to call setAdWillPlayMuted:", error);
448
452
  }
449
453
  }
450
454
  adsRequest.vastLoadTimeout = 5e3;
451
- console.log(`[IMA] Ads request dimensions: ${videoWidth}x${videoHeight}`);
455
+ console.log(`[IMA] \u{1F4D0} Ads request dimensions: ${videoWidth}x${videoHeight}`);
456
+ console.log("[IMA] \u23F1\uFE0F VAST load timeout: 5000ms");
457
+ console.log("[IMA] \u{1F680} Calling adsLoader.requestAds()...");
452
458
  adsLoader.requestAds(adsRequest);
459
+ console.log("[IMA] \u23F3 Waiting for ADS_MANAGER_LOADED or AD_ERROR event...");
453
460
  if (preloadedResponse) {
454
461
  preloadedVast.delete(vastTagUrl);
455
462
  }
@@ -527,22 +534,24 @@ function createImaController(video, options) {
527
534
  });
528
535
  },
529
536
  async requestAds(vastTagUrl) {
530
- console.log("[IMA] Requesting ads:", vastTagUrl);
537
+ console.log("[IMA] \u{1F4E1} === requestAds() called ===");
538
+ console.log("[IMA] VAST URL:", vastTagUrl);
539
+ console.log("[IMA] This will fetch the ad from the server - no visual change yet");
531
540
  if (!vastTagUrl || vastTagUrl.trim() === "") {
532
541
  const error = new Error("VAST tag URL is empty or undefined");
533
- console.warn("[IMA]", error.message);
542
+ console.warn("[IMA] \u274C", error.message);
534
543
  return Promise.reject(error);
535
544
  }
536
545
  try {
537
546
  new URL(vastTagUrl);
538
547
  } catch (e) {
539
548
  const error = new Error(`Invalid VAST tag URL format: ${vastTagUrl}`);
540
- console.warn("[IMA]", error.message);
549
+ console.warn("[IMA] \u274C", error.message);
541
550
  return Promise.reject(error);
542
551
  }
543
552
  if (adPlaying) {
544
553
  console.warn(
545
- "[IMA] Cannot request new ads while an ad is playing. Call stop() first."
554
+ "[IMA] \u26A0\uFE0F Cannot request new ads while an ad is playing. Call stop() first."
546
555
  );
547
556
  return Promise.reject(
548
557
  new Error("Ad already playing - cannot request new ads")
@@ -632,20 +641,85 @@ function createImaController(video, options) {
632
641
  adsLoader.addEventListener(
633
642
  google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
634
643
  (evt) => {
635
- console.log(
636
- "[IMA] Ads manager loaded - enabling preloading for continuous playback"
637
- );
644
+ console.log("[IMA] \u2705 ADS_MANAGER_LOADED - Ads fetched successfully!");
645
+ console.log("[IMA] Setting up ads manager with preloading enabled");
646
+ console.log("[IMA] ========================================");
647
+ console.log("[IMA] EXPECTED EVENT FLOW:");
648
+ console.log("[IMA] 1. requestAds() \u2192 fetch VAST");
649
+ console.log("[IMA] 2. ADS_MANAGER_LOADED \u2192 ads ready");
650
+ console.log("[IMA] 3. play() \u2192 start playback");
651
+ console.log("[IMA] 4. CONTENT_PAUSE_REQUESTED \u2192 show ad layer \u2728");
652
+ console.log("[IMA] 5. STARTED \u2192 ad is playing");
653
+ console.log("[IMA] 6. CONTENT_RESUME_REQUESTED \u2192 ad done");
654
+ console.log("[IMA] 7. ALL_ADS_COMPLETED \u2192 hide ad layer");
655
+ console.log("[IMA] ========================================");
638
656
  try {
639
657
  const adsRenderingSettings = new google.ima.AdsRenderingSettings();
640
658
  adsRenderingSettings.enablePreloading = true;
641
659
  adsManager = evt.getAdsManager(video, adsRenderingSettings);
642
660
  const AdEvent = google.ima.AdEvent.Type;
643
661
  const AdErrorEvent = google.ima.AdErrorEvent.Type;
662
+ console.log("[IMA] ========== IMA EVENT LOGGING ENABLED ==========");
663
+ console.log("[IMA] All IMA SDK events will be logged below");
664
+ const allAdEvents = [
665
+ "AD_BREAK_READY",
666
+ "AD_METADATA",
667
+ "ALL_ADS_COMPLETED",
668
+ "CLICK",
669
+ "COMPLETE",
670
+ "CONTENT_PAUSE_REQUESTED",
671
+ "CONTENT_RESUME_REQUESTED",
672
+ "DURATION_CHANGE",
673
+ "FIRST_QUARTILE",
674
+ "IMPRESSION",
675
+ "INTERACTION",
676
+ "LINEAR_CHANGED",
677
+ "LOADED",
678
+ "LOG",
679
+ "MIDPOINT",
680
+ "PAUSED",
681
+ "RESUMED",
682
+ "SKIPPABLE_STATE_CHANGED",
683
+ "SKIPPED",
684
+ "STARTED",
685
+ "THIRD_QUARTILE",
686
+ "USER_CLOSE",
687
+ "VOLUME_CHANGED",
688
+ "VOLUME_MUTED"
689
+ ];
690
+ allAdEvents.forEach((eventType) => {
691
+ if (AdEvent[eventType]) {
692
+ adsManager.addEventListener(AdEvent[eventType], (e) => {
693
+ var _a, _b, _c, _d, _e, _f;
694
+ const ad = (_a = e.getAd) == null ? void 0 : _a.call(e);
695
+ const adData = ad ? {
696
+ adId: (_b = ad.getAdId) == null ? void 0 : _b.call(ad),
697
+ title: (_c = ad.getTitle) == null ? void 0 : _c.call(ad),
698
+ duration: (_d = ad.getDuration) == null ? void 0 : _d.call(ad),
699
+ isLinear: (_e = ad.isLinear) == null ? void 0 : _e.call(ad),
700
+ contentType: (_f = ad.getContentType) == null ? void 0 : _f.call(ad)
701
+ } : null;
702
+ console.log(`[IMA EVENT] ${eventType}`, {
703
+ eventType,
704
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
705
+ adData
706
+ });
707
+ });
708
+ }
709
+ });
710
+ console.log("[IMA] ========== EVENT LISTENERS ATTACHED ==========");
644
711
  adsManager.addEventListener(
645
712
  AdErrorEvent.AD_ERROR,
646
713
  (errorEvent) => {
647
- var _a;
648
- console.error("[IMA] Ad error:", errorEvent.getError());
714
+ var _a, _b, _c, _d, _e, _f;
715
+ const error = errorEvent.getError();
716
+ console.error("[IMA] \u274C AD_ERROR Event:", {
717
+ message: (_a = error.getMessage) == null ? void 0 : _a.call(error),
718
+ errorCode: (_b = error.getErrorCode) == null ? void 0 : _b.call(error),
719
+ type: (_c = error.getType) == null ? void 0 : _c.call(error),
720
+ vastErrorCode: (_d = error.getVastErrorCode) == null ? void 0 : _d.call(error),
721
+ innerError: (_e = error.getInnerError) == null ? void 0 : _e.call(error)
722
+ });
649
723
  destroyAdsManager();
650
724
  adPlaying = false;
651
725
  setAdPlayingFlag(false);
@@ -687,7 +761,7 @@ function createImaController(video, options) {
687
761
  console.log(
688
762
  "[IMA] Resuming paused video after ad error"
689
763
  );
690
- (_a = video.play()) == null ? void 0 : _a.catch(() => {
764
+ (_f = video.play()) == null ? void 0 : _f.catch(() => {
691
765
  });
692
766
  }
693
767
  }
@@ -697,7 +771,8 @@ function createImaController(video, options) {
697
771
  adsManager.addEventListener(
698
772
  AdEvent.CONTENT_PAUSE_REQUESTED,
699
773
  () => {
700
- console.log("[IMA] Content pause requested");
774
+ console.log("[IMA] \u2705 CONTENT_PAUSE_REQUESTED - Ad is ready to play!");
775
+ console.log("[IMA] This is the event that triggers the ad layer to appear");
701
776
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
702
777
  video.pause();
703
778
  console.log("[IMA] Content video paused (VOD mode)");
@@ -713,15 +788,16 @@ function createImaController(video, options) {
713
788
  adContainerEl.style.backgroundColor = "#000";
714
789
  adContainerEl.offsetHeight;
715
790
  adContainerEl.style.opacity = "1";
716
- console.log("[IMA] Ad container shown on content pause");
791
+ console.log("[IMA] \u2728 Ad container NOW VISIBLE (after content pause)");
717
792
  }
718
793
  adPlaying = true;
719
794
  setAdPlayingFlag(true);
795
+ console.log("[IMA] Emitting 'content_pause' event to player");
720
796
  emit("content_pause");
721
797
  }
722
798
  );
723
799
  adsManager.addEventListener(AdEvent.STARTED, () => {
724
- console.log("[IMA] Ad started - showing ad video");
800
+ console.log("[IMA] \u25B6\uFE0F STARTED - Ad playback has begun");
725
801
  setAdPlayingFlag(true);
726
802
  hideContentVideo();
727
803
  if (adVideoElement) {
@@ -737,20 +813,21 @@ function createImaController(video, options) {
737
813
  adContainerEl.style.backgroundColor = "#000";
738
814
  adContainerEl.offsetHeight;
739
815
  adContainerEl.style.opacity = "1";
740
- console.log("[IMA] Ad container now visible");
816
+ console.log("[IMA] Ad container now visible (STARTED event)");
741
817
  }
742
818
  });
743
819
  adsManager.addEventListener(
744
820
  AdEvent.CONTENT_RESUME_REQUESTED,
745
821
  () => {
746
- console.log("[IMA] Content resume requested");
822
+ console.log("[IMA] \u23F8\uFE0F CONTENT_RESUME_REQUESTED - Single ad completed");
747
823
  adPlaying = false;
748
824
  setAdPlayingFlag(false);
825
+ console.log("[IMA] Emitting 'content_resume' event to player");
749
826
  emit("content_resume");
750
827
  }
751
828
  );
752
829
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
753
- console.log("[IMA] All ads completed - restoring content");
830
+ console.log("[IMA] \u{1F3C1} ALL_ADS_COMPLETED - All ads in break finished");
754
831
  adPlaying = false;
755
832
  setAdPlayingFlag(false);
756
833
  if (adContainerEl) {
@@ -760,7 +837,7 @@ function createImaController(video, options) {
760
837
  if (adContainerEl) {
761
838
  adContainerEl.style.pointerEvents = "none";
762
839
  adContainerEl.style.display = "none";
763
- console.log("[IMA] Ad container hidden");
840
+ console.log("[IMA] \u{1F648} Ad container hidden (ALL_ADS_COMPLETED)");
764
841
  }
765
842
  }, 300);
766
843
  }
@@ -771,6 +848,7 @@ function createImaController(video, options) {
771
848
  console.warn("[IMA] Failed to resume content video:", e);
772
849
  });
773
850
  }
851
+ console.log("[IMA] Emitting 'all_ads_completed' event to player");
774
852
  emit("all_ads_completed");
775
853
  });
776
854
  console.log("[IMA] Ads manager event listeners attached");
@@ -819,7 +897,17 @@ function createImaController(video, options) {
819
897
  adsLoader.addEventListener(
820
898
  google.ima.AdErrorEvent.Type.AD_ERROR,
821
899
  (adErrorEvent) => {
822
- console.error("[IMA] Ads loader error:", adErrorEvent.getError());
900
+ var _a, _b, _c, _d;
901
+ const error = adErrorEvent.getError();
902
+ console.error("[IMA] \u274C ADS_LOADER ERROR - Ad request failed!", {
903
+ message: (_a = error.getMessage) == null ? void 0 : _a.call(error),
904
+ errorCode: (_b = error.getErrorCode) == null ? void 0 : _b.call(error),
905
+ type: (_c = error.getType) == null ? void 0 : _c.call(error),
906
+ vastErrorCode: (_d = error.getVastErrorCode) == null ? void 0 : _d.call(error)
907
+ });
908
+ console.error("[IMA] This means the ad server didn't return valid ads");
909
+ console.error("[IMA] Ad layer will NOT appear (no flicker)");
910
+ console.error("[IMA] Full error object:", adErrorEvent.getError());
823
911
  adPlaying = false;
824
912
  setAdPlayingFlag(false);
825
913
  if (adContainerEl) {
@@ -851,8 +939,10 @@ function createImaController(video, options) {
851
939
  false
852
940
  );
853
941
  }
854
- console.log("[IMA] Making ads request");
942
+ console.log("[IMA] \u{1F680} Making ads request to IMA SDK");
943
+ console.log("[IMA] Waiting for IMA SDK response (LOADED or ERROR event)...");
855
944
  makeAdsRequest(google, vastTagUrl);
945
+ console.log("[IMA] \u23F3 Returning promise that will resolve when ads are loaded");
856
946
  return adsLoadedPromise;
857
947
  } catch (error) {
858
948
  console.error("[IMA] Failed to request ads:", error);
@@ -890,20 +980,23 @@ function createImaController(video, options) {
890
980
  },
891
981
  async play() {
892
982
  var _a, _b;
983
+ console.log("[IMA] \u25B6\uFE0F === play() called ===");
984
+ console.log("[IMA] This initializes and starts the ad");
985
+ console.log("[IMA] Ad layer will appear when CONTENT_PAUSE_REQUESTED fires");
893
986
  if (!((_a = window.google) == null ? void 0 : _a.ima) || !adDisplayContainer) {
894
987
  console.warn(
895
- "[IMA] Cannot play ad: IMA SDK or ad container not available"
988
+ "[IMA] \u274C Cannot play ad: IMA SDK or ad container not available"
896
989
  );
897
990
  return Promise.reject(new Error("IMA SDK not available"));
898
991
  }
899
992
  if (!adsManager) {
900
- console.warn("[IMA] Cannot play ad: No ads manager available");
993
+ console.warn("[IMA] \u274C Cannot play ad: No ads manager available");
901
994
  return Promise.reject(new Error("No ads manager"));
902
995
  }
903
996
  try {
904
997
  const width = video.clientWidth || 640;
905
998
  const height = video.clientHeight || 360;
906
- console.log(`[IMA] Initializing ads manager (${width}x${height})`);
999
+ console.log(`[IMA] \u{1F3AC} Initializing ads manager (${width}x${height})`);
907
1000
  adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
908
1001
  adPlaying = true;
909
1002
  const adVolume = originalMutedState ? 0 : originalVolume;
@@ -911,7 +1004,7 @@ function createImaController(video, options) {
911
1004
  adVideoElement.volume = adVolume;
912
1005
  adVideoElement.muted = originalMutedState;
913
1006
  console.log(
914
- `[IMA] Set dedicated ad video volume to ${adVolume}, muted: ${originalMutedState}`
1007
+ `[IMA] \u{1F50A} Set dedicated ad video volume to ${adVolume}, muted: ${originalMutedState}`
915
1008
  );
916
1009
  }
917
1010
  try {
@@ -920,11 +1013,13 @@ function createImaController(video, options) {
920
1013
  } catch (error) {
921
1014
  console.warn("[IMA] Failed to set IMA manager volume:", error);
922
1015
  }
923
- console.log("[IMA] Starting ad playback");
1016
+ console.log("[IMA] \u{1F3AF} Calling adsManager.start()");
1017
+ console.log("[IMA] If successful, IMA will fire CONTENT_PAUSE_REQUESTED");
924
1018
  adsManager.start();
1019
+ console.log("[IMA] \u2705 play() completed successfully");
925
1020
  return Promise.resolve();
926
1021
  } catch (error) {
927
- console.error("[IMA] Error starting ad playback:", error);
1022
+ console.error("[IMA] \u274C Error starting ad playback:", error);
928
1023
  adPlaying = false;
929
1024
  setAdPlayingFlag(false);
930
1025
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
@@ -2595,10 +2690,9 @@ var StormcloudVideoPlayer = class {
2595
2690
  const nextPreloaded = this.findNextPreloadedAd();
2596
2691
  if (nextPreloaded) {
2597
2692
  this.currentAdIndex++;
2598
- this.enforceAdHoldState();
2599
2693
  if (this.config.debugAdTiming) {
2600
2694
  console.log(
2601
- `[StormcloudVideoPlayer] Playing next preloaded ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak})`
2695
+ `[StormcloudVideoPlayer] Playing next preloaded ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - layer will stay visible if ad loads`
2602
2696
  );
2603
2697
  }
2604
2698
  this.playSingleAd(nextPreloaded).catch(() => {
@@ -3238,10 +3332,9 @@ var StormcloudVideoPlayer = class {
3238
3332
  this.currentAdIndex = 0;
3239
3333
  this.totalAdsInBreak = vastTagUrls.length;
3240
3334
  this.adPodQueue = [...vastTagUrls];
3241
- this.enforceAdHoldState();
3242
3335
  if (this.config.debugAdTiming) {
3243
3336
  console.log(
3244
- `[StormcloudVideoPlayer] Starting ad pod with ${vastTagUrls.length} ads - preloading all ads in parallel`
3337
+ `[StormcloudVideoPlayer] Starting ad pod with ${vastTagUrls.length} ads - preloading all ads in parallel (ad layer will show after ad loads)`
3245
3338
  );
3246
3339
  }
3247
3340
  this.preloadAllAdsInBackground().catch((error) => {
@@ -3332,7 +3425,6 @@ var StormcloudVideoPlayer = class {
3332
3425
  const rest = tags.slice(1);
3333
3426
  this.adPodQueue = rest;
3334
3427
  this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3335
- this.enforceAdHoldState();
3336
3428
  await this.playSingleAd(first);
3337
3429
  this.inAdBreak = true;
3338
3430
  this.expectedAdBreakDurationMs = remainingMs;
@@ -3458,10 +3550,9 @@ var StormcloudVideoPlayer = class {
3458
3550
  try {
3459
3551
  if (this.config.debugAdTiming) {
3460
3552
  console.log(
3461
- "[StormcloudVideoPlayer] Ad request completed, attempting playback"
3553
+ "[StormcloudVideoPlayer] Ad request completed, attempting playback (ad layer will show when IMA triggers content pause)"
3462
3554
  );
3463
3555
  }
3464
- this.enforceAdHoldState();
3465
3556
  await this.ima.play();
3466
3557
  this.showAds = true;
3467
3558
  if (this.config.debugAdTiming) {