stormcloud-video-player 0.3.5 → 0.3.7
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 +2 -2
- package/lib/index.cjs +44 -196
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +44 -196
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +44 -196
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.cjs +44 -196
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/index.cjs +44 -196
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/ima.cjs +6 -80
- package/lib/sdk/ima.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.cjs +44 -196
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -289,7 +289,6 @@ function createImaController(video, options) {
|
|
|
289
289
|
video.muted = true;
|
|
290
290
|
video.volume = 0;
|
|
291
291
|
contentVideoHidden = true;
|
|
292
|
-
console.log("[DEBUG-LAYER] \u{1F534} Content video HIDDEN | muted=true, volume=0");
|
|
293
292
|
}
|
|
294
293
|
}
|
|
295
294
|
function showContentVideo() {
|
|
@@ -301,9 +300,6 @@ function createImaController(video, options) {
|
|
|
301
300
|
video.muted = originalMutedState;
|
|
302
301
|
video.volume = originalVolume;
|
|
303
302
|
contentVideoHidden = false;
|
|
304
|
-
console.log(
|
|
305
|
-
`[DEBUG-LAYER] \u{1F7E2} Content video RESTORED | muted=${originalMutedState}, volume=${originalVolume}`
|
|
306
|
-
);
|
|
307
303
|
}
|
|
308
304
|
}
|
|
309
305
|
function createAdVideoElement() {
|
|
@@ -324,13 +320,9 @@ function createImaController(video, options) {
|
|
|
324
320
|
"canplay",
|
|
325
321
|
() => {
|
|
326
322
|
adVideo.style.opacity = "1";
|
|
327
|
-
console.log("[DEBUG-LAYER] \u{1F4FA} Ad video element ready (canplay fired)");
|
|
328
323
|
},
|
|
329
324
|
{ once: true }
|
|
330
325
|
);
|
|
331
|
-
console.log(
|
|
332
|
-
`[DEBUG-AUDIO] \u{1F50A} Ad video created | volume=${adVideo.volume}, muted=${adVideo.muted}`
|
|
333
|
-
);
|
|
334
326
|
return adVideo;
|
|
335
327
|
}
|
|
336
328
|
function emit(event, payload) {
|
|
@@ -482,10 +474,8 @@ function createImaController(video, options) {
|
|
|
482
474
|
function destroyAdsManager() {
|
|
483
475
|
if (adsManager) {
|
|
484
476
|
try {
|
|
485
|
-
console.log("[IMA] Destroying existing ads manager");
|
|
486
477
|
adsManager.destroy();
|
|
487
|
-
} catch
|
|
488
|
-
console.warn("[IMA] Error destroying ads manager:", error);
|
|
478
|
+
} catch {
|
|
489
479
|
}
|
|
490
480
|
adsManager = void 0;
|
|
491
481
|
}
|
|
@@ -503,9 +493,6 @@ function createImaController(video, options) {
|
|
|
503
493
|
if (!adVideoElement) {
|
|
504
494
|
adVideoElement = createAdVideoElement();
|
|
505
495
|
adContainerEl.appendChild(adVideoElement);
|
|
506
|
-
console.log(
|
|
507
|
-
"[IMA] Dedicated ad video element added to container"
|
|
508
|
-
);
|
|
509
496
|
}
|
|
510
497
|
adDisplayContainer = new google.ima.AdDisplayContainer(
|
|
511
498
|
adContainerEl,
|
|
@@ -513,9 +500,6 @@ function createImaController(video, options) {
|
|
|
513
500
|
);
|
|
514
501
|
try {
|
|
515
502
|
(_a = adDisplayContainer.initialize) == null ? void 0 : _a.call(adDisplayContainer);
|
|
516
|
-
console.log(
|
|
517
|
-
"[IMA] AdDisplayContainer initialized with dedicated ad video"
|
|
518
|
-
);
|
|
519
503
|
} catch {
|
|
520
504
|
}
|
|
521
505
|
}
|
|
@@ -523,9 +507,6 @@ function createImaController(video, options) {
|
|
|
523
507
|
});
|
|
524
508
|
},
|
|
525
509
|
async requestAds(vastTagUrl) {
|
|
526
|
-
console.log("[IMA] \u{1F4E1} === requestAds() called ===");
|
|
527
|
-
console.log("[IMA] VAST URL:", vastTagUrl);
|
|
528
|
-
console.log("[IMA] This will fetch the ad from the server - no visual change yet");
|
|
529
510
|
if (!vastTagUrl || vastTagUrl.trim() === "") {
|
|
530
511
|
const error = new Error("VAST tag URL is empty or undefined");
|
|
531
512
|
console.warn("[IMA] \u274C", error.message);
|
|
@@ -568,7 +549,6 @@ function createImaController(video, options) {
|
|
|
568
549
|
lastAdTagUrl = vastTagUrl;
|
|
569
550
|
retryAttempts = 0;
|
|
570
551
|
if (!adDisplayContainer) {
|
|
571
|
-
console.log("[IMA] Creating ad display container");
|
|
572
552
|
const container = document.createElement("div");
|
|
573
553
|
container.style.position = "absolute";
|
|
574
554
|
container.style.left = "0";
|
|
@@ -591,25 +571,11 @@ function createImaController(video, options) {
|
|
|
591
571
|
if (!adVideoElement) {
|
|
592
572
|
adVideoElement = createAdVideoElement();
|
|
593
573
|
adContainerEl.appendChild(adVideoElement);
|
|
594
|
-
console.log(
|
|
595
|
-
"[IMA] Dedicated ad video element created and added to container"
|
|
596
|
-
);
|
|
597
574
|
}
|
|
598
575
|
adDisplayContainer = new google.ima.AdDisplayContainer(
|
|
599
576
|
container,
|
|
600
577
|
adVideoElement
|
|
601
578
|
);
|
|
602
|
-
try {
|
|
603
|
-
adDisplayContainer.initialize();
|
|
604
|
-
console.log(
|
|
605
|
-
"[IMA] Ad display container initialized with dedicated ad video"
|
|
606
|
-
);
|
|
607
|
-
} catch (error) {
|
|
608
|
-
console.warn(
|
|
609
|
-
"[IMA] Failed to initialize ad display container:",
|
|
610
|
-
error
|
|
611
|
-
);
|
|
612
|
-
}
|
|
613
579
|
}
|
|
614
580
|
const videoWidth = video.offsetWidth || video.clientWidth;
|
|
615
581
|
const videoHeight = video.offsetHeight || video.clientHeight;
|
|
@@ -624,29 +590,17 @@ function createImaController(video, options) {
|
|
|
624
590
|
return Promise.reject(error);
|
|
625
591
|
}
|
|
626
592
|
if (!adsLoader) {
|
|
627
|
-
console.log("[IMA] Creating ads loader");
|
|
628
593
|
const adsLoaderCls = new google.ima.AdsLoader(adDisplayContainer);
|
|
629
594
|
adsLoader = adsLoaderCls;
|
|
630
595
|
adsLoader.addEventListener(
|
|
631
596
|
google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
|
|
632
597
|
(evt) => {
|
|
633
|
-
console.log("[DEBUG-FLOW] \u2705 ADS_MANAGER_LOADED - Setting up manager");
|
|
634
598
|
try {
|
|
635
599
|
const adsRenderingSettings = new google.ima.AdsRenderingSettings();
|
|
636
600
|
adsRenderingSettings.enablePreloading = true;
|
|
637
601
|
adsManager = evt.getAdsManager(video, adsRenderingSettings);
|
|
638
602
|
const AdEvent = google.ima.AdEvent.Type;
|
|
639
603
|
const AdErrorEvent = google.ima.AdErrorEvent.Type;
|
|
640
|
-
const keyEvents = ["STARTED", "COMPLETE", "CONTENT_PAUSE_REQUESTED", "CONTENT_RESUME_REQUESTED", "ALL_ADS_COMPLETED"];
|
|
641
|
-
keyEvents.forEach((eventType) => {
|
|
642
|
-
if (AdEvent[eventType]) {
|
|
643
|
-
adsManager.addEventListener(AdEvent[eventType], (e) => {
|
|
644
|
-
var _a, _b;
|
|
645
|
-
const ad = (_a = e.getAd) == null ? void 0 : _a.call(e);
|
|
646
|
-
console.log(`[DEBUG-FLOW] \u{1F3AC} ${eventType} | title=${((_b = ad == null ? void 0 : ad.getTitle) == null ? void 0 : _b.call(ad)) || "N/A"}`);
|
|
647
|
-
});
|
|
648
|
-
}
|
|
649
|
-
});
|
|
650
604
|
adsManager.addEventListener(
|
|
651
605
|
AdErrorEvent.AD_ERROR,
|
|
652
606
|
(errorEvent) => {
|
|
@@ -663,7 +617,6 @@ function createImaController(video, options) {
|
|
|
663
617
|
if (adContainerEl) {
|
|
664
618
|
adContainerEl.style.pointerEvents = "none";
|
|
665
619
|
adContainerEl.style.display = "none";
|
|
666
|
-
console.log("[DEBUG-LAYER] \u274C Ad container HIDDEN (error)");
|
|
667
620
|
}
|
|
668
621
|
}, 300);
|
|
669
622
|
}
|
|
@@ -695,7 +648,6 @@ function createImaController(video, options) {
|
|
|
695
648
|
adsManager.addEventListener(
|
|
696
649
|
AdEvent.CONTENT_PAUSE_REQUESTED,
|
|
697
650
|
() => {
|
|
698
|
-
console.log("[DEBUG-FLOW] \u{1F3AF} CONTENT_PAUSE_REQUESTED - Ad request accepted");
|
|
699
651
|
if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
|
|
700
652
|
video.pause();
|
|
701
653
|
}
|
|
@@ -705,15 +657,11 @@ function createImaController(video, options) {
|
|
|
705
657
|
}
|
|
706
658
|
);
|
|
707
659
|
adsManager.addEventListener(AdEvent.STARTED, () => {
|
|
708
|
-
console.log("[DEBUG-FLOW] \u25B6\uFE0F STARTED - Ad playing now");
|
|
709
660
|
setAdPlayingFlag(true);
|
|
710
661
|
hideContentVideo();
|
|
711
662
|
if (adVideoElement) {
|
|
712
663
|
adVideoElement.volume = originalMutedState ? 0 : originalVolume;
|
|
713
664
|
adVideoElement.muted = originalMutedState;
|
|
714
|
-
console.log(
|
|
715
|
-
`[DEBUG-AUDIO] \u{1F50A} Ad audio set | volume=${adVideoElement.volume}, muted=${adVideoElement.muted}`
|
|
716
|
-
);
|
|
717
665
|
}
|
|
718
666
|
if (adContainerEl) {
|
|
719
667
|
adContainerEl.style.pointerEvents = "auto";
|
|
@@ -726,15 +674,12 @@ function createImaController(video, options) {
|
|
|
726
674
|
adsManager.addEventListener(
|
|
727
675
|
AdEvent.CONTENT_RESUME_REQUESTED,
|
|
728
676
|
() => {
|
|
729
|
-
console.log("[DEBUG-FLOW] \u23F8\uFE0F CONTENT_RESUME - Single ad done");
|
|
730
677
|
adPlaying = false;
|
|
731
678
|
setAdPlayingFlag(false);
|
|
732
|
-
console.log("[DEBUG-LAYER] \u26A0\uFE0F Waiting for pod manager (more ads, placeholder, or done)");
|
|
733
679
|
emit("content_resume");
|
|
734
680
|
}
|
|
735
681
|
);
|
|
736
682
|
adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
|
|
737
|
-
console.log("[DEBUG-FLOW] \u{1F3C1} ALL_ADS_COMPLETED - Pod finished");
|
|
738
683
|
adPlaying = false;
|
|
739
684
|
setAdPlayingFlag(false);
|
|
740
685
|
if (adContainerEl) {
|
|
@@ -744,19 +689,16 @@ function createImaController(video, options) {
|
|
|
744
689
|
if (adContainerEl) {
|
|
745
690
|
adContainerEl.style.pointerEvents = "none";
|
|
746
691
|
adContainerEl.style.display = "none";
|
|
747
|
-
console.log("[DEBUG-LAYER] \u26AB Ad container HIDDEN (pod done)");
|
|
748
692
|
}
|
|
749
693
|
}, 300);
|
|
750
694
|
}
|
|
751
695
|
showContentVideo();
|
|
752
696
|
if (!(options == null ? void 0 : options.continueLiveStreamDuringAds) && video.paused) {
|
|
753
|
-
video.play().catch((
|
|
754
|
-
console.warn("[DEBUG-ERROR] Failed to resume video:", e);
|
|
697
|
+
video.play().catch(() => {
|
|
755
698
|
});
|
|
756
699
|
}
|
|
757
700
|
emit("all_ads_completed");
|
|
758
701
|
});
|
|
759
|
-
console.log("[IMA] Ads manager event listeners attached");
|
|
760
702
|
if (adsLoadedResolve) {
|
|
761
703
|
adsLoadedResolve();
|
|
762
704
|
adsLoadedResolve = void 0;
|
|
@@ -851,9 +793,7 @@ function createImaController(video, options) {
|
|
|
851
793
|
}
|
|
852
794
|
const preloadPromise = fetchVastDocument(vastTagUrl).then((xml) => {
|
|
853
795
|
preloadedVast.set(vastTagUrl, xml);
|
|
854
|
-
|
|
855
|
-
}).catch((error) => {
|
|
856
|
-
console.warn("[IMA] Failed to preload VAST response:", error);
|
|
796
|
+
}).catch(() => {
|
|
857
797
|
preloadedVast.delete(vastTagUrl);
|
|
858
798
|
}).finally(() => {
|
|
859
799
|
preloadingVast.delete(vastTagUrl);
|
|
@@ -866,7 +806,6 @@ function createImaController(video, options) {
|
|
|
866
806
|
},
|
|
867
807
|
async play() {
|
|
868
808
|
var _a, _b;
|
|
869
|
-
console.log("[DEBUG-FLOW] \u25B6\uFE0F play() - Starting ad playback");
|
|
870
809
|
if (!((_a = window.google) == null ? void 0 : _a.ima) || !adDisplayContainer) {
|
|
871
810
|
return Promise.reject(new Error("IMA SDK not available"));
|
|
872
811
|
}
|
|
@@ -882,19 +821,15 @@ function createImaController(video, options) {
|
|
|
882
821
|
if (adVideoElement) {
|
|
883
822
|
adVideoElement.volume = adVolume;
|
|
884
823
|
adVideoElement.muted = originalMutedState;
|
|
885
|
-
console.log(
|
|
886
|
-
`[DEBUG-AUDIO] \u{1F50A} Pre-start ad audio | volume=${adVolume}, muted=${originalMutedState}`
|
|
887
|
-
);
|
|
888
824
|
}
|
|
889
825
|
try {
|
|
890
826
|
adsManager.setVolume(adVolume);
|
|
891
|
-
} catch
|
|
892
|
-
console.warn("[DEBUG-ERROR] Failed to set IMA manager volume:", error);
|
|
827
|
+
} catch {
|
|
893
828
|
}
|
|
894
829
|
adsManager.start();
|
|
895
830
|
return Promise.resolve();
|
|
896
831
|
} catch (error) {
|
|
897
|
-
console.error("[
|
|
832
|
+
console.error("[IMA] \u274C Error starting ad:", error);
|
|
898
833
|
adPlaying = false;
|
|
899
834
|
setAdPlayingFlag(false);
|
|
900
835
|
if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
|
|
@@ -906,7 +841,6 @@ function createImaController(video, options) {
|
|
|
906
841
|
},
|
|
907
842
|
async stop() {
|
|
908
843
|
var _a;
|
|
909
|
-
console.log("[DEBUG-FLOW] \u23F9\uFE0F stop() - Stopping ad playback");
|
|
910
844
|
adPlaying = false;
|
|
911
845
|
setAdPlayingFlag(false);
|
|
912
846
|
if (adContainerEl) {
|
|
@@ -916,7 +850,6 @@ function createImaController(video, options) {
|
|
|
916
850
|
if (adContainerEl) {
|
|
917
851
|
adContainerEl.style.pointerEvents = "none";
|
|
918
852
|
adContainerEl.style.display = "none";
|
|
919
|
-
console.log("[DEBUG-LAYER] \u26AB Ad container HIDDEN (stop)");
|
|
920
853
|
}
|
|
921
854
|
}, 300);
|
|
922
855
|
}
|
|
@@ -986,9 +919,6 @@ function createImaController(video, options) {
|
|
|
986
919
|
},
|
|
987
920
|
updateOriginalMutedState(muted, volume) {
|
|
988
921
|
const nextVolume = typeof volume === "number" && !Number.isNaN(volume) ? Math.max(0, Math.min(1, volume)) : originalVolume;
|
|
989
|
-
console.log(
|
|
990
|
-
`[DEBUG-AUDIO] \u{1F4BE} Saved original state | muted: ${originalMutedState}->${muted}, volume: ${originalVolume}->${nextVolume}`
|
|
991
|
-
);
|
|
992
922
|
originalMutedState = muted;
|
|
993
923
|
originalVolume = nextVolume;
|
|
994
924
|
},
|
|
@@ -1003,15 +933,11 @@ function createImaController(video, options) {
|
|
|
1003
933
|
if (adVideoElement && adPlaying) {
|
|
1004
934
|
adVideoElement.volume = clampedVolume;
|
|
1005
935
|
adVideoElement.muted = clampedVolume === 0;
|
|
1006
|
-
console.log(
|
|
1007
|
-
`[DEBUG-AUDIO] \u{1F50A} Ad volume changed | volume=${clampedVolume}, muted=${clampedVolume === 0}`
|
|
1008
|
-
);
|
|
1009
936
|
}
|
|
1010
937
|
if (adsManager && adPlaying) {
|
|
1011
938
|
try {
|
|
1012
939
|
adsManager.setVolume(clampedVolume);
|
|
1013
|
-
} catch
|
|
1014
|
-
console.warn("[DEBUG-ERROR] Failed to set IMA manager volume:", error);
|
|
940
|
+
} catch {
|
|
1015
941
|
}
|
|
1016
942
|
}
|
|
1017
943
|
},
|
|
@@ -2501,51 +2427,37 @@ var StormcloudVideoPlayer = class {
|
|
|
2501
2427
|
});
|
|
2502
2428
|
this.ima.on("ad_error", (errorPayload) => {
|
|
2503
2429
|
const remaining = this.getRemainingAdMs();
|
|
2504
|
-
console.error(
|
|
2505
|
-
`[DEBUG-POD] \u274C ad_error event | inBreak=${this.inAdBreak}, queue=${this.adPodQueue.length}, remaining=${remaining}ms`,
|
|
2506
|
-
errorPayload ? `
|
|
2507
|
-
Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
2508
|
-
);
|
|
2430
|
+
console.error("[AD-ERROR] Ad playback failed", errorPayload || "");
|
|
2509
2431
|
if (this.inAdBreak) {
|
|
2510
2432
|
if (remaining > 500 && this.adPodQueue.length > 0) {
|
|
2511
2433
|
const nextPreloaded = this.findNextPreloadedAd();
|
|
2512
2434
|
if (nextPreloaded) {
|
|
2513
2435
|
this.currentAdIndex++;
|
|
2514
|
-
console.log(
|
|
2515
|
-
`[DEBUG-POD] \u27A1\uFE0F Trying next ad after error (${this.currentAdIndex}/${this.totalAdsInBreak})`
|
|
2516
|
-
);
|
|
2517
2436
|
this.playSingleAd(nextPreloaded).catch(() => {
|
|
2518
2437
|
this.handleAdFailure();
|
|
2519
2438
|
});
|
|
2520
2439
|
} else {
|
|
2521
|
-
console.log("[DEBUG-POD] \u26A0\uFE0F No more preloaded ads - calling handleAdFailure");
|
|
2522
2440
|
this.handleAdFailure();
|
|
2523
2441
|
}
|
|
2524
2442
|
} else {
|
|
2525
|
-
console.log("[DEBUG-POD] \u26A0\uFE0F No more ads or time - calling handleAdFailure");
|
|
2526
2443
|
this.handleAdFailure();
|
|
2527
2444
|
}
|
|
2528
2445
|
} else {
|
|
2529
|
-
console.log("[DEBUG-POD] \u26A0\uFE0F Error before ad break established");
|
|
2530
2446
|
this.handleAdFailure();
|
|
2531
2447
|
}
|
|
2532
2448
|
});
|
|
2533
2449
|
this.ima.on("content_pause", () => {
|
|
2534
|
-
console.log(`[DEBUG-POD] \u{1F3AF} content_pause (AD STARTING!) | ad ${this.currentAdIndex}/${this.totalAdsInBreak}, queue=${this.adPodQueue.length}`);
|
|
2535
2450
|
this.clearAdFailsafeTimer();
|
|
2536
2451
|
this.clearAdRequestWatchdog();
|
|
2537
2452
|
this.activeAdRequestToken = null;
|
|
2538
2453
|
this.showAds = true;
|
|
2539
|
-
console.log("[DEBUG-LAYER] \u{1F3AC} Layers: Main=hidden, Ad=visible, Placeholder=no");
|
|
2540
2454
|
});
|
|
2541
2455
|
this.ima.on("content_resume", () => {
|
|
2542
|
-
console.log(`[DEBUG-POD] \u23F8\uFE0F content_resume | ad ${this.currentAdIndex}/${this.totalAdsInBreak}, queue=${this.adPodQueue.length}, remaining=${this.getRemainingAdMs()}ms`);
|
|
2543
2456
|
this.clearAdFailsafeTimer();
|
|
2544
2457
|
this.clearAdRequestWatchdog();
|
|
2545
2458
|
this.activeAdRequestToken = null;
|
|
2546
2459
|
this.showAds = false;
|
|
2547
2460
|
if (!this.inAdBreak) {
|
|
2548
|
-
console.warn("[DEBUG-POD] \u26A0\uFE0F Not in ad break - shouldn't happen");
|
|
2549
2461
|
return;
|
|
2550
2462
|
}
|
|
2551
2463
|
const remaining = this.getRemainingAdMs();
|
|
@@ -2553,17 +2465,13 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
2553
2465
|
const nextPreloaded = this.findNextPreloadedAd();
|
|
2554
2466
|
if (nextPreloaded) {
|
|
2555
2467
|
this.currentAdIndex++;
|
|
2556
|
-
console.log(`[DEBUG-POD] \u27A1\uFE0F Playing next ad ${this.currentAdIndex}/${this.totalAdsInBreak} (preloaded)`);
|
|
2557
2468
|
this.playSingleAd(nextPreloaded).catch(() => {
|
|
2558
|
-
console.error("[DEBUG-POD] \u274C Failed to play next ad");
|
|
2559
2469
|
this.handleAdPodComplete();
|
|
2560
2470
|
});
|
|
2561
2471
|
} else {
|
|
2562
|
-
console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads - ending pod");
|
|
2563
2472
|
this.handleAdPodComplete();
|
|
2564
2473
|
}
|
|
2565
2474
|
} else {
|
|
2566
|
-
console.log("[DEBUG-POD] \u2705 Pod complete (no more ads or time expired)");
|
|
2567
2475
|
this.handleAdPodComplete();
|
|
2568
2476
|
}
|
|
2569
2477
|
});
|
|
@@ -2717,9 +2625,6 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
2717
2625
|
}
|
|
2718
2626
|
if (marker.type === "start") {
|
|
2719
2627
|
if (this.inAdBreak) {
|
|
2720
|
-
console.log(
|
|
2721
|
-
`[DEBUG-POD] \u26A0\uFE0F SCTE-35 start marker ignored - already in ad break (currentTime: ${this.video.currentTime})`
|
|
2722
|
-
);
|
|
2723
2628
|
return;
|
|
2724
2629
|
}
|
|
2725
2630
|
this.inAdBreak = true;
|
|
@@ -2788,9 +2693,6 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
2788
2693
|
return;
|
|
2789
2694
|
}
|
|
2790
2695
|
if (marker.type === "progress" && this.inAdBreak) {
|
|
2791
|
-
console.log(
|
|
2792
|
-
`[DEBUG-POD] \u{1F4CA} SCTE-35 progress marker (currentTime: ${this.video.currentTime})`
|
|
2793
|
-
);
|
|
2794
2696
|
if (marker.durationSeconds != null) {
|
|
2795
2697
|
this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
|
|
2796
2698
|
}
|
|
@@ -2803,7 +2705,6 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
2803
2705
|
this.scheduleAdStopCountdown(remainingMs);
|
|
2804
2706
|
}
|
|
2805
2707
|
if (!this.ima.isAdPlaying() && this.activeAdRequestToken === null) {
|
|
2806
|
-
console.log("[DEBUG-POD] \u{1F4CA} Progress marker: no ad playing, attempting to start");
|
|
2807
2708
|
const scheduled = this.findCurrentOrNextBreak(
|
|
2808
2709
|
this.video.currentTime * 1e3
|
|
2809
2710
|
);
|
|
@@ -2815,24 +2716,16 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
2815
2716
|
this.playSingleAd(first).catch(() => {
|
|
2816
2717
|
});
|
|
2817
2718
|
}
|
|
2818
|
-
} else {
|
|
2819
|
-
console.log(
|
|
2820
|
-
`[DEBUG-POD] \u{1F4CA} Progress marker: ad playing or request active (playing=${this.ima.isAdPlaying()}, token=${this.activeAdRequestToken})`
|
|
2821
|
-
);
|
|
2822
2719
|
}
|
|
2823
2720
|
return;
|
|
2824
2721
|
}
|
|
2825
2722
|
if (marker.type === "end") {
|
|
2826
|
-
console.log(
|
|
2827
|
-
`[DEBUG-POD] \u{1F3C1} SCTE-35 end marker received (currentTime: ${this.video.currentTime})`
|
|
2828
|
-
);
|
|
2829
2723
|
this.inAdBreak = false;
|
|
2830
2724
|
this.expectedAdBreakDurationMs = void 0;
|
|
2831
2725
|
this.currentAdBreakStartWallClockMs = void 0;
|
|
2832
2726
|
this.clearAdStartTimer();
|
|
2833
2727
|
this.clearAdStopTimer();
|
|
2834
2728
|
if (this.ima.isAdPlaying()) {
|
|
2835
|
-
console.log("[DEBUG-POD] \u{1F6D1} Stopping ad due to SCTE-35 end marker");
|
|
2836
2729
|
this.ima.stop().catch(() => {
|
|
2837
2730
|
});
|
|
2838
2731
|
}
|
|
@@ -3233,11 +3126,9 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
3233
3126
|
} else if (tags && tags.length > 0) {
|
|
3234
3127
|
vastTagUrls = tags;
|
|
3235
3128
|
} else {
|
|
3236
|
-
console.log("[DEBUG-POD] \u26A0\uFE0F No VAST tag available");
|
|
3237
3129
|
return;
|
|
3238
3130
|
}
|
|
3239
3131
|
if (vastTagUrls.length > 0) {
|
|
3240
|
-
console.log(`[DEBUG-POD] \u{1F3AF} Starting ad break with ${vastTagUrls.length} ads`);
|
|
3241
3132
|
this.adPodAllUrls = [...vastTagUrls];
|
|
3242
3133
|
this.preloadingAdUrls.clear();
|
|
3243
3134
|
this.vastToMediaUrlMap.clear();
|
|
@@ -3245,9 +3136,6 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
3245
3136
|
this.preloadingMediaUrls.clear();
|
|
3246
3137
|
const currentMuted = this.video.muted;
|
|
3247
3138
|
const currentVolume = this.video.volume;
|
|
3248
|
-
console.log(
|
|
3249
|
-
`[DEBUG-AUDIO] \u{1F4BE} Capturing ORIGINAL state (once) | muted=${currentMuted}, volume=${currentVolume}`
|
|
3250
|
-
);
|
|
3251
3139
|
this.ima.updateOriginalMutedState(currentMuted, currentVolume);
|
|
3252
3140
|
this.inAdBreak = true;
|
|
3253
3141
|
this.currentAdIndex = 0;
|
|
@@ -3255,21 +3143,38 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
3255
3143
|
this.adPodQueue = [...vastTagUrls];
|
|
3256
3144
|
if (this.isAdaptiveMode) {
|
|
3257
3145
|
if (this.config.debugAdTiming) {
|
|
3258
|
-
console.log("[ADAPTIVE-POD]
|
|
3146
|
+
console.log("[ADAPTIVE-POD] \u{1F680} Preloading first 2 ads before starting playback...");
|
|
3259
3147
|
}
|
|
3260
3148
|
try {
|
|
3261
|
-
|
|
3149
|
+
const adsToPreloadBeforeStart = Math.min(2, this.adPodAllUrls.length);
|
|
3150
|
+
for (let i = 0; i < adsToPreloadBeforeStart; i++) {
|
|
3151
|
+
const url = this.adPodAllUrls[i];
|
|
3152
|
+
if (url) {
|
|
3153
|
+
await this.preloadSingleAd(url);
|
|
3154
|
+
if (this.config.debugAdTiming) {
|
|
3155
|
+
console.log(`[ADAPTIVE-POD] \u2705 Preloaded ad ${i + 1}/${adsToPreloadBeforeStart}`);
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3262
3159
|
if (this.config.debugAdTiming) {
|
|
3263
|
-
console.log("[ADAPTIVE-POD]
|
|
3160
|
+
console.log("[ADAPTIVE-POD] \u{1F3AC} First ads preloaded, starting playback immediately");
|
|
3264
3161
|
}
|
|
3265
3162
|
} catch (error) {
|
|
3266
3163
|
if (this.config.debugAdTiming) {
|
|
3267
3164
|
console.warn(
|
|
3268
|
-
"[ADAPTIVE-POD] Error
|
|
3165
|
+
"[ADAPTIVE-POD] \u26A0\uFE0F Error preloading initial ads:",
|
|
3269
3166
|
error
|
|
3270
3167
|
);
|
|
3271
3168
|
}
|
|
3272
3169
|
}
|
|
3170
|
+
this.preloadAllAdsInBackground().catch((error) => {
|
|
3171
|
+
if (this.config.debugAdTiming) {
|
|
3172
|
+
console.warn(
|
|
3173
|
+
"[ADAPTIVE-POD] Error in background preloading:",
|
|
3174
|
+
error
|
|
3175
|
+
);
|
|
3176
|
+
}
|
|
3177
|
+
});
|
|
3273
3178
|
await this.playAdPod();
|
|
3274
3179
|
} else {
|
|
3275
3180
|
this.preloadAllAdsInBackground().catch((error) => {
|
|
@@ -3291,40 +3196,27 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
3291
3196
|
}
|
|
3292
3197
|
async playAdPod() {
|
|
3293
3198
|
if (this.adPodQueue.length === 0) {
|
|
3294
|
-
console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
|
|
3295
3199
|
return;
|
|
3296
3200
|
}
|
|
3297
|
-
const waitTime = this.isAdaptiveMode ?
|
|
3201
|
+
const waitTime = this.isAdaptiveMode ? 50 : 500;
|
|
3298
3202
|
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
3299
|
-
if (this.config.debugAdTiming) {
|
|
3300
|
-
console.log(
|
|
3301
|
-
`[DEBUG-POD] \u{1F50D} Looking for preloaded ad in queue of ${this.adPodQueue.length} URLs`
|
|
3302
|
-
);
|
|
3303
|
-
}
|
|
3304
3203
|
const firstPreloaded = this.findNextPreloadedAd();
|
|
3305
3204
|
if (!firstPreloaded) {
|
|
3306
|
-
console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads found, trying first ad from queue");
|
|
3307
3205
|
const firstAd = this.adPodQueue.shift();
|
|
3308
3206
|
if (firstAd) {
|
|
3309
3207
|
this.currentAdIndex++;
|
|
3310
|
-
console.log(`[DEBUG-POD] \u{1F3AC} Attempting to play first ad (not preloaded): ${firstAd.substring(0, 60)}...`);
|
|
3311
3208
|
try {
|
|
3312
3209
|
await this.playSingleAd(firstAd);
|
|
3313
3210
|
} catch (error) {
|
|
3314
|
-
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3315
3211
|
return;
|
|
3316
3212
|
}
|
|
3317
|
-
} else {
|
|
3318
|
-
console.log("[DEBUG-POD] \u274C No ads available in queue");
|
|
3319
3213
|
}
|
|
3320
3214
|
return;
|
|
3321
3215
|
}
|
|
3322
3216
|
this.currentAdIndex++;
|
|
3323
|
-
console.log(`[DEBUG-POD] \u{1F680} Starting pod with ad ${this.currentAdIndex}/${this.totalAdsInBreak}`);
|
|
3324
3217
|
try {
|
|
3325
3218
|
await this.playSingleAd(firstPreloaded);
|
|
3326
3219
|
} catch (error) {
|
|
3327
|
-
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3328
3220
|
}
|
|
3329
3221
|
}
|
|
3330
3222
|
findCurrentOrNextBreak(nowMs) {
|
|
@@ -3404,15 +3296,9 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
3404
3296
|
const overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
|
|
3405
3297
|
const shouldExtendAdBreak = (adPlaying || pendingAds || this.showAds) && overrunMs < maxExtensionMs;
|
|
3406
3298
|
if (shouldExtendAdBreak) {
|
|
3407
|
-
console.log(
|
|
3408
|
-
`[DEBUG-POD] \u23F3 Extending ad break | elapsed=${elapsedSinceStartMs}ms, expected=${expectedDurationMs}ms, overrun=${overrunMs}ms`
|
|
3409
|
-
);
|
|
3410
3299
|
this.scheduleAdStopCountdown(checkIntervalMs);
|
|
3411
3300
|
return;
|
|
3412
3301
|
}
|
|
3413
|
-
console.log(
|
|
3414
|
-
`[DEBUG-POD] \u23F1\uFE0F Ad break duration expired | elapsed=${elapsedSinceStartMs}ms, expected=${expectedDurationMs}ms`
|
|
3415
|
-
);
|
|
3416
3302
|
if (adPlaying) {
|
|
3417
3303
|
this.ima.stop().catch(() => {
|
|
3418
3304
|
});
|
|
@@ -3445,42 +3331,23 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
3445
3331
|
this.ptsDriftEmaMs = this.ptsDriftEmaMs * (1 - alpha) + sampleMs * alpha;
|
|
3446
3332
|
}
|
|
3447
3333
|
async playSingleAd(vastTagUrl) {
|
|
3448
|
-
console.log(`[DEBUG-POD] \u{1F3AC} playSingleAd | url=${vastTagUrl.substring(0, 60)}...`);
|
|
3449
3334
|
if (this.ima.isAdPlaying()) {
|
|
3450
|
-
console.warn("[DEBUG-POD] \u26A0\uFE0F Ad already playing - skipping request");
|
|
3451
3335
|
return;
|
|
3452
3336
|
}
|
|
3453
3337
|
const requestToken = ++this.adRequestTokenCounter;
|
|
3454
|
-
const wasPreloaded = this.ima.hasPreloadedAd(vastTagUrl);
|
|
3455
3338
|
this.activeAdRequestToken = requestToken;
|
|
3456
|
-
console.log(`[DEBUG-POD] \u{1F4DD} Request token=${requestToken}, preloaded=${wasPreloaded}`);
|
|
3457
3339
|
this.startAdRequestWatchdog(requestToken);
|
|
3458
3340
|
try {
|
|
3459
|
-
console.log(`[DEBUG-POD] \u{1F4E1} Calling ima.requestAds() for token=${requestToken}...`);
|
|
3460
3341
|
await this.ima.requestAds(vastTagUrl);
|
|
3461
|
-
console.log(`[DEBUG-POD] \u2705 ima.requestAds() completed successfully`);
|
|
3462
3342
|
this.clearAdRequestWatchdog();
|
|
3463
3343
|
if (this.activeAdRequestToken !== requestToken) {
|
|
3464
|
-
console.warn(`[DEBUG-POD] \u26A0\uFE0F Token mismatch after requestAds (stale request)`);
|
|
3465
3344
|
return;
|
|
3466
3345
|
}
|
|
3467
|
-
console.log(`[DEBUG-POD] \u{1F4FA} Calling ima.play() to start ad playback...`);
|
|
3468
|
-
console.log(`[DEBUG-POD] \u{1F4CA} Video element state: paused=${this.video.paused}, muted=${this.video.muted}, readyState=${this.video.readyState}`);
|
|
3469
3346
|
try {
|
|
3470
3347
|
this.startAdFailsafeTimer(requestToken);
|
|
3471
3348
|
await this.ima.play();
|
|
3472
|
-
if (this.activeAdRequestToken === requestToken) {
|
|
3473
|
-
console.log(`[DEBUG-POD] \u2705 Ad play initiated successfully (token=${requestToken})`);
|
|
3474
|
-
} else {
|
|
3475
|
-
console.warn(`[DEBUG-POD] \u26A0\uFE0F Token mismatch after play (stale request)`);
|
|
3476
|
-
}
|
|
3477
3349
|
} catch (playError) {
|
|
3478
|
-
console.error(
|
|
3479
|
-
"[DEBUG-POD] \u274C Failed to play ad:",
|
|
3480
|
-
playError instanceof Error ? playError.message : playError,
|
|
3481
|
-
"\nFull error:",
|
|
3482
|
-
playError
|
|
3483
|
-
);
|
|
3350
|
+
console.error("[AD-ERROR] Failed to play ad:", playError);
|
|
3484
3351
|
this.clearAdFailsafeTimer();
|
|
3485
3352
|
if (this.activeAdRequestToken === requestToken) {
|
|
3486
3353
|
this.activeAdRequestToken = null;
|
|
@@ -3489,7 +3356,7 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
3489
3356
|
return;
|
|
3490
3357
|
}
|
|
3491
3358
|
} catch (error) {
|
|
3492
|
-
console.error("[
|
|
3359
|
+
console.error("[AD-ERROR] Ad request failed:", error == null ? void 0 : error.message);
|
|
3493
3360
|
this.clearAdRequestWatchdog();
|
|
3494
3361
|
this.clearAdFailsafeTimer();
|
|
3495
3362
|
if (this.activeAdRequestToken === requestToken) {
|
|
@@ -3500,7 +3367,6 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
3500
3367
|
}
|
|
3501
3368
|
handleAdPodComplete() {
|
|
3502
3369
|
var _a;
|
|
3503
|
-
console.log("[DEBUG-POD] \u{1F3C1} handleAdPodComplete - Ending ad break, restoring content");
|
|
3504
3370
|
this.clearAdRequestWatchdog();
|
|
3505
3371
|
this.clearAdFailsafeTimer();
|
|
3506
3372
|
this.activeAdRequestToken = null;
|
|
@@ -3522,10 +3388,6 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
3522
3388
|
});
|
|
3523
3389
|
const restoredMuted = this.ima.getOriginalMutedState();
|
|
3524
3390
|
const restoredVolume = this.ima.getOriginalVolume();
|
|
3525
|
-
console.log(
|
|
3526
|
-
`[DEBUG-AUDIO] \u{1F50A} Audio restored by IMA | muted=${restoredMuted}, volume=${restoredVolume}`
|
|
3527
|
-
);
|
|
3528
|
-
console.log("[DEBUG-LAYER] \u{1F3AC} Layers: Main=visible, Ad=hidden, Placeholder=no");
|
|
3529
3391
|
if (this.video.muted !== restoredMuted) {
|
|
3530
3392
|
this.video.muted = restoredMuted;
|
|
3531
3393
|
}
|
|
@@ -3533,14 +3395,11 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
3533
3395
|
this.video.volume = restoredVolume;
|
|
3534
3396
|
}
|
|
3535
3397
|
if (!this.shouldContinueLiveStreamDuringAds() && this.video.paused) {
|
|
3536
|
-
|
|
3537
|
-
(_a = this.video.play()) == null ? void 0 : _a.catch((error) => {
|
|
3538
|
-
console.error("[DEBUG-ERROR] Failed to resume video:", error);
|
|
3398
|
+
(_a = this.video.play()) == null ? void 0 : _a.catch(() => {
|
|
3539
3399
|
});
|
|
3540
3400
|
}
|
|
3541
3401
|
}
|
|
3542
3402
|
handleAdFailure() {
|
|
3543
|
-
console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
|
|
3544
3403
|
const remaining = this.getRemainingAdMs();
|
|
3545
3404
|
if (remaining > 500 && this.adPodQueue.length > 0) {
|
|
3546
3405
|
if (this.isAdaptiveMode && this.currentAdIndex <= 1) {
|
|
@@ -3553,14 +3412,12 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
3553
3412
|
const nextPreloaded = this.findNextPreloadedAd();
|
|
3554
3413
|
if (nextPreloaded) {
|
|
3555
3414
|
this.currentAdIndex++;
|
|
3556
|
-
console.log(`[DEBUG-POD] \u27A1\uFE0F Trying next ad after failure (${this.currentAdIndex}/${this.totalAdsInBreak})`);
|
|
3557
3415
|
this.playSingleAd(nextPreloaded).catch(() => {
|
|
3558
3416
|
this.handleAdPodComplete();
|
|
3559
3417
|
});
|
|
3560
3418
|
return;
|
|
3561
3419
|
}
|
|
3562
3420
|
}
|
|
3563
|
-
console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
|
|
3564
3421
|
this.handleAdPodComplete();
|
|
3565
3422
|
}
|
|
3566
3423
|
tryNextAdWithRetry(retryCount) {
|
|
@@ -3860,16 +3717,27 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
3860
3717
|
}
|
|
3861
3718
|
}
|
|
3862
3719
|
async preloadAllAdsInBackground() {
|
|
3720
|
+
var _a, _b;
|
|
3863
3721
|
if (this.adPodAllUrls.length === 0) {
|
|
3864
3722
|
return;
|
|
3865
3723
|
}
|
|
3866
3724
|
if (this.isAdaptiveMode) {
|
|
3867
3725
|
if (this.config.debugAdTiming) {
|
|
3868
3726
|
console.log(
|
|
3869
|
-
`[ADAPTIVE-POD] \u{1F504} Starting sequential preload of
|
|
3727
|
+
`[ADAPTIVE-POD] \u{1F504} Starting sequential preload of remaining ads`
|
|
3870
3728
|
);
|
|
3871
3729
|
}
|
|
3872
3730
|
const processedUrls = /* @__PURE__ */ new Set();
|
|
3731
|
+
for (const url of this.adPodAllUrls) {
|
|
3732
|
+
if (((_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, url)) || this.fetchedAdDurations.has(url)) {
|
|
3733
|
+
processedUrls.add(url);
|
|
3734
|
+
}
|
|
3735
|
+
}
|
|
3736
|
+
if (this.config.debugAdTiming && processedUrls.size > 0) {
|
|
3737
|
+
console.log(
|
|
3738
|
+
`[ADAPTIVE-POD] \u{1F4E6} Skipping ${processedUrls.size} already-preloaded ads`
|
|
3739
|
+
);
|
|
3740
|
+
}
|
|
3873
3741
|
while (true) {
|
|
3874
3742
|
const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
|
|
3875
3743
|
if (!nextUrl) {
|
|
@@ -4002,37 +3870,17 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
|
|
|
4002
3870
|
}
|
|
4003
3871
|
findNextPreloadedAd() {
|
|
4004
3872
|
var _a, _b, _c;
|
|
4005
|
-
if (this.config.debugAdTiming) {
|
|
4006
|
-
console.log(
|
|
4007
|
-
`[DEBUG-POD] \u{1F50E} Searching for preloaded ad in queue (${this.adPodQueue.length} URLs, ${this.preloadedMediaUrls.size} media preloaded, ${this.vastToMediaUrlMap.size} VAST mappings)`
|
|
4008
|
-
);
|
|
4009
|
-
}
|
|
4010
3873
|
for (let i = 0; i < this.adPodQueue.length; i++) {
|
|
4011
3874
|
const vastTagUrl = this.adPodQueue[i];
|
|
4012
3875
|
if (!vastTagUrl) continue;
|
|
4013
3876
|
const hasImaPreload = (_c = (_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, vastTagUrl)) != null ? _c : false;
|
|
4014
3877
|
const mediaUrls = this.vastToMediaUrlMap.get(vastTagUrl);
|
|
4015
3878
|
const hasMediaPreload = mediaUrls && mediaUrls.length > 0 ? this.preloadedMediaUrls.has(mediaUrls[0]) : false;
|
|
4016
|
-
if (this.config.debugAdTiming) {
|
|
4017
|
-
console.log(
|
|
4018
|
-
`[DEBUG-POD] Ad ${i}: IMA=${hasImaPreload}, Media=${hasMediaPreload}, MediaURLs=${(mediaUrls == null ? void 0 : mediaUrls.length) || 0}, URL=${vastTagUrl.substring(0, 60)}...`
|
|
4019
|
-
);
|
|
4020
|
-
}
|
|
4021
3879
|
if (hasImaPreload || hasMediaPreload) {
|
|
4022
|
-
if (this.config.debugAdTiming) {
|
|
4023
|
-
console.log(
|
|
4024
|
-
`[DEBUG-POD] \u2705 Found preloaded ad at index ${i}`
|
|
4025
|
-
);
|
|
4026
|
-
}
|
|
4027
3880
|
this.adPodQueue.splice(0, i + 1);
|
|
4028
3881
|
return vastTagUrl;
|
|
4029
3882
|
}
|
|
4030
3883
|
}
|
|
4031
|
-
if (this.config.debugAdTiming) {
|
|
4032
|
-
console.log(
|
|
4033
|
-
`[DEBUG-POD] \u274C No preloaded ads found in queue`
|
|
4034
|
-
);
|
|
4035
|
-
}
|
|
4036
3884
|
return void 0;
|
|
4037
3885
|
}
|
|
4038
3886
|
getRemainingAdMs() {
|