stormcloud-video-player 0.7.36 → 0.7.38

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
  });
@@ -7185,7 +7265,8 @@ var OverlayRenderer = function OverlayRenderer(param) {
7185
7265
  var activeOverlays = (0, import_react.useMemo)(function() {
7186
7266
  if (showcaseMode) {
7187
7267
  return overlays.filter(function(o) {
7188
- return o.visible && showcasePhase < SHOWCASE_POP_OUT_END_MS;
7268
+ if (!o.visible) return false;
7269
+ return showcasePhase < SHOWCASE_POP_OUT_END_MS;
7189
7270
  });
7190
7271
  }
7191
7272
  return overlays.filter(function(o) {
@@ -7204,7 +7285,7 @@ var OverlayRenderer = function OverlayRenderer(param) {
7204
7285
  }, [
7205
7286
  activeOverlays
7206
7287
  ]);
7207
- (0, import_react.useEffect)(function() {
7288
+ (0, import_react.useLayoutEffect)(function() {
7208
7289
  var activeIds = new Set(activeOverlays.map(function(o) {
7209
7290
  return o.id;
7210
7291
  }));
@@ -7393,8 +7474,9 @@ var OverlayRenderer = function OverlayRenderer(param) {
7393
7474
  var height = overlay.height * scaleY;
7394
7475
  var baseOpacity = Math.max(0, Math.min(100, overlay.opacity)) / 100;
7395
7476
  var inShowcaseBeat = showcaseMode && activeBeatIds.has(overlay.id);
7396
- var opacity = inShowcaseBeat ? baseOpacity * showcaseOpacity(showcasePhase) : visible ? baseOpacity : 0;
7397
- var popScale = inShowcaseBeat ? showcaseScale(showcasePhase) : 1;
7477
+ var useShowcasePop = inShowcaseBeat;
7478
+ var opacity = useShowcasePop ? baseOpacity * showcaseOpacity(showcasePhase) : visible ? baseOpacity : 0;
7479
+ var popScale = useShowcasePop ? showcaseScale(showcasePhase) : 1;
7398
7480
  var sz = {
7399
7481
  w: width,
7400
7482
  h: height
@@ -7407,9 +7489,9 @@ var OverlayRenderer = function OverlayRenderer(param) {
7407
7489
  width: "".concat(width, "px"),
7408
7490
  height: "".concat(height, "px"),
7409
7491
  opacity: opacity,
7410
- transition: inShowcaseBeat ? "none" : "opacity ".concat(FADE_DURATION_MS, "ms ease"),
7411
- transform: showcaseMode ? "scale(".concat(popScale, ")") : void 0,
7412
- transformOrigin: showcaseMode ? "center center" : void 0,
7492
+ transition: useShowcasePop ? "none" : "opacity ".concat(FADE_DURATION_MS, "ms ease"),
7493
+ transform: showcaseMode && useShowcasePop ? "scale(".concat(popScale, ")") : void 0,
7494
+ transformOrigin: showcaseMode && useShowcasePop ? "center center" : void 0,
7413
7495
  zIndex: overlay.z_index,
7414
7496
  overflow: "hidden"
7415
7497
  },
@@ -7535,7 +7617,7 @@ var PANEL_BASE_RIGHT_OFFSET = 10;
7535
7617
  var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props) {
7536
7618
  var _ref;
7537
7619
  var _aiLiveContext_context;
7538
- 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, [
7539
7621
  "src",
7540
7622
  "autoplay",
7541
7623
  "muted",
@@ -7565,6 +7647,8 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7565
7647
  "disableFiller",
7566
7648
  "swirlProjectId",
7567
7649
  "swirlShowcaseDemo",
7650
+ "swirlOverlayApiBaseUrl",
7651
+ "swirlOverlayCoordinateSpace",
7568
7652
  "adcisionChannelId",
7569
7653
  "disableOverlays",
7570
7654
  "showAdsControl",
@@ -7601,13 +7685,21 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7601
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];
7602
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];
7603
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
+ ]);
7604
7693
  var displayOverlays = import_react2.default.useMemo(function() {
7605
7694
  if (!swirlProjectId || !swirlShowcaseDemo) return overlays;
7606
- if (overlays.some(function(o) {
7695
+ if (overlays.some(scrollerLooksLikeMarketsStock)) return overlays;
7696
+ var hasOtherScroller = overlays.some(function(o) {
7607
7697
  return o.type === "scroller";
7608
- })) return overlays;
7698
+ });
7609
7699
  return _to_consumable_array(overlays).concat([
7610
- createDemoStockTickerOverlay(swirlProjectId)
7700
+ createDemoStockTickerOverlay(swirlProjectId, {
7701
+ stackAboveNews: hasOtherScroller
7702
+ })
7611
7703
  ]);
7612
7704
  }, [
7613
7705
  overlays,
@@ -7887,7 +7979,7 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7887
7979
  }
7888
7980
  var cancelled = false;
7889
7981
  var loadOverlays = function loadOverlays() {
7890
- fetchProjectOverlays(swirlProjectId).then(function(data) {
7982
+ fetchProjectOverlays(swirlProjectId, overlayApiBase).then(function(data) {
7891
7983
  if (!cancelled) setOverlays(data);
7892
7984
  }).catch(function(err) {
7893
7985
  if (!cancelled) {
@@ -7903,41 +7995,69 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7903
7995
  };
7904
7996
  }, [
7905
7997
  swirlProjectId,
7906
- adcisionChannelId
7998
+ adcisionChannelId,
7999
+ overlayApiBase
7907
8000
  ]);
7908
8001
  (0, import_react2.useEffect)(function() {
8002
+ var _playerRef_current;
7909
8003
  if (!swirlProjectId) return;
7910
- var player = playerRef.current;
7911
- if (!player) return;
7912
- var attempts = 0;
7913
- var maxAttempts = 30;
7914
8004
  var tryResolve = function tryResolve() {
7915
- var res = player.getMinHlsResolution();
7916
- if (res) {
7917
- 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
+ });
7918
8013
  return true;
7919
8014
  }
7920
- var video = player.videoElement;
7921
- 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) {
7922
8018
  setOverlayCoordSpace({
7923
- width: video.videoWidth,
7924
- height: video.videoHeight
8019
+ width: video2.videoWidth,
8020
+ height: video2.videoHeight
7925
8021
  });
7926
8022
  return true;
7927
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
+ }
7928
8034
  return false;
7929
8035
  };
7930
- if (tryResolve()) return;
8036
+ var attempts = 0;
8037
+ var maxAttempts = 40;
8038
+ tryResolve();
7931
8039
  var interval = setInterval(function() {
7932
8040
  attempts++;
7933
- if (tryResolve() || attempts >= maxAttempts) clearInterval(interval);
8041
+ if (!swirlOverlayCoordinateSpace) {
8042
+ tryResolve();
8043
+ }
8044
+ if (attempts >= maxAttempts) clearInterval(interval);
7934
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);
7935
8053
  return function() {
7936
- return clearInterval(interval);
8054
+ clearInterval(interval);
8055
+ video === null || video === void 0 ? void 0 : video.removeEventListener("loadedmetadata", onVideoDims);
7937
8056
  };
7938
8057
  }, [
7939
8058
  swirlProjectId,
7940
- criticalPropsKey
8059
+ criticalPropsKey,
8060
+ swirlOverlayCoordinateSpace
7941
8061
  ]);
7942
8062
  (0, import_react2.useEffect)(function() {
7943
8063
  if (!playerRef.current) return;
@@ -9739,6 +9859,8 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
9739
9859
  "children",
9740
9860
  "swirlProjectId",
9741
9861
  "swirlShowcaseDemo",
9862
+ "swirlOverlayApiBaseUrl",
9863
+ "swirlOverlayCoordinateSpace",
9742
9864
  "adcisionChannelId",
9743
9865
  "disableOverlays",
9744
9866
  "showAdsControl",