stormcloud-video-player 0.6.10 → 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.
@@ -737,7 +737,8 @@ function fireTrackingPixels(urls, sessionId) {
737
737
  });
738
738
  }
739
739
  // src/sdk/vastManager.ts
740
- 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";
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
- if (initialized) return [
773
- 2
774
- ];
775
- initialized = true;
776
- log("Initialized, VAST tag URL:", VAST_TAG_URL.split("?")[0]);
777
- return [
778
- 2
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 = VAST_TAG_URL.replace("[placeholder]", correlator);
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 {
@@ -3171,9 +3254,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3171
3254
  this.video = config.videoElement;
3172
3255
  this.adTransitionGapMs = (_this_config_adTransitionGapMs = this.config.adTransitionGapMs) !== null && _this_config_adTransitionGapMs !== void 0 ? _this_config_adTransitionGapMs : 100;
3173
3256
  logBrowserInfo(config.debugAdTiming);
3174
- this.vastManager = createVastManager(config.debugAdTiming !== void 0 ? {
3175
- debug: !!config.debugAdTiming
3176
- } : {});
3257
+ this.vastManager = createVastManager(_object_spread({
3258
+ debug: config.debugAdTiming !== void 0 ? !!config.debugAdTiming : false
3259
+ }, config.licenseKey ? {
3260
+ licenseKey: config.licenseKey
3261
+ } : {}));
3177
3262
  var browserForAdLayer = detectBrowser();
3178
3263
  var isSinglePipeline = browserForAdLayer.isSmartTV || !!this.config.singlePipelineMode;
3179
3264
  this.adLayer = createVastAdLayer(this.video, {
@@ -3224,6 +3309,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3224
3309
  this.attach();
3225
3310
  }
3226
3311
  this.initializeTracking();
3312
+ if (!this.config.disableAds) {
3313
+ this.vastManager.initialize().catch(function() {});
3314
+ }
3227
3315
  if (!this.shouldUseNativeHls()) return [
3228
3316
  3,
3229
3317
  3