stormcloud-video-player 0.7.37 → 0.7.39

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
@@ -440,6 +440,9 @@ __export(index_exports, {
440
440
  IS_SAFARI: function IS_SAFARI1() {
441
441
  return IS_SAFARI;
442
442
  },
443
+ OVERLAY_API_BASE: function OVERLAY_API_BASE1() {
444
+ return OVERLAY_API_BASE;
445
+ },
443
446
  SUPPORTS_DASH: function SUPPORTS_DASH1() {
444
447
  return SUPPORTS_DASH;
445
448
  },
@@ -503,6 +506,9 @@ __export(index_exports, {
503
506
  merge: function merge1() {
504
507
  return merge;
505
508
  },
509
+ normalizeSwirlOverlay: function normalizeSwirlOverlay1() {
510
+ return normalizeSwirlOverlay;
511
+ },
506
512
  omit: function omit1() {
507
513
  return omit;
508
514
  },
@@ -518,6 +524,9 @@ __export(index_exports, {
518
524
  resolveImageUrl: function resolveImageUrl1() {
519
525
  return resolveImageUrl;
520
526
  },
527
+ scrollerLooksLikeMarketsStock: function scrollerLooksLikeMarketsStock1() {
528
+ return scrollerLooksLikeMarketsStock;
529
+ },
521
530
  sendHeartbeat: function sendHeartbeat1() {
522
531
  return sendHeartbeat;
523
532
  },
@@ -5683,6 +5692,46 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5683
5692
  return min;
5684
5693
  }
5685
5694
  },
5695
+ {
5696
+ key: "getMaxHlsResolution",
5697
+ value: function getMaxHlsResolution() {
5698
+ var _this_hls;
5699
+ var levels = (_this_hls = this.hls) === null || _this_hls === void 0 ? void 0 : _this_hls.levels;
5700
+ if (!levels || levels.length === 0) return null;
5701
+ var max = null;
5702
+ var maxPixels = 0;
5703
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
5704
+ try {
5705
+ for(var _iterator = levels[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
5706
+ var level = _step.value;
5707
+ if (level.width && level.height) {
5708
+ var pixels = level.width * level.height;
5709
+ if (pixels > maxPixels) {
5710
+ maxPixels = pixels;
5711
+ max = {
5712
+ width: level.width,
5713
+ height: level.height
5714
+ };
5715
+ }
5716
+ }
5717
+ }
5718
+ } catch (err) {
5719
+ _didIteratorError = true;
5720
+ _iteratorError = err;
5721
+ } finally{
5722
+ try {
5723
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
5724
+ _iterator.return();
5725
+ }
5726
+ } finally{
5727
+ if (_didIteratorError) {
5728
+ throw _iteratorError;
5729
+ }
5730
+ }
5731
+ }
5732
+ return max;
5733
+ }
5734
+ },
5686
5735
  {
5687
5736
  key: "getCurrentHlsSegmentDurationMs",
5688
5737
  value: function getCurrentHlsSegmentDurationMs() {
@@ -5830,7 +5879,15 @@ function isOverlayActive(overlay, currentTime) {
5830
5879
  if (durationSec <= 0) return false;
5831
5880
  return currentTime >= startSec && currentTime < startSec + durationSec;
5832
5881
  }
5833
- function createDemoStockTickerOverlay(projectId) {
5882
+ function scrollerLooksLikeMarketsStock(o) {
5883
+ var _ref, _ref1, _ref2, _ref3;
5884
+ if (o.type !== "scroller") return false;
5885
+ var cfg = o.scroller_config;
5886
+ var blob = "".concat(o.name, " ").concat((_ref = cfg === null || cfg === void 0 ? void 0 : cfg.label) !== null && _ref !== void 0 ? _ref : "", " ").concat((_ref1 = cfg === null || cfg === void 0 ? void 0 : cfg.label_line2) !== null && _ref1 !== void 0 ? _ref1 : "", " ").concat((_ref2 = cfg === null || cfg === void 0 ? void 0 : cfg.custom_text) !== null && _ref2 !== void 0 ? _ref2 : "", " ").concat((_ref3 = cfg === null || cfg === void 0 ? void 0 : cfg.preset) !== null && _ref3 !== void 0 ? _ref3 : "");
5887
+ return /\b(MARKETS?|NYSE|NASDAQ|DJIA|\bS&P\b|STOCK|AAPL|TSLA|NVDA|EQUITIES)\b/i.test(blob);
5888
+ }
5889
+ function createDemoStockTickerOverlay(projectId, opts) {
5890
+ var stack = (opts === null || opts === void 0 ? void 0 : opts.stackAboveNews) === true;
5834
5891
  return {
5835
5892
  id: -9001,
5836
5893
  project_id: projectId,
@@ -5838,13 +5895,13 @@ function createDemoStockTickerOverlay(projectId) {
5838
5895
  type: "scroller",
5839
5896
  visible: true,
5840
5897
  x: 144,
5841
- y: 950,
5898
+ y: stack ? 818 : 950,
5842
5899
  width: 1632,
5843
- height: 97,
5900
+ height: stack ? 78 : 97,
5844
5901
  opacity: 100,
5845
5902
  start_time: "00:00:00.000",
5846
5903
  duration: "24:00:00.000",
5847
- z_index: 120,
5904
+ z_index: stack ? 125 : 120,
5848
5905
  scroller_config: {
5849
5906
  use_custom_text: true,
5850
5907
  custom_text: "AAPL +1.24% \u2022 MSFT +0.42% \u2022 GOOGL \u22120.11% \u2022 TSLA +2.31% \u2022 NVDA +1.87% \u2022 AMZN +0.65% \u2022 META +0.38% \u2022 DJIA +0.52% \u2022 S&P 500 +0.33% \u2022 NDAQ +0.41%",
@@ -5866,17 +5923,43 @@ function createDemoStockTickerOverlay(projectId) {
5866
5923
  }
5867
5924
  };
5868
5925
  }
5926
+ function normalizeScrollerConfig(raw) {
5927
+ if (!raw || (typeof raw === "undefined" ? "undefined" : _type_of(raw)) !== "object") return void 0;
5928
+ var r = raw;
5929
+ var merged = _object_spread({}, raw);
5930
+ if (merged.use_custom_text === void 0 && typeof r.useCustomText === "boolean") {
5931
+ merged.use_custom_text = r.useCustomText;
5932
+ }
5933
+ if ((merged.custom_text === void 0 || merged.custom_text === "") && typeof r.customText === "string") {
5934
+ merged.custom_text = r.customText;
5935
+ }
5936
+ if (!merged.rss_url && typeof r.rssUrl === "string") {
5937
+ merged.rss_url = r.rssUrl;
5938
+ }
5939
+ return merged;
5940
+ }
5941
+ function normalizeSwirlOverlay(raw) {
5942
+ var o = _object_spread({}, raw);
5943
+ if (o.type === "scroller") {
5944
+ var _raw_scroller_config;
5945
+ var sc = (_raw_scroller_config = raw.scroller_config) !== null && _raw_scroller_config !== void 0 ? _raw_scroller_config : raw.scrollerConfig;
5946
+ var normalized = normalizeScrollerConfig(sc);
5947
+ if (normalized) o.scroller_config = normalized;
5948
+ }
5949
+ return o;
5950
+ }
5869
5951
  function fetchProjectOverlays(_0) {
5870
5952
  return _async_to_generator(function(projectId) {
5871
- var apiBaseUrl, response, data;
5953
+ var apiBaseUrl, base, response, data;
5872
5954
  var _arguments = arguments;
5873
5955
  return _ts_generator(this, function(_state) {
5874
5956
  switch(_state.label){
5875
5957
  case 0:
5876
5958
  apiBaseUrl = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : OVERLAY_API_BASE;
5959
+ base = apiBaseUrl.replace(/\/$/, "");
5877
5960
  return [
5878
5961
  4,
5879
- fetch("".concat(apiBaseUrl, "/adstorm/swirl/projects/").concat(projectId, "/overlays"))
5962
+ fetch("".concat(base, "/adstorm/swirl/projects/").concat(projectId, "/overlays"))
5880
5963
  ];
5881
5964
  case 1:
5882
5965
  response = _state.sent();
@@ -5889,9 +5972,15 @@ function fetchProjectOverlays(_0) {
5889
5972
  ];
5890
5973
  case 2:
5891
5974
  data = _state.sent();
5975
+ if (!Array.isArray(data)) return [
5976
+ 2,
5977
+ []
5978
+ ];
5892
5979
  return [
5893
5980
  2,
5894
- Array.isArray(data) ? data : []
5981
+ data.map(function(row) {
5982
+ return normalizeSwirlOverlay(row);
5983
+ })
5895
5984
  ];
5896
5985
  }
5897
5986
  });
@@ -7302,7 +7391,7 @@ function showcaseOpacity(phase) {
7302
7391
  }
7303
7392
  function showcaseScale(phase) {
7304
7393
  if (phase < SHOWCASE_POP_IN_MS) {
7305
- return 0.78 + 0.22 * easeOutBack(phase / SHOWCASE_POP_IN_MS);
7394
+ return Math.min(1, 0.78 + 0.22 * easeOutBack(phase / SHOWCASE_POP_IN_MS));
7306
7395
  }
7307
7396
  if (phase >= SHOWCASE_STEADY_END_MS && phase < SHOWCASE_POP_OUT_END_MS) {
7308
7397
  return 1 - 0.14 * easeInCubic((phase - SHOWCASE_STEADY_END_MS) / SHOWCASE_POP_OUT_MS);
@@ -7367,7 +7456,6 @@ var OverlayRenderer = function OverlayRenderer(param) {
7367
7456
  if (showcaseMode) {
7368
7457
  return overlays.filter(function(o) {
7369
7458
  if (!o.visible) return false;
7370
- if (o.type === "scroller") return true;
7371
7459
  return showcasePhase < SHOWCASE_POP_OUT_END_MS;
7372
7460
  });
7373
7461
  }
@@ -7387,7 +7475,7 @@ var OverlayRenderer = function OverlayRenderer(param) {
7387
7475
  }, [
7388
7476
  activeOverlays
7389
7477
  ]);
7390
- (0, import_react.useEffect)(function() {
7478
+ (0, import_react.useLayoutEffect)(function() {
7391
7479
  var activeIds = new Set(activeOverlays.map(function(o) {
7392
7480
  return o.id;
7393
7481
  }));
@@ -7575,10 +7663,9 @@ var OverlayRenderer = function OverlayRenderer(param) {
7575
7663
  var width = overlay.width * scaleX;
7576
7664
  var height = overlay.height * scaleY;
7577
7665
  var baseOpacity = Math.max(0, Math.min(100, overlay.opacity)) / 100;
7578
- var isScrollerTicker = overlay.type === "scroller";
7579
7666
  var inShowcaseBeat = showcaseMode && activeBeatIds.has(overlay.id);
7580
- var useShowcasePop = inShowcaseBeat && !isScrollerTicker;
7581
- var opacity = useShowcasePop ? baseOpacity * showcaseOpacity(showcasePhase) : inShowcaseBeat && isScrollerTicker ? baseOpacity : visible ? baseOpacity : 0;
7667
+ var useShowcasePop = inShowcaseBeat;
7668
+ var opacity = useShowcasePop ? baseOpacity * showcaseOpacity(showcasePhase) : visible ? baseOpacity : 0;
7582
7669
  var popScale = useShowcasePop ? showcaseScale(showcasePhase) : 1;
7583
7670
  var sz = {
7584
7671
  w: width,
@@ -7720,7 +7807,7 @@ var PANEL_BASE_RIGHT_OFFSET = 10;
7720
7807
  var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props) {
7721
7808
  var _ref;
7722
7809
  var _aiLiveContext_context;
7723
- var src = props.src, autoplay = props.autoplay, muted = props.muted, lowLatencyMode = props.lowLatencyMode, allowNativeHls = props.allowNativeHls, driftToleranceMs = props.driftToleranceMs, immediateManifestAds = props.immediateManifestAds, debugAdTiming = props.debugAdTiming, showCustomControls = props.showCustomControls, hideLoadingIndicator = props.hideLoadingIndicator, onVolumeToggle = props.onVolumeToggle, onFullscreenToggle = props.onFullscreenToggle, onControlClick = props.onControlClick, onReady = props.onReady, wrapperClassName = props.wrapperClassName, wrapperStyle = props.wrapperStyle, className = props.className, style = props.style, controls = props.controls, playsInline = props.playsInline, preload = props.preload, poster = props.poster, children = props.children, licenseKey = props.licenseKey, minSegmentsBeforePlay = props.minSegmentsBeforePlay, disableAds = props.disableAds, disableFiller = props.disableFiller, swirlProjectId = props.swirlProjectId, swirlShowcaseDemo = props.swirlShowcaseDemo, adcisionChannelId = props.adcisionChannelId, disableOverlays = props.disableOverlays, showAdsControl = props.showAdsControl, showOverlaysControl = props.showOverlaysControl, showAiContextControl = props.showAiContextControl, showDebugControl = props.showDebugControl, restVideoAttrs = _object_without_properties(props, [
7810
+ var src = props.src, autoplay = props.autoplay, muted = props.muted, lowLatencyMode = props.lowLatencyMode, allowNativeHls = props.allowNativeHls, driftToleranceMs = props.driftToleranceMs, immediateManifestAds = props.immediateManifestAds, debugAdTiming = props.debugAdTiming, showCustomControls = props.showCustomControls, hideLoadingIndicator = props.hideLoadingIndicator, onVolumeToggle = props.onVolumeToggle, onFullscreenToggle = props.onFullscreenToggle, onControlClick = props.onControlClick, onReady = props.onReady, wrapperClassName = props.wrapperClassName, wrapperStyle = props.wrapperStyle, className = props.className, style = props.style, controls = props.controls, playsInline = props.playsInline, preload = props.preload, poster = props.poster, children = props.children, licenseKey = props.licenseKey, minSegmentsBeforePlay = props.minSegmentsBeforePlay, disableAds = props.disableAds, disableFiller = props.disableFiller, swirlProjectId = props.swirlProjectId, swirlShowcaseDemo = props.swirlShowcaseDemo, swirlOverlayApiBaseUrl = props.swirlOverlayApiBaseUrl, swirlOverlayCoordinateSpace = props.swirlOverlayCoordinateSpace, adcisionChannelId = props.adcisionChannelId, disableOverlays = props.disableOverlays, showAdsControl = props.showAdsControl, showOverlaysControl = props.showOverlaysControl, showAiContextControl = props.showAiContextControl, showDebugControl = props.showDebugControl, restVideoAttrs = _object_without_properties(props, [
7724
7811
  "src",
7725
7812
  "autoplay",
7726
7813
  "muted",
@@ -7750,6 +7837,8 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7750
7837
  "disableFiller",
7751
7838
  "swirlProjectId",
7752
7839
  "swirlShowcaseDemo",
7840
+ "swirlOverlayApiBaseUrl",
7841
+ "swirlOverlayCoordinateSpace",
7753
7842
  "adcisionChannelId",
7754
7843
  "disableOverlays",
7755
7844
  "showAdsControl",
@@ -7786,13 +7875,21 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7786
7875
  var _import_react2_default_useState14 = _sliced_to_array(import_react2.default.useState(false), 2), showLicenseWarning = _import_react2_default_useState14[0], setShowLicenseWarning = _import_react2_default_useState14[1];
7787
7876
  var _import_react2_default_useState15 = _sliced_to_array(import_react2.default.useState(true), 2), controlsVisible = _import_react2_default_useState15[0], setControlsVisible = _import_react2_default_useState15[1];
7788
7877
  var _import_react2_default_useState16 = _sliced_to_array(import_react2.default.useState([]), 2), overlays = _import_react2_default_useState16[0], setOverlays = _import_react2_default_useState16[1];
7878
+ var overlayApiBase = import_react2.default.useMemo(function() {
7879
+ return (swirlOverlayApiBaseUrl === null || swirlOverlayApiBaseUrl === void 0 ? void 0 : swirlOverlayApiBaseUrl.replace(/\/$/, "")) || OVERLAY_API_BASE;
7880
+ }, [
7881
+ swirlOverlayApiBaseUrl
7882
+ ]);
7789
7883
  var displayOverlays = import_react2.default.useMemo(function() {
7790
7884
  if (!swirlProjectId || !swirlShowcaseDemo) return overlays;
7791
- if (overlays.some(function(o) {
7885
+ if (overlays.some(scrollerLooksLikeMarketsStock)) return overlays;
7886
+ var hasOtherScroller = overlays.some(function(o) {
7792
7887
  return o.type === "scroller";
7793
- })) return overlays;
7888
+ });
7794
7889
  return _to_consumable_array(overlays).concat([
7795
- createDemoStockTickerOverlay(swirlProjectId)
7890
+ createDemoStockTickerOverlay(swirlProjectId, {
7891
+ stackAboveNews: hasOtherScroller
7892
+ })
7796
7893
  ]);
7797
7894
  }, [
7798
7895
  overlays,
@@ -8072,7 +8169,7 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
8072
8169
  }
8073
8170
  var cancelled = false;
8074
8171
  var loadOverlays = function loadOverlays() {
8075
- fetchProjectOverlays(swirlProjectId).then(function(data) {
8172
+ fetchProjectOverlays(swirlProjectId, overlayApiBase).then(function(data) {
8076
8173
  if (!cancelled) setOverlays(data);
8077
8174
  }).catch(function(err) {
8078
8175
  if (!cancelled) {
@@ -8088,41 +8185,69 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
8088
8185
  };
8089
8186
  }, [
8090
8187
  swirlProjectId,
8091
- adcisionChannelId
8188
+ adcisionChannelId,
8189
+ overlayApiBase
8092
8190
  ]);
8093
8191
  (0, import_react2.useEffect)(function() {
8192
+ var _playerRef_current;
8094
8193
  if (!swirlProjectId) return;
8095
- var player = playerRef.current;
8096
- if (!player) return;
8097
- var attempts = 0;
8098
- var maxAttempts = 30;
8099
8194
  var tryResolve = function tryResolve() {
8100
- var res = player.getMinHlsResolution();
8101
- if (res) {
8102
- setOverlayCoordSpace(res);
8195
+ var _player_getMaxHlsResolution, _player_getMinHlsResolution;
8196
+ var player = playerRef.current;
8197
+ var fixed = swirlOverlayCoordinateSpace;
8198
+ if (fixed && fixed.width > 0 && fixed.height > 0) {
8199
+ setOverlayCoordSpace({
8200
+ width: fixed.width,
8201
+ height: fixed.height
8202
+ });
8103
8203
  return true;
8104
8204
  }
8105
- var video = player.videoElement;
8106
- if (video && video.videoWidth > 0 && video.videoHeight > 0) {
8205
+ if (!player) return false;
8206
+ var video2 = player.videoElement;
8207
+ if (video2 && video2.videoWidth > 0 && video2.videoHeight > 0) {
8107
8208
  setOverlayCoordSpace({
8108
- width: video.videoWidth,
8109
- height: video.videoHeight
8209
+ width: video2.videoWidth,
8210
+ height: video2.videoHeight
8110
8211
  });
8111
8212
  return true;
8112
8213
  }
8214
+ var maxRes = (_player_getMaxHlsResolution = player.getMaxHlsResolution) === null || _player_getMaxHlsResolution === void 0 ? void 0 : _player_getMaxHlsResolution.call(player);
8215
+ if (maxRes) {
8216
+ setOverlayCoordSpace(maxRes);
8217
+ return true;
8218
+ }
8219
+ var minRes = (_player_getMinHlsResolution = player.getMinHlsResolution) === null || _player_getMinHlsResolution === void 0 ? void 0 : _player_getMinHlsResolution.call(player);
8220
+ if (minRes) {
8221
+ setOverlayCoordSpace(minRes);
8222
+ return true;
8223
+ }
8113
8224
  return false;
8114
8225
  };
8115
- if (tryResolve()) return;
8226
+ var attempts = 0;
8227
+ var maxAttempts = 40;
8228
+ tryResolve();
8116
8229
  var interval = setInterval(function() {
8117
8230
  attempts++;
8118
- if (tryResolve() || attempts >= maxAttempts) clearInterval(interval);
8231
+ if (!swirlOverlayCoordinateSpace) {
8232
+ tryResolve();
8233
+ }
8234
+ if (attempts >= maxAttempts) clearInterval(interval);
8119
8235
  }, 300);
8236
+ var onVideoDims = function onVideoDims() {
8237
+ if (!swirlOverlayCoordinateSpace) {
8238
+ tryResolve();
8239
+ }
8240
+ };
8241
+ var video = (_playerRef_current = playerRef.current) === null || _playerRef_current === void 0 ? void 0 : _playerRef_current.videoElement;
8242
+ video === null || video === void 0 ? void 0 : video.addEventListener("loadedmetadata", onVideoDims);
8120
8243
  return function() {
8121
- return clearInterval(interval);
8244
+ clearInterval(interval);
8245
+ video === null || video === void 0 ? void 0 : video.removeEventListener("loadedmetadata", onVideoDims);
8122
8246
  };
8123
8247
  }, [
8124
8248
  swirlProjectId,
8125
- criticalPropsKey
8249
+ criticalPropsKey,
8250
+ swirlOverlayCoordinateSpace
8126
8251
  ]);
8127
8252
  (0, import_react2.useEffect)(function() {
8128
8253
  if (!playerRef.current) return;
@@ -9924,6 +10049,8 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
9924
10049
  "children",
9925
10050
  "swirlProjectId",
9926
10051
  "swirlShowcaseDemo",
10052
+ "swirlOverlayApiBaseUrl",
10053
+ "swirlOverlayCoordinateSpace",
9927
10054
  "adcisionChannelId",
9928
10055
  "disableOverlays",
9929
10056
  "showAdsControl",
@@ -11151,6 +11278,7 @@ var StormcloudPlayer_default = StormcloudPlayer;
11151
11278
  IS_GLOBAL: IS_GLOBAL,
11152
11279
  IS_IOS: IS_IOS,
11153
11280
  IS_SAFARI: IS_SAFARI,
11281
+ OVERLAY_API_BASE: OVERLAY_API_BASE,
11154
11282
  SUPPORTS_DASH: SUPPORTS_DASH,
11155
11283
  SUPPORTS_HLS: SUPPORTS_HLS,
11156
11284
  StormcloudPlayer: StormcloudPlayer,
@@ -11171,11 +11299,13 @@ var StormcloudPlayer_default = StormcloudPlayer;
11171
11299
  lazy: lazy,
11172
11300
  logBrowserInfo: logBrowserInfo,
11173
11301
  merge: merge,
11302
+ normalizeSwirlOverlay: normalizeSwirlOverlay,
11174
11303
  omit: omit,
11175
11304
  parseQuery: parseQuery,
11176
11305
  players: players,
11177
11306
  randomString: randomString,
11178
11307
  resolveImageUrl: resolveImageUrl,
11308
+ scrollerLooksLikeMarketsStock: scrollerLooksLikeMarketsStock,
11179
11309
  sendHeartbeat: sendHeartbeat,
11180
11310
  sendInitialTracking: sendInitialTracking,
11181
11311
  supportsFeature: supportsFeature,