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.cjs CHANGED
@@ -831,7 +831,8 @@ function fireTrackingPixels(urls, sessionId) {
831
831
  });
832
832
  }
833
833
  // src/sdk/vastManager.ts
834
- 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";
834
+ 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";
835
+ var ADSTORM_API_URL = "https://adstorm.co/api-adstorm-dev/adstorm/ads/web";
835
836
  var DEFAULT_TIMEOUT_MS = 5e3;
836
837
  var MAX_RETRIES = 3;
837
838
  var RETRY_BACKOFF_MS = 1500;
@@ -839,6 +840,7 @@ function createVastManager() {
839
840
  var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
840
841
  var _options_debug;
841
842
  var initialized = false;
843
+ var vastTagUrl = VAST_TAG_URL_FALLBACK;
842
844
  var debug = (_options_debug = options.debug) !== null && _options_debug !== void 0 ? _options_debug : false;
843
845
  function log() {
844
846
  for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
@@ -860,17 +862,97 @@ function createVastManager() {
860
862
  "[VastManager]"
861
863
  ].concat(_to_consumable_array(args)));
862
864
  }
865
+ function fetchVastUrlFromApi() {
866
+ return _async_to_generator(function() {
867
+ var apiUrl, _data_response_ima_publisherdeskima, _data_response_ima, _data_response, res, data, payload, err;
868
+ return _ts_generator(this, function(_state) {
869
+ switch(_state.label){
870
+ case 0:
871
+ apiUrl = options.adstormApiUrl || ADSTORM_API_URL;
872
+ _state.label = 1;
873
+ case 1:
874
+ _state.trys.push([
875
+ 1,
876
+ 4,
877
+ ,
878
+ 5
879
+ ]);
880
+ return [
881
+ 4,
882
+ fetch(apiUrl, {
883
+ method: "GET",
884
+ headers: {
885
+ Authorization: "Bearer ".concat(options.licenseKey),
886
+ Accept: "application/json"
887
+ }
888
+ })
889
+ ];
890
+ case 2:
891
+ res = _state.sent();
892
+ if (!res.ok) {
893
+ warn("Failed to fetch VAST URL from API (HTTP ".concat(res.status, "), using fallback"));
894
+ return [
895
+ 2
896
+ ];
897
+ }
898
+ return [
899
+ 4,
900
+ res.json()
901
+ ];
902
+ case 3:
903
+ data = _state.sent();
904
+ 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;
905
+ if (payload) {
906
+ vastTagUrl = payload;
907
+ log("VAST tag URL fetched from API:", vastTagUrl.split("?")[0]);
908
+ } else {
909
+ log("API response had no VAST payload, using fallback URL");
910
+ }
911
+ return [
912
+ 3,
913
+ 5
914
+ ];
915
+ case 4:
916
+ err = _state.sent();
917
+ warn("Error fetching VAST URL from API, using fallback:", err);
918
+ return [
919
+ 3,
920
+ 5
921
+ ];
922
+ case 5:
923
+ return [
924
+ 2
925
+ ];
926
+ }
927
+ });
928
+ })();
929
+ }
863
930
  function initialize() {
864
931
  return _async_to_generator(function() {
865
932
  return _ts_generator(this, function(_state) {
866
- if (initialized) return [
867
- 2
868
- ];
869
- initialized = true;
870
- log("Initialized, VAST tag URL:", VAST_TAG_URL.split("?")[0]);
871
- return [
872
- 2
873
- ];
933
+ switch(_state.label){
934
+ case 0:
935
+ if (initialized) return [
936
+ 2
937
+ ];
938
+ initialized = true;
939
+ if (!options.licenseKey) return [
940
+ 3,
941
+ 2
942
+ ];
943
+ return [
944
+ 4,
945
+ fetchVastUrlFromApi()
946
+ ];
947
+ case 1:
948
+ _state.sent();
949
+ _state.label = 2;
950
+ case 2:
951
+ log("Initialized, VAST tag URL:", vastTagUrl.split("?")[0]);
952
+ return [
953
+ 2
954
+ ];
955
+ }
874
956
  });
875
957
  })();
876
958
  }
@@ -884,7 +966,7 @@ function createVastManager() {
884
966
  throw new Error("VastManager not initialized. Call initialize() first.");
885
967
  }
886
968
  correlator = Math.floor(Math.random() * 1e12).toString();
887
- url = VAST_TAG_URL.replace("[placeholder]", correlator);
969
+ url = vastTagUrl.replace("[placeholder]", correlator);
888
970
  log("Fetching VAST tag, correlator:", correlator);
889
971
  controller = typeof AbortController !== "undefined" ? new AbortController() : null;
890
972
  timeoutId = setTimeout(function() {
@@ -1078,6 +1160,7 @@ function createVastManager() {
1078
1160
  }
1079
1161
  function destroy() {
1080
1162
  initialized = false;
1163
+ vastTagUrl = VAST_TAG_URL_FALLBACK;
1081
1164
  log("Destroyed");
1082
1165
  }
1083
1166
  return {
@@ -3290,9 +3373,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3290
3373
  this.video = config.videoElement;
3291
3374
  this.adTransitionGapMs = (_this_config_adTransitionGapMs = this.config.adTransitionGapMs) !== null && _this_config_adTransitionGapMs !== void 0 ? _this_config_adTransitionGapMs : 100;
3292
3375
  logBrowserInfo(config.debugAdTiming);
3293
- this.vastManager = createVastManager(config.debugAdTiming !== void 0 ? {
3294
- debug: !!config.debugAdTiming
3295
- } : {});
3376
+ this.vastManager = createVastManager(_object_spread({
3377
+ debug: config.debugAdTiming !== void 0 ? !!config.debugAdTiming : false
3378
+ }, config.licenseKey ? {
3379
+ licenseKey: config.licenseKey
3380
+ } : {}));
3296
3381
  var browserForAdLayer = detectBrowser();
3297
3382
  var isSinglePipeline = browserForAdLayer.isSmartTV || !!this.config.singlePipelineMode;
3298
3383
  this.adLayer = createVastAdLayer(this.video, {
@@ -3343,6 +3428,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3343
3428
  this.attach();
3344
3429
  }
3345
3430
  this.initializeTracking();
3431
+ if (!this.config.disableAds) {
3432
+ this.vastManager.initialize().catch(function() {});
3433
+ }
3346
3434
  if (!this.shouldUseNativeHls()) return [
3347
3435
  3,
3348
3436
  3