Skip to content

Commit

Permalink
Merge pull request #226 from XiaooSe/main
Browse files Browse the repository at this point in the history
Add low-power privacy mode
  • Loading branch information
ShinyLeee authored Sep 3, 2024
2 parents d1c17bc + 86926f5 commit ba2ebf8
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NativeModules } from 'react-native';
import CameraManager from '../ty-ipc-native/nativeApi';
import CameraPlayer from '../ty-ipc-player/nativePlayer';
import OrientationManager from '../ty-ipc-native/tyrctOrientationManager';
Expand All @@ -11,6 +12,8 @@ import HomeDeviceManager from '../ty-ipc-multiple-player/native/homeDeviceManage
import MultiCameraManager from '../ty-ipc-multiple-player/native/multiCameraManager';
import MultiDeviceManager from '../ty-ipc-multiple-player/native/multiDeviceManager';

const MqttManager = NativeModules.TYRCTMqttManager;

export default {
/**
* @description IPC 功能控制模块
Expand Down Expand Up @@ -52,4 +55,8 @@ export default {
* @description 跨设备下发
*/
MultiDeviceManager,
/**
* @description mqtt监听
*/
MqttManager,
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
const Global = {
requestTimeOut: null,
enterBackTimeOut: null,
isLowPowerDevicePrivate: false,
lowPrivateFlagTimeOut: null,
lowWarlessWakeInterval: null,
};

export default Global;
5 changes: 5 additions & 0 deletions packages/tuya-panel-ipc-sdk/src/ty-ipc-player/i18n/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export default {
tyIpc_private_mode_sleep_close: 'Turn on the camera',
tyIpc_video_channel_connecting: 'Establishing an encrypted channel...',
tyIpc_video_channel_connect_fail: 'Failed to establish the encrypted channel',
tyIpc_private_mode_wireless_device_wake_ing: 'Waking up the device...',
tyIpc_private_mode_wireless_device_wake_fail:
'Connection failed. Please click below to restart',
tyIpc_video_get_stream_ing: 'Retrieving video stream...',
tyIpc_video_get_stream_failure: 'Failed to retrieve video stream',
tyIpc_net_err: 'Device connection is interrupted, please check the device and network',
Expand Down Expand Up @@ -35,6 +38,8 @@ export default {
tyIpc_private_mode_sleep_close: '开启摄像头',
tyIpc_video_channel_connecting: '正在构建加密通道',
tyIpc_video_channel_connect_fail: '构建加密通道失败',
tyIpc_private_mode_wireless_device_wake_ing: '正在唤醒设备中',
tyIpc_private_mode_wireless_device_wake_fail: '连接失败,点击下方重新开启',
tyIpc_video_get_stream_ing: '正在获取视频流',
tyIpc_video_get_stream_failure: '获取视频流失败',
tyIpc_net_err: '设备连接中断,请检查设备及网络',
Expand Down
103 changes: 92 additions & 11 deletions packages/tuya-panel-ipc-sdk/src/ty-ipc-player/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import native from '../ty-ipc-native-module';
import Strings from './i18n';
import Config from './config';
import Global from './config/global';
import {
enterBackTimeOut,
cancelEnterBackTimeOut,
Expand All @@ -42,7 +43,7 @@ import { videoLoadText } from '../ty-ipc-native/cameraData';
import TYRCTLifecycleManager from './components/tyrctLifecycleManager';
import TYRCTOrientationManager from '../ty-ipc-native/tyrctOrientationManager';

const { CameraPlayer: NativePlayer, CameraManager } = native;
const { CameraPlayer: NativePlayer, CameraManager, MqttManager } = native;

const { normalPlayerWidth, normalPlayerHeight, isIOS } = Config;
if (!isIOS && UIManager.setLayoutAnimationEnabledExperimental) {
Expand Down Expand Up @@ -145,6 +146,25 @@ class TYIpcPlayer extends React.Component<TYIpcPlayerProps, TYIpcPlayerState> {
TYEvent.on('getCameraConfig', this.getCameraConfig);
TYEvent.on('isEnterRnPage', this.judgeIsEnterRnPage);
TYEvent.on('activeChangeScale', this.activeChangeScale);
MqttManager.receiverMqttDataWithDevId(TYSdk.devInfo.devId, 1);
TYSdk.DeviceEventEmitter.addListener('receiveMqttData', data => {
if (data?.protocol === 1 && data?.messageData?.online) {
// 监听到设备唤醒, 清除设置的定时
if (Global.isLowPowerDevicePrivate) {
// 说明设备唤醒了, 这里延迟1s再进行下发,看日志有时用到唤醒DP会滞后, 隐私模式下发后,监听DP变更即可,走正常拉流
Global.lowWarlessWakeInterval && clearInterval(Global.lowWarlessWakeInterval);
// 清除15秒唤醒定时
Global.lowPrivateFlagTimeOut && clearTimeout(Global.lowPrivateFlagTimeOut);
setTimeout(() => {
TYDevice.putDeviceData({
basic_private: false,
});
}, 1000);
Global.isLowPowerDevicePrivate = false;
}
}
});

TYIpcPlayerManager.startPlay(
this.props.isWirless,
this.props.privateMode,
Expand Down Expand Up @@ -363,13 +383,18 @@ class TYIpcPlayer extends React.Component<TYIpcPlayerProps, TYIpcPlayerState> {
channelNum,
scaleMultiple,
activeConnect,
wirelessAwake,
} = this.props;
if (
!_.isEqual(privateMode, nextProps.privateMode) ||
!_.isEqual(deviceOnline, nextProps.deviceOnline) ||
!_.isEqual(channelNum, nextProps.channelNum) ||
!_.isEqual(activeConnect, nextProps.activeConnect)
) {
if (!_.isEqual(privateMode, nextProps.privateMode) && !nextProps.privateMode) {
Global.isLowPowerDevicePrivate = false;
}

TYIpcPlayerManager.startPlay(
nextProps.isWirless,
nextProps.privateMode,
Expand All @@ -387,6 +412,22 @@ class TYIpcPlayer extends React.Component<TYIpcPlayerProps, TYIpcPlayerState> {
zoomVideoStatus: nextProps.zoomStatus,
});
}

if (!_.isEqual(wirelessAwake, nextProps.wirelessAwake) && nextProps.wirelessAwake) {
// 大部分低功耗设备会接入DP表示设备唤醒
if (Global.isLowPowerDevicePrivate) {
// 说明设备唤醒了, 这里延迟1s再进行下发,看日志有时用到唤醒DP会滞后, 隐私模式下发后,监听DP变更即可,走正常拉流
Global.lowWarlessWakeInterval && clearInterval(Global.lowWarlessWakeInterval);
// 清除15秒唤醒定时
Global.lowPrivateFlagTimeOut && clearTimeout(Global.lowPrivateFlagTimeOut);
setTimeout(() => {
TYNative.putDpData({
basic_private: false,
});
}, 1000);
Global.isLowPowerDevicePrivate = false;
}
}
if (!_.isEqual(scaleMultiple, nextProps.scaleMultiple)) {
this.setState({
zoomVideoStatus: nextProps.scaleMultiple,
Expand Down Expand Up @@ -706,12 +747,8 @@ class TYIpcPlayer extends React.Component<TYIpcPlayerProps, TYIpcPlayerState> {

handleAppStateChange = nextAppState => {
// 表示手机应用滑到后台,统一断开disconenct, 安卓和ios差异限制, 安卓立即断开,ios5秒后断开
const {
enterBackDisConP2P,
isWirless,
deviceOnline,
notNeedJudgeConnectForeground,
} = this.props;
const { enterBackDisConP2P, isWirless, deviceOnline, notNeedJudgeConnectForeground } =
this.props;
if (nextAppState === 'background' && !enterBackDisConP2P) {
enterBackTimeOutSpecial();
}
Expand Down Expand Up @@ -779,6 +816,11 @@ class TYIpcPlayer extends React.Component<TYIpcPlayerProps, TYIpcPlayerState> {
status === 1 &&
((retryText = Strings.getLang('tyIpc_private_mode_sleep_close')), (showAnimation = false));

// 新增加状态10, 针对低功耗设备, 提示唤醒中
status === 10 &&
((loadText = Strings.getLang('tyIpc_private_mode_wireless_device_wake_ing')),
(retryText = ''));

if (status === 3) {
if (this.netDisconnect) {
// 不显示重连,准备二次重连
Expand Down Expand Up @@ -849,9 +891,43 @@ class TYIpcPlayer extends React.Component<TYIpcPlayerProps, TYIpcPlayerState> {
loadText: Strings.getLang('tyIpc_re_connect_stream'),
showAnimation: true,
});
TYDevice.putDeviceData({
basic_private: false,
});
if (isWirless) {
const wirelessAwake = TYSdk.device.getState('wireless_awake');
if (wirelessAwake) {
// 如果为唤醒直接状态
TYDevice.putDeviceData({
basic_private: false,
});
} else {
Global.isLowPowerDevicePrivate = true;
CameraManager.wakeUpDoorBell();
Global.lowWarlessWakeInterval = setInterval(() => {
CameraManager.wakeUpDoorBell();
}, 300);
// 唤醒设备先
this.setState({
showLoading: true,
showRetry: false,
loadText: Strings.getLang('tyIpc_private_mode_wireless_device_wake_ing'),
showAnimation: true,
});
// 15秒持续发唤醒, 若唤醒不上来提示失败, 若成功则清除对应定时
Global.lowPrivateFlagTimeOut = setTimeout(() => {
clearInterval(Global.lowWarlessWakeInterval);
this.setState({
showLoading: true,
showRetry: true,
loadText: Strings.getLang('tyIpc_private_mode_wireless_device_wake_fail'),
showAnimation: false,
});
}, 15000);
}
} else {
TYDevice.putDeviceData({
basic_private: false,
});
}

return false;
}

Expand Down Expand Up @@ -938,7 +1014,12 @@ class TYIpcPlayer extends React.Component<TYIpcPlayerProps, TYIpcPlayerState> {
onChangePreview={this.onChangePreview}
action={cameraAction}
// scaleMultiple={isFullScreen ? -2 : zoomVideoStatus}
scaleMultiple={this.getRealPlayerScale(isFullScreen, zoomVideoStatus, playerProps, displayInPortrait)}
scaleMultiple={this.getRealPlayerScale(
isFullScreen,
zoomVideoStatus,
playerProps,
displayInPortrait
)}
style={{
width: realWidth,
height: realHeight,
Expand Down
4 changes: 3 additions & 1 deletion packages/tuya-panel-ipc-sdk/src/ty-ipc-player/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export interface TYIpcPlayerProps {
cancelSessionEmit: boolean;
displayInPortrait: boolean;
useCustomContainer: boolean;
wirelessAwake: boolean;
}

export const _defaultProps = {
Expand Down Expand Up @@ -243,6 +244,7 @@ export const _defaultProps = {
activeConnect: 'connect',
notNeedJudgeConnectForeground: false,
cancelSessionEmit: false,
displayInPortrait : true,
displayInPortrait: true,
useCustomContainer: false,
wirelessAwake: false,
};

0 comments on commit ba2ebf8

Please sign in to comment.