stormcloud-video-player 0.6.9 → 0.6.11
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 +124 -17
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +124 -17
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +124 -17
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.cjs +124 -17
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/index.cjs +124 -17
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/vastAdLayer.cjs +15 -1
- package/lib/sdk/vastAdLayer.cjs.map +1 -1
- package/lib/sdk/vastManager.cjs +93 -10
- package/lib/sdk/vastManager.cjs.map +1 -1
- package/lib/sdk/vastManager.d.cts +2 -0
- package/lib/ui/StormcloudVideoPlayer.cjs +124 -17
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/package.json +1 -1
package/lib/players/index.cjs
CHANGED
|
@@ -737,7 +737,8 @@ function fireTrackingPixels(urls, sessionId) {
|
|
|
737
737
|
});
|
|
738
738
|
}
|
|
739
739
|
// src/sdk/vastManager.ts
|
|
740
|
-
var
|
|
740
|
+
var VAST_TAG_URL_FALLBACK = "https://pubads.g.doubleclick.net/gampad/ads?iu=/21821455290/Airy-Android&description_url=http%3A%2F%2Fairy.tv&tfcd=0&npa=0&sz=1x1%7C300x250%7C400x300%7C640x480&gdfp_req=1&unviewed_position_start=1&correlator=[placeholder]&vpos=preroll&output=vast&env=vp&vpmute=0&vpa=click";
|
|
741
|
+
var ADSTORM_API_URL = "https://adstorm.co/api-adstorm-dev/adstorm/ads/web";
|
|
741
742
|
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
742
743
|
var MAX_RETRIES = 3;
|
|
743
744
|
var RETRY_BACKOFF_MS = 1500;
|
|
@@ -745,6 +746,7 @@ function createVastManager() {
|
|
|
745
746
|
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
746
747
|
var _options_debug;
|
|
747
748
|
var initialized = false;
|
|
749
|
+
var vastTagUrl = VAST_TAG_URL_FALLBACK;
|
|
748
750
|
var debug = (_options_debug = options.debug) !== null && _options_debug !== void 0 ? _options_debug : false;
|
|
749
751
|
function log() {
|
|
750
752
|
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
@@ -766,17 +768,97 @@ function createVastManager() {
|
|
|
766
768
|
"[VastManager]"
|
|
767
769
|
].concat(_to_consumable_array(args)));
|
|
768
770
|
}
|
|
771
|
+
function fetchVastUrlFromApi() {
|
|
772
|
+
return _async_to_generator(function() {
|
|
773
|
+
var apiUrl, _data_response_ima_publisherdeskima, _data_response_ima, _data_response, res, data, payload, err;
|
|
774
|
+
return _ts_generator(this, function(_state) {
|
|
775
|
+
switch(_state.label){
|
|
776
|
+
case 0:
|
|
777
|
+
apiUrl = options.adstormApiUrl || ADSTORM_API_URL;
|
|
778
|
+
_state.label = 1;
|
|
779
|
+
case 1:
|
|
780
|
+
_state.trys.push([
|
|
781
|
+
1,
|
|
782
|
+
4,
|
|
783
|
+
,
|
|
784
|
+
5
|
|
785
|
+
]);
|
|
786
|
+
return [
|
|
787
|
+
4,
|
|
788
|
+
fetch(apiUrl, {
|
|
789
|
+
method: "GET",
|
|
790
|
+
headers: {
|
|
791
|
+
Authorization: "Bearer ".concat(options.licenseKey),
|
|
792
|
+
Accept: "application/json"
|
|
793
|
+
}
|
|
794
|
+
})
|
|
795
|
+
];
|
|
796
|
+
case 2:
|
|
797
|
+
res = _state.sent();
|
|
798
|
+
if (!res.ok) {
|
|
799
|
+
warn("Failed to fetch VAST URL from API (HTTP ".concat(res.status, "), using fallback"));
|
|
800
|
+
return [
|
|
801
|
+
2
|
|
802
|
+
];
|
|
803
|
+
}
|
|
804
|
+
return [
|
|
805
|
+
4,
|
|
806
|
+
res.json()
|
|
807
|
+
];
|
|
808
|
+
case 3:
|
|
809
|
+
data = _state.sent();
|
|
810
|
+
payload = data === null || data === void 0 ? void 0 : (_data_response = data.response) === null || _data_response === void 0 ? void 0 : (_data_response_ima = _data_response.ima) === null || _data_response_ima === void 0 ? void 0 : (_data_response_ima_publisherdeskima = _data_response_ima["publisherdesk.ima"]) === null || _data_response_ima_publisherdeskima === void 0 ? void 0 : _data_response_ima_publisherdeskima.payload;
|
|
811
|
+
if (payload) {
|
|
812
|
+
vastTagUrl = payload;
|
|
813
|
+
log("VAST tag URL fetched from API:", vastTagUrl.split("?")[0]);
|
|
814
|
+
} else {
|
|
815
|
+
log("API response had no VAST payload, using fallback URL");
|
|
816
|
+
}
|
|
817
|
+
return [
|
|
818
|
+
3,
|
|
819
|
+
5
|
|
820
|
+
];
|
|
821
|
+
case 4:
|
|
822
|
+
err = _state.sent();
|
|
823
|
+
warn("Error fetching VAST URL from API, using fallback:", err);
|
|
824
|
+
return [
|
|
825
|
+
3,
|
|
826
|
+
5
|
|
827
|
+
];
|
|
828
|
+
case 5:
|
|
829
|
+
return [
|
|
830
|
+
2
|
|
831
|
+
];
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
})();
|
|
835
|
+
}
|
|
769
836
|
function initialize() {
|
|
770
837
|
return _async_to_generator(function() {
|
|
771
838
|
return _ts_generator(this, function(_state) {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
839
|
+
switch(_state.label){
|
|
840
|
+
case 0:
|
|
841
|
+
if (initialized) return [
|
|
842
|
+
2
|
|
843
|
+
];
|
|
844
|
+
initialized = true;
|
|
845
|
+
if (!options.licenseKey) return [
|
|
846
|
+
3,
|
|
847
|
+
2
|
|
848
|
+
];
|
|
849
|
+
return [
|
|
850
|
+
4,
|
|
851
|
+
fetchVastUrlFromApi()
|
|
852
|
+
];
|
|
853
|
+
case 1:
|
|
854
|
+
_state.sent();
|
|
855
|
+
_state.label = 2;
|
|
856
|
+
case 2:
|
|
857
|
+
log("Initialized, VAST tag URL:", vastTagUrl.split("?")[0]);
|
|
858
|
+
return [
|
|
859
|
+
2
|
|
860
|
+
];
|
|
861
|
+
}
|
|
780
862
|
});
|
|
781
863
|
})();
|
|
782
864
|
}
|
|
@@ -790,7 +872,7 @@ function createVastManager() {
|
|
|
790
872
|
throw new Error("VastManager not initialized. Call initialize() first.");
|
|
791
873
|
}
|
|
792
874
|
correlator = Math.floor(Math.random() * 1e12).toString();
|
|
793
|
-
url =
|
|
875
|
+
url = vastTagUrl.replace("[placeholder]", correlator);
|
|
794
876
|
log("Fetching VAST tag, correlator:", correlator);
|
|
795
877
|
controller = typeof AbortController !== "undefined" ? new AbortController() : null;
|
|
796
878
|
timeoutId = setTimeout(function() {
|
|
@@ -984,6 +1066,7 @@ function createVastManager() {
|
|
|
984
1066
|
}
|
|
985
1067
|
function destroy() {
|
|
986
1068
|
initialized = false;
|
|
1069
|
+
vastTagUrl = VAST_TAG_URL_FALLBACK;
|
|
987
1070
|
log("Destroyed");
|
|
988
1071
|
}
|
|
989
1072
|
return {
|
|
@@ -1025,6 +1108,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1025
1108
|
var adHls;
|
|
1026
1109
|
var adContainerEl;
|
|
1027
1110
|
var currentAd;
|
|
1111
|
+
var currentMediaFile;
|
|
1028
1112
|
var sessionId;
|
|
1029
1113
|
var destroyed = false;
|
|
1030
1114
|
var tornDown = false;
|
|
@@ -1271,7 +1355,12 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1271
1355
|
adContainerEl.style.display = "none";
|
|
1272
1356
|
adContainerEl.style.pointerEvents = "none";
|
|
1273
1357
|
}
|
|
1274
|
-
emit("ad_impression"
|
|
1358
|
+
emit("ad_impression", {
|
|
1359
|
+
adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
|
|
1360
|
+
adTitle: currentAd === null || currentAd === void 0 ? void 0 : currentAd.title,
|
|
1361
|
+
adUrl: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.url,
|
|
1362
|
+
mediaType: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.type
|
|
1363
|
+
});
|
|
1275
1364
|
emit("content_resume");
|
|
1276
1365
|
}
|
|
1277
1366
|
function handleAdError() {
|
|
@@ -1293,6 +1382,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1293
1382
|
adHls.destroy();
|
|
1294
1383
|
adHls = void 0;
|
|
1295
1384
|
}
|
|
1385
|
+
currentMediaFile = void 0;
|
|
1296
1386
|
if (adVideoElement) {
|
|
1297
1387
|
if (singleElementMode && adVideoElement === contentVideo) {
|
|
1298
1388
|
contentVideo.pause();
|
|
@@ -1457,6 +1547,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1457
1547
|
adVideoElement.volume = Math.max(0, Math.min(1, adVolume2));
|
|
1458
1548
|
adVideoElement.muted = false;
|
|
1459
1549
|
mediaFile2 = selectBestMediaFile(ad.mediaFiles);
|
|
1550
|
+
currentMediaFile = mediaFile2;
|
|
1460
1551
|
if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile2.url));
|
|
1461
1552
|
startPlayback(mediaFile2);
|
|
1462
1553
|
return [
|
|
@@ -1503,6 +1594,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1503
1594
|
}
|
|
1504
1595
|
emit("content_pause");
|
|
1505
1596
|
mediaFile = selectBestMediaFile(ad.mediaFiles);
|
|
1597
|
+
currentMediaFile = mediaFile;
|
|
1506
1598
|
if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile.url));
|
|
1507
1599
|
startPlayback(mediaFile);
|
|
1508
1600
|
return [
|
|
@@ -1668,6 +1760,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1668
1760
|
];
|
|
1669
1761
|
mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
|
|
1670
1762
|
teardownCurrentPlayback();
|
|
1763
|
+
currentMediaFile = slot.mediaFile;
|
|
1671
1764
|
adVideoElement = contentVideo;
|
|
1672
1765
|
adHls = void 0;
|
|
1673
1766
|
adPlaying = true;
|
|
@@ -1702,6 +1795,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1702
1795
|
case 2:
|
|
1703
1796
|
if (smartTVMode && !slot.videoEl) {
|
|
1704
1797
|
teardownCurrentPlayback();
|
|
1798
|
+
currentMediaFile = slot.mediaFile;
|
|
1705
1799
|
if (adVideoElement) {
|
|
1706
1800
|
adVideoElement.remove();
|
|
1707
1801
|
adVideoElement = void 0;
|
|
@@ -1733,6 +1827,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1733
1827
|
];
|
|
1734
1828
|
}
|
|
1735
1829
|
teardownCurrentPlayback();
|
|
1830
|
+
currentMediaFile = slot.mediaFile;
|
|
1736
1831
|
if (adVideoElement && adVideoElement !== slot.videoEl) {
|
|
1737
1832
|
adVideoElement.remove();
|
|
1738
1833
|
}
|
|
@@ -1864,6 +1959,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1864
1959
|
}
|
|
1865
1960
|
}
|
|
1866
1961
|
currentAd = void 0;
|
|
1962
|
+
currentMediaFile = void 0;
|
|
1867
1963
|
tornDown = false;
|
|
1868
1964
|
return [
|
|
1869
1965
|
2
|
|
@@ -1916,6 +2012,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1916
2012
|
}
|
|
1917
2013
|
adContainerEl = void 0;
|
|
1918
2014
|
currentAd = void 0;
|
|
2015
|
+
currentMediaFile = void 0;
|
|
1919
2016
|
listeners.clear();
|
|
1920
2017
|
},
|
|
1921
2018
|
isAdPlaying: function isAdPlaying() {
|
|
@@ -3157,9 +3254,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3157
3254
|
this.video = config.videoElement;
|
|
3158
3255
|
this.adTransitionGapMs = (_this_config_adTransitionGapMs = this.config.adTransitionGapMs) !== null && _this_config_adTransitionGapMs !== void 0 ? _this_config_adTransitionGapMs : 100;
|
|
3159
3256
|
logBrowserInfo(config.debugAdTiming);
|
|
3160
|
-
this.vastManager = createVastManager(
|
|
3161
|
-
debug: !!config.debugAdTiming
|
|
3162
|
-
}
|
|
3257
|
+
this.vastManager = createVastManager(_object_spread({
|
|
3258
|
+
debug: config.debugAdTiming !== void 0 ? !!config.debugAdTiming : false
|
|
3259
|
+
}, config.licenseKey ? {
|
|
3260
|
+
licenseKey: config.licenseKey
|
|
3261
|
+
} : {}));
|
|
3163
3262
|
var browserForAdLayer = detectBrowser();
|
|
3164
3263
|
var isSinglePipeline = browserForAdLayer.isSmartTV || !!this.config.singlePipelineMode;
|
|
3165
3264
|
this.adLayer = createVastAdLayer(this.video, {
|
|
@@ -3210,6 +3309,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3210
3309
|
this.attach();
|
|
3211
3310
|
}
|
|
3212
3311
|
this.initializeTracking();
|
|
3312
|
+
if (!this.config.disableAds) {
|
|
3313
|
+
this.vastManager.initialize().catch(function() {});
|
|
3314
|
+
}
|
|
3213
3315
|
if (!this.shouldUseNativeHls()) return [
|
|
3214
3316
|
3,
|
|
3215
3317
|
3
|
|
@@ -3663,13 +3765,18 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3663
3765
|
key: "attachAdLayerEventListeners",
|
|
3664
3766
|
value: function attachAdLayerEventListeners() {
|
|
3665
3767
|
var _this = this;
|
|
3666
|
-
this.adLayer.on("ad_impression", function() {
|
|
3768
|
+
this.adLayer.on("ad_impression", function(payload) {
|
|
3667
3769
|
if (_this.config.licenseKey) {
|
|
3770
|
+
var _ref;
|
|
3771
|
+
var adUrl = (_ref = payload === null || payload === void 0 ? void 0 : payload.adUrl) !== null && _ref !== void 0 ? _ref : _this.lastServedAdUrl;
|
|
3772
|
+
if (adUrl) {
|
|
3773
|
+
_this.lastServedAdUrl = adUrl;
|
|
3774
|
+
}
|
|
3668
3775
|
sendAdImpressionTracking(_this.config.licenseKey, _object_spread_props(_object_spread({
|
|
3669
3776
|
source: _this.getAdSource(),
|
|
3670
3777
|
adIndex: _this.currentAdIndex
|
|
3671
|
-
},
|
|
3672
|
-
adUrl:
|
|
3778
|
+
}, adUrl ? {
|
|
3779
|
+
adUrl: adUrl
|
|
3673
3780
|
} : {}), {
|
|
3674
3781
|
timestamp: /* @__PURE__ */ new Date().toISOString()
|
|
3675
3782
|
}), _this.getAnalyticsContext());
|