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.
@@ -206,6 +206,7 @@ function createImaController(video, options) {
206
206
  const listeners = /* @__PURE__ */ new Map();
207
207
  const preloadedVast = /* @__PURE__ */ new Map();
208
208
  const preloadingVast = /* @__PURE__ */ new Map();
209
+ let adVideoElement;
209
210
  function setAdPlayingFlag(isPlaying) {
210
211
  if (isPlaying) {
211
212
  video.dataset.stormcloudAdPlaying = "true";
@@ -213,6 +214,24 @@ function createImaController(video, options) {
213
214
  delete video.dataset.stormcloudAdPlaying;
214
215
  }
215
216
  }
217
+ function createAdVideoElement() {
218
+ const adVideo = document.createElement("video");
219
+ adVideo.style.position = "absolute";
220
+ adVideo.style.top = "0";
221
+ adVideo.style.left = "0";
222
+ adVideo.style.width = "100%";
223
+ adVideo.style.height = "100%";
224
+ adVideo.style.objectFit = "contain";
225
+ adVideo.style.backgroundColor = "#000";
226
+ adVideo.style.zIndex = "15";
227
+ adVideo.playsInline = true;
228
+ adVideo.muted = false;
229
+ adVideo.volume = originalMutedState ? 0 : originalVolume;
230
+ console.log(
231
+ `[IMA] Created dedicated ad video element with volume: ${adVideo.volume}, muted: ${adVideo.muted}`
232
+ );
233
+ return adVideo;
234
+ }
216
235
  function emit(event, payload) {
217
236
  const set = listeners.get(event);
218
237
  if (!set) return;
@@ -379,12 +398,22 @@ function createImaController(video, options) {
379
398
  const google = window.google;
380
399
  ensurePlaceholderContainer();
381
400
  if (!adDisplayContainer && adContainerEl) {
401
+ if (!adVideoElement) {
402
+ adVideoElement = createAdVideoElement();
403
+ adContainerEl.appendChild(adVideoElement);
404
+ console.log(
405
+ "[IMA] Dedicated ad video element added to container"
406
+ );
407
+ }
382
408
  adDisplayContainer = new google.ima.AdDisplayContainer(
383
409
  adContainerEl,
384
- video
410
+ adVideoElement
385
411
  );
386
412
  try {
387
413
  (_a = adDisplayContainer.initialize) == null ? void 0 : _a.call(adDisplayContainer);
414
+ console.log(
415
+ "[IMA] AdDisplayContainer initialized with dedicated ad video"
416
+ );
388
417
  } catch {
389
418
  }
390
419
  }
@@ -453,13 +482,22 @@ function createImaController(video, options) {
453
482
  }
454
483
  video.parentElement.appendChild(container);
455
484
  adContainerEl = container;
485
+ if (!adVideoElement) {
486
+ adVideoElement = createAdVideoElement();
487
+ adContainerEl.appendChild(adVideoElement);
488
+ console.log(
489
+ "[IMA] Dedicated ad video element created and added to container"
490
+ );
491
+ }
456
492
  adDisplayContainer = new google.ima.AdDisplayContainer(
457
493
  container,
458
- video
494
+ adVideoElement
459
495
  );
460
496
  try {
461
497
  adDisplayContainer.initialize();
462
- console.log("[IMA] Ad display container initialized");
498
+ console.log(
499
+ "[IMA] Ad display container initialized with dedicated ad video"
500
+ );
463
501
  } catch (error) {
464
502
  console.warn(
465
503
  "[IMA] Failed to initialize ad display container:",
@@ -502,11 +540,10 @@ function createImaController(video, options) {
502
540
  console.error("[IMA] Ad error:", errorEvent.getError());
503
541
  destroyAdsManager();
504
542
  adPlaying = false;
505
- const previousMutedState = video.muted;
506
- video.muted = originalMutedState;
543
+ video.style.visibility = "visible";
507
544
  setAdPlayingFlag(false);
508
545
  console.log(
509
- `[IMA] Restored mute state after ad error: ${previousMutedState} -> ${originalMutedState}`
546
+ "[IMA] Restored main video visibility after ad error"
510
547
  );
511
548
  if (adContainerEl) {
512
549
  adContainerEl.style.pointerEvents = "none";
@@ -550,18 +587,17 @@ function createImaController(video, options) {
550
587
  AdEvent.CONTENT_PAUSE_REQUESTED,
551
588
  () => {
552
589
  console.log(
553
- "[IMA] Content pause requested - FORCE MUTING main video"
590
+ "[IMA] Content pause requested - hiding main video, showing ad video"
554
591
  );
555
592
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
556
593
  video.pause();
557
- console.log("[IMA] Video paused (VOD mode)");
594
+ console.log("[IMA] Content video paused (VOD mode)");
558
595
  } else {
559
596
  console.log(
560
- "[IMA] Video continues playing but muted (Live mode)"
597
+ "[IMA] Content video continues playing in background (Live mode)"
561
598
  );
562
599
  }
563
- video.muted = true;
564
- video.volume = 0;
600
+ video.style.visibility = "hidden";
565
601
  adPlaying = true;
566
602
  setAdPlayingFlag(true);
567
603
  emit("content_pause");
@@ -569,36 +605,46 @@ function createImaController(video, options) {
569
605
  );
570
606
  adsManager.addEventListener(AdEvent.STARTED, () => {
571
607
  console.log(
572
- "[IMA] Ad started playing - FORCE MUTING main video"
608
+ "[IMA] Ad started playing - showing dedicated ad video"
573
609
  );
574
610
  setAdPlayingFlag(true);
575
- video.muted = true;
576
- video.volume = 0;
611
+ video.style.visibility = "hidden";
612
+ if (adVideoElement) {
613
+ adVideoElement.volume = originalMutedState ? 0 : originalVolume;
614
+ adVideoElement.muted = originalMutedState;
615
+ console.log(
616
+ `[IMA] Ad video volume: ${adVideoElement.volume}, muted: ${adVideoElement.muted}`
617
+ );
618
+ }
577
619
  if (adContainerEl) {
578
620
  adContainerEl.style.pointerEvents = "auto";
579
621
  adContainerEl.style.display = "flex";
580
622
  console.log(
581
- "[IMA] Ad container visibility set to flex with pointer events enabled"
623
+ "[IMA] Ad container visible with dedicated ad video"
582
624
  );
583
625
  }
584
626
  });
585
627
  adsManager.addEventListener(
586
628
  AdEvent.CONTENT_RESUME_REQUESTED,
587
629
  () => {
588
- console.log("[IMA] Content resume requested");
630
+ console.log(
631
+ "[IMA] Content resume requested - showing main video"
632
+ );
589
633
  adPlaying = false;
590
634
  setAdPlayingFlag(false);
635
+ video.style.visibility = "visible";
591
636
  emit("content_resume");
592
637
  setTimeout(() => {
593
638
  const stillInPod = video.dataset.stormcloudAdPlaying === "true";
594
639
  if (stillInPod) {
595
640
  console.log(
596
- "[IMA] Still in ad pod - keeping ad container visible (black screen)"
641
+ "[IMA] Still in ad pod - keeping ad video visible"
597
642
  );
598
643
  if (adContainerEl) {
599
644
  adContainerEl.style.display = "flex";
600
645
  adContainerEl.style.pointerEvents = "auto";
601
646
  }
647
+ video.style.visibility = "hidden";
602
648
  }
603
649
  }, 50);
604
650
  }
@@ -618,7 +664,7 @@ function createImaController(video, options) {
618
664
  } catch (e) {
619
665
  console.error("[IMA] Error setting up ads manager:", e);
620
666
  adPlaying = false;
621
- video.muted = originalMutedState;
667
+ video.style.visibility = "visible";
622
668
  setAdPlayingFlag(false);
623
669
  if (adContainerEl) {
624
670
  adContainerEl.style.pointerEvents = "none";
@@ -649,11 +695,10 @@ function createImaController(video, options) {
649
695
  (adErrorEvent) => {
650
696
  console.error("[IMA] Ads loader error:", adErrorEvent.getError());
651
697
  adPlaying = false;
652
- const previousMutedState = video.muted;
653
- video.muted = originalMutedState;
698
+ video.style.visibility = "visible";
654
699
  setAdPlayingFlag(false);
655
700
  console.log(
656
- `[IMA] Restored mute state: ${previousMutedState} -> ${originalMutedState}`
701
+ "[IMA] Restored main video visibility after loader error"
657
702
  );
658
703
  if (adContainerEl) {
659
704
  adContainerEl.style.pointerEvents = "none";
@@ -733,11 +778,18 @@ function createImaController(video, options) {
733
778
  adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
734
779
  adPlaying = true;
735
780
  const adVolume = originalMutedState ? 0 : originalVolume;
781
+ if (adVideoElement) {
782
+ adVideoElement.volume = adVolume;
783
+ adVideoElement.muted = originalMutedState;
784
+ console.log(
785
+ `[IMA] Set dedicated ad video volume to ${adVolume}, muted: ${originalMutedState}`
786
+ );
787
+ }
736
788
  try {
737
789
  adsManager.setVolume(adVolume);
738
- console.log(`[IMA] Set ad volume to ${adVolume}`);
790
+ console.log(`[IMA] Set IMA manager volume to ${adVolume}`);
739
791
  } catch (error) {
740
- console.warn("[IMA] Failed to set ad volume:", error);
792
+ console.warn("[IMA] Failed to set IMA manager volume:", error);
741
793
  }
742
794
  console.log("[IMA] Starting ad playback");
743
795
  adsManager.start();
@@ -758,6 +810,7 @@ function createImaController(video, options) {
758
810
  console.log("[IMA] Stopping ad playback");
759
811
  adPlaying = false;
760
812
  setAdPlayingFlag(false);
813
+ video.style.visibility = "visible";
761
814
  if (adContainerEl) {
762
815
  adContainerEl.style.pointerEvents = "none";
763
816
  adContainerEl.style.display = "none";
@@ -773,8 +826,7 @@ function createImaController(video, options) {
773
826
  var _a;
774
827
  destroyAdsManager();
775
828
  adPlaying = false;
776
- video.muted = originalMutedState;
777
- video.volume = originalVolume;
829
+ video.style.visibility = "visible";
778
830
  setAdPlayingFlag(false);
779
831
  if (adContainerEl) {
780
832
  adContainerEl.style.pointerEvents = "none";
@@ -790,6 +842,7 @@ function createImaController(video, options) {
790
842
  adContainerEl = void 0;
791
843
  adDisplayContainer = void 0;
792
844
  adsLoader = void 0;
845
+ adVideoElement = void 0;
793
846
  preloadedVast.clear();
794
847
  preloadingVast.clear();
795
848
  },
@@ -834,15 +887,26 @@ function createImaController(video, options) {
834
887
  return originalVolume;
835
888
  },
836
889
  setAdVolume(volume) {
890
+ const clampedVolume = Math.max(0, Math.min(1, volume));
891
+ if (adVideoElement && adPlaying) {
892
+ adVideoElement.volume = clampedVolume;
893
+ adVideoElement.muted = clampedVolume === 0;
894
+ console.log(
895
+ `[IMA] Set dedicated ad video volume to ${clampedVolume}, muted: ${clampedVolume === 0}`
896
+ );
897
+ }
837
898
  if (adsManager && adPlaying) {
838
899
  try {
839
- adsManager.setVolume(Math.max(0, Math.min(1, volume)));
900
+ adsManager.setVolume(clampedVolume);
840
901
  } catch (error) {
841
- console.warn("[IMA] Failed to set ad volume:", error);
902
+ console.warn("[IMA] Failed to set IMA manager volume:", error);
842
903
  }
843
904
  }
844
905
  },
845
906
  getAdVolume() {
907
+ if (adVideoElement && adPlaying) {
908
+ return adVideoElement.volume;
909
+ }
846
910
  if (adsManager && adPlaying) {
847
911
  try {
848
912
  return adsManager.getVolume();
@@ -3459,11 +3523,6 @@ var StormcloudVideoPlayer = class {
3459
3523
  }
3460
3524
  return false;
3461
3525
  }
3462
- if (this.config.debugAdTiming) {
3463
- console.log(
3464
- `[StormcloudVideoPlayer] isMuted() no ad playing: video.muted=${this.video.muted}`
3465
- );
3466
- }
3467
3526
  return this.video.muted;
3468
3527
  }
3469
3528
  setMuted(muted) {