diff --git a/packages/tuya-panel-ipc-sdk/src/ty-ipc-native-module/index.tsx b/packages/tuya-panel-ipc-sdk/src/ty-ipc-native-module/index.tsx index d5a9842fd..c0fa2cf47 100644 --- a/packages/tuya-panel-ipc-sdk/src/ty-ipc-native-module/index.tsx +++ b/packages/tuya-panel-ipc-sdk/src/ty-ipc-native-module/index.tsx @@ -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'; @@ -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 功能控制模块 @@ -52,4 +55,8 @@ export default { * @description 跨设备下发 */ MultiDeviceManager, + /** + * @description mqtt监听 + */ + MqttManager, }; diff --git a/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/config/global.ts b/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/config/global.ts index a0387b932..25aa5f455 100644 --- a/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/config/global.ts +++ b/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/config/global.ts @@ -3,6 +3,9 @@ const Global = { requestTimeOut: null, enterBackTimeOut: null, + isLowPowerDevicePrivate: false, + lowPrivateFlagTimeOut: null, + lowWarlessWakeInterval: null, }; export default Global; diff --git a/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/i18n/string.ts b/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/i18n/string.ts index 04e07c272..7af569e2a 100644 --- a/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/i18n/string.ts +++ b/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/i18n/string.ts @@ -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', @@ -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: '设备连接中断,请检查设备及网络', diff --git a/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/index.tsx b/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/index.tsx index c11e500b4..76becdaca 100644 --- a/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/index.tsx +++ b/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/index.tsx @@ -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, @@ -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) { @@ -145,6 +146,25 @@ class TYIpcPlayer extends React.Component { 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, @@ -363,6 +383,7 @@ class TYIpcPlayer extends React.Component { channelNum, scaleMultiple, activeConnect, + wirelessAwake, } = this.props; if ( !_.isEqual(privateMode, nextProps.privateMode) || @@ -370,6 +391,10 @@ class TYIpcPlayer extends React.Component { !_.isEqual(channelNum, nextProps.channelNum) || !_.isEqual(activeConnect, nextProps.activeConnect) ) { + if (!_.isEqual(privateMode, nextProps.privateMode) && !nextProps.privateMode) { + Global.isLowPowerDevicePrivate = false; + } + TYIpcPlayerManager.startPlay( nextProps.isWirless, nextProps.privateMode, @@ -387,6 +412,22 @@ class TYIpcPlayer extends React.Component { 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, @@ -706,12 +747,8 @@ class TYIpcPlayer extends React.Component { handleAppStateChange = nextAppState => { // 表示手机应用滑到后台,统一断开disconenct, 安卓和ios差异限制, 安卓立即断开,ios5秒后断开 - const { - enterBackDisConP2P, - isWirless, - deviceOnline, - notNeedJudgeConnectForeground, - } = this.props; + const { enterBackDisConP2P, isWirless, deviceOnline, notNeedJudgeConnectForeground } = + this.props; if (nextAppState === 'background' && !enterBackDisConP2P) { enterBackTimeOutSpecial(); } @@ -779,6 +816,11 @@ class TYIpcPlayer extends React.Component { 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) { // 不显示重连,准备二次重连 @@ -849,9 +891,43 @@ class TYIpcPlayer extends React.Component { 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; } @@ -938,7 +1014,12 @@ class TYIpcPlayer extends React.Component { 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, diff --git a/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/interface.ts b/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/interface.ts index 9b4a89200..b1806ab99 100644 --- a/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/interface.ts +++ b/packages/tuya-panel-ipc-sdk/src/ty-ipc-player/interface.ts @@ -190,6 +190,7 @@ export interface TYIpcPlayerProps { cancelSessionEmit: boolean; displayInPortrait: boolean; useCustomContainer: boolean; + wirelessAwake: boolean; } export const _defaultProps = { @@ -243,6 +244,7 @@ export const _defaultProps = { activeConnect: 'connect', notNeedJudgeConnectForeground: false, cancelSessionEmit: false, - displayInPortrait : true, + displayInPortrait: true, useCustomContainer: false, + wirelessAwake: false, };