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