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.
@@ -701,7 +701,8 @@ function fireTrackingPixels(urls, sessionId) {
701
701
  });
702
702
  }
703
703
  // src/sdk/vastManager.ts
704
- var VAST_TAG_URL = "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";
704
+ 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";
705
+ var ADSTORM_API_URL = "https://adstorm.co/api-adstorm-dev/adstorm/ads/web";
705
706
  var DEFAULT_TIMEOUT_MS = 5e3;
706
707
  var MAX_RETRIES = 3;
707
708
  var RETRY_BACKOFF_MS = 1500;
@@ -709,6 +710,7 @@ function createVastManager() {
709
710
  var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
710
711
  var _options_debug;
711
712
  var initialized = false;
713
+ var vastTagUrl = VAST_TAG_URL_FALLBACK;
712
714
  var debug = (_options_debug = options.debug) !== null && _options_debug !== void 0 ? _options_debug : false;
713
715
  function log() {
714
716
  for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
@@ -730,17 +732,97 @@ function createVastManager() {
730
732
  "[VastManager]"
731
733
  ].concat(_to_consumable_array(args)));
732
734
  }
735
+ function fetchVastUrlFromApi() {
736
+ return _async_to_generator(function() {
737
+ var apiUrl, _data_response_ima_publisherdeskima, _data_response_ima, _data_response, res, data, payload, err;
738
+ return _ts_generator(this, function(_state) {
739
+ switch(_state.label){
740
+ case 0:
741
+ apiUrl = options.adstormApiUrl || ADSTORM_API_URL;
742
+ _state.label = 1;
743
+ case 1:
744
+ _state.trys.push([
745
+ 1,
746
+ 4,
747
+ ,
748
+ 5
749
+ ]);
750
+ return [
751
+ 4,
752
+ fetch(apiUrl, {
753
+ method: "GET",
754
+ headers: {
755
+ Authorization: "Bearer ".concat(options.licenseKey),
756
+ Accept: "application/json"
757
+ }
758
+ })
759
+ ];
760
+ case 2:
761
+ res = _state.sent();
762
+ if (!res.ok) {
763
+ warn("Failed to fetch VAST URL from API (HTTP ".concat(res.status, "), using fallback"));
764
+ return [
765
+ 2
766
+ ];
767
+ }
768
+ return [
769
+ 4,
770
+ res.json()
771
+ ];
772
+ case 3:
773
+ data = _state.sent();
774
+ 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;
775
+ if (payload) {
776
+ vastTagUrl = payload;
777
+ log("VAST tag URL fetched from API:", vastTagUrl.split("?")[0]);
778
+ } else {
779
+ log("API response had no VAST payload, using fallback URL");
780
+ }
781
+ return [
782
+ 3,
783
+ 5
784
+ ];
785
+ case 4:
786
+ err = _state.sent();
787
+ warn("Error fetching VAST URL from API, using fallback:", err);
788
+ return [
789
+ 3,
790
+ 5
791
+ ];
792
+ case 5:
793
+ return [
794
+ 2
795
+ ];
796
+ }
797
+ });
798
+ })();
799
+ }
733
800
  function initialize() {
734
801
  return _async_to_generator(function() {
735
802
  return _ts_generator(this, function(_state) {
736
- if (initialized) return [
737
- 2
738
- ];
739
- initialized = true;
740
- log("Initialized, VAST tag URL:", VAST_TAG_URL.split("?")[0]);
741
- return [
742
- 2
743
- ];
803
+ switch(_state.label){
804
+ case 0:
805
+ if (initialized) return [
806
+ 2
807
+ ];
808
+ initialized = true;
809
+ if (!options.licenseKey) return [
810
+ 3,
811
+ 2
812
+ ];
813
+ return [
814
+ 4,
815
+ fetchVastUrlFromApi()
816
+ ];
817
+ case 1:
818
+ _state.sent();
819
+ _state.label = 2;
820
+ case 2:
821
+ log("Initialized, VAST tag URL:", vastTagUrl.split("?")[0]);
822
+ return [
823
+ 2
824
+ ];
825
+ }
744
826
  });
745
827
  })();
746
828
  }
@@ -754,7 +836,7 @@ function createVastManager() {
754
836
  throw new Error("VastManager not initialized. Call initialize() first.");
755
837
  }
756
838
  correlator = Math.floor(Math.random() * 1e12).toString();
757
- url = VAST_TAG_URL.replace("[placeholder]", correlator);
839
+ url = vastTagUrl.replace("[placeholder]", correlator);
758
840
  log("Fetching VAST tag, correlator:", correlator);
759
841
  controller = typeof AbortController !== "undefined" ? new AbortController() : null;
760
842
  timeoutId = setTimeout(function() {
@@ -948,6 +1030,7 @@ function createVastManager() {
948
1030
  }
949
1031
  function destroy() {
950
1032
  initialized = false;
1033
+ vastTagUrl = VAST_TAG_URL_FALLBACK;
951
1034
  log("Destroyed");
952
1035
  }
953
1036
  return {
@@ -989,6 +1072,7 @@ function createVastAdLayer(contentVideo, options) {
989
1072
  var adHls;
990
1073
  var adContainerEl;
991
1074
  var currentAd;
1075
+ var currentMediaFile;
992
1076
  var sessionId;
993
1077
  var destroyed = false;
994
1078
  var tornDown = false;
@@ -1235,7 +1319,12 @@ function createVastAdLayer(contentVideo, options) {
1235
1319
  adContainerEl.style.display = "none";
1236
1320
  adContainerEl.style.pointerEvents = "none";
1237
1321
  }
1238
- emit("ad_impression");
1322
+ emit("ad_impression", {
1323
+ adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
1324
+ adTitle: currentAd === null || currentAd === void 0 ? void 0 : currentAd.title,
1325
+ adUrl: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.url,
1326
+ mediaType: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.type
1327
+ });
1239
1328
  emit("content_resume");
1240
1329
  }
1241
1330
  function handleAdError() {
@@ -1257,6 +1346,7 @@ function createVastAdLayer(contentVideo, options) {
1257
1346
  adHls.destroy();
1258
1347
  adHls = void 0;
1259
1348
  }
1349
+ currentMediaFile = void 0;
1260
1350
  if (adVideoElement) {
1261
1351
  if (singleElementMode && adVideoElement === contentVideo) {
1262
1352
  contentVideo.pause();
@@ -1421,6 +1511,7 @@ function createVastAdLayer(contentVideo, options) {
1421
1511
  adVideoElement.volume = Math.max(0, Math.min(1, adVolume2));
1422
1512
  adVideoElement.muted = false;
1423
1513
  mediaFile2 = selectBestMediaFile(ad.mediaFiles);
1514
+ currentMediaFile = mediaFile2;
1424
1515
  if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile2.url));
1425
1516
  startPlayback(mediaFile2);
1426
1517
  return [
@@ -1467,6 +1558,7 @@ function createVastAdLayer(contentVideo, options) {
1467
1558
  }
1468
1559
  emit("content_pause");
1469
1560
  mediaFile = selectBestMediaFile(ad.mediaFiles);
1561
+ currentMediaFile = mediaFile;
1470
1562
  if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile.url));
1471
1563
  startPlayback(mediaFile);
1472
1564
  return [
@@ -1632,6 +1724,7 @@ function createVastAdLayer(contentVideo, options) {
1632
1724
  ];
1633
1725
  mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1634
1726
  teardownCurrentPlayback();
1727
+ currentMediaFile = slot.mediaFile;
1635
1728
  adVideoElement = contentVideo;
1636
1729
  adHls = void 0;
1637
1730
  adPlaying = true;
@@ -1666,6 +1759,7 @@ function createVastAdLayer(contentVideo, options) {
1666
1759
  case 2:
1667
1760
  if (smartTVMode && !slot.videoEl) {
1668
1761
  teardownCurrentPlayback();
1762
+ currentMediaFile = slot.mediaFile;
1669
1763
  if (adVideoElement) {
1670
1764
  adVideoElement.remove();
1671
1765
  adVideoElement = void 0;
@@ -1697,6 +1791,7 @@ function createVastAdLayer(contentVideo, options) {
1697
1791
  ];
1698
1792
  }
1699
1793
  teardownCurrentPlayback();
1794
+ currentMediaFile = slot.mediaFile;
1700
1795
  if (adVideoElement && adVideoElement !== slot.videoEl) {
1701
1796
  adVideoElement.remove();
1702
1797
  }
@@ -1828,6 +1923,7 @@ function createVastAdLayer(contentVideo, options) {
1828
1923
  }
1829
1924
  }
1830
1925
  currentAd = void 0;
1926
+ currentMediaFile = void 0;
1831
1927
  tornDown = false;
1832
1928
  return [
1833
1929
  2
@@ -1880,6 +1976,7 @@ function createVastAdLayer(contentVideo, options) {
1880
1976
  }
1881
1977
  adContainerEl = void 0;
1882
1978
  currentAd = void 0;
1979
+ currentMediaFile = void 0;
1883
1980
  listeners.clear();
1884
1981
  },
1885
1982
  isAdPlaying: function isAdPlaying() {
@@ -3121,9 +3218,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3121
3218
  this.video = config.videoElement;
3122
3219
  this.adTransitionGapMs = (_this_config_adTransitionGapMs = this.config.adTransitionGapMs) !== null && _this_config_adTransitionGapMs !== void 0 ? _this_config_adTransitionGapMs : 100;
3123
3220
  logBrowserInfo(config.debugAdTiming);
3124
- this.vastManager = createVastManager(config.debugAdTiming !== void 0 ? {
3125
- debug: !!config.debugAdTiming
3126
- } : {});
3221
+ this.vastManager = createVastManager(_object_spread({
3222
+ debug: config.debugAdTiming !== void 0 ? !!config.debugAdTiming : false
3223
+ }, config.licenseKey ? {
3224
+ licenseKey: config.licenseKey
3225
+ } : {}));
3127
3226
  var browserForAdLayer = detectBrowser();
3128
3227
  var isSinglePipeline = browserForAdLayer.isSmartTV || !!this.config.singlePipelineMode;
3129
3228
  this.adLayer = createVastAdLayer(this.video, {
@@ -3174,6 +3273,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3174
3273
  this.attach();
3175
3274
  }
3176
3275
  this.initializeTracking();
3276
+ if (!this.config.disableAds) {
3277
+ this.vastManager.initialize().catch(function() {});
3278
+ }
3177
3279
  if (!this.shouldUseNativeHls()) return [
3178
3280
  3,
3179
3281
  3
@@ -3627,13 +3729,18 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3627
3729
  key: "attachAdLayerEventListeners",
3628
3730
  value: function attachAdLayerEventListeners() {
3629
3731
  var _this = this;
3630
- this.adLayer.on("ad_impression", function() {
3732
+ this.adLayer.on("ad_impression", function(payload) {
3631
3733
  if (_this.config.licenseKey) {
3734
+ var _ref;
3735
+ var adUrl = (_ref = payload === null || payload === void 0 ? void 0 : payload.adUrl) !== null && _ref !== void 0 ? _ref : _this.lastServedAdUrl;
3736
+ if (adUrl) {
3737
+ _this.lastServedAdUrl = adUrl;
3738
+ }
3632
3739
  sendAdImpressionTracking(_this.config.licenseKey, _object_spread_props(_object_spread({
3633
3740
  source: _this.getAdSource(),
3634
3741
  adIndex: _this.currentAdIndex
3635
- }, _this.lastServedAdUrl ? {
3636
- adUrl: _this.lastServedAdUrl
3742
+ }, adUrl ? {
3743
+ adUrl: adUrl
3637
3744
  } : {}), {
3638
3745
  timestamp: /* @__PURE__ */ new Date().toISOString()
3639
3746
  }), _this.getAnalyticsContext());