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.
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 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";
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
- if (initialized) return [
707
- 2
708
- ];
709
- initialized = true;
710
- log("Initialized, VAST tag URL:", VAST_TAG_URL.split("?")[0]);
711
- return [
712
- 2
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 = VAST_TAG_URL.replace("[placeholder]", correlator);
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 {
@@ -3133,9 +3216,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3133
3216
  this.video = config.videoElement;
3134
3217
  this.adTransitionGapMs = (_this_config_adTransitionGapMs = this.config.adTransitionGapMs) !== null && _this_config_adTransitionGapMs !== void 0 ? _this_config_adTransitionGapMs : 100;
3135
3218
  logBrowserInfo(config.debugAdTiming);
3136
- this.vastManager = createVastManager(config.debugAdTiming !== void 0 ? {
3137
- debug: !!config.debugAdTiming
3138
- } : {});
3219
+ this.vastManager = createVastManager(_object_spread({
3220
+ debug: config.debugAdTiming !== void 0 ? !!config.debugAdTiming : false
3221
+ }, config.licenseKey ? {
3222
+ licenseKey: config.licenseKey
3223
+ } : {}));
3139
3224
  var browserForAdLayer = detectBrowser();
3140
3225
  var isSinglePipeline = browserForAdLayer.isSmartTV || !!this.config.singlePipelineMode;
3141
3226
  this.adLayer = createVastAdLayer(this.video, {
@@ -3186,6 +3271,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3186
3271
  this.attach();
3187
3272
  }
3188
3273
  this.initializeTracking();
3274
+ if (!this.config.disableAds) {
3275
+ this.vastManager.initialize().catch(function() {});
3276
+ }
3189
3277
  if (!this.shouldUseNativeHls()) return [
3190
3278
  3,
3191
3279
  3