stormcloud-video-player 0.2.28 → 0.2.30

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,40 +708,34 @@ 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";
700
720
  emit("content_resume");
701
- setTimeout(() => {
702
- const stillInPod = video.dataset.stormcloudAdPlaying === "true";
703
- if (stillInPod) {
704
- console.log(
705
- "[IMA] Still in ad pod - keeping ad video visible"
706
- );
707
- if (adContainerEl) {
708
- adContainerEl.style.display = "flex";
709
- adContainerEl.style.pointerEvents = "auto";
710
- }
711
- video.style.visibility = "hidden";
712
- }
713
- }, 50);
714
721
  }
715
722
  );
716
723
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
717
- console.log("[IMA] All ads completed - notifying parent");
724
+ console.log("[IMA] All ads completed - restoring content");
718
725
  adPlaying = false;
719
726
  setAdPlayingFlag(false);
727
+ showContentVideo();
728
+ if (adContainerEl) {
729
+ adContainerEl.style.pointerEvents = "none";
730
+ adContainerEl.style.display = "none";
731
+ console.log("[IMA] Ad container hidden");
732
+ }
733
+ if (!(options == null ? void 0 : options.continueLiveStreamDuringAds) && video.paused) {
734
+ console.log("[IMA] Resuming content video playback");
735
+ video.play().catch((e) => {
736
+ console.warn("[IMA] Failed to resume content video:", e);
737
+ });
738
+ }
720
739
  emit("all_ads_completed");
721
740
  });
722
741
  console.log("[IMA] Ads manager event listeners attached");
@@ -728,7 +747,7 @@ function createImaController(video, options) {
728
747
  } catch (e) {
729
748
  console.error("[IMA] Error setting up ads manager:", e);
730
749
  adPlaying = false;
731
- video.style.visibility = "visible";
750
+ showContentVideo();
732
751
  setAdPlayingFlag(false);
733
752
  if (adContainerEl) {
734
753
  adContainerEl.style.pointerEvents = "none";
@@ -759,11 +778,8 @@ function createImaController(video, options) {
759
778
  (adErrorEvent) => {
760
779
  console.error("[IMA] Ads loader error:", adErrorEvent.getError());
761
780
  adPlaying = false;
762
- video.style.visibility = "visible";
781
+ showContentVideo();
763
782
  setAdPlayingFlag(false);
764
- console.log(
765
- "[IMA] Restored main video visibility after loader error"
766
- );
767
783
  if (adContainerEl) {
768
784
  adContainerEl.style.pointerEvents = "none";
769
785
  adContainerEl.style.display = "none";
@@ -874,7 +890,7 @@ function createImaController(video, options) {
874
890
  console.log("[IMA] Stopping ad playback");
875
891
  adPlaying = false;
876
892
  setAdPlayingFlag(false);
877
- video.style.visibility = "visible";
893
+ showContentVideo();
878
894
  if (adContainerEl) {
879
895
  adContainerEl.style.pointerEvents = "none";
880
896
  adContainerEl.style.display = "none";
@@ -890,7 +906,7 @@ function createImaController(video, options) {
890
906
  var _a;
891
907
  destroyAdsManager();
892
908
  adPlaying = false;
893
- video.style.visibility = "visible";
909
+ showContentVideo();
894
910
  setAdPlayingFlag(false);
895
911
  if (adContainerEl) {
896
912
  adContainerEl.style.pointerEvents = "none";
@@ -907,6 +923,7 @@ function createImaController(video, options) {
907
923
  adDisplayContainer = void 0;
908
924
  adsLoader = void 0;
909
925
  adVideoElement = void 0;
926
+ contentVideoHidden = false;
910
927
  preloadedVast.clear();
911
928
  preloadingVast.clear();
912
929
  },