stormcloud-video-player 0.2.26 → 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.
- package/dist/stormcloud-vp.min.js +1 -1
- package/lib/index.cjs +114 -36
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +114 -36
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +111 -32
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/player/StormcloudVideoPlayer.d.cts +1 -0
- package/lib/players/HlsPlayer.cjs +111 -32
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/index.cjs +111 -32
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/ima.cjs +91 -27
- package/lib/sdk/ima.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.cjs +114 -36
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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
|
-
|
|
494
|
+
adVideoElement
|
|
459
495
|
);
|
|
460
496
|
try {
|
|
461
497
|
adDisplayContainer.initialize();
|
|
462
|
-
console.log(
|
|
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
|
-
|
|
506
|
-
video.muted = originalMutedState;
|
|
543
|
+
video.style.visibility = "visible";
|
|
507
544
|
setAdPlayingFlag(false);
|
|
508
545
|
console.log(
|
|
509
|
-
|
|
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 -
|
|
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]
|
|
594
|
+
console.log("[IMA] Content video paused (VOD mode)");
|
|
558
595
|
} else {
|
|
559
596
|
console.log(
|
|
560
|
-
"[IMA]
|
|
597
|
+
"[IMA] Content video continues playing in background (Live mode)"
|
|
561
598
|
);
|
|
562
599
|
}
|
|
563
|
-
video.
|
|
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 -
|
|
608
|
+
"[IMA] Ad started playing - showing dedicated ad video"
|
|
573
609
|
);
|
|
574
610
|
setAdPlayingFlag(true);
|
|
575
|
-
video.
|
|
576
|
-
|
|
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
|
|
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(
|
|
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
|
|
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.
|
|
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
|
-
|
|
653
|
-
video.muted = originalMutedState;
|
|
698
|
+
video.style.visibility = "visible";
|
|
654
699
|
setAdPlayingFlag(false);
|
|
655
700
|
console.log(
|
|
656
|
-
|
|
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
|
|
790
|
+
console.log(`[IMA] Set IMA manager volume to ${adVolume}`);
|
|
739
791
|
} catch (error) {
|
|
740
|
-
console.warn("[IMA] Failed to set
|
|
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.
|
|
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(
|
|
900
|
+
adsManager.setVolume(clampedVolume);
|
|
840
901
|
} catch (error) {
|
|
841
|
-
console.warn("[IMA] Failed to set
|
|
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) {
|
|
@@ -3493,6 +3552,26 @@ var StormcloudVideoPlayer = class {
|
|
|
3493
3552
|
console.log("[StormcloudVideoPlayer] setMuted called:", muted);
|
|
3494
3553
|
}
|
|
3495
3554
|
}
|
|
3555
|
+
setVolume(volume) {
|
|
3556
|
+
const clampedVolume = Math.max(0, Math.min(1, volume));
|
|
3557
|
+
const adPlaying = this.ima.isAdPlaying();
|
|
3558
|
+
if (adPlaying) {
|
|
3559
|
+
this.ima.setAdVolume(clampedVolume);
|
|
3560
|
+
this.ima.updateOriginalMutedState(clampedVolume === 0, clampedVolume);
|
|
3561
|
+
if (this.config.debugAdTiming) {
|
|
3562
|
+
console.log("[StormcloudVideoPlayer] setVolume applied during ad", {
|
|
3563
|
+
volume: clampedVolume
|
|
3564
|
+
});
|
|
3565
|
+
}
|
|
3566
|
+
} else {
|
|
3567
|
+
this.video.volume = clampedVolume;
|
|
3568
|
+
this.video.muted = clampedVolume === 0;
|
|
3569
|
+
this.ima.updateOriginalMutedState(clampedVolume === 0, clampedVolume);
|
|
3570
|
+
if (this.config.debugAdTiming) {
|
|
3571
|
+
console.log("[StormcloudVideoPlayer] setVolume called:", clampedVolume);
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3496
3575
|
isFullscreen() {
|
|
3497
3576
|
return !!document.fullscreenElement;
|
|
3498
3577
|
}
|
|
@@ -3664,10 +3743,9 @@ var StormcloudVideoPlayerComponent = import_react.default.memo(
|
|
|
3664
3743
|
}
|
|
3665
3744
|
};
|
|
3666
3745
|
const handleVolumeChange = (newVolume) => {
|
|
3667
|
-
if (
|
|
3746
|
+
if (playerRef.current && isFinite(newVolume)) {
|
|
3668
3747
|
const clampedVolume = Math.max(0, Math.min(1, newVolume));
|
|
3669
|
-
|
|
3670
|
-
videoRef.current.muted = clampedVolume === 0;
|
|
3748
|
+
playerRef.current.setVolume(clampedVolume);
|
|
3671
3749
|
}
|
|
3672
3750
|
};
|
|
3673
3751
|
const handlePlaybackRateChange = (rate) => {
|
|
@@ -3769,7 +3847,7 @@ var StormcloudVideoPlayerComponent = import_react.default.memo(
|
|
|
3769
3847
|
if (autoplay !== void 0 && playerRef.current.videoElement) {
|
|
3770
3848
|
playerRef.current.videoElement.autoplay = autoplay;
|
|
3771
3849
|
}
|
|
3772
|
-
if (muted !== void 0) {
|
|
3850
|
+
if (muted !== void 0 && !playerRef.current.isShowingAds()) {
|
|
3773
3851
|
playerRef.current.setMuted(muted);
|
|
3774
3852
|
}
|
|
3775
3853
|
} catch (error) {
|