stormcloud-video-player 0.7.16 → 0.7.18

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
@@ -7368,6 +7368,33 @@ var OverlayRenderer = function OverlayRenderer(param) {
7368
7368
  })
7369
7369
  });
7370
7370
  };
7371
+ // src/utils/adcision.ts
7372
+ var ADCISION_API_BASE = "https://adstorm.co/api-adstorm-dev";
7373
+ function fetchAdcisionChannel(_0) {
7374
+ return _async_to_generator(function(channelId) {
7375
+ var apiBaseUrl, response;
7376
+ var _arguments = arguments;
7377
+ return _ts_generator(this, function(_state) {
7378
+ switch(_state.label){
7379
+ case 0:
7380
+ apiBaseUrl = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : ADCISION_API_BASE;
7381
+ return [
7382
+ 4,
7383
+ fetch("".concat(apiBaseUrl, "/adstorm/adcision/channels/").concat(channelId))
7384
+ ];
7385
+ case 1:
7386
+ response = _state.sent();
7387
+ if (!response.ok) {
7388
+ throw new Error("Failed to fetch adcision channel ".concat(channelId, ": ").concat(response.status, " ").concat(response.statusText));
7389
+ }
7390
+ return [
7391
+ 2,
7392
+ response.json()
7393
+ ];
7394
+ }
7395
+ });
7396
+ }).apply(this, arguments);
7397
+ }
7371
7398
  // src/ui/StormcloudVideoPlayer.tsx
7372
7399
  var import_jsx_runtime2 = require("react/jsx-runtime");
7373
7400
  var CRITICAL_PROPS = [
@@ -7387,7 +7414,7 @@ var PANEL_BASE_RIGHT_OFFSET = 10;
7387
7414
  var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props) {
7388
7415
  var _ref;
7389
7416
  var _aiLiveContext_context;
7390
- 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, restVideoAttrs = _object_without_properties(props, [
7417
+ 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, adcisionChannelId = props.adcisionChannelId, disableOverlays = props.disableOverlays, showAdsControl = props.showAdsControl, showOverlaysControl = props.showOverlaysControl, showAiContextControl = props.showAiContextControl, showDebugControl = props.showDebugControl, restVideoAttrs = _object_without_properties(props, [
7391
7418
  "src",
7392
7419
  "autoplay",
7393
7420
  "muted",
@@ -7415,8 +7442,15 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7415
7442
  "minSegmentsBeforePlay",
7416
7443
  "disableAds",
7417
7444
  "disableFiller",
7418
- "swirlProjectId"
7445
+ "swirlProjectId",
7446
+ "adcisionChannelId",
7447
+ "disableOverlays",
7448
+ "showAdsControl",
7449
+ "showOverlaysControl",
7450
+ "showAiContextControl",
7451
+ "showDebugControl"
7419
7452
  ]);
7453
+ var _ref1 = _sliced_to_array((0, import_react2.useState)(null), 2), adcisionSrc = _ref1[0], setAdcisionSrc = _ref1[1];
7420
7454
  var videoRef = (0, import_react2.useRef)(null);
7421
7455
  var playerRef = (0, import_react2.useRef)(null);
7422
7456
  var bufferingTimeoutRef = (0, import_react2.useRef)(null);
@@ -7452,12 +7486,13 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7452
7486
  var _import_react2_default_useState22 = _sliced_to_array(import_react2.default.useState([]), 2), debugMarkers = _import_react2_default_useState22[0], setDebugMarkers = _import_react2_default_useState22[1];
7453
7487
  var _import_react2_default_useState23 = _sliced_to_array(import_react2.default.useState(false), 2), showAiPanel = _import_react2_default_useState23[0], setShowAiPanel = _import_react2_default_useState23[1];
7454
7488
  var _import_react2_default_useState24 = _sliced_to_array(import_react2.default.useState(disableAds !== null && disableAds !== void 0 ? disableAds : false), 2), adsDisabled = _import_react2_default_useState24[0], setAdsDisabled = _import_react2_default_useState24[1];
7455
- var _import_react2_default_useState25 = _sliced_to_array(import_react2.default.useState({
7489
+ var _import_react2_default_useState25 = _sliced_to_array(import_react2.default.useState(disableOverlays !== null && disableOverlays !== void 0 ? disableOverlays : false), 2), overlaysDisabled = _import_react2_default_useState25[0], setOverlaysDisabled = _import_react2_default_useState25[1];
7490
+ var _import_react2_default_useState26 = _sliced_to_array(import_react2.default.useState({
7456
7491
  context: null,
7457
7492
  isLoading: false,
7458
7493
  error: null,
7459
7494
  lastPolledAt: null
7460
- }), 2), aiLiveContext = _import_react2_default_useState25[0], setAiLiveContext = _import_react2_default_useState25[1];
7495
+ }), 2), aiLiveContext = _import_react2_default_useState26[0], setAiLiveContext = _import_react2_default_useState26[1];
7461
7496
  var getResponsiveScale = function getResponsiveScale() {
7462
7497
  if (viewportWidth < 480) return 0.7;
7463
7498
  if (viewportWidth < 768) return 0.8;
@@ -7615,21 +7650,43 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7615
7650
  var debugPanelBottomOffset = shouldShowEnhancedControls ? Math.max(74, 92 * responsiveScale) : Math.max(52, 58 * responsiveScale);
7616
7651
  var panelBaseRight = PANEL_BASE_RIGHT_OFFSET * responsiveScale;
7617
7652
  var debugPanelRightOffset = showAiPanel && !shouldStackPanels ? panelBaseRight + analyzerPanelWidth + panelGap : panelBaseRight;
7653
+ (0, import_react2.useEffect)(function() {
7654
+ if (!adcisionChannelId) {
7655
+ setAdcisionSrc(null);
7656
+ return;
7657
+ }
7658
+ var cancelled = false;
7659
+ fetchAdcisionChannel(adcisionChannelId).then(function(ch) {
7660
+ if (!cancelled) setAdcisionSrc(ch.stream_url);
7661
+ }).catch(function(err) {
7662
+ if (!cancelled) {
7663
+ console.warn("[StormcloudVideoPlayer] Failed to fetch adcision channel:", err);
7664
+ }
7665
+ });
7666
+ return function() {
7667
+ cancelled = true;
7668
+ };
7669
+ }, [
7670
+ adcisionChannelId
7671
+ ]);
7672
+ var effectiveSrc = adcisionChannelId ? adcisionSrc : src;
7618
7673
  var criticalPropsKey = (0, import_react2.useMemo)(function() {
7619
- return CRITICAL_PROPS.map(function(prop) {
7620
- return "".concat(prop, ":").concat(props[prop]);
7674
+ var baseParts = CRITICAL_PROPS.map(function(prop) {
7675
+ return prop === "src" ? "src:".concat(effectiveSrc) : "".concat(prop, ":").concat(props[prop]);
7621
7676
  }).join("|");
7677
+ return "".concat(baseParts, "|adcisionChannelId:").concat(adcisionChannelId !== null && adcisionChannelId !== void 0 ? adcisionChannelId : "");
7622
7678
  }, [
7623
- src,
7679
+ effectiveSrc,
7624
7680
  allowNativeHls,
7625
7681
  licenseKey,
7626
7682
  lowLatencyMode,
7627
- driftToleranceMs
7683
+ driftToleranceMs,
7684
+ adcisionChannelId
7628
7685
  ]);
7629
7686
  (0, import_react2.useEffect)(function() {
7630
7687
  if (typeof window === "undefined") return;
7631
7688
  var el = videoRef.current;
7632
- if (!el || !src) return;
7689
+ if (!el || !effectiveSrc) return;
7633
7690
  if (!licenseKey) {
7634
7691
  setShowLicenseWarning(true);
7635
7692
  setIsLoading(false);
@@ -7643,7 +7700,7 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7643
7700
  playerRef.current = null;
7644
7701
  }
7645
7702
  var cfg = {
7646
- src: src,
7703
+ src: effectiveSrc,
7647
7704
  videoElement: el
7648
7705
  };
7649
7706
  if (autoplay !== void 0) cfg.autoplay = autoplay;
@@ -7661,7 +7718,7 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7661
7718
  if (minSegmentsBeforePlay !== void 0) cfg.minSegmentsBeforePlay = minSegmentsBeforePlay;
7662
7719
  if (disableAds !== void 0) cfg.disableAds = disableAds;
7663
7720
  cfg.disableFiller = disableFiller !== null && disableFiller !== void 0 ? disableFiller : true;
7664
- if (swirlProjectId !== void 0) cfg.projectId = String(swirlProjectId);
7721
+ if (!adcisionChannelId && swirlProjectId !== void 0) cfg.projectId = String(swirlProjectId);
7665
7722
  var player = new StormcloudVideoPlayer(cfg);
7666
7723
  playerRef.current = player;
7667
7724
  player.load().then(function() {
@@ -7683,7 +7740,7 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7683
7740
  criticalPropsKey
7684
7741
  ]);
7685
7742
  (0, import_react2.useEffect)(function() {
7686
- if (!swirlProjectId) {
7743
+ if (!swirlProjectId || adcisionChannelId) {
7687
7744
  setOverlays([]);
7688
7745
  setOverlayCoordSpace(null);
7689
7746
  return;
@@ -7700,7 +7757,8 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7700
7757
  cancelled = true;
7701
7758
  };
7702
7759
  }, [
7703
- swirlProjectId
7760
+ swirlProjectId,
7761
+ adcisionChannelId
7704
7762
  ]);
7705
7763
  (0, import_react2.useEffect)(function() {
7706
7764
  if (!swirlProjectId) return;
@@ -7942,7 +8000,7 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7942
8000
  criticalPropsKey
7943
8001
  ]);
7944
8002
  (0, import_react2.useEffect)(function() {
7945
- if (!swirlProjectId) {
8003
+ if (!swirlProjectId || adcisionChannelId) {
7946
8004
  setShowAiPanel(false);
7947
8005
  setAiLiveContext({
7948
8006
  context: null,
@@ -7952,10 +8010,11 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
7952
8010
  });
7953
8011
  }
7954
8012
  }, [
7955
- swirlProjectId
8013
+ swirlProjectId,
8014
+ adcisionChannelId
7956
8015
  ]);
7957
8016
  (0, import_react2.useEffect)(function() {
7958
- if (!showAiPanel || !swirlProjectId) return;
8017
+ if (!showAiPanel || !swirlProjectId || adcisionChannelId) return;
7959
8018
  var cancelled = false;
7960
8019
  var pollTimeoutId = null;
7961
8020
  var inFlight = false;
@@ -8132,7 +8191,7 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
8132
8191
  }, restVideoAttrs), {
8133
8192
  children: children
8134
8193
  })),
8135
- overlays.length > 0 && !adStatus.showAds && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OverlayRenderer, {
8194
+ overlays.length > 0 && !adStatus.showAds && !overlaysDisabled && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OverlayRenderer, {
8136
8195
  overlays: overlays,
8137
8196
  currentTime: currentTime,
8138
8197
  videoRef: videoRef,
@@ -8944,7 +9003,7 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
8944
9003
  gap: "".concat(8 * responsiveScale, "px")
8945
9004
  },
8946
9005
  children: [
8947
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
9006
+ (showAdsControl !== null && showAdsControl !== void 0 ? showAdsControl : true) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
8948
9007
  className: "sc-ctrl-btn",
8949
9008
  onClick: function onClick() {
8950
9009
  var _playerRef_current;
@@ -8969,7 +9028,29 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
8969
9028
  title: adsDisabled ? "Enable ads" : "Disable ads",
8970
9029
  children: "AD"
8971
9030
  }),
8972
- swirlProjectId && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
9031
+ swirlProjectId && (showOverlaysControl !== null && showOverlaysControl !== void 0 ? showOverlaysControl : true) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
9032
+ className: "sc-ctrl-btn",
9033
+ onClick: function onClick() {
9034
+ setOverlaysDisabled(function(prev) {
9035
+ return !prev;
9036
+ });
9037
+ resetControlsTimer();
9038
+ },
9039
+ style: {
9040
+ padding: "".concat(8 * responsiveScale, "px"),
9041
+ borderRadius: "50%",
9042
+ minWidth: "".concat(36 * responsiveScale, "px"),
9043
+ minHeight: "".concat(36 * responsiveScale, "px"),
9044
+ background: overlaysDisabled ? "rgba(239, 68, 68, 0.28)" : "transparent",
9045
+ color: overlaysDisabled ? "rgba(252, 165, 165, 0.9)" : "rgba(255, 255, 255, 0.75)",
9046
+ opacity: overlaysDisabled ? 1 : 0.9
9047
+ },
9048
+ title: overlaysDisabled ? "Enable overlays" : "Disable overlays",
9049
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_fa.FaLayerGroup, {
9050
+ size: Math.max(14, 18 * responsiveScale)
9051
+ })
9052
+ }),
9053
+ swirlProjectId && (showAiContextControl !== null && showAiContextControl !== void 0 ? showAiContextControl : true) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
8973
9054
  className: "sc-ctrl-btn",
8974
9055
  onClick: function onClick() {
8975
9056
  setShowAiPanel(function(prev) {
@@ -8991,7 +9072,7 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
8991
9072
  title: showAiPanel ? "Hide AI context" : "Show AI context",
8992
9073
  children: "AI"
8993
9074
  }),
8994
- debugAdTiming && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
9075
+ debugAdTiming && (showDebugControl !== null && showDebugControl !== void 0 ? showDebugControl : true) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
8995
9076
  className: "sc-ctrl-btn",
8996
9077
  onClick: function onClick() {
8997
9078
  setShowDebugPanel(function(prev) {
@@ -9262,7 +9343,7 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
9262
9343
  })
9263
9344
  ]
9264
9345
  }),
9265
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
9346
+ (showAdsControl !== null && showAdsControl !== void 0 ? showAdsControl : true) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
9266
9347
  className: "sc-ctrl-btn",
9267
9348
  onClick: function onClick() {
9268
9349
  var _playerRef_current;
@@ -9287,7 +9368,28 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
9287
9368
  title: adsDisabled ? "Enable ads" : "Disable ads",
9288
9369
  children: "AD"
9289
9370
  }),
9290
- swirlProjectId && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
9371
+ swirlProjectId && (showOverlaysControl !== null && showOverlaysControl !== void 0 ? showOverlaysControl : true) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
9372
+ className: "sc-ctrl-btn",
9373
+ onClick: function onClick() {
9374
+ setOverlaysDisabled(function(prev) {
9375
+ return !prev;
9376
+ });
9377
+ resetControlsTimer();
9378
+ },
9379
+ style: {
9380
+ padding: "".concat(8 * responsiveScale, "px"),
9381
+ borderRadius: "50%",
9382
+ minWidth: "".concat(36 * responsiveScale, "px"),
9383
+ minHeight: "".concat(36 * responsiveScale, "px"),
9384
+ background: overlaysDisabled ? "rgba(239, 68, 68, 0.28)" : "rgba(0, 0, 0, 0.6)",
9385
+ color: overlaysDisabled ? "rgba(252, 165, 165, 0.9)" : "rgba(255, 255, 255, 0.75)"
9386
+ },
9387
+ title: overlaysDisabled ? "Enable overlays" : "Disable overlays",
9388
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_fa.FaLayerGroup, {
9389
+ size: Math.max(14, 18 * responsiveScale)
9390
+ })
9391
+ }),
9392
+ swirlProjectId && (showAiContextControl !== null && showAiContextControl !== void 0 ? showAiContextControl : true) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
9291
9393
  className: "sc-ctrl-btn",
9292
9394
  onClick: function onClick() {
9293
9395
  setShowAiPanel(function(prev) {
@@ -9309,7 +9411,7 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
9309
9411
  title: showAiPanel ? "Hide AI context" : "Show AI context",
9310
9412
  children: "AI"
9311
9413
  }),
9312
- debugAdTiming && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
9414
+ debugAdTiming && (showDebugControl !== null && showDebugControl !== void 0 ? showDebugControl : true) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", {
9313
9415
  className: "sc-ctrl-btn",
9314
9416
  onClick: function onClick() {
9315
9417
  setShowDebugPanel(function(prev) {
@@ -9411,7 +9513,13 @@ var StormcloudVideoPlayerComponent = import_react2.default.memo(function(props)
9411
9513
  "preload",
9412
9514
  "poster",
9413
9515
  "children",
9414
- "swirlProjectId"
9516
+ "swirlProjectId",
9517
+ "adcisionChannelId",
9518
+ "disableOverlays",
9519
+ "showAdsControl",
9520
+ "showOverlaysControl",
9521
+ "showAiContextControl",
9522
+ "showDebugControl"
9415
9523
  ];
9416
9524
  var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
9417
9525
  try {