stormcloud-video-player 0.2.28 → 0.2.29

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
@@ -265,6 +265,7 @@ function supportsFeature(feature) {
265
265
  // src/sdk/ima.ts
266
266
  function createImaController(video, options) {
267
267
  let adPlaying = false;
268
+ let contentVideoHidden = false;
268
269
  let originalMutedState = false;
269
270
  let originalVolume = typeof video.volume === "number" && !Number.isNaN(video.volume) ? Math.max(0, Math.min(1, video.volume)) : 1;
270
271
  const listeners = /* @__PURE__ */ new Map();
@@ -278,6 +279,26 @@ function createImaController(video, options) {
278
279
  delete video.dataset.stormcloudAdPlaying;
279
280
  }
280
281
  }
282
+ function hideContentVideo() {
283
+ if (!contentVideoHidden) {
284
+ video.style.visibility = "hidden";
285
+ video.muted = true;
286
+ video.volume = 0;
287
+ contentVideoHidden = true;
288
+ console.log("[IMA] Content video hidden and muted");
289
+ }
290
+ }
291
+ function showContentVideo() {
292
+ if (contentVideoHidden) {
293
+ video.style.visibility = "visible";
294
+ video.muted = originalMutedState;
295
+ video.volume = originalVolume;
296
+ contentVideoHidden = false;
297
+ console.log(
298
+ `[IMA] Content video restored (muted: ${originalMutedState}, volume: ${originalVolume})`
299
+ );
300
+ }
301
+ }
281
302
  function createAdVideoElement() {
282
303
  const adVideo = document.createElement("video");
283
304
  adVideo.style.position = "absolute";
@@ -286,11 +307,20 @@ function createImaController(video, options) {
286
307
  adVideo.style.width = "100%";
287
308
  adVideo.style.height = "100%";
288
309
  adVideo.style.objectFit = "contain";
289
- adVideo.style.backgroundColor = "#000";
310
+ adVideo.style.backgroundColor = "transparent";
290
311
  adVideo.style.zIndex = "15";
291
312
  adVideo.playsInline = true;
292
313
  adVideo.muted = false;
293
314
  adVideo.volume = originalMutedState ? 0 : originalVolume;
315
+ adVideo.style.opacity = "0";
316
+ adVideo.addEventListener(
317
+ "canplay",
318
+ () => {
319
+ adVideo.style.opacity = "1";
320
+ console.log("[IMA] Ad video ready to play");
321
+ },
322
+ { once: true }
323
+ );
294
324
  console.log(
295
325
  `[IMA] Created dedicated ad video element with volume: ${adVideo.volume}, muted: ${adVideo.muted}`
296
326
  );
@@ -454,6 +484,9 @@ function createImaController(video, options) {
454
484
  }
455
485
  adsManager = void 0;
456
486
  }
487
+ if (adVideoElement) {
488
+ adVideoElement.style.opacity = "0";
489
+ }
457
490
  }
458
491
  return {
459
492
  initialize() {
@@ -604,11 +637,8 @@ function createImaController(video, options) {
604
637
  console.error("[IMA] Ad error:", errorEvent.getError());
605
638
  destroyAdsManager();
606
639
  adPlaying = false;
607
- video.style.visibility = "visible";
640
+ showContentVideo();
608
641
  setAdPlayingFlag(false);
609
- console.log(
610
- "[IMA] Restored main video visibility after ad error"
611
- );
612
642
  if (adContainerEl) {
613
643
  adContainerEl.style.pointerEvents = "none";
614
644
  adContainerEl.style.display = "none";
@@ -650,29 +680,24 @@ function createImaController(video, options) {
650
680
  adsManager.addEventListener(
651
681
  AdEvent.CONTENT_PAUSE_REQUESTED,
652
682
  () => {
653
- console.log(
654
- "[IMA] Content pause requested - hiding main video, showing ad video"
655
- );
683
+ console.log("[IMA] Content pause requested");
656
684
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
657
685
  video.pause();
658
686
  console.log("[IMA] Content video paused (VOD mode)");
659
687
  } else {
660
688
  console.log(
661
- "[IMA] Content video continues playing in background (Live mode)"
689
+ "[IMA] Content video continues in background (Live mode)"
662
690
  );
663
691
  }
664
- video.style.visibility = "hidden";
665
692
  adPlaying = true;
666
693
  setAdPlayingFlag(true);
667
694
  emit("content_pause");
668
695
  }
669
696
  );
670
697
  adsManager.addEventListener(AdEvent.STARTED, () => {
671
- console.log(
672
- "[IMA] Ad started playing - showing dedicated ad video"
673
- );
698
+ console.log("[IMA] Ad started - showing ad video");
674
699
  setAdPlayingFlag(true);
675
- video.style.visibility = "hidden";
700
+ hideContentVideo();
676
701
  if (adVideoElement) {
677
702
  adVideoElement.volume = originalMutedState ? 0 : originalVolume;
678
703
  adVideoElement.muted = originalMutedState;
@@ -683,32 +708,28 @@ function createImaController(video, options) {
683
708
  if (adContainerEl) {
684
709
  adContainerEl.style.pointerEvents = "auto";
685
710
  adContainerEl.style.display = "flex";
686
- console.log(
687
- "[IMA] Ad container visible with dedicated ad video"
688
- );
711
+ console.log("[IMA] Ad container now visible");
689
712
  }
690
713
  });
691
714
  adsManager.addEventListener(
692
715
  AdEvent.CONTENT_RESUME_REQUESTED,
693
716
  () => {
694
- console.log(
695
- "[IMA] Content resume requested - showing main video"
696
- );
717
+ console.log("[IMA] Content resume requested");
697
718
  adPlaying = false;
698
719
  setAdPlayingFlag(false);
699
- video.style.visibility = "visible";
720
+ showContentVideo();
700
721
  emit("content_resume");
701
722
  setTimeout(() => {
702
723
  const stillInPod = video.dataset.stormcloudAdPlaying === "true";
703
724
  if (stillInPod) {
704
725
  console.log(
705
- "[IMA] Still in ad pod - keeping ad video visible"
726
+ "[IMA] Still in ad pod - keeping ad container visible"
706
727
  );
707
728
  if (adContainerEl) {
708
729
  adContainerEl.style.display = "flex";
709
730
  adContainerEl.style.pointerEvents = "auto";
710
731
  }
711
- video.style.visibility = "hidden";
732
+ hideContentVideo();
712
733
  }
713
734
  }, 50);
714
735
  }
@@ -728,7 +749,7 @@ function createImaController(video, options) {
728
749
  } catch (e) {
729
750
  console.error("[IMA] Error setting up ads manager:", e);
730
751
  adPlaying = false;
731
- video.style.visibility = "visible";
752
+ showContentVideo();
732
753
  setAdPlayingFlag(false);
733
754
  if (adContainerEl) {
734
755
  adContainerEl.style.pointerEvents = "none";
@@ -759,11 +780,8 @@ function createImaController(video, options) {
759
780
  (adErrorEvent) => {
760
781
  console.error("[IMA] Ads loader error:", adErrorEvent.getError());
761
782
  adPlaying = false;
762
- video.style.visibility = "visible";
783
+ showContentVideo();
763
784
  setAdPlayingFlag(false);
764
- console.log(
765
- "[IMA] Restored main video visibility after loader error"
766
- );
767
785
  if (adContainerEl) {
768
786
  adContainerEl.style.pointerEvents = "none";
769
787
  adContainerEl.style.display = "none";
@@ -874,7 +892,7 @@ function createImaController(video, options) {
874
892
  console.log("[IMA] Stopping ad playback");
875
893
  adPlaying = false;
876
894
  setAdPlayingFlag(false);
877
- video.style.visibility = "visible";
895
+ showContentVideo();
878
896
  if (adContainerEl) {
879
897
  adContainerEl.style.pointerEvents = "none";
880
898
  adContainerEl.style.display = "none";
@@ -890,7 +908,7 @@ function createImaController(video, options) {
890
908
  var _a;
891
909
  destroyAdsManager();
892
910
  adPlaying = false;
893
- video.style.visibility = "visible";
911
+ showContentVideo();
894
912
  setAdPlayingFlag(false);
895
913
  if (adContainerEl) {
896
914
  adContainerEl.style.pointerEvents = "none";
@@ -907,6 +925,7 @@ function createImaController(video, options) {
907
925
  adDisplayContainer = void 0;
908
926
  adsLoader = void 0;
909
927
  adVideoElement = void 0;
928
+ contentVideoHidden = false;
910
929
  preloadedVast.clear();
911
930
  preloadingVast.clear();
912
931
  },