stormcloud-video-player 0.2.27 → 0.2.28

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.
@@ -245,6 +245,7 @@ function createImaController(video, options) {
245
245
  const listeners = /* @__PURE__ */ new Map();
246
246
  const preloadedVast = /* @__PURE__ */ new Map();
247
247
  const preloadingVast = /* @__PURE__ */ new Map();
248
+ let adVideoElement;
248
249
  function setAdPlayingFlag(isPlaying) {
249
250
  if (isPlaying) {
250
251
  video.dataset.stormcloudAdPlaying = "true";
@@ -252,6 +253,24 @@ function createImaController(video, options) {
252
253
  delete video.dataset.stormcloudAdPlaying;
253
254
  }
254
255
  }
256
+ function createAdVideoElement() {
257
+ const adVideo = document.createElement("video");
258
+ adVideo.style.position = "absolute";
259
+ adVideo.style.top = "0";
260
+ adVideo.style.left = "0";
261
+ adVideo.style.width = "100%";
262
+ adVideo.style.height = "100%";
263
+ adVideo.style.objectFit = "contain";
264
+ adVideo.style.backgroundColor = "#000";
265
+ adVideo.style.zIndex = "15";
266
+ adVideo.playsInline = true;
267
+ adVideo.muted = false;
268
+ adVideo.volume = originalMutedState ? 0 : originalVolume;
269
+ console.log(
270
+ `[IMA] Created dedicated ad video element with volume: ${adVideo.volume}, muted: ${adVideo.muted}`
271
+ );
272
+ return adVideo;
273
+ }
255
274
  function emit(event, payload) {
256
275
  const set = listeners.get(event);
257
276
  if (!set) return;
@@ -418,12 +437,22 @@ function createImaController(video, options) {
418
437
  const google = window.google;
419
438
  ensurePlaceholderContainer();
420
439
  if (!adDisplayContainer && adContainerEl) {
440
+ if (!adVideoElement) {
441
+ adVideoElement = createAdVideoElement();
442
+ adContainerEl.appendChild(adVideoElement);
443
+ console.log(
444
+ "[IMA] Dedicated ad video element added to container"
445
+ );
446
+ }
421
447
  adDisplayContainer = new google.ima.AdDisplayContainer(
422
448
  adContainerEl,
423
- video
449
+ adVideoElement
424
450
  );
425
451
  try {
426
452
  (_a = adDisplayContainer.initialize) == null ? void 0 : _a.call(adDisplayContainer);
453
+ console.log(
454
+ "[IMA] AdDisplayContainer initialized with dedicated ad video"
455
+ );
427
456
  } catch {
428
457
  }
429
458
  }
@@ -492,13 +521,22 @@ function createImaController(video, options) {
492
521
  }
493
522
  video.parentElement.appendChild(container);
494
523
  adContainerEl = container;
524
+ if (!adVideoElement) {
525
+ adVideoElement = createAdVideoElement();
526
+ adContainerEl.appendChild(adVideoElement);
527
+ console.log(
528
+ "[IMA] Dedicated ad video element created and added to container"
529
+ );
530
+ }
495
531
  adDisplayContainer = new google.ima.AdDisplayContainer(
496
532
  container,
497
- video
533
+ adVideoElement
498
534
  );
499
535
  try {
500
536
  adDisplayContainer.initialize();
501
- console.log("[IMA] Ad display container initialized");
537
+ console.log(
538
+ "[IMA] Ad display container initialized with dedicated ad video"
539
+ );
502
540
  } catch (error) {
503
541
  console.warn(
504
542
  "[IMA] Failed to initialize ad display container:",
@@ -541,11 +579,10 @@ function createImaController(video, options) {
541
579
  console.error("[IMA] Ad error:", errorEvent.getError());
542
580
  destroyAdsManager();
543
581
  adPlaying = false;
544
- const previousMutedState = video.muted;
545
- video.muted = originalMutedState;
582
+ video.style.visibility = "visible";
546
583
  setAdPlayingFlag(false);
547
584
  console.log(
548
- `[IMA] Restored mute state after ad error: ${previousMutedState} -> ${originalMutedState}`
585
+ "[IMA] Restored main video visibility after ad error"
549
586
  );
550
587
  if (adContainerEl) {
551
588
  adContainerEl.style.pointerEvents = "none";
@@ -589,18 +626,17 @@ function createImaController(video, options) {
589
626
  AdEvent.CONTENT_PAUSE_REQUESTED,
590
627
  () => {
591
628
  console.log(
592
- "[IMA] Content pause requested - FORCE MUTING main video"
629
+ "[IMA] Content pause requested - hiding main video, showing ad video"
593
630
  );
594
631
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
595
632
  video.pause();
596
- console.log("[IMA] Video paused (VOD mode)");
633
+ console.log("[IMA] Content video paused (VOD mode)");
597
634
  } else {
598
635
  console.log(
599
- "[IMA] Video continues playing but muted (Live mode)"
636
+ "[IMA] Content video continues playing in background (Live mode)"
600
637
  );
601
638
  }
602
- video.muted = true;
603
- video.volume = 0;
639
+ video.style.visibility = "hidden";
604
640
  adPlaying = true;
605
641
  setAdPlayingFlag(true);
606
642
  emit("content_pause");
@@ -608,36 +644,46 @@ function createImaController(video, options) {
608
644
  );
609
645
  adsManager.addEventListener(AdEvent.STARTED, () => {
610
646
  console.log(
611
- "[IMA] Ad started playing - FORCE MUTING main video"
647
+ "[IMA] Ad started playing - showing dedicated ad video"
612
648
  );
613
649
  setAdPlayingFlag(true);
614
- video.muted = true;
615
- video.volume = 0;
650
+ video.style.visibility = "hidden";
651
+ if (adVideoElement) {
652
+ adVideoElement.volume = originalMutedState ? 0 : originalVolume;
653
+ adVideoElement.muted = originalMutedState;
654
+ console.log(
655
+ `[IMA] Ad video volume: ${adVideoElement.volume}, muted: ${adVideoElement.muted}`
656
+ );
657
+ }
616
658
  if (adContainerEl) {
617
659
  adContainerEl.style.pointerEvents = "auto";
618
660
  adContainerEl.style.display = "flex";
619
661
  console.log(
620
- "[IMA] Ad container visibility set to flex with pointer events enabled"
662
+ "[IMA] Ad container visible with dedicated ad video"
621
663
  );
622
664
  }
623
665
  });
624
666
  adsManager.addEventListener(
625
667
  AdEvent.CONTENT_RESUME_REQUESTED,
626
668
  () => {
627
- console.log("[IMA] Content resume requested");
669
+ console.log(
670
+ "[IMA] Content resume requested - showing main video"
671
+ );
628
672
  adPlaying = false;
629
673
  setAdPlayingFlag(false);
674
+ video.style.visibility = "visible";
630
675
  emit("content_resume");
631
676
  setTimeout(() => {
632
677
  const stillInPod = video.dataset.stormcloudAdPlaying === "true";
633
678
  if (stillInPod) {
634
679
  console.log(
635
- "[IMA] Still in ad pod - keeping ad container visible (black screen)"
680
+ "[IMA] Still in ad pod - keeping ad video visible"
636
681
  );
637
682
  if (adContainerEl) {
638
683
  adContainerEl.style.display = "flex";
639
684
  adContainerEl.style.pointerEvents = "auto";
640
685
  }
686
+ video.style.visibility = "hidden";
641
687
  }
642
688
  }, 50);
643
689
  }
@@ -657,7 +703,7 @@ function createImaController(video, options) {
657
703
  } catch (e) {
658
704
  console.error("[IMA] Error setting up ads manager:", e);
659
705
  adPlaying = false;
660
- video.muted = originalMutedState;
706
+ video.style.visibility = "visible";
661
707
  setAdPlayingFlag(false);
662
708
  if (adContainerEl) {
663
709
  adContainerEl.style.pointerEvents = "none";
@@ -688,11 +734,10 @@ function createImaController(video, options) {
688
734
  (adErrorEvent) => {
689
735
  console.error("[IMA] Ads loader error:", adErrorEvent.getError());
690
736
  adPlaying = false;
691
- const previousMutedState = video.muted;
692
- video.muted = originalMutedState;
737
+ video.style.visibility = "visible";
693
738
  setAdPlayingFlag(false);
694
739
  console.log(
695
- `[IMA] Restored mute state: ${previousMutedState} -> ${originalMutedState}`
740
+ "[IMA] Restored main video visibility after loader error"
696
741
  );
697
742
  if (adContainerEl) {
698
743
  adContainerEl.style.pointerEvents = "none";
@@ -772,11 +817,18 @@ function createImaController(video, options) {
772
817
  adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
773
818
  adPlaying = true;
774
819
  const adVolume = originalMutedState ? 0 : originalVolume;
820
+ if (adVideoElement) {
821
+ adVideoElement.volume = adVolume;
822
+ adVideoElement.muted = originalMutedState;
823
+ console.log(
824
+ `[IMA] Set dedicated ad video volume to ${adVolume}, muted: ${originalMutedState}`
825
+ );
826
+ }
775
827
  try {
776
828
  adsManager.setVolume(adVolume);
777
- console.log(`[IMA] Set ad volume to ${adVolume}`);
829
+ console.log(`[IMA] Set IMA manager volume to ${adVolume}`);
778
830
  } catch (error) {
779
- console.warn("[IMA] Failed to set ad volume:", error);
831
+ console.warn("[IMA] Failed to set IMA manager volume:", error);
780
832
  }
781
833
  console.log("[IMA] Starting ad playback");
782
834
  adsManager.start();
@@ -797,6 +849,7 @@ function createImaController(video, options) {
797
849
  console.log("[IMA] Stopping ad playback");
798
850
  adPlaying = false;
799
851
  setAdPlayingFlag(false);
852
+ video.style.visibility = "visible";
800
853
  if (adContainerEl) {
801
854
  adContainerEl.style.pointerEvents = "none";
802
855
  adContainerEl.style.display = "none";
@@ -812,8 +865,7 @@ function createImaController(video, options) {
812
865
  var _a;
813
866
  destroyAdsManager();
814
867
  adPlaying = false;
815
- video.muted = originalMutedState;
816
- video.volume = originalVolume;
868
+ video.style.visibility = "visible";
817
869
  setAdPlayingFlag(false);
818
870
  if (adContainerEl) {
819
871
  adContainerEl.style.pointerEvents = "none";
@@ -829,6 +881,7 @@ function createImaController(video, options) {
829
881
  adContainerEl = void 0;
830
882
  adDisplayContainer = void 0;
831
883
  adsLoader = void 0;
884
+ adVideoElement = void 0;
832
885
  preloadedVast.clear();
833
886
  preloadingVast.clear();
834
887
  },
@@ -873,15 +926,26 @@ function createImaController(video, options) {
873
926
  return originalVolume;
874
927
  },
875
928
  setAdVolume(volume) {
929
+ const clampedVolume = Math.max(0, Math.min(1, volume));
930
+ if (adVideoElement && adPlaying) {
931
+ adVideoElement.volume = clampedVolume;
932
+ adVideoElement.muted = clampedVolume === 0;
933
+ console.log(
934
+ `[IMA] Set dedicated ad video volume to ${clampedVolume}, muted: ${clampedVolume === 0}`
935
+ );
936
+ }
876
937
  if (adsManager && adPlaying) {
877
938
  try {
878
- adsManager.setVolume(Math.max(0, Math.min(1, volume)));
939
+ adsManager.setVolume(clampedVolume);
879
940
  } catch (error) {
880
- console.warn("[IMA] Failed to set ad volume:", error);
941
+ console.warn("[IMA] Failed to set IMA manager volume:", error);
881
942
  }
882
943
  }
883
944
  },
884
945
  getAdVolume() {
946
+ if (adVideoElement && adPlaying) {
947
+ return adVideoElement.volume;
948
+ }
885
949
  if (adsManager && adPlaying) {
886
950
  try {
887
951
  return adsManager.getVolume();
@@ -3498,11 +3562,6 @@ var StormcloudVideoPlayer = class {
3498
3562
  }
3499
3563
  return false;
3500
3564
  }
3501
- if (this.config.debugAdTiming) {
3502
- console.log(
3503
- `[StormcloudVideoPlayer] isMuted() no ad playing: video.muted=${this.video.muted}`
3504
- );
3505
- }
3506
3565
  return this.video.muted;
3507
3566
  }
3508
3567
  setMuted(muted) {