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.
@@ -240,6 +240,7 @@ function getBrowserConfigOverrides() {
240
240
  // src/sdk/ima.ts
241
241
  function createImaController(video, options) {
242
242
  let adPlaying = false;
243
+ let contentVideoHidden = false;
243
244
  let originalMutedState = false;
244
245
  let originalVolume = typeof video.volume === "number" && !Number.isNaN(video.volume) ? Math.max(0, Math.min(1, video.volume)) : 1;
245
246
  const listeners = /* @__PURE__ */ new Map();
@@ -253,6 +254,26 @@ function createImaController(video, options) {
253
254
  delete video.dataset.stormcloudAdPlaying;
254
255
  }
255
256
  }
257
+ function hideContentVideo() {
258
+ if (!contentVideoHidden) {
259
+ video.style.visibility = "hidden";
260
+ video.muted = true;
261
+ video.volume = 0;
262
+ contentVideoHidden = true;
263
+ console.log("[IMA] Content video hidden and muted");
264
+ }
265
+ }
266
+ function showContentVideo() {
267
+ if (contentVideoHidden) {
268
+ video.style.visibility = "visible";
269
+ video.muted = originalMutedState;
270
+ video.volume = originalVolume;
271
+ contentVideoHidden = false;
272
+ console.log(
273
+ `[IMA] Content video restored (muted: ${originalMutedState}, volume: ${originalVolume})`
274
+ );
275
+ }
276
+ }
256
277
  function createAdVideoElement() {
257
278
  const adVideo = document.createElement("video");
258
279
  adVideo.style.position = "absolute";
@@ -261,11 +282,20 @@ function createImaController(video, options) {
261
282
  adVideo.style.width = "100%";
262
283
  adVideo.style.height = "100%";
263
284
  adVideo.style.objectFit = "contain";
264
- adVideo.style.backgroundColor = "#000";
285
+ adVideo.style.backgroundColor = "transparent";
265
286
  adVideo.style.zIndex = "15";
266
287
  adVideo.playsInline = true;
267
288
  adVideo.muted = false;
268
289
  adVideo.volume = originalMutedState ? 0 : originalVolume;
290
+ adVideo.style.opacity = "0";
291
+ adVideo.addEventListener(
292
+ "canplay",
293
+ () => {
294
+ adVideo.style.opacity = "1";
295
+ console.log("[IMA] Ad video ready to play");
296
+ },
297
+ { once: true }
298
+ );
269
299
  console.log(
270
300
  `[IMA] Created dedicated ad video element with volume: ${adVideo.volume}, muted: ${adVideo.muted}`
271
301
  );
@@ -429,6 +459,9 @@ function createImaController(video, options) {
429
459
  }
430
460
  adsManager = void 0;
431
461
  }
462
+ if (adVideoElement) {
463
+ adVideoElement.style.opacity = "0";
464
+ }
432
465
  }
433
466
  return {
434
467
  initialize() {
@@ -579,11 +612,8 @@ function createImaController(video, options) {
579
612
  console.error("[IMA] Ad error:", errorEvent.getError());
580
613
  destroyAdsManager();
581
614
  adPlaying = false;
582
- video.style.visibility = "visible";
615
+ showContentVideo();
583
616
  setAdPlayingFlag(false);
584
- console.log(
585
- "[IMA] Restored main video visibility after ad error"
586
- );
587
617
  if (adContainerEl) {
588
618
  adContainerEl.style.pointerEvents = "none";
589
619
  adContainerEl.style.display = "none";
@@ -625,29 +655,24 @@ function createImaController(video, options) {
625
655
  adsManager.addEventListener(
626
656
  AdEvent.CONTENT_PAUSE_REQUESTED,
627
657
  () => {
628
- console.log(
629
- "[IMA] Content pause requested - hiding main video, showing ad video"
630
- );
658
+ console.log("[IMA] Content pause requested");
631
659
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
632
660
  video.pause();
633
661
  console.log("[IMA] Content video paused (VOD mode)");
634
662
  } else {
635
663
  console.log(
636
- "[IMA] Content video continues playing in background (Live mode)"
664
+ "[IMA] Content video continues in background (Live mode)"
637
665
  );
638
666
  }
639
- video.style.visibility = "hidden";
640
667
  adPlaying = true;
641
668
  setAdPlayingFlag(true);
642
669
  emit("content_pause");
643
670
  }
644
671
  );
645
672
  adsManager.addEventListener(AdEvent.STARTED, () => {
646
- console.log(
647
- "[IMA] Ad started playing - showing dedicated ad video"
648
- );
673
+ console.log("[IMA] Ad started - showing ad video");
649
674
  setAdPlayingFlag(true);
650
- video.style.visibility = "hidden";
675
+ hideContentVideo();
651
676
  if (adVideoElement) {
652
677
  adVideoElement.volume = originalMutedState ? 0 : originalVolume;
653
678
  adVideoElement.muted = originalMutedState;
@@ -658,40 +683,34 @@ function createImaController(video, options) {
658
683
  if (adContainerEl) {
659
684
  adContainerEl.style.pointerEvents = "auto";
660
685
  adContainerEl.style.display = "flex";
661
- console.log(
662
- "[IMA] Ad container visible with dedicated ad video"
663
- );
686
+ console.log("[IMA] Ad container now visible");
664
687
  }
665
688
  });
666
689
  adsManager.addEventListener(
667
690
  AdEvent.CONTENT_RESUME_REQUESTED,
668
691
  () => {
669
- console.log(
670
- "[IMA] Content resume requested - showing main video"
671
- );
692
+ console.log("[IMA] Content resume requested");
672
693
  adPlaying = false;
673
694
  setAdPlayingFlag(false);
674
- video.style.visibility = "visible";
675
695
  emit("content_resume");
676
- setTimeout(() => {
677
- const stillInPod = video.dataset.stormcloudAdPlaying === "true";
678
- if (stillInPod) {
679
- console.log(
680
- "[IMA] Still in ad pod - keeping ad video visible"
681
- );
682
- if (adContainerEl) {
683
- adContainerEl.style.display = "flex";
684
- adContainerEl.style.pointerEvents = "auto";
685
- }
686
- video.style.visibility = "hidden";
687
- }
688
- }, 50);
689
696
  }
690
697
  );
691
698
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
692
- console.log("[IMA] All ads completed - notifying parent");
699
+ console.log("[IMA] All ads completed - restoring content");
693
700
  adPlaying = false;
694
701
  setAdPlayingFlag(false);
702
+ showContentVideo();
703
+ if (adContainerEl) {
704
+ adContainerEl.style.pointerEvents = "none";
705
+ adContainerEl.style.display = "none";
706
+ console.log("[IMA] Ad container hidden");
707
+ }
708
+ if (!(options == null ? void 0 : options.continueLiveStreamDuringAds) && video.paused) {
709
+ console.log("[IMA] Resuming content video playback");
710
+ video.play().catch((e) => {
711
+ console.warn("[IMA] Failed to resume content video:", e);
712
+ });
713
+ }
695
714
  emit("all_ads_completed");
696
715
  });
697
716
  console.log("[IMA] Ads manager event listeners attached");
@@ -703,7 +722,7 @@ function createImaController(video, options) {
703
722
  } catch (e) {
704
723
  console.error("[IMA] Error setting up ads manager:", e);
705
724
  adPlaying = false;
706
- video.style.visibility = "visible";
725
+ showContentVideo();
707
726
  setAdPlayingFlag(false);
708
727
  if (adContainerEl) {
709
728
  adContainerEl.style.pointerEvents = "none";
@@ -734,11 +753,8 @@ function createImaController(video, options) {
734
753
  (adErrorEvent) => {
735
754
  console.error("[IMA] Ads loader error:", adErrorEvent.getError());
736
755
  adPlaying = false;
737
- video.style.visibility = "visible";
756
+ showContentVideo();
738
757
  setAdPlayingFlag(false);
739
- console.log(
740
- "[IMA] Restored main video visibility after loader error"
741
- );
742
758
  if (adContainerEl) {
743
759
  adContainerEl.style.pointerEvents = "none";
744
760
  adContainerEl.style.display = "none";
@@ -849,7 +865,7 @@ function createImaController(video, options) {
849
865
  console.log("[IMA] Stopping ad playback");
850
866
  adPlaying = false;
851
867
  setAdPlayingFlag(false);
852
- video.style.visibility = "visible";
868
+ showContentVideo();
853
869
  if (adContainerEl) {
854
870
  adContainerEl.style.pointerEvents = "none";
855
871
  adContainerEl.style.display = "none";
@@ -865,7 +881,7 @@ function createImaController(video, options) {
865
881
  var _a;
866
882
  destroyAdsManager();
867
883
  adPlaying = false;
868
- video.style.visibility = "visible";
884
+ showContentVideo();
869
885
  setAdPlayingFlag(false);
870
886
  if (adContainerEl) {
871
887
  adContainerEl.style.pointerEvents = "none";
@@ -882,6 +898,7 @@ function createImaController(video, options) {
882
898
  adDisplayContainer = void 0;
883
899
  adsLoader = void 0;
884
900
  adVideoElement = void 0;
901
+ contentVideoHidden = false;
885
902
  preloadedVast.clear();
886
903
  preloadingVast.clear();
887
904
  },