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.d.cts
CHANGED
|
@@ -4022,6 +4022,8 @@ declare function supportsFeature(feature: string): boolean;
|
|
|
4022
4022
|
|
|
4023
4023
|
interface VastManagerOptions {
|
|
4024
4024
|
debug?: boolean;
|
|
4025
|
+
licenseKey?: string;
|
|
4026
|
+
adstormApiUrl?: string;
|
|
4025
4027
|
}
|
|
4026
4028
|
declare function createVastManager(options?: VastManagerOptions): VastManager;
|
|
4027
4029
|
|
package/lib/index.d.ts
CHANGED
|
@@ -4022,6 +4022,8 @@ declare function supportsFeature(feature: string): boolean;
|
|
|
4022
4022
|
|
|
4023
4023
|
interface VastManagerOptions {
|
|
4024
4024
|
debug?: boolean;
|
|
4025
|
+
licenseKey?: string;
|
|
4026
|
+
adstormApiUrl?: string;
|
|
4025
4027
|
}
|
|
4026
4028
|
declare function createVastManager(options?: VastManagerOptions): VastManager;
|
|
4027
4029
|
|
package/lib/index.js
CHANGED
|
@@ -671,7 +671,8 @@ function fireTrackingPixels(urls, sessionId) {
|
|
|
671
671
|
});
|
|
672
672
|
}
|
|
673
673
|
// src/sdk/vastManager.ts
|
|
674
|
-
var
|
|
674
|
+
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";
|
|
675
|
+
var ADSTORM_API_URL = "https://adstorm.co/api-adstorm-dev/adstorm/ads/web";
|
|
675
676
|
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
676
677
|
var MAX_RETRIES = 3;
|
|
677
678
|
var RETRY_BACKOFF_MS = 1500;
|
|
@@ -679,6 +680,7 @@ function createVastManager() {
|
|
|
679
680
|
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
680
681
|
var _options_debug;
|
|
681
682
|
var initialized = false;
|
|
683
|
+
var vastTagUrl = VAST_TAG_URL_FALLBACK;
|
|
682
684
|
var debug = (_options_debug = options.debug) !== null && _options_debug !== void 0 ? _options_debug : false;
|
|
683
685
|
function log() {
|
|
684
686
|
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
@@ -700,17 +702,97 @@ function createVastManager() {
|
|
|
700
702
|
"[VastManager]"
|
|
701
703
|
].concat(_to_consumable_array(args)));
|
|
702
704
|
}
|
|
705
|
+
function fetchVastUrlFromApi() {
|
|
706
|
+
return _async_to_generator(function() {
|
|
707
|
+
var apiUrl, _data_response_ima_publisherdeskima, _data_response_ima, _data_response, res, data, payload, err;
|
|
708
|
+
return _ts_generator(this, function(_state) {
|
|
709
|
+
switch(_state.label){
|
|
710
|
+
case 0:
|
|
711
|
+
apiUrl = options.adstormApiUrl || ADSTORM_API_URL;
|
|
712
|
+
_state.label = 1;
|
|
713
|
+
case 1:
|
|
714
|
+
_state.trys.push([
|
|
715
|
+
1,
|
|
716
|
+
4,
|
|
717
|
+
,
|
|
718
|
+
5
|
|
719
|
+
]);
|
|
720
|
+
return [
|
|
721
|
+
4,
|
|
722
|
+
fetch(apiUrl, {
|
|
723
|
+
method: "GET",
|
|
724
|
+
headers: {
|
|
725
|
+
Authorization: "Bearer ".concat(options.licenseKey),
|
|
726
|
+
Accept: "application/json"
|
|
727
|
+
}
|
|
728
|
+
})
|
|
729
|
+
];
|
|
730
|
+
case 2:
|
|
731
|
+
res = _state.sent();
|
|
732
|
+
if (!res.ok) {
|
|
733
|
+
warn("Failed to fetch VAST URL from API (HTTP ".concat(res.status, "), using fallback"));
|
|
734
|
+
return [
|
|
735
|
+
2
|
|
736
|
+
];
|
|
737
|
+
}
|
|
738
|
+
return [
|
|
739
|
+
4,
|
|
740
|
+
res.json()
|
|
741
|
+
];
|
|
742
|
+
case 3:
|
|
743
|
+
data = _state.sent();
|
|
744
|
+
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;
|
|
745
|
+
if (payload) {
|
|
746
|
+
vastTagUrl = payload;
|
|
747
|
+
log("VAST tag URL fetched from API:", vastTagUrl.split("?")[0]);
|
|
748
|
+
} else {
|
|
749
|
+
log("API response had no VAST payload, using fallback URL");
|
|
750
|
+
}
|
|
751
|
+
return [
|
|
752
|
+
3,
|
|
753
|
+
5
|
|
754
|
+
];
|
|
755
|
+
case 4:
|
|
756
|
+
err = _state.sent();
|
|
757
|
+
warn("Error fetching VAST URL from API, using fallback:", err);
|
|
758
|
+
return [
|
|
759
|
+
3,
|
|
760
|
+
5
|
|
761
|
+
];
|
|
762
|
+
case 5:
|
|
763
|
+
return [
|
|
764
|
+
2
|
|
765
|
+
];
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
})();
|
|
769
|
+
}
|
|
703
770
|
function initialize() {
|
|
704
771
|
return _async_to_generator(function() {
|
|
705
772
|
return _ts_generator(this, function(_state) {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
773
|
+
switch(_state.label){
|
|
774
|
+
case 0:
|
|
775
|
+
if (initialized) return [
|
|
776
|
+
2
|
|
777
|
+
];
|
|
778
|
+
initialized = true;
|
|
779
|
+
if (!options.licenseKey) return [
|
|
780
|
+
3,
|
|
781
|
+
2
|
|
782
|
+
];
|
|
783
|
+
return [
|
|
784
|
+
4,
|
|
785
|
+
fetchVastUrlFromApi()
|
|
786
|
+
];
|
|
787
|
+
case 1:
|
|
788
|
+
_state.sent();
|
|
789
|
+
_state.label = 2;
|
|
790
|
+
case 2:
|
|
791
|
+
log("Initialized, VAST tag URL:", vastTagUrl.split("?")[0]);
|
|
792
|
+
return [
|
|
793
|
+
2
|
|
794
|
+
];
|
|
795
|
+
}
|
|
714
796
|
});
|
|
715
797
|
})();
|
|
716
798
|
}
|
|
@@ -724,7 +806,7 @@ function createVastManager() {
|
|
|
724
806
|
throw new Error("VastManager not initialized. Call initialize() first.");
|
|
725
807
|
}
|
|
726
808
|
correlator = Math.floor(Math.random() * 1e12).toString();
|
|
727
|
-
url =
|
|
809
|
+
url = vastTagUrl.replace("[placeholder]", correlator);
|
|
728
810
|
log("Fetching VAST tag, correlator:", correlator);
|
|
729
811
|
controller = typeof AbortController !== "undefined" ? new AbortController() : null;
|
|
730
812
|
timeoutId = setTimeout(function() {
|
|
@@ -918,6 +1000,7 @@ function createVastManager() {
|
|
|
918
1000
|
}
|
|
919
1001
|
function destroy() {
|
|
920
1002
|
initialized = false;
|
|
1003
|
+
vastTagUrl = VAST_TAG_URL_FALLBACK;
|
|
921
1004
|
log("Destroyed");
|
|
922
1005
|
}
|
|
923
1006
|
return {
|
|
@@ -959,6 +1042,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
959
1042
|
var adHls;
|
|
960
1043
|
var adContainerEl;
|
|
961
1044
|
var currentAd;
|
|
1045
|
+
var currentMediaFile;
|
|
962
1046
|
var sessionId;
|
|
963
1047
|
var destroyed = false;
|
|
964
1048
|
var tornDown = false;
|
|
@@ -1205,7 +1289,12 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1205
1289
|
adContainerEl.style.display = "none";
|
|
1206
1290
|
adContainerEl.style.pointerEvents = "none";
|
|
1207
1291
|
}
|
|
1208
|
-
emit("ad_impression"
|
|
1292
|
+
emit("ad_impression", {
|
|
1293
|
+
adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
|
|
1294
|
+
adTitle: currentAd === null || currentAd === void 0 ? void 0 : currentAd.title,
|
|
1295
|
+
adUrl: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.url,
|
|
1296
|
+
mediaType: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.type
|
|
1297
|
+
});
|
|
1209
1298
|
emit("content_resume");
|
|
1210
1299
|
}
|
|
1211
1300
|
function handleAdError() {
|
|
@@ -1227,6 +1316,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1227
1316
|
adHls.destroy();
|
|
1228
1317
|
adHls = void 0;
|
|
1229
1318
|
}
|
|
1319
|
+
currentMediaFile = void 0;
|
|
1230
1320
|
if (adVideoElement) {
|
|
1231
1321
|
if (singleElementMode && adVideoElement === contentVideo) {
|
|
1232
1322
|
contentVideo.pause();
|
|
@@ -1391,6 +1481,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1391
1481
|
adVideoElement.volume = Math.max(0, Math.min(1, adVolume2));
|
|
1392
1482
|
adVideoElement.muted = false;
|
|
1393
1483
|
mediaFile2 = selectBestMediaFile(ad.mediaFiles);
|
|
1484
|
+
currentMediaFile = mediaFile2;
|
|
1394
1485
|
if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile2.url));
|
|
1395
1486
|
startPlayback(mediaFile2);
|
|
1396
1487
|
return [
|
|
@@ -1437,6 +1528,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1437
1528
|
}
|
|
1438
1529
|
emit("content_pause");
|
|
1439
1530
|
mediaFile = selectBestMediaFile(ad.mediaFiles);
|
|
1531
|
+
currentMediaFile = mediaFile;
|
|
1440
1532
|
if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile.url));
|
|
1441
1533
|
startPlayback(mediaFile);
|
|
1442
1534
|
return [
|
|
@@ -1602,6 +1694,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1602
1694
|
];
|
|
1603
1695
|
mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
|
|
1604
1696
|
teardownCurrentPlayback();
|
|
1697
|
+
currentMediaFile = slot.mediaFile;
|
|
1605
1698
|
adVideoElement = contentVideo;
|
|
1606
1699
|
adHls = void 0;
|
|
1607
1700
|
adPlaying = true;
|
|
@@ -1636,6 +1729,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1636
1729
|
case 2:
|
|
1637
1730
|
if (smartTVMode && !slot.videoEl) {
|
|
1638
1731
|
teardownCurrentPlayback();
|
|
1732
|
+
currentMediaFile = slot.mediaFile;
|
|
1639
1733
|
if (adVideoElement) {
|
|
1640
1734
|
adVideoElement.remove();
|
|
1641
1735
|
adVideoElement = void 0;
|
|
@@ -1667,6 +1761,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1667
1761
|
];
|
|
1668
1762
|
}
|
|
1669
1763
|
teardownCurrentPlayback();
|
|
1764
|
+
currentMediaFile = slot.mediaFile;
|
|
1670
1765
|
if (adVideoElement && adVideoElement !== slot.videoEl) {
|
|
1671
1766
|
adVideoElement.remove();
|
|
1672
1767
|
}
|
|
@@ -1798,6 +1893,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1798
1893
|
}
|
|
1799
1894
|
}
|
|
1800
1895
|
currentAd = void 0;
|
|
1896
|
+
currentMediaFile = void 0;
|
|
1801
1897
|
tornDown = false;
|
|
1802
1898
|
return [
|
|
1803
1899
|
2
|
|
@@ -1850,6 +1946,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1850
1946
|
}
|
|
1851
1947
|
adContainerEl = void 0;
|
|
1852
1948
|
currentAd = void 0;
|
|
1949
|
+
currentMediaFile = void 0;
|
|
1853
1950
|
listeners.clear();
|
|
1854
1951
|
},
|
|
1855
1952
|
isAdPlaying: function isAdPlaying() {
|
|
@@ -3119,9 +3216,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3119
3216
|
this.video = config.videoElement;
|
|
3120
3217
|
this.adTransitionGapMs = (_this_config_adTransitionGapMs = this.config.adTransitionGapMs) !== null && _this_config_adTransitionGapMs !== void 0 ? _this_config_adTransitionGapMs : 100;
|
|
3121
3218
|
logBrowserInfo(config.debugAdTiming);
|
|
3122
|
-
this.vastManager = createVastManager(
|
|
3123
|
-
debug: !!config.debugAdTiming
|
|
3124
|
-
}
|
|
3219
|
+
this.vastManager = createVastManager(_object_spread({
|
|
3220
|
+
debug: config.debugAdTiming !== void 0 ? !!config.debugAdTiming : false
|
|
3221
|
+
}, config.licenseKey ? {
|
|
3222
|
+
licenseKey: config.licenseKey
|
|
3223
|
+
} : {}));
|
|
3125
3224
|
var browserForAdLayer = detectBrowser();
|
|
3126
3225
|
var isSinglePipeline = browserForAdLayer.isSmartTV || !!this.config.singlePipelineMode;
|
|
3127
3226
|
this.adLayer = createVastAdLayer(this.video, {
|
|
@@ -3172,6 +3271,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3172
3271
|
this.attach();
|
|
3173
3272
|
}
|
|
3174
3273
|
this.initializeTracking();
|
|
3274
|
+
if (!this.config.disableAds) {
|
|
3275
|
+
this.vastManager.initialize().catch(function() {});
|
|
3276
|
+
}
|
|
3175
3277
|
if (!this.shouldUseNativeHls()) return [
|
|
3176
3278
|
3,
|
|
3177
3279
|
3
|
|
@@ -3625,13 +3727,18 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3625
3727
|
key: "attachAdLayerEventListeners",
|
|
3626
3728
|
value: function attachAdLayerEventListeners() {
|
|
3627
3729
|
var _this = this;
|
|
3628
|
-
this.adLayer.on("ad_impression", function() {
|
|
3730
|
+
this.adLayer.on("ad_impression", function(payload) {
|
|
3629
3731
|
if (_this.config.licenseKey) {
|
|
3732
|
+
var _ref;
|
|
3733
|
+
var adUrl = (_ref = payload === null || payload === void 0 ? void 0 : payload.adUrl) !== null && _ref !== void 0 ? _ref : _this.lastServedAdUrl;
|
|
3734
|
+
if (adUrl) {
|
|
3735
|
+
_this.lastServedAdUrl = adUrl;
|
|
3736
|
+
}
|
|
3630
3737
|
sendAdImpressionTracking(_this.config.licenseKey, _object_spread_props(_object_spread({
|
|
3631
3738
|
source: _this.getAdSource(),
|
|
3632
3739
|
adIndex: _this.currentAdIndex
|
|
3633
|
-
},
|
|
3634
|
-
adUrl:
|
|
3740
|
+
}, adUrl ? {
|
|
3741
|
+
adUrl: adUrl
|
|
3635
3742
|
} : {}), {
|
|
3636
3743
|
timestamp: /* @__PURE__ */ new Date().toISOString()
|
|
3637
3744
|
}), _this.getAnalyticsContext());
|