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.
@@ -5502,6 +5502,46 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5502
5502
  return min;
5503
5503
  }
5504
5504
  },
5505
+ {
5506
+ key: "getMaxHlsResolution",
5507
+ value: function getMaxHlsResolution() {
5508
+ var _this_hls;
5509
+ var levels = (_this_hls = this.hls) === null || _this_hls === void 0 ? void 0 : _this_hls.levels;
5510
+ if (!levels || levels.length === 0) return null;
5511
+ var max = null;
5512
+ var maxPixels = 0;
5513
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
5514
+ try {
5515
+ for(var _iterator = levels[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
5516
+ var level = _step.value;
5517
+ if (level.width && level.height) {
5518
+ var pixels = level.width * level.height;
5519
+ if (pixels > maxPixels) {
5520
+ maxPixels = pixels;
5521
+ max = {
5522
+ width: level.width,
5523
+ height: level.height
5524
+ };
5525
+ }
5526
+ }
5527
+ }
5528
+ } catch (err) {
5529
+ _didIteratorError = true;
5530
+ _iteratorError = err;
5531
+ } finally{
5532
+ try {
5533
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
5534
+ _iterator.return();
5535
+ }
5536
+ } finally{
5537
+ if (_didIteratorError) {
5538
+ throw _iteratorError;
5539
+ }
5540
+ }
5541
+ }
5542
+ return max;
5543
+ }
5544
+ },
5505
5545
  {
5506
5546
  key: "getCurrentHlsSegmentDurationMs",
5507
5547
  value: function getCurrentHlsSegmentDurationMs() {
@@ -5649,7 +5689,15 @@ function isOverlayActive(overlay, currentTime) {
5649
5689
  if (durationSec <= 0) return false;
5650
5690
  return currentTime >= startSec && currentTime < startSec + durationSec;
5651
5691
  }
5652
- function createDemoStockTickerOverlay(projectId) {
5692
+ function scrollerLooksLikeMarketsStock(o) {
5693
+ var _ref, _ref1, _ref2, _ref3;
5694
+ if (o.type !== "scroller") return false;
5695
+ var cfg = o.scroller_config;
5696
+ 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 : "");
5697
+ return /\b(MARKETS?|NYSE|NASDAQ|DJIA|\bS&P\b|STOCK|AAPL|TSLA|NVDA|EQUITIES)\b/i.test(blob);
5698
+ }
5699
+ function createDemoStockTickerOverlay(projectId, opts) {
5700
+ var stack = (opts === null || opts === void 0 ? void 0 : opts.stackAboveNews) === true;
5653
5701
  return {
5654
5702
  id: -9001,
5655
5703
  project_id: projectId,
@@ -5657,13 +5705,13 @@ function createDemoStockTickerOverlay(projectId) {
5657
5705
  type: "scroller",
5658
5706
  visible: true,
5659
5707
  x: 144,
5660
- y: 950,
5708
+ y: stack ? 818 : 950,
5661
5709
  width: 1632,
5662
- height: 97,
5710
+ height: stack ? 78 : 97,
5663
5711
  opacity: 100,
5664
5712
  start_time: "00:00:00.000",
5665
5713
  duration: "24:00:00.000",
5666
- z_index: 120,
5714
+ z_index: stack ? 125 : 120,
5667
5715
  scroller_config: {
5668
5716
  use_custom_text: true,
5669
5717
  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%",
@@ -5685,17 +5733,43 @@ function createDemoStockTickerOverlay(projectId) {
5685
5733
  }
5686
5734
  };
5687
5735
  }
5736
+ function normalizeScrollerConfig(raw) {
5737
+ if (!raw || (typeof raw === "undefined" ? "undefined" : _type_of(raw)) !== "object") return void 0;
5738
+ var r = raw;
5739
+ var merged = _object_spread({}, raw);
5740
+ if (merged.use_custom_text === void 0 && typeof r.useCustomText === "boolean") {
5741
+ merged.use_custom_text = r.useCustomText;
5742
+ }
5743
+ if ((merged.custom_text === void 0 || merged.custom_text === "") && typeof r.customText === "string") {
5744
+ merged.custom_text = r.customText;
5745
+ }
5746
+ if (!merged.rss_url && typeof r.rssUrl === "string") {
5747
+ merged.rss_url = r.rssUrl;
5748
+ }
5749
+ return merged;
5750
+ }
5751
+ function normalizeSwirlOverlay(raw) {
5752
+ var o = _object_spread({}, raw);
5753
+ if (o.type === "scroller") {
5754
+ var _raw_scroller_config;
5755
+ var sc = (_raw_scroller_config = raw.scroller_config) !== null && _raw_scroller_config !== void 0 ? _raw_scroller_config : raw.scrollerConfig;
5756
+ var normalized = normalizeScrollerConfig(sc);
5757
+ if (normalized) o.scroller_config = normalized;
5758
+ }
5759
+ return o;
5760
+ }
5688
5761
  function fetchProjectOverlays(_0) {
5689
5762
  return _async_to_generator(function(projectId) {
5690
- var apiBaseUrl, response, data;
5763
+ var apiBaseUrl, base, response, data;
5691
5764
  var _arguments = arguments;
5692
5765
  return _ts_generator(this, function(_state) {
5693
5766
  switch(_state.label){
5694
5767
  case 0:
5695
5768
  apiBaseUrl = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : OVERLAY_API_BASE;
5769
+ base = apiBaseUrl.replace(/\/$/, "");
5696
5770
  return [
5697
5771
  4,
5698
- fetch("".concat(apiBaseUrl, "/adstorm/swirl/projects/").concat(projectId, "/overlays"))
5772
+ fetch("".concat(base, "/adstorm/swirl/projects/").concat(projectId, "/overlays"))
5699
5773
  ];
5700
5774
  case 1:
5701
5775
  response = _state.sent();
@@ -5708,9 +5782,15 @@ function fetchProjectOverlays(_0) {
5708
5782
  ];
5709
5783
  case 2:
5710
5784
  data = _state.sent();
5785
+ if (!Array.isArray(data)) return [
5786
+ 2,
5787
+ []
5788
+ ];
5711
5789
  return [
5712
5790
  2,
5713
- Array.isArray(data) ? data : []
5791
+ data.map(function(row) {
5792
+ return normalizeSwirlOverlay(row);
5793
+ })
5714
5794
  ];
5715
5795
  }
5716
5796
  });
@@ -7121,7 +7201,7 @@ function showcaseOpacity(phase) {
7121
7201
  }
7122
7202
  function showcaseScale(phase) {
7123
7203
  if (phase < SHOWCASE_POP_IN_MS) {
7124
- return 0.78 + 0.22 * easeOutBack(phase / SHOWCASE_POP_IN_MS);
7204
+ return Math.min(1, 0.78 + 0.22 * easeOutBack(phase / SHOWCASE_POP_IN_MS));
7125
7205
  }
7126
7206
  if (phase >= SHOWCASE_STEADY_END_MS && phase < SHOWCASE_POP_OUT_END_MS) {
7127
7207
  return 1 - 0.14 * easeInCubic((phase - SHOWCASE_STEADY_END_MS) / SHOWCASE_POP_OUT_MS);
@@ -7186,7 +7266,6 @@ var OverlayRenderer = function OverlayRenderer(param) {
7186
7266
  if (showcaseMode) {
7187
7267
  return overlays.filter(function(o) {
7188
7268
  if (!o.visible) return false;
7189
- if (o.type === "scroller") return true;
7190
7269
  return showcasePhase < SHOWCASE_POP_OUT_END_MS;
7191
7270
  });
7192
7271
  }
@@ -7206,7 +7285,7 @@ var OverlayRenderer = function OverlayRenderer(param) {
7206
7285
  }, [
7207
7286
  activeOverlays
7208
7287
  ]);
7209
- (0, import_react.useEffect)(function() {
7288
+ (0, import_react.useLayoutEffect)(function() {
7210
7289
  var activeIds = new Set(activeOverlays.map(function(o) {
7211
7290
  return o.id;
7212
7291
  }));
@@ -7394,10 +7473,9 @@ var OverlayRenderer = function OverlayRenderer(param) {
7394
7473
  var width = overlay.width * scaleX;
7395
7474
  var height = overlay.height * scaleY;
7396
7475
  var baseOpacity = Math.max(0, Math.min(100, overlay.opacity)) / 100;
7397
- var isScrollerTicker = overlay.type === "scroller";
7398
7476
  var inShowcaseBeat = showcaseMode && activeBeatIds.has(overlay.id);
7399
- var useShowcasePop = inShowcaseBeat && !isScrollerTicker;
7400
- var opacity = useShowcasePop ? baseOpacity * showcaseOpacity(showcasePhase) : inShowcaseBeat && isScrollerTicker ? baseOpacity : visible ? baseOpacity : 0;
7477
+ var useShowcasePop = inShowcaseBeat;
7478
+ var opacity = useShowcasePop ? baseOpacity * showcaseOpacity(showcasePhase) : visible ? baseOpacity : 0;
7401
7479
  var popScale = useShowcasePop ? showcaseScale(showcasePhase) : 1;
7402
7480
  var sz = {
7403
7481
  w: width,
@@ -7539,7 +7617,7 @@ var PANEL_BASE_RIGHT_OFFSET = 10;
7539
7617
  var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props) {
7540
7618
  var _ref;
7541
7619
  var _aiLiveContext_context;
7542
- 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, [
7620
+ 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, [
7543
7621
  "src",
7544
7622
  "autoplay",
7545
7623
  "muted",
@@ -7569,6 +7647,8 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7569
7647
  "disableFiller",
7570
7648
  "swirlProjectId",
7571
7649
  "swirlShowcaseDemo",
7650
+ "swirlOverlayApiBaseUrl",
7651
+ "swirlOverlayCoordinateSpace",
7572
7652
  "adcisionChannelId",
7573
7653
  "disableOverlays",
7574
7654
  "showAdsControl",
@@ -7605,13 +7685,21 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7605
7685
  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];
7606
7686
  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];
7607
7687
  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];
7688
+ var overlayApiBase = import_react2.default.useMemo(function() {
7689
+ return (swirlOverlayApiBaseUrl === null || swirlOverlayApiBaseUrl === void 0 ? void 0 : swirlOverlayApiBaseUrl.replace(/\/$/, "")) || OVERLAY_API_BASE;
7690
+ }, [
7691
+ swirlOverlayApiBaseUrl
7692
+ ]);
7608
7693
  var displayOverlays = import_react2.default.useMemo(function() {
7609
7694
  if (!swirlProjectId || !swirlShowcaseDemo) return overlays;
7610
- if (overlays.some(function(o) {
7695
+ if (overlays.some(scrollerLooksLikeMarketsStock)) return overlays;
7696
+ var hasOtherScroller = overlays.some(function(o) {
7611
7697
  return o.type === "scroller";
7612
- })) return overlays;
7698
+ });
7613
7699
  return _to_consumable_array(overlays).concat([
7614
- createDemoStockTickerOverlay(swirlProjectId)
7700
+ createDemoStockTickerOverlay(swirlProjectId, {
7701
+ stackAboveNews: hasOtherScroller
7702
+ })
7615
7703
  ]);
7616
7704
  }, [
7617
7705
  overlays,
@@ -7891,7 +7979,7 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7891
7979
  }
7892
7980
  var cancelled = false;
7893
7981
  var loadOverlays = function loadOverlays() {
7894
- fetchProjectOverlays(swirlProjectId).then(function(data) {
7982
+ fetchProjectOverlays(swirlProjectId, overlayApiBase).then(function(data) {
7895
7983
  if (!cancelled) setOverlays(data);
7896
7984
  }).catch(function(err) {
7897
7985
  if (!cancelled) {
@@ -7907,41 +7995,69 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7907
7995
  };
7908
7996
  }, [
7909
7997
  swirlProjectId,
7910
- adcisionChannelId
7998
+ adcisionChannelId,
7999
+ overlayApiBase
7911
8000
  ]);
7912
8001
  (0, import_react2.useEffect)(function() {
8002
+ var _playerRef_current;
7913
8003
  if (!swirlProjectId) return;
7914
- var player = playerRef.current;
7915
- if (!player) return;
7916
- var attempts = 0;
7917
- var maxAttempts = 30;
7918
8004
  var tryResolve = function tryResolve() {
7919
- var res = player.getMinHlsResolution();
7920
- if (res) {
7921
- setOverlayCoordSpace(res);
8005
+ var _player_getMaxHlsResolution, _player_getMinHlsResolution;
8006
+ var player = playerRef.current;
8007
+ var fixed = swirlOverlayCoordinateSpace;
8008
+ if (fixed && fixed.width > 0 && fixed.height > 0) {
8009
+ setOverlayCoordSpace({
8010
+ width: fixed.width,
8011
+ height: fixed.height
8012
+ });
7922
8013
  return true;
7923
8014
  }
7924
- var video = player.videoElement;
7925
- if (video && video.videoWidth > 0 && video.videoHeight > 0) {
8015
+ if (!player) return false;
8016
+ var video2 = player.videoElement;
8017
+ if (video2 && video2.videoWidth > 0 && video2.videoHeight > 0) {
7926
8018
  setOverlayCoordSpace({
7927
- width: video.videoWidth,
7928
- height: video.videoHeight
8019
+ width: video2.videoWidth,
8020
+ height: video2.videoHeight
7929
8021
  });
7930
8022
  return true;
7931
8023
  }
8024
+ var maxRes = (_player_getMaxHlsResolution = player.getMaxHlsResolution) === null || _player_getMaxHlsResolution === void 0 ? void 0 : _player_getMaxHlsResolution.call(player);
8025
+ if (maxRes) {
8026
+ setOverlayCoordSpace(maxRes);
8027
+ return true;
8028
+ }
8029
+ var minRes = (_player_getMinHlsResolution = player.getMinHlsResolution) === null || _player_getMinHlsResolution === void 0 ? void 0 : _player_getMinHlsResolution.call(player);
8030
+ if (minRes) {
8031
+ setOverlayCoordSpace(minRes);
8032
+ return true;
8033
+ }
7932
8034
  return false;
7933
8035
  };
7934
- if (tryResolve()) return;
8036
+ var attempts = 0;
8037
+ var maxAttempts = 40;
8038
+ tryResolve();
7935
8039
  var interval = setInterval(function() {
7936
8040
  attempts++;
7937
- if (tryResolve() || attempts >= maxAttempts) clearInterval(interval);
8041
+ if (!swirlOverlayCoordinateSpace) {
8042
+ tryResolve();
8043
+ }
8044
+ if (attempts >= maxAttempts) clearInterval(interval);
7938
8045
  }, 300);
8046
+ var onVideoDims = function onVideoDims() {
8047
+ if (!swirlOverlayCoordinateSpace) {
8048
+ tryResolve();
8049
+ }
8050
+ };
8051
+ var video = (_playerRef_current = playerRef.current) === null || _playerRef_current === void 0 ? void 0 : _playerRef_current.videoElement;
8052
+ video === null || video === void 0 ? void 0 : video.addEventListener("loadedmetadata", onVideoDims);
7939
8053
  return function() {
7940
- return clearInterval(interval);
8054
+ clearInterval(interval);
8055
+ video === null || video === void 0 ? void 0 : video.removeEventListener("loadedmetadata", onVideoDims);
7941
8056
  };
7942
8057
  }, [
7943
8058
  swirlProjectId,
7944
- criticalPropsKey
8059
+ criticalPropsKey,
8060
+ swirlOverlayCoordinateSpace
7945
8061
  ]);
7946
8062
  (0, import_react2.useEffect)(function() {
7947
8063
  if (!playerRef.current) return;
@@ -9743,6 +9859,8 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
9743
9859
  "children",
9744
9860
  "swirlProjectId",
9745
9861
  "swirlShowcaseDemo",
9862
+ "swirlOverlayApiBaseUrl",
9863
+ "swirlOverlayCoordinateSpace",
9746
9864
  "adcisionChannelId",
9747
9865
  "disableOverlays",
9748
9866
  "showAdsControl",