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/index.cjs
CHANGED
|
@@ -831,7 +831,8 @@ function fireTrackingPixels(urls, sessionId) {
|
|
|
831
831
|
});
|
|
832
832
|
}
|
|
833
833
|
// src/sdk/vastManager.ts
|
|
834
|
-
var
|
|
834
|
+
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";
|
|
835
|
+
var ADSTORM_API_URL = "https://adstorm.co/api-adstorm-dev/adstorm/ads/web";
|
|
835
836
|
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
836
837
|
var MAX_RETRIES = 3;
|
|
837
838
|
var RETRY_BACKOFF_MS = 1500;
|
|
@@ -839,6 +840,7 @@ function createVastManager() {
|
|
|
839
840
|
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
840
841
|
var _options_debug;
|
|
841
842
|
var initialized = false;
|
|
843
|
+
var vastTagUrl = VAST_TAG_URL_FALLBACK;
|
|
842
844
|
var debug = (_options_debug = options.debug) !== null && _options_debug !== void 0 ? _options_debug : false;
|
|
843
845
|
function log() {
|
|
844
846
|
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
@@ -860,17 +862,97 @@ function createVastManager() {
|
|
|
860
862
|
"[VastManager]"
|
|
861
863
|
].concat(_to_consumable_array(args)));
|
|
862
864
|
}
|
|
865
|
+
function fetchVastUrlFromApi() {
|
|
866
|
+
return _async_to_generator(function() {
|
|
867
|
+
var apiUrl, _data_response_ima_publisherdeskima, _data_response_ima, _data_response, res, data, payload, err;
|
|
868
|
+
return _ts_generator(this, function(_state) {
|
|
869
|
+
switch(_state.label){
|
|
870
|
+
case 0:
|
|
871
|
+
apiUrl = options.adstormApiUrl || ADSTORM_API_URL;
|
|
872
|
+
_state.label = 1;
|
|
873
|
+
case 1:
|
|
874
|
+
_state.trys.push([
|
|
875
|
+
1,
|
|
876
|
+
4,
|
|
877
|
+
,
|
|
878
|
+
5
|
|
879
|
+
]);
|
|
880
|
+
return [
|
|
881
|
+
4,
|
|
882
|
+
fetch(apiUrl, {
|
|
883
|
+
method: "GET",
|
|
884
|
+
headers: {
|
|
885
|
+
Authorization: "Bearer ".concat(options.licenseKey),
|
|
886
|
+
Accept: "application/json"
|
|
887
|
+
}
|
|
888
|
+
})
|
|
889
|
+
];
|
|
890
|
+
case 2:
|
|
891
|
+
res = _state.sent();
|
|
892
|
+
if (!res.ok) {
|
|
893
|
+
warn("Failed to fetch VAST URL from API (HTTP ".concat(res.status, "), using fallback"));
|
|
894
|
+
return [
|
|
895
|
+
2
|
|
896
|
+
];
|
|
897
|
+
}
|
|
898
|
+
return [
|
|
899
|
+
4,
|
|
900
|
+
res.json()
|
|
901
|
+
];
|
|
902
|
+
case 3:
|
|
903
|
+
data = _state.sent();
|
|
904
|
+
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;
|
|
905
|
+
if (payload) {
|
|
906
|
+
vastTagUrl = payload;
|
|
907
|
+
log("VAST tag URL fetched from API:", vastTagUrl.split("?")[0]);
|
|
908
|
+
} else {
|
|
909
|
+
log("API response had no VAST payload, using fallback URL");
|
|
910
|
+
}
|
|
911
|
+
return [
|
|
912
|
+
3,
|
|
913
|
+
5
|
|
914
|
+
];
|
|
915
|
+
case 4:
|
|
916
|
+
err = _state.sent();
|
|
917
|
+
warn("Error fetching VAST URL from API, using fallback:", err);
|
|
918
|
+
return [
|
|
919
|
+
3,
|
|
920
|
+
5
|
|
921
|
+
];
|
|
922
|
+
case 5:
|
|
923
|
+
return [
|
|
924
|
+
2
|
|
925
|
+
];
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
})();
|
|
929
|
+
}
|
|
863
930
|
function initialize() {
|
|
864
931
|
return _async_to_generator(function() {
|
|
865
932
|
return _ts_generator(this, function(_state) {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
933
|
+
switch(_state.label){
|
|
934
|
+
case 0:
|
|
935
|
+
if (initialized) return [
|
|
936
|
+
2
|
|
937
|
+
];
|
|
938
|
+
initialized = true;
|
|
939
|
+
if (!options.licenseKey) return [
|
|
940
|
+
3,
|
|
941
|
+
2
|
|
942
|
+
];
|
|
943
|
+
return [
|
|
944
|
+
4,
|
|
945
|
+
fetchVastUrlFromApi()
|
|
946
|
+
];
|
|
947
|
+
case 1:
|
|
948
|
+
_state.sent();
|
|
949
|
+
_state.label = 2;
|
|
950
|
+
case 2:
|
|
951
|
+
log("Initialized, VAST tag URL:", vastTagUrl.split("?")[0]);
|
|
952
|
+
return [
|
|
953
|
+
2
|
|
954
|
+
];
|
|
955
|
+
}
|
|
874
956
|
});
|
|
875
957
|
})();
|
|
876
958
|
}
|
|
@@ -884,7 +966,7 @@ function createVastManager() {
|
|
|
884
966
|
throw new Error("VastManager not initialized. Call initialize() first.");
|
|
885
967
|
}
|
|
886
968
|
correlator = Math.floor(Math.random() * 1e12).toString();
|
|
887
|
-
url =
|
|
969
|
+
url = vastTagUrl.replace("[placeholder]", correlator);
|
|
888
970
|
log("Fetching VAST tag, correlator:", correlator);
|
|
889
971
|
controller = typeof AbortController !== "undefined" ? new AbortController() : null;
|
|
890
972
|
timeoutId = setTimeout(function() {
|
|
@@ -1078,6 +1160,7 @@ function createVastManager() {
|
|
|
1078
1160
|
}
|
|
1079
1161
|
function destroy() {
|
|
1080
1162
|
initialized = false;
|
|
1163
|
+
vastTagUrl = VAST_TAG_URL_FALLBACK;
|
|
1081
1164
|
log("Destroyed");
|
|
1082
1165
|
}
|
|
1083
1166
|
return {
|
|
@@ -1119,6 +1202,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1119
1202
|
var adHls;
|
|
1120
1203
|
var adContainerEl;
|
|
1121
1204
|
var currentAd;
|
|
1205
|
+
var currentMediaFile;
|
|
1122
1206
|
var sessionId;
|
|
1123
1207
|
var destroyed = false;
|
|
1124
1208
|
var tornDown = false;
|
|
@@ -1365,7 +1449,12 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1365
1449
|
adContainerEl.style.display = "none";
|
|
1366
1450
|
adContainerEl.style.pointerEvents = "none";
|
|
1367
1451
|
}
|
|
1368
|
-
emit("ad_impression"
|
|
1452
|
+
emit("ad_impression", {
|
|
1453
|
+
adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
|
|
1454
|
+
adTitle: currentAd === null || currentAd === void 0 ? void 0 : currentAd.title,
|
|
1455
|
+
adUrl: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.url,
|
|
1456
|
+
mediaType: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.type
|
|
1457
|
+
});
|
|
1369
1458
|
emit("content_resume");
|
|
1370
1459
|
}
|
|
1371
1460
|
function handleAdError() {
|
|
@@ -1387,6 +1476,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1387
1476
|
adHls.destroy();
|
|
1388
1477
|
adHls = void 0;
|
|
1389
1478
|
}
|
|
1479
|
+
currentMediaFile = void 0;
|
|
1390
1480
|
if (adVideoElement) {
|
|
1391
1481
|
if (singleElementMode && adVideoElement === contentVideo) {
|
|
1392
1482
|
contentVideo.pause();
|
|
@@ -1551,6 +1641,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1551
1641
|
adVideoElement.volume = Math.max(0, Math.min(1, adVolume2));
|
|
1552
1642
|
adVideoElement.muted = false;
|
|
1553
1643
|
mediaFile2 = selectBestMediaFile(ad.mediaFiles);
|
|
1644
|
+
currentMediaFile = mediaFile2;
|
|
1554
1645
|
if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile2.url));
|
|
1555
1646
|
startPlayback(mediaFile2);
|
|
1556
1647
|
return [
|
|
@@ -1597,6 +1688,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1597
1688
|
}
|
|
1598
1689
|
emit("content_pause");
|
|
1599
1690
|
mediaFile = selectBestMediaFile(ad.mediaFiles);
|
|
1691
|
+
currentMediaFile = mediaFile;
|
|
1600
1692
|
if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile.url));
|
|
1601
1693
|
startPlayback(mediaFile);
|
|
1602
1694
|
return [
|
|
@@ -1762,6 +1854,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1762
1854
|
];
|
|
1763
1855
|
mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
|
|
1764
1856
|
teardownCurrentPlayback();
|
|
1857
|
+
currentMediaFile = slot.mediaFile;
|
|
1765
1858
|
adVideoElement = contentVideo;
|
|
1766
1859
|
adHls = void 0;
|
|
1767
1860
|
adPlaying = true;
|
|
@@ -1796,6 +1889,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1796
1889
|
case 2:
|
|
1797
1890
|
if (smartTVMode && !slot.videoEl) {
|
|
1798
1891
|
teardownCurrentPlayback();
|
|
1892
|
+
currentMediaFile = slot.mediaFile;
|
|
1799
1893
|
if (adVideoElement) {
|
|
1800
1894
|
adVideoElement.remove();
|
|
1801
1895
|
adVideoElement = void 0;
|
|
@@ -1827,6 +1921,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1827
1921
|
];
|
|
1828
1922
|
}
|
|
1829
1923
|
teardownCurrentPlayback();
|
|
1924
|
+
currentMediaFile = slot.mediaFile;
|
|
1830
1925
|
if (adVideoElement && adVideoElement !== slot.videoEl) {
|
|
1831
1926
|
adVideoElement.remove();
|
|
1832
1927
|
}
|
|
@@ -1958,6 +2053,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1958
2053
|
}
|
|
1959
2054
|
}
|
|
1960
2055
|
currentAd = void 0;
|
|
2056
|
+
currentMediaFile = void 0;
|
|
1961
2057
|
tornDown = false;
|
|
1962
2058
|
return [
|
|
1963
2059
|
2
|
|
@@ -2010,6 +2106,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
2010
2106
|
}
|
|
2011
2107
|
adContainerEl = void 0;
|
|
2012
2108
|
currentAd = void 0;
|
|
2109
|
+
currentMediaFile = void 0;
|
|
2013
2110
|
listeners.clear();
|
|
2014
2111
|
},
|
|
2015
2112
|
isAdPlaying: function isAdPlaying() {
|
|
@@ -3276,9 +3373,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3276
3373
|
this.video = config.videoElement;
|
|
3277
3374
|
this.adTransitionGapMs = (_this_config_adTransitionGapMs = this.config.adTransitionGapMs) !== null && _this_config_adTransitionGapMs !== void 0 ? _this_config_adTransitionGapMs : 100;
|
|
3278
3375
|
logBrowserInfo(config.debugAdTiming);
|
|
3279
|
-
this.vastManager = createVastManager(
|
|
3280
|
-
debug: !!config.debugAdTiming
|
|
3281
|
-
}
|
|
3376
|
+
this.vastManager = createVastManager(_object_spread({
|
|
3377
|
+
debug: config.debugAdTiming !== void 0 ? !!config.debugAdTiming : false
|
|
3378
|
+
}, config.licenseKey ? {
|
|
3379
|
+
licenseKey: config.licenseKey
|
|
3380
|
+
} : {}));
|
|
3282
3381
|
var browserForAdLayer = detectBrowser();
|
|
3283
3382
|
var isSinglePipeline = browserForAdLayer.isSmartTV || !!this.config.singlePipelineMode;
|
|
3284
3383
|
this.adLayer = createVastAdLayer(this.video, {
|
|
@@ -3329,6 +3428,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3329
3428
|
this.attach();
|
|
3330
3429
|
}
|
|
3331
3430
|
this.initializeTracking();
|
|
3431
|
+
if (!this.config.disableAds) {
|
|
3432
|
+
this.vastManager.initialize().catch(function() {});
|
|
3433
|
+
}
|
|
3332
3434
|
if (!this.shouldUseNativeHls()) return [
|
|
3333
3435
|
3,
|
|
3334
3436
|
3
|
|
@@ -3782,13 +3884,18 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3782
3884
|
key: "attachAdLayerEventListeners",
|
|
3783
3885
|
value: function attachAdLayerEventListeners() {
|
|
3784
3886
|
var _this = this;
|
|
3785
|
-
this.adLayer.on("ad_impression", function() {
|
|
3887
|
+
this.adLayer.on("ad_impression", function(payload) {
|
|
3786
3888
|
if (_this.config.licenseKey) {
|
|
3889
|
+
var _ref;
|
|
3890
|
+
var adUrl = (_ref = payload === null || payload === void 0 ? void 0 : payload.adUrl) !== null && _ref !== void 0 ? _ref : _this.lastServedAdUrl;
|
|
3891
|
+
if (adUrl) {
|
|
3892
|
+
_this.lastServedAdUrl = adUrl;
|
|
3893
|
+
}
|
|
3787
3894
|
sendAdImpressionTracking(_this.config.licenseKey, _object_spread_props(_object_spread({
|
|
3788
3895
|
source: _this.getAdSource(),
|
|
3789
3896
|
adIndex: _this.currentAdIndex
|
|
3790
|
-
},
|
|
3791
|
-
adUrl:
|
|
3897
|
+
}, adUrl ? {
|
|
3898
|
+
adUrl: adUrl
|
|
3792
3899
|
} : {}), {
|
|
3793
3900
|
timestamp: /* @__PURE__ */ new Date().toISOString()
|
|
3794
3901
|
}), _this.getAnalyticsContext());
|