@ray-js/ipc-player-integration 0.0.35-beta.11 → 0.0.35-beta.13

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.
@@ -8,7 +8,7 @@ import { useStore } from '../ctx/store';
8
8
  import { useComponentHideState } from './hooks';
9
9
  import { TrialBadge, useTrialBadge } from '../widgets/trialBadge';
10
10
  /** 右侧透明渐变宽度,用于提示横向可滑动 */
11
- const FADE_MASK = 'linear-gradient(to right, #000 calc(100% - 16px), transparent 100%)';
11
+ const FADE_MASK = 'linear-gradient(to right, #000 calc(100% - 48px), transparent 100%)';
12
12
 
13
13
  /**
14
14
  * 试用徽章在不同 screenType 下的容器样式。
@@ -58,15 +58,10 @@ const BottomLeftContent = _ref => {
58
58
  const tryExp = bottomLeftContent === null || bottomLeftContent === void 0 ? void 0 : bottomLeftContent.find(item => item.id === 'TryExperience');
59
59
  return (_trialRemainingSec = tryExp === null || tryExp === void 0 || (_tryExp$initProps2 = tryExp.initProps) === null || _tryExp$initProps2 === void 0 ? void 0 : _tryExp$initProps2.trialRemainingSec) !== null && _trialRemainingSec !== void 0 ? _trialRemainingSec : 0;
60
60
  }, [bottomLeftContent]);
61
- const refreshToken = useMemo(() => {
62
- var _refreshToken, _tryExp$initProps3;
63
- const tryExp = bottomLeftContent === null || bottomLeftContent === void 0 ? void 0 : bottomLeftContent.find(item => item.id === 'TryExperience');
64
- return (_refreshToken = tryExp === null || tryExp === void 0 || (_tryExp$initProps3 = tryExp.initProps) === null || _tryExp$initProps3 === void 0 ? void 0 : _tryExp$initProps3.refreshToken) !== null && _refreshToken !== void 0 ? _refreshToken : 0;
65
- }, [bottomLeftContent]);
66
61
  const isLowPhone = useMemo(() => {
67
- var _isLowPhone, _tryExp$initProps4;
62
+ var _isLowPhone, _tryExp$initProps3;
68
63
  const tryExp = bottomLeftContent === null || bottomLeftContent === void 0 ? void 0 : bottomLeftContent.find(item => item.id === 'TryExperience');
69
- return (_isLowPhone = tryExp === null || tryExp === void 0 || (_tryExp$initProps4 = tryExp.initProps) === null || _tryExp$initProps4 === void 0 ? void 0 : _tryExp$initProps4.isLowPhone) !== null && _isLowPhone !== void 0 ? _isLowPhone : false;
64
+ return (_isLowPhone = tryExp === null || tryExp === void 0 || (_tryExp$initProps3 = tryExp.initProps) === null || _tryExp$initProps3 === void 0 ? void 0 : _tryExp$initProps3.isLowPhone) !== null && _isLowPhone !== void 0 ? _isLowPhone : false;
70
65
  }, []);
71
66
  const [shouldHide] = useComponentHideState();
72
67
  const {
@@ -76,6 +71,13 @@ const BottomLeftContent = _ref => {
76
71
  } = useTrialBadge(ctx.event, ctx.devId, trialRemainingSec);
77
72
  const paddingLeftPx = screenType === 'vertical' ? 0 : 25;
78
73
  const trialBadgeWrapStyle = screenType === 'vertical' ? TRIAL_BADGE_WRAP_STYLE_VERTICAL : TRIAL_BADGE_WRAP_STYLE_FULL;
74
+ const showBadge = showSmartImageQuality && showTrialBadge && canOpenSettings && !isLowPhone && trialRemainingSec > 0;
75
+ const containerHeight = (() => {
76
+ if (showBadge) {
77
+ return screenType === 'vertical' ? '40px' : '58px';
78
+ }
79
+ return screenType === 'vertical' ? shouldHide ? '41px' : '40px' : shouldHide ? '57px' : '58px';
80
+ })();
79
81
  return /*#__PURE__*/React.createElement(CoverView, {
80
82
  className: clsx('ipc-player-bottom-left-content-wrap')
81
83
  // 注意:不要在这里覆盖 position,CSS 类已经设置 position: absolute; left: 0; bottom: 0
@@ -83,19 +85,17 @@ const BottomLeftContent = _ref => {
83
85
  ,
84
86
  style: {
85
87
  right: `${reservedRight}px`,
86
- height: screenType === 'vertical' ? shouldHide ? '41px' : '40px' : shouldHide ? '57px' : '58px'
88
+ height: containerHeight
87
89
  }
88
- }, showSmartImageQuality && showTrialBadge && canOpenSettings && !isLowPhone && /*#__PURE__*/React.createElement(View, {
90
+ }, showBadge && /*#__PURE__*/React.createElement(View, {
89
91
  className: clsx('bottom-left-item-container'),
90
92
  style: _objectSpread(_objectSpread({}, trialBadgeWrapStyle), {}, {
91
- transform: shouldHide ? 'translateY(40px)' : 'translateY(0)',
92
93
  opacity: shouldHide ? 0 : 1,
93
- transition: 'transform 0.3s ease-in-out, opacity 0.3s ease-in-out'
94
+ pointerEvents: shouldHide ? 'none' : 'auto'
94
95
  })
95
96
  }, /*#__PURE__*/React.createElement(TrialBadge, {
96
97
  brandColor: brandColor,
97
98
  trialRemainingSec: trialRemainingSec,
98
- refreshToken: refreshToken,
99
99
  onSubscribe: handleTrialSubscribe,
100
100
  onCountdownEnd: handleCountdownEnd
101
101
  })), /*#__PURE__*/React.createElement(View, {
package/lib/ui/ui.js CHANGED
@@ -448,25 +448,22 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
448
448
  setVerticalMic(verticalMic);
449
449
  }, [brandColor, verticalMic]);
450
450
  const refreshSmartImageQuality = useMemoizedFn(async () => {
451
- let res = await getSmartImageQualityState(devId);
452
- console.log('res===refreshSmartImageQuality1', res);
453
- // if (res === undefined) return;
454
- // TODO: TEST
455
- if (res === undefined) {
456
- res = {
457
- isPurchase: false,
458
- buttonState: 0,
459
- trialRemainingSec: 20,
460
- canOpenSettings: true
461
- };
462
- }
451
+ const res = await getSmartImageQualityState(devId);
452
+ if (res === undefined) return;
453
+ // 可调试
454
+ // res = {
455
+ // isPurchase: false,
456
+ // buttonState: 0,
457
+ // trialRemainingSec: 20,
458
+ // canOpenSettings: true,
459
+ // };
460
+ console.log('res===refreshSmartImageQuality', res);
463
461
  updatePlayerWidgetProps(instance, 'bottomLeft', 'TryExperience', {
464
462
  isPurchase: res.isPurchase,
465
463
  buttonState: res.buttonState,
466
464
  trialRemainingSec: res.trialRemainingSec,
467
465
  canOpenSettings: res.canOpenSettings,
468
- isLowPhone: isLowPhoneRef.current,
469
- refreshToken: Date.now()
466
+ isLowPhone: isLowPhoneRef.current
470
467
  });
471
468
  });
472
469
  useEffect(() => {
@@ -10,8 +10,8 @@ export const miniIdLabs = {
10
10
  };
11
11
  export function gotoAIDrawMiniProgram(devId, brandColor) {
12
12
  const color = new Color(brandColor);
13
- color.rgb().toString();
14
- const url = `godzilla://${miniIdLabs.aiDrawMini}${'/pages/smartImageQuality/index'}?deviceId=${devId}`;
13
+ const rgbColor = color.rgb().toString();
14
+ const url = `godzilla://${miniIdLabs.aiDrawMini}?deviceId=${devId}&themeColor=${rgbColor}`;
15
15
  goToMiniProgramByShortLink(url, 'right');
16
16
  }
17
17
  export async function gotoSecurityCloudService(homeId, uuid) {
@@ -6,12 +6,10 @@ type Props = {
6
6
  brandColor?: string;
7
7
  /** 试看倒计时初始秒数,来源于 smartImageQualityState.trialRemainingSec */
8
8
  trialRemainingSec?: number;
9
- /** 刷新令牌,变化时重置倒计时状态 */
10
- refreshToken?: number;
11
9
  /** 点击「开通」按钮回调 */
12
10
  onSubscribe?: () => void;
13
11
  /** 倒计时归零时触发,本组件保证整个生命周期内只回调一次 */
14
12
  onCountdownEnd?: () => void;
15
13
  };
16
- export declare const TrialBadge: ({ className, brandColor, trialRemainingSec, refreshToken, onSubscribe, onCountdownEnd, }: Props) => React.JSX.Element;
14
+ export declare const TrialBadge: ({ className, brandColor, trialRemainingSec, onSubscribe, onCountdownEnd, }: Props) => React.JSX.Element;
17
15
  export { useTrialBadge } from './useTrialBadge';
@@ -18,21 +18,25 @@ export const TrialBadge = _ref => {
18
18
  className,
19
19
  brandColor = FALLBACK_BRAND_COLOR,
20
20
  trialRemainingSec = 0,
21
- refreshToken,
22
21
  onSubscribe,
23
22
  onCountdownEnd
24
23
  } = _ref;
25
24
  const [remainingSec, setRemainingSec] = useState(Math.max(0, Math.floor(trialRemainingSec)));
26
- /** 防止 onCountdownEnd 被重复触发;同时持有最新回调,避免依赖变化导致 effect 重跑 */
27
25
  const endedRef = useRef(false);
28
26
  const onCountdownEndRef = useRef(onCountdownEnd);
29
27
  onCountdownEndRef.current = onCountdownEnd;
28
+ const startTimeRef = useRef(Date.now());
29
+ const initialSecRef = useRef(Math.max(0, Math.floor(trialRemainingSec)));
30
30
  useEffect(() => {
31
+ console.log('res===trialRemainingSec', trialRemainingSec);
32
+ const sec = Math.max(0, Math.floor(trialRemainingSec));
31
33
  endedRef.current = false;
32
- setRemainingSec(Math.max(0, Math.floor(trialRemainingSec)));
33
- }, [trialRemainingSec, refreshToken]);
34
+ initialSecRef.current = sec;
35
+ startTimeRef.current = Date.now();
36
+ setRemainingSec(sec);
37
+ }, [trialRemainingSec]);
34
38
  useEffect(() => {
35
- if (remainingSec <= 0) {
39
+ if (trialRemainingSec <= 0) {
36
40
  if (!endedRef.current) {
37
41
  var _onCountdownEndRef$cu;
38
42
  endedRef.current = true;
@@ -41,22 +45,20 @@ export const TrialBadge = _ref => {
41
45
  return undefined;
42
46
  }
43
47
  const timer = setInterval(() => {
44
- setRemainingSec(prev => {
45
- const next = prev - 1;
46
- if (next <= 0) {
47
- clearInterval(timer);
48
- if (!endedRef.current) {
49
- var _onCountdownEndRef$cu2;
50
- endedRef.current = true;
51
- (_onCountdownEndRef$cu2 = onCountdownEndRef.current) === null || _onCountdownEndRef$cu2 === void 0 || _onCountdownEndRef$cu2.call(onCountdownEndRef);
52
- }
53
- return 0;
48
+ const elapsed = Math.floor((Date.now() - startTimeRef.current) / 1000);
49
+ const next = Math.max(0, initialSecRef.current - elapsed);
50
+ setRemainingSec(next);
51
+ if (next <= 0) {
52
+ clearInterval(timer);
53
+ if (!endedRef.current) {
54
+ var _onCountdownEndRef$cu2;
55
+ endedRef.current = true;
56
+ (_onCountdownEndRef$cu2 = onCountdownEndRef.current) === null || _onCountdownEndRef$cu2 === void 0 || _onCountdownEndRef$cu2.call(onCountdownEndRef);
54
57
  }
55
- return next;
56
- });
58
+ }
57
59
  }, 1000);
58
60
  return () => clearInterval(timer);
59
- }, [trialRemainingSec, refreshToken]);
61
+ }, [trialRemainingSec]);
60
62
  const countdownText = formatCountdown(remainingSec);
61
63
  return /*#__PURE__*/React.createElement(View, {
62
64
  className: clsx('ipc-player-trial-badge', className)
@@ -1,7 +1,7 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import { View, Image, getSystemInfoSync, showToast } from '@ray-js/ray';
3
3
  import clsx from 'clsx';
4
- import React, { useState, useEffect, useCallback } from 'react';
4
+ import React, { useState, useEffect, useCallback, useRef } from 'react';
5
5
  import { useStore } from '../../ctx/store';
6
6
  import Strings from '../../i18n';
7
7
  import { getAIFrameFeature, gotoAIDrawMiniProgram, setAIFrameFeature } from '../../utils';
@@ -60,6 +60,7 @@ export const TryExperience = props => {
60
60
  recording: props.recording
61
61
  });
62
62
  const [imgSrc, setImgSrc] = useState();
63
+ const lockRef = useRef(false);
63
64
  useEffect(() => {
64
65
  updateImgSrc();
65
66
  }, [buttonState]);
@@ -77,6 +78,7 @@ export const TryExperience = props => {
77
78
  }
78
79
  }, [buttonState]);
79
80
  const onTryExperience = useCallback(async () => {
81
+ if (lockRef.current) return;
80
82
  if (isLowPhone) {
81
83
  showToast({
82
84
  title: Strings.getLang('ipc_player_low_phone_not_support'),
@@ -91,10 +93,12 @@ export const TryExperience = props => {
91
93
  });
92
94
  return;
93
95
  }
96
+ lockRef.current = true;
94
97
  try {
95
98
  const getAI = await getAIFrameFeature(devId);
96
99
  if (buttonState === TryExperienceStatus.Open) {
97
100
  var _getAI$aiFrameFeature, _getAI$aiFrameFeature2, _getAI$aiFrameFeature3, _props$event;
101
+ // 由开变关的时候,只关inPreview
98
102
  const scope = _objectSpread(_objectSpread({}, (_getAI$aiFrameFeature = getAI.aiFrameFeature) === null || _getAI$aiFrameFeature === void 0 ? void 0 : _getAI$aiFrameFeature.scope), {}, {
99
103
  inPreview: false
100
104
  });
@@ -115,11 +119,12 @@ export const TryExperience = props => {
115
119
  const scope = _objectSpread(_objectSpread({}, (_getAI$aiFrameFeature4 = getAI.aiFrameFeature) === null || _getAI$aiFrameFeature4 === void 0 ? void 0 : _getAI$aiFrameFeature4.scope), {}, {
116
120
  inPreview: true
117
121
  });
122
+ // 由关变开的时候,enabled和inPreview两个都开
118
123
  await setAIFrameFeature({
119
124
  devId,
120
125
  scene: 'inPreview',
121
126
  // 实时预览场景
122
- enabled: getAI.enabled,
127
+ enabled: true,
123
128
  aiFrameFeature: {
124
129
  scope,
125
130
  feature: (_getAI$aiFrameFeature5 = getAI.aiFrameFeature) === null || _getAI$aiFrameFeature5 === void 0 ? void 0 : _getAI$aiFrameFeature5.feature,
@@ -132,6 +137,8 @@ export const TryExperience = props => {
132
137
  }
133
138
  } catch (error) {
134
139
  //
140
+ } finally {
141
+ lockRef.current = false;
135
142
  }
136
143
  }, [buttonState, recording, isPurchase, trialRemainingSec]);
137
144
  if (hideTryExperienceMenu) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.35-beta.11",
3
+ "version": "0.0.35-beta.13",
4
4
  "description": "IPC 融合播放器",
5
5
  "main": "lib/index",
6
6
  "files": [