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.
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
  });
@@ -7366,7 +7455,8 @@ var OverlayRenderer = function OverlayRenderer(param) {
7366
7455
  var activeOverlays = (0, import_react.useMemo)(function() {
7367
7456
  if (showcaseMode) {
7368
7457
  return overlays.filter(function(o) {
7369
- return o.visible && showcasePhase < SHOWCASE_POP_OUT_END_MS;
7458
+ if (!o.visible) return false;
7459
+ return showcasePhase < SHOWCASE_POP_OUT_END_MS;
7370
7460
  });
7371
7461
  }
7372
7462
  return overlays.filter(function(o) {
@@ -7385,7 +7475,7 @@ var OverlayRenderer = function OverlayRenderer(param) {
7385
7475
  }, [
7386
7476
  activeOverlays
7387
7477
  ]);
7388
- (0, import_react.useEffect)(function() {
7478
+ (0, import_react.useLayoutEffect)(function() {
7389
7479
  var activeIds = new Set(activeOverlays.map(function(o) {
7390
7480
  return o.id;
7391
7481
  }));
@@ -7574,8 +7664,9 @@ var OverlayRenderer = function OverlayRenderer(param) {
7574
7664
  var height = overlay.height * scaleY;
7575
7665
  var baseOpacity = Math.max(0, Math.min(100, overlay.opacity)) / 100;
7576
7666
  var inShowcaseBeat = showcaseMode && activeBeatIds.has(overlay.id);
7577
- var opacity = inShowcaseBeat ? baseOpacity * showcaseOpacity(showcasePhase) : visible ? baseOpacity : 0;
7578
- var popScale = inShowcaseBeat ? showcaseScale(showcasePhase) : 1;
7667
+ var useShowcasePop = inShowcaseBeat;
7668
+ var opacity = useShowcasePop ? baseOpacity * showcaseOpacity(showcasePhase) : visible ? baseOpacity : 0;
7669
+ var popScale = useShowcasePop ? showcaseScale(showcasePhase) : 1;
7579
7670
  var sz = {
7580
7671
  w: width,
7581
7672
  h: height
@@ -7588,9 +7679,9 @@ var OverlayRenderer = function OverlayRenderer(param) {
7588
7679
  width: "".concat(width, "px"),
7589
7680
  height: "".concat(height, "px"),
7590
7681
  opacity: opacity,
7591
- transition: inShowcaseBeat ? "none" : "opacity ".concat(FADE_DURATION_MS, "ms ease"),
7592
- transform: showcaseMode ? "scale(".concat(popScale, ")") : void 0,
7593
- transformOrigin: showcaseMode ? "center center" : void 0,
7682
+ transition: useShowcasePop ? "none" : "opacity ".concat(FADE_DURATION_MS, "ms ease"),
7683
+ transform: showcaseMode && useShowcasePop ? "scale(".concat(popScale, ")") : void 0,
7684
+ transformOrigin: showcaseMode && useShowcasePop ? "center center" : void 0,
7594
7685
  zIndex: overlay.z_index,
7595
7686
  overflow: "hidden"
7596
7687
  },
@@ -7716,7 +7807,7 @@ var PANEL_BASE_RIGHT_OFFSET = 10;
7716
7807
  var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props) {
7717
7808
  var _ref;
7718
7809
  var _aiLiveContext_context;
7719
- 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, [
7720
7811
  "src",
7721
7812
  "autoplay",
7722
7813
  "muted",
@@ -7746,6 +7837,8 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7746
7837
  "disableFiller",
7747
7838
  "swirlProjectId",
7748
7839
  "swirlShowcaseDemo",
7840
+ "swirlOverlayApiBaseUrl",
7841
+ "swirlOverlayCoordinateSpace",
7749
7842
  "adcisionChannelId",
7750
7843
  "disableOverlays",
7751
7844
  "showAdsControl",
@@ -7782,13 +7875,21 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7782
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];
7783
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];
7784
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
+ ]);
7785
7883
  var displayOverlays = import_react2.default.useMemo(function() {
7786
7884
  if (!swirlProjectId || !swirlShowcaseDemo) return overlays;
7787
- if (overlays.some(function(o) {
7885
+ if (overlays.some(scrollerLooksLikeMarketsStock)) return overlays;
7886
+ var hasOtherScroller = overlays.some(function(o) {
7788
7887
  return o.type === "scroller";
7789
- })) return overlays;
7888
+ });
7790
7889
  return _to_consumable_array(overlays).concat([
7791
- createDemoStockTickerOverlay(swirlProjectId)
7890
+ createDemoStockTickerOverlay(swirlProjectId, {
7891
+ stackAboveNews: hasOtherScroller
7892
+ })
7792
7893
  ]);
7793
7894
  }, [
7794
7895
  overlays,
@@ -8068,7 +8169,7 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
8068
8169
  }
8069
8170
  var cancelled = false;
8070
8171
  var loadOverlays = function loadOverlays() {
8071
- fetchProjectOverlays(swirlProjectId).then(function(data) {
8172
+ fetchProjectOverlays(swirlProjectId, overlayApiBase).then(function(data) {
8072
8173
  if (!cancelled) setOverlays(data);
8073
8174
  }).catch(function(err) {
8074
8175
  if (!cancelled) {
@@ -8084,41 +8185,69 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
8084
8185
  };
8085
8186
  }, [
8086
8187
  swirlProjectId,
8087
- adcisionChannelId
8188
+ adcisionChannelId,
8189
+ overlayApiBase
8088
8190
  ]);
8089
8191
  (0, import_react2.useEffect)(function() {
8192
+ var _playerRef_current;
8090
8193
  if (!swirlProjectId) return;
8091
- var player = playerRef.current;
8092
- if (!player) return;
8093
- var attempts = 0;
8094
- var maxAttempts = 30;
8095
8194
  var tryResolve = function tryResolve() {
8096
- var res = player.getMinHlsResolution();
8097
- if (res) {
8098
- 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
+ });
8099
8203
  return true;
8100
8204
  }
8101
- var video = player.videoElement;
8102
- 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) {
8103
8208
  setOverlayCoordSpace({
8104
- width: video.videoWidth,
8105
- height: video.videoHeight
8209
+ width: video2.videoWidth,
8210
+ height: video2.videoHeight
8106
8211
  });
8107
8212
  return true;
8108
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
+ }
8109
8224
  return false;
8110
8225
  };
8111
- if (tryResolve()) return;
8226
+ var attempts = 0;
8227
+ var maxAttempts = 40;
8228
+ tryResolve();
8112
8229
  var interval = setInterval(function() {
8113
8230
  attempts++;
8114
- if (tryResolve() || attempts >= maxAttempts) clearInterval(interval);
8231
+ if (!swirlOverlayCoordinateSpace) {
8232
+ tryResolve();
8233
+ }
8234
+ if (attempts >= maxAttempts) clearInterval(interval);
8115
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);
8116
8243
  return function() {
8117
- return clearInterval(interval);
8244
+ clearInterval(interval);
8245
+ video === null || video === void 0 ? void 0 : video.removeEventListener("loadedmetadata", onVideoDims);
8118
8246
  };
8119
8247
  }, [
8120
8248
  swirlProjectId,
8121
- criticalPropsKey
8249
+ criticalPropsKey,
8250
+ swirlOverlayCoordinateSpace
8122
8251
  ]);
8123
8252
  (0, import_react2.useEffect)(function() {
8124
8253
  if (!playerRef.current) return;
@@ -9920,6 +10049,8 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
9920
10049
  "children",
9921
10050
  "swirlProjectId",
9922
10051
  "swirlShowcaseDemo",
10052
+ "swirlOverlayApiBaseUrl",
10053
+ "swirlOverlayCoordinateSpace",
9923
10054
  "adcisionChannelId",
9924
10055
  "disableOverlays",
9925
10056
  "showAdsControl",
@@ -11147,6 +11278,7 @@ var StormcloudPlayer_default = StormcloudPlayer;
11147
11278
  IS_GLOBAL: IS_GLOBAL,
11148
11279
  IS_IOS: IS_IOS,
11149
11280
  IS_SAFARI: IS_SAFARI,
11281
+ OVERLAY_API_BASE: OVERLAY_API_BASE,
11150
11282
  SUPPORTS_DASH: SUPPORTS_DASH,
11151
11283
  SUPPORTS_HLS: SUPPORTS_HLS,
11152
11284
  StormcloudPlayer: StormcloudPlayer,
@@ -11167,11 +11299,13 @@ var StormcloudPlayer_default = StormcloudPlayer;
11167
11299
  lazy: lazy,
11168
11300
  logBrowserInfo: logBrowserInfo,
11169
11301
  merge: merge,
11302
+ normalizeSwirlOverlay: normalizeSwirlOverlay,
11170
11303
  omit: omit,
11171
11304
  parseQuery: parseQuery,
11172
11305
  players: players,
11173
11306
  randomString: randomString,
11174
11307
  resolveImageUrl: resolveImageUrl,
11308
+ scrollerLooksLikeMarketsStock: scrollerLooksLikeMarketsStock,
11175
11309
  sendHeartbeat: sendHeartbeat,
11176
11310
  sendInitialTracking: sendInitialTracking,
11177
11311
  supportsFeature: supportsFeature,