stormcloud-video-player 0.8.25 → 0.8.27
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 +714 -128
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +7 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +714 -128
- package/lib/index.js.map +1 -1
- package/lib/player/AdBreakOrchestrator.cjs +278 -49
- package/lib/player/AdBreakOrchestrator.cjs.map +1 -1
- package/lib/player/AdBreakOrchestrator.d.cts +4 -1
- package/lib/player/AdConfigManager.cjs +144 -14
- package/lib/player/AdConfigManager.cjs.map +1 -1
- package/lib/player/AdConfigManager.d.cts +12 -1
- package/lib/player/AdPreloadPool.d.cts +1 -1
- package/lib/player/AdTimingService.cjs +7 -0
- package/lib/player/AdTimingService.cjs.map +1 -1
- package/lib/player/AdTimingService.d.cts +2 -1
- package/lib/player/HlsEngine.d.cts +1 -1
- package/lib/player/PlayerControls.d.cts +1 -1
- package/lib/player/Scte35CueManager.d.cts +1 -1
- package/lib/player/Scte35Parser.d.cts +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +714 -128
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/player/StormcloudVideoPlayer.d.cts +2 -1
- package/lib/player/playerTypes.d.cts +1 -1
- package/lib/players/HlsPlayer.cjs +714 -128
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.d.cts +1 -1
- package/lib/players/index.cjs +714 -128
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/hlsAdPlayer.cjs +343 -71
- package/lib/sdk/hlsAdPlayer.cjs.map +1 -1
- package/lib/sdk/hlsAdPlayer.d.cts +1 -1
- package/lib/{types-Bz4aRmzc.d.cts → types-Xgz2_W1C.d.cts} +6 -0
- package/lib/ui/StormcloudVideoPlayer.cjs +714 -128
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
- package/lib/utils/ctvVastSignals.cjs +80 -8
- package/lib/utils/ctvVastSignals.cjs.map +1 -1
- package/lib/utils/tracking.cjs +80 -8
- package/lib/utils/tracking.cjs.map +1 -1
- package/lib/utils/tracking.d.cts +1 -1
- package/lib/utils/vastEnvironmentSignals.cjs +83 -13
- package/lib/utils/vastEnvironmentSignals.cjs.map +1 -1
- package/lib/utils/vastMacros.cjs +15 -1
- package/lib/utils/vastMacros.cjs.map +1 -1
- package/lib/utils/vastMacros.d.cts +3 -0
- package/package.json +1 -1
package/lib/sdk/hlsAdPlayer.cjs
CHANGED
|
@@ -210,6 +210,8 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
210
210
|
var adHls;
|
|
211
211
|
var adContainerEl;
|
|
212
212
|
var currentAd;
|
|
213
|
+
var podAds = [];
|
|
214
|
+
var podIndex = 0;
|
|
213
215
|
var sessionId;
|
|
214
216
|
var preloadedAds = /* @__PURE__ */ new Map();
|
|
215
217
|
var preloadingAds = /* @__PURE__ */ new Map();
|
|
@@ -374,14 +376,14 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
374
376
|
error: []
|
|
375
377
|
};
|
|
376
378
|
}
|
|
377
|
-
function extractTrackingUrls(
|
|
379
|
+
function extractTrackingUrls(scope) {
|
|
378
380
|
var trackingUrls = createEmptyTrackingUrls();
|
|
379
|
-
|
|
381
|
+
scope.querySelectorAll("Impression").forEach(function(el) {
|
|
380
382
|
var _el_textContent;
|
|
381
383
|
var url = (_el_textContent = el.textContent) === null || _el_textContent === void 0 ? void 0 : _el_textContent.trim();
|
|
382
384
|
if (url) trackingUrls.impression.push(url);
|
|
383
385
|
});
|
|
384
|
-
|
|
386
|
+
scope.querySelectorAll("Tracking").forEach(function(el) {
|
|
385
387
|
var _el_textContent;
|
|
386
388
|
var event = el.getAttribute("event");
|
|
387
389
|
var url = (_el_textContent = el.textContent) === null || _el_textContent === void 0 ? void 0 : _el_textContent.trim();
|
|
@@ -392,7 +394,7 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
392
394
|
}
|
|
393
395
|
}
|
|
394
396
|
});
|
|
395
|
-
|
|
397
|
+
scope.querySelectorAll("Error").forEach(function(el) {
|
|
396
398
|
var _el_textContent;
|
|
397
399
|
var url = (_el_textContent = el.textContent) === null || _el_textContent === void 0 ? void 0 : _el_textContent.trim();
|
|
398
400
|
if (url) trackingUrls.error.push(url);
|
|
@@ -502,6 +504,75 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
502
504
|
};
|
|
503
505
|
}
|
|
504
506
|
}
|
|
507
|
+
function parseAdElement(adElement) {
|
|
508
|
+
try {
|
|
509
|
+
var _adElement_querySelector, _adElement_querySelector_textContent, _adElement_querySelector1, _adElement_querySelector_textContent1, _adElement_querySelector2, _adElement_querySelector3;
|
|
510
|
+
var adId = adElement.getAttribute("id") || "unknown";
|
|
511
|
+
var title = ((_adElement_querySelector = adElement.querySelector("AdTitle")) === null || _adElement_querySelector === void 0 ? void 0 : _adElement_querySelector.textContent) || "Ad";
|
|
512
|
+
var clickThrough = (_adElement_querySelector1 = adElement.querySelector("ClickThrough")) === null || _adElement_querySelector1 === void 0 ? void 0 : (_adElement_querySelector_textContent = _adElement_querySelector1.textContent) === null || _adElement_querySelector_textContent === void 0 ? void 0 : _adElement_querySelector_textContent.trim();
|
|
513
|
+
var wrapperUri = (_adElement_querySelector2 = adElement.querySelector("VASTAdTagURI")) === null || _adElement_querySelector2 === void 0 ? void 0 : (_adElement_querySelector_textContent1 = _adElement_querySelector2.textContent) === null || _adElement_querySelector_textContent1 === void 0 ? void 0 : _adElement_querySelector_textContent1.trim();
|
|
514
|
+
if (wrapperUri) {
|
|
515
|
+
return {
|
|
516
|
+
type: "wrapper",
|
|
517
|
+
vastAdTagUri: wrapperUri,
|
|
518
|
+
trackingUrls: extractTrackingUrls(adElement),
|
|
519
|
+
clickThrough: clickThrough
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
var isNoAdAvailable = adId === "empty" || title.toLowerCase().includes("no ad available") || title.toLowerCase() === "no ad available";
|
|
523
|
+
var durationText = ((_adElement_querySelector3 = adElement.querySelector("Duration")) === null || _adElement_querySelector3 === void 0 ? void 0 : _adElement_querySelector3.textContent) || "00:00:30";
|
|
524
|
+
var durationParts = durationText.split(":");
|
|
525
|
+
var duration = parseInt(durationParts[0] || "0", 10) * 3600 + parseInt(durationParts[1] || "0", 10) * 60 + parseInt(durationParts[2] || "0", 10);
|
|
526
|
+
var mediaFileElements = adElement.querySelectorAll("MediaFile");
|
|
527
|
+
var mediaFiles = [];
|
|
528
|
+
mediaFileElements.forEach(function(mf) {
|
|
529
|
+
var _mf_textContent;
|
|
530
|
+
var type = mf.getAttribute("type") || "";
|
|
531
|
+
var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
|
|
532
|
+
var width = mf.getAttribute("width") || "";
|
|
533
|
+
var height = mf.getAttribute("height") || "";
|
|
534
|
+
if (!url) return;
|
|
535
|
+
var bitrateAttr = mf.getAttribute("bitrate");
|
|
536
|
+
var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
|
|
537
|
+
var mediaFile = {
|
|
538
|
+
url: url,
|
|
539
|
+
type: type,
|
|
540
|
+
width: parseInt(width || "1920", 10),
|
|
541
|
+
height: parseInt(height || "1080", 10),
|
|
542
|
+
bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
|
|
543
|
+
};
|
|
544
|
+
if (isHlsMediaFile(mediaFile) || isProgressiveMediaFile(mediaFile)) {
|
|
545
|
+
mediaFiles.push(mediaFile);
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
if (mediaFiles.length === 0) {
|
|
549
|
+
if (isNoAdAvailable) {
|
|
550
|
+
console.warn("[HlsAdPlayer] Pod <Ad> indicates no ad available");
|
|
551
|
+
} else {
|
|
552
|
+
console.warn("[HlsAdPlayer] No supported media files in pod <Ad>");
|
|
553
|
+
}
|
|
554
|
+
return {
|
|
555
|
+
type: "empty"
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
return {
|
|
559
|
+
type: "inline",
|
|
560
|
+
ad: {
|
|
561
|
+
id: adId,
|
|
562
|
+
title: title,
|
|
563
|
+
duration: duration,
|
|
564
|
+
mediaFiles: mediaFiles,
|
|
565
|
+
trackingUrls: extractTrackingUrls(adElement),
|
|
566
|
+
clickThrough: clickThrough
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
} catch (error) {
|
|
570
|
+
console.error("[HlsAdPlayer] Error parsing pod <Ad> element:", error);
|
|
571
|
+
return {
|
|
572
|
+
type: "empty"
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
}
|
|
505
576
|
function fetchVastXml(vastTagUrl) {
|
|
506
577
|
return _async_to_generator(function() {
|
|
507
578
|
var response;
|
|
@@ -578,6 +649,146 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
578
649
|
});
|
|
579
650
|
}).apply(this, arguments);
|
|
580
651
|
}
|
|
652
|
+
function fetchAndParsePod(vastTagUrl) {
|
|
653
|
+
return _async_to_generator(function() {
|
|
654
|
+
var vastXml, parser, xmlDoc, adElements, ads, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, adElement, parsed, resolved, error, err;
|
|
655
|
+
return _ts_generator(this, function(_state) {
|
|
656
|
+
switch(_state.label){
|
|
657
|
+
case 0:
|
|
658
|
+
return [
|
|
659
|
+
4,
|
|
660
|
+
fetchVastXml(vastTagUrl)
|
|
661
|
+
];
|
|
662
|
+
case 1:
|
|
663
|
+
vastXml = _state.sent();
|
|
664
|
+
console.log("[HlsAdPlayer] Pod VAST XML received");
|
|
665
|
+
parser = new DOMParser();
|
|
666
|
+
xmlDoc = parser.parseFromString(vastXml, "text/xml");
|
|
667
|
+
if (xmlDoc.querySelector("parsererror")) {
|
|
668
|
+
console.error("[HlsAdPlayer] Pod VAST XML parsing error (malformed)");
|
|
669
|
+
return [
|
|
670
|
+
2,
|
|
671
|
+
[]
|
|
672
|
+
];
|
|
673
|
+
}
|
|
674
|
+
adElements = Array.from(xmlDoc.querySelectorAll("Ad"));
|
|
675
|
+
if (adElements.length === 0) {
|
|
676
|
+
console.warn("[HlsAdPlayer] No <Ad> elements found in pod VAST response");
|
|
677
|
+
return [
|
|
678
|
+
2,
|
|
679
|
+
[]
|
|
680
|
+
];
|
|
681
|
+
}
|
|
682
|
+
adElements.sort(function(a, b) {
|
|
683
|
+
var aSeq = parseInt(a.getAttribute("sequence") || "", 10);
|
|
684
|
+
var bSeq = parseInt(b.getAttribute("sequence") || "", 10);
|
|
685
|
+
var aVal = Number.isFinite(aSeq) ? aSeq : Number.MAX_SAFE_INTEGER;
|
|
686
|
+
var bVal = Number.isFinite(bSeq) ? bSeq : Number.MAX_SAFE_INTEGER;
|
|
687
|
+
return aVal - bVal;
|
|
688
|
+
});
|
|
689
|
+
ads = [];
|
|
690
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
691
|
+
_state.label = 2;
|
|
692
|
+
case 2:
|
|
693
|
+
_state.trys.push([
|
|
694
|
+
2,
|
|
695
|
+
10,
|
|
696
|
+
11,
|
|
697
|
+
12
|
|
698
|
+
]);
|
|
699
|
+
_iterator = adElements[Symbol.iterator]();
|
|
700
|
+
_state.label = 3;
|
|
701
|
+
case 3:
|
|
702
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
703
|
+
3,
|
|
704
|
+
9
|
|
705
|
+
];
|
|
706
|
+
adElement = _step.value;
|
|
707
|
+
parsed = parseAdElement(adElement);
|
|
708
|
+
if (!(parsed.type === "inline")) return [
|
|
709
|
+
3,
|
|
710
|
+
4
|
|
711
|
+
];
|
|
712
|
+
ads.push(parsed.ad);
|
|
713
|
+
return [
|
|
714
|
+
3,
|
|
715
|
+
8
|
|
716
|
+
];
|
|
717
|
+
case 4:
|
|
718
|
+
if (!(parsed.type === "wrapper")) return [
|
|
719
|
+
3,
|
|
720
|
+
8
|
|
721
|
+
];
|
|
722
|
+
_state.label = 5;
|
|
723
|
+
case 5:
|
|
724
|
+
_state.trys.push([
|
|
725
|
+
5,
|
|
726
|
+
7,
|
|
727
|
+
,
|
|
728
|
+
8
|
|
729
|
+
]);
|
|
730
|
+
return [
|
|
731
|
+
4,
|
|
732
|
+
fetchAndParseVastAd(parsed.vastAdTagUri, 1, parsed.trackingUrls)
|
|
733
|
+
];
|
|
734
|
+
case 6:
|
|
735
|
+
resolved = _state.sent();
|
|
736
|
+
if (resolved) {
|
|
737
|
+
ads.push(resolved);
|
|
738
|
+
}
|
|
739
|
+
return [
|
|
740
|
+
3,
|
|
741
|
+
8
|
|
742
|
+
];
|
|
743
|
+
case 7:
|
|
744
|
+
error = _state.sent();
|
|
745
|
+
console.warn("[HlsAdPlayer] Failed to resolve wrapper <Ad> in pod:", error);
|
|
746
|
+
return [
|
|
747
|
+
3,
|
|
748
|
+
8
|
|
749
|
+
];
|
|
750
|
+
case 8:
|
|
751
|
+
_iteratorNormalCompletion = true;
|
|
752
|
+
return [
|
|
753
|
+
3,
|
|
754
|
+
3
|
|
755
|
+
];
|
|
756
|
+
case 9:
|
|
757
|
+
return [
|
|
758
|
+
3,
|
|
759
|
+
12
|
|
760
|
+
];
|
|
761
|
+
case 10:
|
|
762
|
+
err = _state.sent();
|
|
763
|
+
_didIteratorError = true;
|
|
764
|
+
_iteratorError = err;
|
|
765
|
+
return [
|
|
766
|
+
3,
|
|
767
|
+
12
|
|
768
|
+
];
|
|
769
|
+
case 11:
|
|
770
|
+
try {
|
|
771
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
772
|
+
_iterator.return();
|
|
773
|
+
}
|
|
774
|
+
} finally{
|
|
775
|
+
if (_didIteratorError) {
|
|
776
|
+
throw _iteratorError;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
return [
|
|
780
|
+
7
|
|
781
|
+
];
|
|
782
|
+
case 12:
|
|
783
|
+
console.log("[HlsAdPlayer] Parsed ".concat(ads.length, " ad(s) from pod VAST response"));
|
|
784
|
+
return [
|
|
785
|
+
2,
|
|
786
|
+
ads
|
|
787
|
+
];
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
})();
|
|
791
|
+
}
|
|
581
792
|
function createAdVideoElement() {
|
|
582
793
|
var video = document.createElement("video");
|
|
583
794
|
video.style.position = "absolute";
|
|
@@ -622,6 +833,9 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
622
833
|
trackingFired.complete = true;
|
|
623
834
|
fireTrackingPixels(currentAd.trackingUrls.complete);
|
|
624
835
|
console.log("[HlsAdPlayer] Ad completed");
|
|
836
|
+
if (podIndex < podAds.length - 1 && advanceToNextPodAd()) {
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
625
839
|
handleAdComplete();
|
|
626
840
|
});
|
|
627
841
|
adVideoElement.addEventListener("error", function(e) {
|
|
@@ -630,6 +844,9 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
630
844
|
if (currentAd) {
|
|
631
845
|
fireTrackingPixels(currentAd.trackingUrls.error);
|
|
632
846
|
}
|
|
847
|
+
if (podIndex < podAds.length - 1 && advanceToNextPodAd()) {
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
633
850
|
handleAdError();
|
|
634
851
|
});
|
|
635
852
|
adVideoElement.addEventListener("volumechange", function() {
|
|
@@ -658,6 +875,94 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
658
875
|
delete contentVideo.dataset.stormcloudAdPlaying;
|
|
659
876
|
}
|
|
660
877
|
}
|
|
878
|
+
function resetQuartileTracking(preserveImpression) {
|
|
879
|
+
trackingFired = {
|
|
880
|
+
impression: preserveImpression ? trackingFired.impression : false,
|
|
881
|
+
start: false,
|
|
882
|
+
firstQuartile: false,
|
|
883
|
+
midpoint: false,
|
|
884
|
+
thirdQuartile: false,
|
|
885
|
+
complete: false
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
function loadCurrentAdMedia() {
|
|
889
|
+
if (!adVideoElement || !currentAd) {
|
|
890
|
+
throw new Error("No ad video element or ad to load");
|
|
891
|
+
}
|
|
892
|
+
var mediaFile = selectBestMediaFile(currentAd.mediaFiles);
|
|
893
|
+
if (!mediaFile) {
|
|
894
|
+
throw new Error("No media file available for ad");
|
|
895
|
+
}
|
|
896
|
+
var isHlsAd = isHlsMediaFile(mediaFile);
|
|
897
|
+
console.log("[HlsAdPlayer] Loading ".concat(isHlsAd ? "HLS" : "progressive", " ad (pod ").concat(podIndex + 1, "/").concat(podAds.length || 1, ") from: ").concat(mediaFile.url));
|
|
898
|
+
if (isHlsAd && import_hls.default.isSupported()) {
|
|
899
|
+
if (adHls) {
|
|
900
|
+
adHls.destroy();
|
|
901
|
+
}
|
|
902
|
+
adHls = new import_hls.default({
|
|
903
|
+
enableWorker: true,
|
|
904
|
+
lowLatencyMode: false
|
|
905
|
+
});
|
|
906
|
+
adHls.loadSource(mediaFile.url);
|
|
907
|
+
adHls.attachMedia(adVideoElement);
|
|
908
|
+
adHls.on(import_hls.default.Events.MANIFEST_PARSED, function() {
|
|
909
|
+
console.log("[HlsAdPlayer] HLS manifest parsed, starting playback");
|
|
910
|
+
adVideoElement.play().catch(function(error) {
|
|
911
|
+
console.error("[HlsAdPlayer] Error starting ad playback:", error);
|
|
912
|
+
handleAdError();
|
|
913
|
+
});
|
|
914
|
+
});
|
|
915
|
+
adHls.on(import_hls.default.Events.ERROR, function(_event, data) {
|
|
916
|
+
console.error("[HlsAdPlayer] HLS error:", data);
|
|
917
|
+
if (data.fatal) {
|
|
918
|
+
handleAdError();
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
} else if (isHlsAd && adVideoElement.canPlayType("application/vnd.apple.mpegurl")) {
|
|
922
|
+
adVideoElement.src = mediaFile.url;
|
|
923
|
+
adVideoElement.play().catch(function(error) {
|
|
924
|
+
console.error("[HlsAdPlayer] Error starting ad playback:", error);
|
|
925
|
+
handleAdError();
|
|
926
|
+
});
|
|
927
|
+
} else if (!isHlsAd && isProgressiveMediaFile(mediaFile)) {
|
|
928
|
+
if (adHls) {
|
|
929
|
+
adHls.destroy();
|
|
930
|
+
adHls = void 0;
|
|
931
|
+
}
|
|
932
|
+
adVideoElement.src = mediaFile.url;
|
|
933
|
+
adVideoElement.load();
|
|
934
|
+
adVideoElement.play().catch(function(error) {
|
|
935
|
+
console.error("[HlsAdPlayer] Error starting progressive ad playback:", error);
|
|
936
|
+
handleAdError();
|
|
937
|
+
});
|
|
938
|
+
} else {
|
|
939
|
+
throw new Error("Unsupported ad media file type: ".concat(mediaFile.type));
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
function advanceToNextPodAd() {
|
|
943
|
+
if (podIndex >= podAds.length - 1) {
|
|
944
|
+
return false;
|
|
945
|
+
}
|
|
946
|
+
podIndex++;
|
|
947
|
+
currentAd = podAds[podIndex];
|
|
948
|
+
resetQuartileTracking(false);
|
|
949
|
+
if (currentAd) {
|
|
950
|
+
fireTrackingPixels(currentAd.trackingUrls.impression);
|
|
951
|
+
trackingFired.impression = true;
|
|
952
|
+
console.log("[HlsAdPlayer] Advancing to next pod ad (".concat(podIndex + 1, "/").concat(podAds.length, "): ").concat(currentAd.title, ", duration: ").concat(currentAd.duration, "s"));
|
|
953
|
+
}
|
|
954
|
+
try {
|
|
955
|
+
loadCurrentAdMedia();
|
|
956
|
+
emit("pod_ad_started", {
|
|
957
|
+
index: podIndex,
|
|
958
|
+
total: podAds.length
|
|
959
|
+
});
|
|
960
|
+
return true;
|
|
961
|
+
} catch (error) {
|
|
962
|
+
console.error("[HlsAdPlayer] Failed to load next pod ad:", error);
|
|
963
|
+
return false;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
661
966
|
function handleAdComplete() {
|
|
662
967
|
console.log("[HlsAdPlayer] Handling ad completion");
|
|
663
968
|
adPlaying = false;
|
|
@@ -711,7 +1016,7 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
711
1016
|
},
|
|
712
1017
|
requestAds: function requestAds(vastTagUrl) {
|
|
713
1018
|
return _async_to_generator(function() {
|
|
714
|
-
var
|
|
1019
|
+
var ads, preloaded, error;
|
|
715
1020
|
return _ts_generator(this, function(_state) {
|
|
716
1021
|
switch(_state.label){
|
|
717
1022
|
case 0:
|
|
@@ -732,12 +1037,18 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
732
1037
|
6
|
|
733
1038
|
]);
|
|
734
1039
|
sessionId = generateSessionId();
|
|
1040
|
+
ads = [];
|
|
735
1041
|
if (!preloadedAds.has(vastTagUrl)) return [
|
|
736
1042
|
3,
|
|
737
1043
|
2
|
|
738
1044
|
];
|
|
739
|
-
|
|
1045
|
+
preloaded = preloadedAds.get(vastTagUrl);
|
|
740
1046
|
preloadedAds.delete(vastTagUrl);
|
|
1047
|
+
if (preloaded) {
|
|
1048
|
+
ads = [
|
|
1049
|
+
preloaded
|
|
1050
|
+
];
|
|
1051
|
+
}
|
|
741
1052
|
console.log("[HlsAdPlayer] Using preloaded VAST response:", vastTagUrl);
|
|
742
1053
|
return [
|
|
743
1054
|
3,
|
|
@@ -746,13 +1057,13 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
746
1057
|
case 2:
|
|
747
1058
|
return [
|
|
748
1059
|
4,
|
|
749
|
-
|
|
1060
|
+
fetchAndParsePod(vastTagUrl)
|
|
750
1061
|
];
|
|
751
1062
|
case 3:
|
|
752
|
-
|
|
1063
|
+
ads = _state.sent();
|
|
753
1064
|
_state.label = 4;
|
|
754
1065
|
case 4:
|
|
755
|
-
if (!
|
|
1066
|
+
if (!ads.length) {
|
|
756
1067
|
console.warn("[HlsAdPlayer] No ads available from VAST response");
|
|
757
1068
|
emit("ad_error");
|
|
758
1069
|
return [
|
|
@@ -760,10 +1071,14 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
760
1071
|
Promise.reject(new Error("No ads available from VAST response"))
|
|
761
1072
|
];
|
|
762
1073
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
1074
|
+
podAds = ads;
|
|
1075
|
+
podIndex = 0;
|
|
1076
|
+
currentAd = ads[0];
|
|
1077
|
+
console.log("[HlsAdPlayer] Pod parsed: ".concat(ads.length, ' ad(s), first="').concat(currentAd === null || currentAd === void 0 ? void 0 : currentAd.title, '", duration=').concat(currentAd === null || currentAd === void 0 ? void 0 : currentAd.duration, "s"));
|
|
1078
|
+
if (currentAd) {
|
|
1079
|
+
fireTrackingPixels(currentAd.trackingUrls.impression);
|
|
1080
|
+
trackingFired.impression = true;
|
|
1081
|
+
}
|
|
767
1082
|
return [
|
|
768
1083
|
2,
|
|
769
1084
|
Promise.resolve()
|
|
@@ -786,7 +1101,7 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
786
1101
|
},
|
|
787
1102
|
play: function play() {
|
|
788
1103
|
return _async_to_generator(function() {
|
|
789
|
-
var contentVolume
|
|
1104
|
+
var contentVolume;
|
|
790
1105
|
return _ts_generator(this, function(_state) {
|
|
791
1106
|
if (!currentAd) {
|
|
792
1107
|
console.warn("[HlsAdPlayer] Cannot play: No ad loaded (no ads available)");
|
|
@@ -802,14 +1117,7 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
802
1117
|
adContainerEl === null || adContainerEl === void 0 ? void 0 : adContainerEl.appendChild(adVideoElement);
|
|
803
1118
|
setupAdEventListeners();
|
|
804
1119
|
}
|
|
805
|
-
|
|
806
|
-
impression: trackingFired.impression,
|
|
807
|
-
start: false,
|
|
808
|
-
firstQuartile: false,
|
|
809
|
-
midpoint: false,
|
|
810
|
-
thirdQuartile: false,
|
|
811
|
-
complete: false
|
|
812
|
-
};
|
|
1120
|
+
resetQuartileTracking(true);
|
|
813
1121
|
contentVolume = contentVideo.volume;
|
|
814
1122
|
originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
|
|
815
1123
|
if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
|
|
@@ -827,60 +1135,12 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
827
1135
|
adVideoElement.muted = originalMutedState;
|
|
828
1136
|
console.log("[HlsAdPlayer] Set ad video volume to ".concat(adVideoElement.volume, ", muted: ").concat(adVideoElement.muted, ", originalMutedState: ").concat(originalMutedState, ", contentVolume: ").concat(contentVolume));
|
|
829
1137
|
}
|
|
830
|
-
mediaFile = selectBestMediaFile(currentAd.mediaFiles);
|
|
831
|
-
if (!mediaFile) {
|
|
832
|
-
throw new Error("No media file available for ad");
|
|
833
|
-
}
|
|
834
1138
|
if (adContainerEl) {
|
|
835
1139
|
adContainerEl.style.display = "flex";
|
|
836
1140
|
adContainerEl.style.pointerEvents = "auto";
|
|
837
1141
|
}
|
|
838
1142
|
emit("content_pause");
|
|
839
|
-
|
|
840
|
-
console.log("[HlsAdPlayer] Loading ".concat(isHlsAd ? "HLS" : "progressive", " ad from: ").concat(mediaFile.url));
|
|
841
|
-
if (isHlsAd && import_hls.default.isSupported()) {
|
|
842
|
-
if (adHls) {
|
|
843
|
-
adHls.destroy();
|
|
844
|
-
}
|
|
845
|
-
adHls = new import_hls.default({
|
|
846
|
-
enableWorker: true,
|
|
847
|
-
lowLatencyMode: false
|
|
848
|
-
});
|
|
849
|
-
adHls.loadSource(mediaFile.url);
|
|
850
|
-
adHls.attachMedia(adVideoElement);
|
|
851
|
-
adHls.on(import_hls.default.Events.MANIFEST_PARSED, function() {
|
|
852
|
-
console.log("[HlsAdPlayer] HLS manifest parsed, starting playback");
|
|
853
|
-
adVideoElement.play().catch(function(error) {
|
|
854
|
-
console.error("[HlsAdPlayer] Error starting ad playback:", error);
|
|
855
|
-
handleAdError();
|
|
856
|
-
});
|
|
857
|
-
});
|
|
858
|
-
adHls.on(import_hls.default.Events.ERROR, function(event, data) {
|
|
859
|
-
console.error("[HlsAdPlayer] HLS error:", data);
|
|
860
|
-
if (data.fatal) {
|
|
861
|
-
handleAdError();
|
|
862
|
-
}
|
|
863
|
-
});
|
|
864
|
-
} else if (isHlsAd && adVideoElement.canPlayType("application/vnd.apple.mpegurl")) {
|
|
865
|
-
adVideoElement.src = mediaFile.url;
|
|
866
|
-
adVideoElement.play().catch(function(error) {
|
|
867
|
-
console.error("[HlsAdPlayer] Error starting ad playback:", error);
|
|
868
|
-
handleAdError();
|
|
869
|
-
});
|
|
870
|
-
} else if (!isHlsAd && isProgressiveMediaFile(mediaFile)) {
|
|
871
|
-
if (adHls) {
|
|
872
|
-
adHls.destroy();
|
|
873
|
-
adHls = void 0;
|
|
874
|
-
}
|
|
875
|
-
adVideoElement.src = mediaFile.url;
|
|
876
|
-
adVideoElement.load();
|
|
877
|
-
adVideoElement.play().catch(function(error) {
|
|
878
|
-
console.error("[HlsAdPlayer] Error starting progressive ad playback:", error);
|
|
879
|
-
handleAdError();
|
|
880
|
-
});
|
|
881
|
-
} else {
|
|
882
|
-
throw new Error("Unsupported ad media file type: ".concat(mediaFile.type));
|
|
883
|
-
}
|
|
1143
|
+
loadCurrentAdMedia();
|
|
884
1144
|
return [
|
|
885
1145
|
2,
|
|
886
1146
|
Promise.resolve()
|
|
@@ -955,6 +1215,8 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
955
1215
|
adVideoElement.src = "";
|
|
956
1216
|
}
|
|
957
1217
|
currentAd = void 0;
|
|
1218
|
+
podAds = [];
|
|
1219
|
+
podIndex = 0;
|
|
958
1220
|
return [
|
|
959
1221
|
2
|
|
960
1222
|
];
|
|
@@ -1004,6 +1266,8 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
1004
1266
|
}
|
|
1005
1267
|
adContainerEl = void 0;
|
|
1006
1268
|
currentAd = void 0;
|
|
1269
|
+
podAds = [];
|
|
1270
|
+
podIndex = 0;
|
|
1007
1271
|
listeners.clear();
|
|
1008
1272
|
preloadedAds.clear();
|
|
1009
1273
|
preloadingAds.clear();
|
|
@@ -1095,6 +1359,14 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
1095
1359
|
},
|
|
1096
1360
|
getLoadedAdId: function getLoadedAdId() {
|
|
1097
1361
|
return currentAd === null || currentAd === void 0 ? void 0 : currentAd.id;
|
|
1362
|
+
},
|
|
1363
|
+
getPodAdCount: function getPodAdCount() {
|
|
1364
|
+
return podAds.length;
|
|
1365
|
+
},
|
|
1366
|
+
getPodTotalDurationMs: function getPodTotalDurationMs() {
|
|
1367
|
+
return podAds.reduce(function(total, ad) {
|
|
1368
|
+
return total + (ad.duration > 0 ? ad.duration * 1e3 : 0);
|
|
1369
|
+
}, 0);
|
|
1098
1370
|
}
|
|
1099
1371
|
};
|
|
1100
1372
|
}
|