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.
@@ -649,7 +649,8 @@ function fireTrackingPixels(urls, sessionId) {
649
649
  });
650
650
  }
651
651
  // src/sdk/vastManager.ts
652
- 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";
652
+ 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";
653
+ var ADSTORM_API_URL = "https://adstorm.co/api-adstorm-dev/adstorm/ads/web";
653
654
  var DEFAULT_TIMEOUT_MS = 5e3;
654
655
  var MAX_RETRIES = 3;
655
656
  var RETRY_BACKOFF_MS = 1500;
@@ -657,6 +658,7 @@ function createVastManager() {
657
658
  var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
658
659
  var _options_debug;
659
660
  var initialized = false;
661
+ var vastTagUrl = VAST_TAG_URL_FALLBACK;
660
662
  var debug = (_options_debug = options.debug) !== null && _options_debug !== void 0 ? _options_debug : false;
661
663
  function log() {
662
664
  for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
@@ -678,17 +680,97 @@ function createVastManager() {
678
680
  "[VastManager]"
679
681
  ].concat(_to_consumable_array(args)));
680
682
  }
683
+ function fetchVastUrlFromApi() {
684
+ return _async_to_generator(function() {
685
+ var apiUrl, _data_response_ima_publisherdeskima, _data_response_ima, _data_response, res, data, payload, err;
686
+ return _ts_generator(this, function(_state) {
687
+ switch(_state.label){
688
+ case 0:
689
+ apiUrl = options.adstormApiUrl || ADSTORM_API_URL;
690
+ _state.label = 1;
691
+ case 1:
692
+ _state.trys.push([
693
+ 1,
694
+ 4,
695
+ ,
696
+ 5
697
+ ]);
698
+ return [
699
+ 4,
700
+ fetch(apiUrl, {
701
+ method: "GET",
702
+ headers: {
703
+ Authorization: "Bearer ".concat(options.licenseKey),
704
+ Accept: "application/json"
705
+ }
706
+ })
707
+ ];
708
+ case 2:
709
+ res = _state.sent();
710
+ if (!res.ok) {
711
+ warn("Failed to fetch VAST URL from API (HTTP ".concat(res.status, "), using fallback"));
712
+ return [
713
+ 2
714
+ ];
715
+ }
716
+ return [
717
+ 4,
718
+ res.json()
719
+ ];
720
+ case 3:
721
+ data = _state.sent();
722
+ 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;
723
+ if (payload) {
724
+ vastTagUrl = payload;
725
+ log("VAST tag URL fetched from API:", vastTagUrl.split("?")[0]);
726
+ } else {
727
+ log("API response had no VAST payload, using fallback URL");
728
+ }
729
+ return [
730
+ 3,
731
+ 5
732
+ ];
733
+ case 4:
734
+ err = _state.sent();
735
+ warn("Error fetching VAST URL from API, using fallback:", err);
736
+ return [
737
+ 3,
738
+ 5
739
+ ];
740
+ case 5:
741
+ return [
742
+ 2
743
+ ];
744
+ }
745
+ });
746
+ })();
747
+ }
681
748
  function initialize() {
682
749
  return _async_to_generator(function() {
683
750
  return _ts_generator(this, function(_state) {
684
- if (initialized) return [
685
- 2
686
- ];
687
- initialized = true;
688
- log("Initialized, VAST tag URL:", VAST_TAG_URL.split("?")[0]);
689
- return [
690
- 2
691
- ];
751
+ switch(_state.label){
752
+ case 0:
753
+ if (initialized) return [
754
+ 2
755
+ ];
756
+ initialized = true;
757
+ if (!options.licenseKey) return [
758
+ 3,
759
+ 2
760
+ ];
761
+ return [
762
+ 4,
763
+ fetchVastUrlFromApi()
764
+ ];
765
+ case 1:
766
+ _state.sent();
767
+ _state.label = 2;
768
+ case 2:
769
+ log("Initialized, VAST tag URL:", vastTagUrl.split("?")[0]);
770
+ return [
771
+ 2
772
+ ];
773
+ }
692
774
  });
693
775
  })();
694
776
  }
@@ -702,7 +784,7 @@ function createVastManager() {
702
784
  throw new Error("VastManager not initialized. Call initialize() first.");
703
785
  }
704
786
  correlator = Math.floor(Math.random() * 1e12).toString();
705
- url = VAST_TAG_URL.replace("[placeholder]", correlator);
787
+ url = vastTagUrl.replace("[placeholder]", correlator);
706
788
  log("Fetching VAST tag, correlator:", correlator);
707
789
  controller = typeof AbortController !== "undefined" ? new AbortController() : null;
708
790
  timeoutId = setTimeout(function() {
@@ -896,6 +978,7 @@ function createVastManager() {
896
978
  }
897
979
  function destroy() {
898
980
  initialized = false;
981
+ vastTagUrl = VAST_TAG_URL_FALLBACK;
899
982
  log("Destroyed");
900
983
  }
901
984
  return {
@@ -3083,9 +3166,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3083
3166
  this.video = config.videoElement;
3084
3167
  this.adTransitionGapMs = (_this_config_adTransitionGapMs = this.config.adTransitionGapMs) !== null && _this_config_adTransitionGapMs !== void 0 ? _this_config_adTransitionGapMs : 100;
3085
3168
  logBrowserInfo(config.debugAdTiming);
3086
- this.vastManager = createVastManager(config.debugAdTiming !== void 0 ? {
3087
- debug: !!config.debugAdTiming
3088
- } : {});
3169
+ this.vastManager = createVastManager(_object_spread({
3170
+ debug: config.debugAdTiming !== void 0 ? !!config.debugAdTiming : false
3171
+ }, config.licenseKey ? {
3172
+ licenseKey: config.licenseKey
3173
+ } : {}));
3089
3174
  var browserForAdLayer = detectBrowser();
3090
3175
  var isSinglePipeline = browserForAdLayer.isSmartTV || !!this.config.singlePipelineMode;
3091
3176
  this.adLayer = createVastAdLayer(this.video, {
@@ -3136,6 +3221,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3136
3221
  this.attach();
3137
3222
  }
3138
3223
  this.initializeTracking();
3224
+ if (!this.config.disableAds) {
3225
+ this.vastManager.initialize().catch(function() {});
3226
+ }
3139
3227
  if (!this.shouldUseNativeHls()) return [
3140
3228
  3,
3141
3229
  3