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.js CHANGED
@@ -346,15 +346,17 @@ function createImaController(video, options) {
346
346
  let adsLoadedResolve;
347
347
  let adsLoadedReject;
348
348
  function makeAdsRequest(google, vastTagUrl) {
349
+ console.log("[IMA] \u{1F4CB} === makeAdsRequest() - Building IMA request ===");
349
350
  const adsRequest = new google.ima.AdsRequest();
350
351
  const preloadedResponse = preloadedVast.get(vastTagUrl);
351
352
  if (preloadedResponse) {
352
353
  adsRequest.adsResponse = preloadedResponse;
353
354
  console.log(
354
- "[IMA] Using preloaded VAST response for immediate ad request"
355
+ "[IMA] \u26A1 Using preloaded VAST response for immediate ad request"
355
356
  );
356
357
  } else {
357
358
  adsRequest.adTagUrl = vastTagUrl;
359
+ console.log("[IMA] \u{1F310} Will fetch VAST from URL:", vastTagUrl);
358
360
  }
359
361
  const videoWidth = video.offsetWidth || video.clientWidth || 640;
360
362
  const videoHeight = video.offsetHeight || video.clientHeight || 360;
@@ -366,6 +368,7 @@ function createImaController(video, options) {
366
368
  try {
367
369
  const willAutoPlay = !video.paused || video.autoplay;
368
370
  adsRequest.setAdWillAutoPlay(willAutoPlay);
371
+ console.log(`[IMA] Ad will autoplay: ${willAutoPlay}`);
369
372
  } catch (error) {
370
373
  console.warn("[IMA] Failed to call setAdWillAutoPlay:", error);
371
374
  }
@@ -374,13 +377,17 @@ function createImaController(video, options) {
374
377
  try {
375
378
  const willPlayMuted = video.muted || video.volume === 0;
376
379
  adsRequest.setAdWillPlayMuted(willPlayMuted);
380
+ console.log(`[IMA] Ad will play muted: ${willPlayMuted}`);
377
381
  } catch (error) {
378
382
  console.warn("[IMA] Failed to call setAdWillPlayMuted:", error);
379
383
  }
380
384
  }
381
385
  adsRequest.vastLoadTimeout = 5e3;
382
- console.log(`[IMA] Ads request dimensions: ${videoWidth}x${videoHeight}`);
386
+ console.log(`[IMA] \u{1F4D0} Ads request dimensions: ${videoWidth}x${videoHeight}`);
387
+ console.log("[IMA] \u23F1\uFE0F VAST load timeout: 5000ms");
388
+ console.log("[IMA] \u{1F680} Calling adsLoader.requestAds()...");
383
389
  adsLoader.requestAds(adsRequest);
390
+ console.log("[IMA] \u23F3 Waiting for ADS_MANAGER_LOADED or AD_ERROR event...");
384
391
  if (preloadedResponse) {
385
392
  preloadedVast.delete(vastTagUrl);
386
393
  }
@@ -458,22 +465,24 @@ function createImaController(video, options) {
458
465
  });
459
466
  },
460
467
  async requestAds(vastTagUrl) {
461
- console.log("[IMA] Requesting ads:", vastTagUrl);
468
+ console.log("[IMA] \u{1F4E1} === requestAds() called ===");
469
+ console.log("[IMA] VAST URL:", vastTagUrl);
470
+ console.log("[IMA] This will fetch the ad from the server - no visual change yet");
462
471
  if (!vastTagUrl || vastTagUrl.trim() === "") {
463
472
  const error = new Error("VAST tag URL is empty or undefined");
464
- console.warn("[IMA]", error.message);
473
+ console.warn("[IMA] \u274C", error.message);
465
474
  return Promise.reject(error);
466
475
  }
467
476
  try {
468
477
  new URL(vastTagUrl);
469
478
  } catch (e) {
470
479
  const error = new Error(`Invalid VAST tag URL format: ${vastTagUrl}`);
471
- console.warn("[IMA]", error.message);
480
+ console.warn("[IMA] \u274C", error.message);
472
481
  return Promise.reject(error);
473
482
  }
474
483
  if (adPlaying) {
475
484
  console.warn(
476
- "[IMA] Cannot request new ads while an ad is playing. Call stop() first."
485
+ "[IMA] \u26A0\uFE0F Cannot request new ads while an ad is playing. Call stop() first."
477
486
  );
478
487
  return Promise.reject(
479
488
  new Error("Ad already playing - cannot request new ads")
@@ -563,20 +572,85 @@ function createImaController(video, options) {
563
572
  adsLoader.addEventListener(
564
573
  google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
565
574
  (evt) => {
566
- console.log(
567
- "[IMA] Ads manager loaded - enabling preloading for continuous playback"
568
- );
575
+ console.log("[IMA] \u2705 ADS_MANAGER_LOADED - Ads fetched successfully!");
576
+ console.log("[IMA] Setting up ads manager with preloading enabled");
577
+ console.log("[IMA] ========================================");
578
+ console.log("[IMA] EXPECTED EVENT FLOW:");
579
+ console.log("[IMA] 1. requestAds() \u2192 fetch VAST");
580
+ console.log("[IMA] 2. ADS_MANAGER_LOADED \u2192 ads ready");
581
+ console.log("[IMA] 3. play() \u2192 start playback");
582
+ console.log("[IMA] 4. CONTENT_PAUSE_REQUESTED \u2192 show ad layer \u2728");
583
+ console.log("[IMA] 5. STARTED \u2192 ad is playing");
584
+ console.log("[IMA] 6. CONTENT_RESUME_REQUESTED \u2192 ad done");
585
+ console.log("[IMA] 7. ALL_ADS_COMPLETED \u2192 hide ad layer");
586
+ console.log("[IMA] ========================================");
569
587
  try {
570
588
  const adsRenderingSettings = new google.ima.AdsRenderingSettings();
571
589
  adsRenderingSettings.enablePreloading = true;
572
590
  adsManager = evt.getAdsManager(video, adsRenderingSettings);
573
591
  const AdEvent = google.ima.AdEvent.Type;
574
592
  const AdErrorEvent = google.ima.AdErrorEvent.Type;
593
+ console.log("[IMA] ========== IMA EVENT LOGGING ENABLED ==========");
594
+ console.log("[IMA] All IMA SDK events will be logged below");
595
+ const allAdEvents = [
596
+ "AD_BREAK_READY",
597
+ "AD_METADATA",
598
+ "ALL_ADS_COMPLETED",
599
+ "CLICK",
600
+ "COMPLETE",
601
+ "CONTENT_PAUSE_REQUESTED",
602
+ "CONTENT_RESUME_REQUESTED",
603
+ "DURATION_CHANGE",
604
+ "FIRST_QUARTILE",
605
+ "IMPRESSION",
606
+ "INTERACTION",
607
+ "LINEAR_CHANGED",
608
+ "LOADED",
609
+ "LOG",
610
+ "MIDPOINT",
611
+ "PAUSED",
612
+ "RESUMED",
613
+ "SKIPPABLE_STATE_CHANGED",
614
+ "SKIPPED",
615
+ "STARTED",
616
+ "THIRD_QUARTILE",
617
+ "USER_CLOSE",
618
+ "VOLUME_CHANGED",
619
+ "VOLUME_MUTED"
620
+ ];
621
+ allAdEvents.forEach((eventType) => {
622
+ if (AdEvent[eventType]) {
623
+ adsManager.addEventListener(AdEvent[eventType], (e) => {
624
+ var _a, _b, _c, _d, _e, _f;
625
+ const ad = (_a = e.getAd) == null ? void 0 : _a.call(e);
626
+ const adData = ad ? {
627
+ adId: (_b = ad.getAdId) == null ? void 0 : _b.call(ad),
628
+ title: (_c = ad.getTitle) == null ? void 0 : _c.call(ad),
629
+ duration: (_d = ad.getDuration) == null ? void 0 : _d.call(ad),
630
+ isLinear: (_e = ad.isLinear) == null ? void 0 : _e.call(ad),
631
+ contentType: (_f = ad.getContentType) == null ? void 0 : _f.call(ad)
632
+ } : null;
633
+ console.log(`[IMA EVENT] ${eventType}`, {
634
+ eventType,
635
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
636
+ adData
637
+ });
638
+ });
639
+ }
640
+ });
641
+ console.log("[IMA] ========== EVENT LISTENERS ATTACHED ==========");
575
642
  adsManager.addEventListener(
576
643
  AdErrorEvent.AD_ERROR,
577
644
  (errorEvent) => {
578
- var _a;
579
- console.error("[IMA] Ad error:", errorEvent.getError());
645
+ var _a, _b, _c, _d, _e, _f;
646
+ const error = errorEvent.getError();
647
+ console.error("[IMA] \u274C AD_ERROR Event:", {
648
+ message: (_a = error.getMessage) == null ? void 0 : _a.call(error),
649
+ errorCode: (_b = error.getErrorCode) == null ? void 0 : _b.call(error),
650
+ type: (_c = error.getType) == null ? void 0 : _c.call(error),
651
+ vastErrorCode: (_d = error.getVastErrorCode) == null ? void 0 : _d.call(error),
652
+ innerError: (_e = error.getInnerError) == null ? void 0 : _e.call(error)
653
+ });
580
654
  destroyAdsManager();
581
655
  adPlaying = false;
582
656
  setAdPlayingFlag(false);
@@ -618,7 +692,7 @@ function createImaController(video, options) {
618
692
  console.log(
619
693
  "[IMA] Resuming paused video after ad error"
620
694
  );
621
- (_a = video.play()) == null ? void 0 : _a.catch(() => {
695
+ (_f = video.play()) == null ? void 0 : _f.catch(() => {
622
696
  });
623
697
  }
624
698
  }
@@ -628,7 +702,8 @@ function createImaController(video, options) {
628
702
  adsManager.addEventListener(
629
703
  AdEvent.CONTENT_PAUSE_REQUESTED,
630
704
  () => {
631
- console.log("[IMA] Content pause requested");
705
+ console.log("[IMA] \u2705 CONTENT_PAUSE_REQUESTED - Ad is ready to play!");
706
+ console.log("[IMA] This is the event that triggers the ad layer to appear");
632
707
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
633
708
  video.pause();
634
709
  console.log("[IMA] Content video paused (VOD mode)");
@@ -644,15 +719,16 @@ function createImaController(video, options) {
644
719
  adContainerEl.style.backgroundColor = "#000";
645
720
  adContainerEl.offsetHeight;
646
721
  adContainerEl.style.opacity = "1";
647
- console.log("[IMA] Ad container shown on content pause");
722
+ console.log("[IMA] \u2728 Ad container NOW VISIBLE (after content pause)");
648
723
  }
649
724
  adPlaying = true;
650
725
  setAdPlayingFlag(true);
726
+ console.log("[IMA] Emitting 'content_pause' event to player");
651
727
  emit("content_pause");
652
728
  }
653
729
  );
654
730
  adsManager.addEventListener(AdEvent.STARTED, () => {
655
- console.log("[IMA] Ad started - showing ad video");
731
+ console.log("[IMA] \u25B6\uFE0F STARTED - Ad playback has begun");
656
732
  setAdPlayingFlag(true);
657
733
  hideContentVideo();
658
734
  if (adVideoElement) {
@@ -668,20 +744,21 @@ function createImaController(video, options) {
668
744
  adContainerEl.style.backgroundColor = "#000";
669
745
  adContainerEl.offsetHeight;
670
746
  adContainerEl.style.opacity = "1";
671
- console.log("[IMA] Ad container now visible");
747
+ console.log("[IMA] Ad container now visible (STARTED event)");
672
748
  }
673
749
  });
674
750
  adsManager.addEventListener(
675
751
  AdEvent.CONTENT_RESUME_REQUESTED,
676
752
  () => {
677
- console.log("[IMA] Content resume requested");
753
+ console.log("[IMA] \u23F8\uFE0F CONTENT_RESUME_REQUESTED - Single ad completed");
678
754
  adPlaying = false;
679
755
  setAdPlayingFlag(false);
756
+ console.log("[IMA] Emitting 'content_resume' event to player");
680
757
  emit("content_resume");
681
758
  }
682
759
  );
683
760
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
684
- console.log("[IMA] All ads completed - restoring content");
761
+ console.log("[IMA] \u{1F3C1} ALL_ADS_COMPLETED - All ads in break finished");
685
762
  adPlaying = false;
686
763
  setAdPlayingFlag(false);
687
764
  if (adContainerEl) {
@@ -691,7 +768,7 @@ function createImaController(video, options) {
691
768
  if (adContainerEl) {
692
769
  adContainerEl.style.pointerEvents = "none";
693
770
  adContainerEl.style.display = "none";
694
- console.log("[IMA] Ad container hidden");
771
+ console.log("[IMA] \u{1F648} Ad container hidden (ALL_ADS_COMPLETED)");
695
772
  }
696
773
  }, 300);
697
774
  }
@@ -702,6 +779,7 @@ function createImaController(video, options) {
702
779
  console.warn("[IMA] Failed to resume content video:", e);
703
780
  });
704
781
  }
782
+ console.log("[IMA] Emitting 'all_ads_completed' event to player");
705
783
  emit("all_ads_completed");
706
784
  });
707
785
  console.log("[IMA] Ads manager event listeners attached");
@@ -750,7 +828,17 @@ function createImaController(video, options) {
750
828
  adsLoader.addEventListener(
751
829
  google.ima.AdErrorEvent.Type.AD_ERROR,
752
830
  (adErrorEvent) => {
753
- console.error("[IMA] Ads loader error:", adErrorEvent.getError());
831
+ var _a, _b, _c, _d;
832
+ const error = adErrorEvent.getError();
833
+ console.error("[IMA] \u274C ADS_LOADER ERROR - Ad request failed!", {
834
+ message: (_a = error.getMessage) == null ? void 0 : _a.call(error),
835
+ errorCode: (_b = error.getErrorCode) == null ? void 0 : _b.call(error),
836
+ type: (_c = error.getType) == null ? void 0 : _c.call(error),
837
+ vastErrorCode: (_d = error.getVastErrorCode) == null ? void 0 : _d.call(error)
838
+ });
839
+ console.error("[IMA] This means the ad server didn't return valid ads");
840
+ console.error("[IMA] Ad layer will NOT appear (no flicker)");
841
+ console.error("[IMA] Full error object:", adErrorEvent.getError());
754
842
  adPlaying = false;
755
843
  setAdPlayingFlag(false);
756
844
  if (adContainerEl) {
@@ -782,8 +870,10 @@ function createImaController(video, options) {
782
870
  false
783
871
  );
784
872
  }
785
- console.log("[IMA] Making ads request");
873
+ console.log("[IMA] \u{1F680} Making ads request to IMA SDK");
874
+ console.log("[IMA] Waiting for IMA SDK response (LOADED or ERROR event)...");
786
875
  makeAdsRequest(google, vastTagUrl);
876
+ console.log("[IMA] \u23F3 Returning promise that will resolve when ads are loaded");
787
877
  return adsLoadedPromise;
788
878
  } catch (error) {
789
879
  console.error("[IMA] Failed to request ads:", error);
@@ -821,20 +911,23 @@ function createImaController(video, options) {
821
911
  },
822
912
  async play() {
823
913
  var _a, _b;
914
+ console.log("[IMA] \u25B6\uFE0F === play() called ===");
915
+ console.log("[IMA] This initializes and starts the ad");
916
+ console.log("[IMA] Ad layer will appear when CONTENT_PAUSE_REQUESTED fires");
824
917
  if (!((_a = window.google) == null ? void 0 : _a.ima) || !adDisplayContainer) {
825
918
  console.warn(
826
- "[IMA] Cannot play ad: IMA SDK or ad container not available"
919
+ "[IMA] \u274C Cannot play ad: IMA SDK or ad container not available"
827
920
  );
828
921
  return Promise.reject(new Error("IMA SDK not available"));
829
922
  }
830
923
  if (!adsManager) {
831
- console.warn("[IMA] Cannot play ad: No ads manager available");
924
+ console.warn("[IMA] \u274C Cannot play ad: No ads manager available");
832
925
  return Promise.reject(new Error("No ads manager"));
833
926
  }
834
927
  try {
835
928
  const width = video.clientWidth || 640;
836
929
  const height = video.clientHeight || 360;
837
- console.log(`[IMA] Initializing ads manager (${width}x${height})`);
930
+ console.log(`[IMA] \u{1F3AC} Initializing ads manager (${width}x${height})`);
838
931
  adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
839
932
  adPlaying = true;
840
933
  const adVolume = originalMutedState ? 0 : originalVolume;
@@ -842,7 +935,7 @@ function createImaController(video, options) {
842
935
  adVideoElement.volume = adVolume;
843
936
  adVideoElement.muted = originalMutedState;
844
937
  console.log(
845
- `[IMA] Set dedicated ad video volume to ${adVolume}, muted: ${originalMutedState}`
938
+ `[IMA] \u{1F50A} Set dedicated ad video volume to ${adVolume}, muted: ${originalMutedState}`
846
939
  );
847
940
  }
848
941
  try {
@@ -851,11 +944,13 @@ function createImaController(video, options) {
851
944
  } catch (error) {
852
945
  console.warn("[IMA] Failed to set IMA manager volume:", error);
853
946
  }
854
- console.log("[IMA] Starting ad playback");
947
+ console.log("[IMA] \u{1F3AF} Calling adsManager.start()");
948
+ console.log("[IMA] If successful, IMA will fire CONTENT_PAUSE_REQUESTED");
855
949
  adsManager.start();
950
+ console.log("[IMA] \u2705 play() completed successfully");
856
951
  return Promise.resolve();
857
952
  } catch (error) {
858
- console.error("[IMA] Error starting ad playback:", error);
953
+ console.error("[IMA] \u274C Error starting ad playback:", error);
859
954
  adPlaying = false;
860
955
  setAdPlayingFlag(false);
861
956
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
@@ -2526,10 +2621,9 @@ var StormcloudVideoPlayer = class {
2526
2621
  const nextPreloaded = this.findNextPreloadedAd();
2527
2622
  if (nextPreloaded) {
2528
2623
  this.currentAdIndex++;
2529
- this.enforceAdHoldState();
2530
2624
  if (this.config.debugAdTiming) {
2531
2625
  console.log(
2532
- `[StormcloudVideoPlayer] Playing next preloaded ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak})`
2626
+ `[StormcloudVideoPlayer] Playing next preloaded ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - layer will stay visible if ad loads`
2533
2627
  );
2534
2628
  }
2535
2629
  this.playSingleAd(nextPreloaded).catch(() => {
@@ -3169,10 +3263,9 @@ var StormcloudVideoPlayer = class {
3169
3263
  this.currentAdIndex = 0;
3170
3264
  this.totalAdsInBreak = vastTagUrls.length;
3171
3265
  this.adPodQueue = [...vastTagUrls];
3172
- this.enforceAdHoldState();
3173
3266
  if (this.config.debugAdTiming) {
3174
3267
  console.log(
3175
- `[StormcloudVideoPlayer] Starting ad pod with ${vastTagUrls.length} ads - preloading all ads in parallel`
3268
+ `[StormcloudVideoPlayer] Starting ad pod with ${vastTagUrls.length} ads - preloading all ads in parallel (ad layer will show after ad loads)`
3176
3269
  );
3177
3270
  }
3178
3271
  this.preloadAllAdsInBackground().catch((error) => {
@@ -3263,7 +3356,6 @@ var StormcloudVideoPlayer = class {
3263
3356
  const rest = tags.slice(1);
3264
3357
  this.adPodQueue = rest;
3265
3358
  this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3266
- this.enforceAdHoldState();
3267
3359
  await this.playSingleAd(first);
3268
3360
  this.inAdBreak = true;
3269
3361
  this.expectedAdBreakDurationMs = remainingMs;
@@ -3389,10 +3481,9 @@ var StormcloudVideoPlayer = class {
3389
3481
  try {
3390
3482
  if (this.config.debugAdTiming) {
3391
3483
  console.log(
3392
- "[StormcloudVideoPlayer] Ad request completed, attempting playback"
3484
+ "[StormcloudVideoPlayer] Ad request completed, attempting playback (ad layer will show when IMA triggers content pause)"
3393
3485
  );
3394
3486
  }
3395
- this.enforceAdHoldState();
3396
3487
  await this.ima.play();
3397
3488
  this.showAds = true;
3398
3489
  if (this.config.debugAdTiming) {