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.js CHANGED
@@ -196,6 +196,7 @@ function supportsFeature(feature) {
196
196
  // src/sdk/ima.ts
197
197
  function createImaController(video, options) {
198
198
  let adPlaying = false;
199
+ let contentVideoHidden = false;
199
200
  let originalMutedState = false;
200
201
  let originalVolume = typeof video.volume === "number" && !Number.isNaN(video.volume) ? Math.max(0, Math.min(1, video.volume)) : 1;
201
202
  const listeners = /* @__PURE__ */ new Map();
@@ -209,6 +210,26 @@ function createImaController(video, options) {
209
210
  delete video.dataset.stormcloudAdPlaying;
210
211
  }
211
212
  }
213
+ function hideContentVideo() {
214
+ if (!contentVideoHidden) {
215
+ video.style.visibility = "hidden";
216
+ video.muted = true;
217
+ video.volume = 0;
218
+ contentVideoHidden = true;
219
+ console.log("[IMA] Content video hidden and muted");
220
+ }
221
+ }
222
+ function showContentVideo() {
223
+ if (contentVideoHidden) {
224
+ video.style.visibility = "visible";
225
+ video.muted = originalMutedState;
226
+ video.volume = originalVolume;
227
+ contentVideoHidden = false;
228
+ console.log(
229
+ `[IMA] Content video restored (muted: ${originalMutedState}, volume: ${originalVolume})`
230
+ );
231
+ }
232
+ }
212
233
  function createAdVideoElement() {
213
234
  const adVideo = document.createElement("video");
214
235
  adVideo.style.position = "absolute";
@@ -217,11 +238,20 @@ function createImaController(video, options) {
217
238
  adVideo.style.width = "100%";
218
239
  adVideo.style.height = "100%";
219
240
  adVideo.style.objectFit = "contain";
220
- adVideo.style.backgroundColor = "#000";
241
+ adVideo.style.backgroundColor = "transparent";
221
242
  adVideo.style.zIndex = "15";
222
243
  adVideo.playsInline = true;
223
244
  adVideo.muted = false;
224
245
  adVideo.volume = originalMutedState ? 0 : originalVolume;
246
+ adVideo.style.opacity = "0";
247
+ adVideo.addEventListener(
248
+ "canplay",
249
+ () => {
250
+ adVideo.style.opacity = "1";
251
+ console.log("[IMA] Ad video ready to play");
252
+ },
253
+ { once: true }
254
+ );
225
255
  console.log(
226
256
  `[IMA] Created dedicated ad video element with volume: ${adVideo.volume}, muted: ${adVideo.muted}`
227
257
  );
@@ -385,6 +415,9 @@ function createImaController(video, options) {
385
415
  }
386
416
  adsManager = void 0;
387
417
  }
418
+ if (adVideoElement) {
419
+ adVideoElement.style.opacity = "0";
420
+ }
388
421
  }
389
422
  return {
390
423
  initialize() {
@@ -535,11 +568,8 @@ function createImaController(video, options) {
535
568
  console.error("[IMA] Ad error:", errorEvent.getError());
536
569
  destroyAdsManager();
537
570
  adPlaying = false;
538
- video.style.visibility = "visible";
571
+ showContentVideo();
539
572
  setAdPlayingFlag(false);
540
- console.log(
541
- "[IMA] Restored main video visibility after ad error"
542
- );
543
573
  if (adContainerEl) {
544
574
  adContainerEl.style.pointerEvents = "none";
545
575
  adContainerEl.style.display = "none";
@@ -581,29 +611,24 @@ function createImaController(video, options) {
581
611
  adsManager.addEventListener(
582
612
  AdEvent.CONTENT_PAUSE_REQUESTED,
583
613
  () => {
584
- console.log(
585
- "[IMA] Content pause requested - hiding main video, showing ad video"
586
- );
614
+ console.log("[IMA] Content pause requested");
587
615
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
588
616
  video.pause();
589
617
  console.log("[IMA] Content video paused (VOD mode)");
590
618
  } else {
591
619
  console.log(
592
- "[IMA] Content video continues playing in background (Live mode)"
620
+ "[IMA] Content video continues in background (Live mode)"
593
621
  );
594
622
  }
595
- video.style.visibility = "hidden";
596
623
  adPlaying = true;
597
624
  setAdPlayingFlag(true);
598
625
  emit("content_pause");
599
626
  }
600
627
  );
601
628
  adsManager.addEventListener(AdEvent.STARTED, () => {
602
- console.log(
603
- "[IMA] Ad started playing - showing dedicated ad video"
604
- );
629
+ console.log("[IMA] Ad started - showing ad video");
605
630
  setAdPlayingFlag(true);
606
- video.style.visibility = "hidden";
631
+ hideContentVideo();
607
632
  if (adVideoElement) {
608
633
  adVideoElement.volume = originalMutedState ? 0 : originalVolume;
609
634
  adVideoElement.muted = originalMutedState;
@@ -614,40 +639,34 @@ function createImaController(video, options) {
614
639
  if (adContainerEl) {
615
640
  adContainerEl.style.pointerEvents = "auto";
616
641
  adContainerEl.style.display = "flex";
617
- console.log(
618
- "[IMA] Ad container visible with dedicated ad video"
619
- );
642
+ console.log("[IMA] Ad container now visible");
620
643
  }
621
644
  });
622
645
  adsManager.addEventListener(
623
646
  AdEvent.CONTENT_RESUME_REQUESTED,
624
647
  () => {
625
- console.log(
626
- "[IMA] Content resume requested - showing main video"
627
- );
648
+ console.log("[IMA] Content resume requested");
628
649
  adPlaying = false;
629
650
  setAdPlayingFlag(false);
630
- video.style.visibility = "visible";
631
651
  emit("content_resume");
632
- setTimeout(() => {
633
- const stillInPod = video.dataset.stormcloudAdPlaying === "true";
634
- if (stillInPod) {
635
- console.log(
636
- "[IMA] Still in ad pod - keeping ad video visible"
637
- );
638
- if (adContainerEl) {
639
- adContainerEl.style.display = "flex";
640
- adContainerEl.style.pointerEvents = "auto";
641
- }
642
- video.style.visibility = "hidden";
643
- }
644
- }, 50);
645
652
  }
646
653
  );
647
654
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
648
- console.log("[IMA] All ads completed - notifying parent");
655
+ console.log("[IMA] All ads completed - restoring content");
649
656
  adPlaying = false;
650
657
  setAdPlayingFlag(false);
658
+ showContentVideo();
659
+ if (adContainerEl) {
660
+ adContainerEl.style.pointerEvents = "none";
661
+ adContainerEl.style.display = "none";
662
+ console.log("[IMA] Ad container hidden");
663
+ }
664
+ if (!(options == null ? void 0 : options.continueLiveStreamDuringAds) && video.paused) {
665
+ console.log("[IMA] Resuming content video playback");
666
+ video.play().catch((e) => {
667
+ console.warn("[IMA] Failed to resume content video:", e);
668
+ });
669
+ }
651
670
  emit("all_ads_completed");
652
671
  });
653
672
  console.log("[IMA] Ads manager event listeners attached");
@@ -659,7 +678,7 @@ function createImaController(video, options) {
659
678
  } catch (e) {
660
679
  console.error("[IMA] Error setting up ads manager:", e);
661
680
  adPlaying = false;
662
- video.style.visibility = "visible";
681
+ showContentVideo();
663
682
  setAdPlayingFlag(false);
664
683
  if (adContainerEl) {
665
684
  adContainerEl.style.pointerEvents = "none";
@@ -690,11 +709,8 @@ function createImaController(video, options) {
690
709
  (adErrorEvent) => {
691
710
  console.error("[IMA] Ads loader error:", adErrorEvent.getError());
692
711
  adPlaying = false;
693
- video.style.visibility = "visible";
712
+ showContentVideo();
694
713
  setAdPlayingFlag(false);
695
- console.log(
696
- "[IMA] Restored main video visibility after loader error"
697
- );
698
714
  if (adContainerEl) {
699
715
  adContainerEl.style.pointerEvents = "none";
700
716
  adContainerEl.style.display = "none";
@@ -805,7 +821,7 @@ function createImaController(video, options) {
805
821
  console.log("[IMA] Stopping ad playback");
806
822
  adPlaying = false;
807
823
  setAdPlayingFlag(false);
808
- video.style.visibility = "visible";
824
+ showContentVideo();
809
825
  if (adContainerEl) {
810
826
  adContainerEl.style.pointerEvents = "none";
811
827
  adContainerEl.style.display = "none";
@@ -821,7 +837,7 @@ function createImaController(video, options) {
821
837
  var _a;
822
838
  destroyAdsManager();
823
839
  adPlaying = false;
824
- video.style.visibility = "visible";
840
+ showContentVideo();
825
841
  setAdPlayingFlag(false);
826
842
  if (adContainerEl) {
827
843
  adContainerEl.style.pointerEvents = "none";
@@ -838,6 +854,7 @@ function createImaController(video, options) {
838
854
  adDisplayContainer = void 0;
839
855
  adsLoader = void 0;
840
856
  adVideoElement = void 0;
857
+ contentVideoHidden = false;
841
858
  preloadedVast.clear();
842
859
  preloadingVast.clear();
843
860
  },