@ray-js/robot-data-stream 0.0.13-beta-5 → 0.0.13-beta-7
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/api/index.d.ts +12 -2
- package/lib/api/index.js +172 -1
- package/lib/api/p2pApi.d.ts +27 -8
- package/lib/api/p2pApi.js +169 -271
- package/lib/api/sweeperP2p.d.ts +23 -49
- package/lib/api/sweeperP2p.js +248 -311
- package/lib/constant.d.ts +52 -0
- package/lib/constant.js +54 -0
- package/lib/index.d.ts +1 -10
- package/lib/index.js +2 -165
- package/lib/mqtt/createCommonOptions.d.ts +56 -15
- package/lib/mqtt/createCommonOptions.js +44 -8
- package/lib/mqtt/index.d.ts +2 -1
- package/lib/mqtt/index.js +2 -1
- package/lib/mqtt/mqttProvider.d.ts +23 -15
- package/lib/mqtt/mqttProvider.js +63 -26
- package/lib/mqtt/promise.js +8 -3
- package/lib/mqtt/type/index.d.ts +14 -0
- package/lib/mqtt/type/index.js +14 -0
- package/lib/mqtt/type/requestType.d.ts +8 -0
- package/lib/mqtt/type/requestType.js +10 -0
- package/lib/mqtt/useDevInfo.d.ts +2 -7
- package/lib/mqtt/useDevInfo.js +25 -9
- package/lib/mqtt/useHistoryMap.d.ts +13 -21
- package/lib/mqtt/useHistoryMap.js +82 -32
- package/lib/mqtt/usePartDivision.d.ts +5 -7
- package/lib/mqtt/usePartDivision.js +41 -16
- package/lib/mqtt/usePartMerge.d.ts +5 -7
- package/lib/mqtt/usePartMerge.js +36 -18
- package/lib/mqtt/usePassword.js +59 -28
- package/lib/mqtt/useQuiteHours.d.ts +9 -24
- package/lib/mqtt/useQuiteHours.js +95 -52
- package/lib/mqtt/useResetMap.d.ts +10 -7
- package/lib/mqtt/useResetMap.js +40 -11
- package/lib/mqtt/useRoomProperty.js +23 -16
- package/lib/mqtt/useSchedule.d.ts +17 -4
- package/lib/mqtt/useSchedule.js +101 -49
- package/lib/mqtt/useSelectRoomClean.d.ts +20 -16
- package/lib/mqtt/useSelectRoomClean.js +145 -49
- package/lib/mqtt/useSpotClean.d.ts +3 -3
- package/lib/mqtt/useSpotClean.js +72 -50
- package/lib/mqtt/useVirtualArea.d.ts +6 -9
- package/lib/mqtt/useVirtualArea.js +112 -42
- package/lib/mqtt/useVirtualWall.d.ts +13 -10
- package/lib/mqtt/useVirtualWall.js +97 -34
- package/lib/mqtt/useVoice.d.ts +3 -6
- package/lib/mqtt/useVoice.js +73 -33
- package/lib/mqtt/useWifiMap.d.ts +8 -0
- package/lib/mqtt/useWifiMap.js +53 -0
- package/lib/mqtt/useZoneClean.d.ts +13 -13
- package/lib/mqtt/useZoneClean.js +149 -76
- package/lib/ttt/index.d.ts +153 -0
- package/lib/ttt/index.js +458 -0
- package/lib/utils/index.d.ts +20 -1
- package/lib/utils/index.js +19 -0
- package/package.json +1 -1
- package/lib/mqtt/myError.d.ts +0 -4
- package/lib/mqtt/myError.js +0 -6
package/lib/api/index.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
type TOnLogger = (type: 'warn' | 'error' | 'info', data: string) => void;
|
|
2
|
+
export declare const useP2PDataStream: (devId: string, onReceiveMapData: (data: string) => void, onReceivePathData: (data: string) => void, opt?: {
|
|
3
|
+
logTag?: string | undefined;
|
|
4
|
+
onReceiveAIPicData?: ((data: string) => void) | undefined;
|
|
5
|
+
onReceiveAIPicHDData?: ((data: string) => void) | undefined;
|
|
6
|
+
onReceiveWifiMapData?: ((data: string) => void) | undefined;
|
|
7
|
+
onLogger?: TOnLogger | undefined;
|
|
8
|
+
onDefineStructuredMode?: ((isStructured: boolean) => void) | undefined;
|
|
9
|
+
} | undefined) => {
|
|
10
|
+
appendDownloadStreamDuringTask: (files: Array<string>, successCb?: () => void, failedCb?: () => void) => Promise<boolean> | void;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
package/lib/api/index.js
CHANGED
|
@@ -1,2 +1,173 @@
|
|
|
1
1
|
import SweeperP2pInstance from './sweeperP2p';
|
|
2
|
-
|
|
2
|
+
import log4js from '@ray-js/log4js';
|
|
3
|
+
import { getSystemInfoSync, usePageEvent } from '@ray-js/ray';
|
|
4
|
+
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
5
|
+
import { trace } from '../trace';
|
|
6
|
+
import { createLogger } from '../utils';
|
|
7
|
+
export const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
|
|
8
|
+
const traceId = `${devId}_${Date.now()}`;
|
|
9
|
+
global.robotPanelTraceId = traceId;
|
|
10
|
+
const {
|
|
11
|
+
logTag,
|
|
12
|
+
onReceiveAIPicData,
|
|
13
|
+
onReceiveAIPicHDData,
|
|
14
|
+
onReceiveWifiMapData,
|
|
15
|
+
onLogger,
|
|
16
|
+
onDefineStructuredMode
|
|
17
|
+
} = opt || {};
|
|
18
|
+
const isInit = useRef(false);
|
|
19
|
+
const offSessionStatusChange = useRef(null);
|
|
20
|
+
const isAppOnBackground = useRef(false);
|
|
21
|
+
const timer = useRef(null);
|
|
22
|
+
const isIDE = getSystemInfoSync().brand === 'devtools';
|
|
23
|
+
|
|
24
|
+
// 创建 logger 实例,避免重复创建
|
|
25
|
+
const log = useMemo(() => createLogger(onLogger), [onLogger]);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 启动数据观察
|
|
29
|
+
*/
|
|
30
|
+
const startObserver = useCallback(() => {
|
|
31
|
+
SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData, onReceiveWifiMapData, onDefineStructuredMode);
|
|
32
|
+
offSessionStatusChange.current = SweeperP2pInstance.onSessionStatusChange(SweeperP2pInstance.sessionStatusCallback);
|
|
33
|
+
}, [devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData, onReceiveWifiMapData, onDefineStructuredMode]);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* p2p连接
|
|
37
|
+
*/
|
|
38
|
+
const connectP2p = useCallback(async () => {
|
|
39
|
+
log.info({
|
|
40
|
+
msg: 'hooks has been started connectP2p'
|
|
41
|
+
});
|
|
42
|
+
// 开始进行连接时作为整个p2p连接的开始,将trace的开始时间戳记录下来
|
|
43
|
+
trace.initTimeStamps = Date.now();
|
|
44
|
+
SweeperP2pInstance.connectDevice(() => {
|
|
45
|
+
trace.pointFn({
|
|
46
|
+
devId,
|
|
47
|
+
eventName: 'connectDeviceSuccess'
|
|
48
|
+
});
|
|
49
|
+
isInit.current = true;
|
|
50
|
+
startObserver();
|
|
51
|
+
}, () => {
|
|
52
|
+
trace.pointFn({
|
|
53
|
+
devId,
|
|
54
|
+
eventName: 'connectDeviceFail'
|
|
55
|
+
});
|
|
56
|
+
SweeperP2pInstance.reconnectP2p(() => {
|
|
57
|
+
isInit.current = true;
|
|
58
|
+
trace.pointFn({
|
|
59
|
+
devId,
|
|
60
|
+
eventName: 'reconnectP2p'
|
|
61
|
+
});
|
|
62
|
+
startObserver();
|
|
63
|
+
}, '');
|
|
64
|
+
});
|
|
65
|
+
}, [log, devId, startObserver]);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* p2p断开
|
|
69
|
+
*/
|
|
70
|
+
const unmount = useCallback(() => {
|
|
71
|
+
log.info({
|
|
72
|
+
msg: 'hooks has been started unmount'
|
|
73
|
+
});
|
|
74
|
+
isInit.current = false;
|
|
75
|
+
SweeperP2pInstance.stopObserverSweeperDataByP2P();
|
|
76
|
+
if (offSessionStatusChange.current) {
|
|
77
|
+
offSessionStatusChange.current();
|
|
78
|
+
offSessionStatusChange.current = null;
|
|
79
|
+
}
|
|
80
|
+
}, [log]);
|
|
81
|
+
const handleAppHide = useCallback(() => {
|
|
82
|
+
log.info({
|
|
83
|
+
msg: 'hooks onAppHide'
|
|
84
|
+
});
|
|
85
|
+
isAppOnBackground.current = true;
|
|
86
|
+
if (isInit.current) {
|
|
87
|
+
timer.current = setTimeout(() => {
|
|
88
|
+
log.info({
|
|
89
|
+
msg: `background timer has been exe,isAppOnBackground: ${isAppOnBackground.current}`
|
|
90
|
+
});
|
|
91
|
+
if (isAppOnBackground.current) {
|
|
92
|
+
unmount();
|
|
93
|
+
}
|
|
94
|
+
clearTimeout(timer.current);
|
|
95
|
+
timer.current = null;
|
|
96
|
+
}, 10 * 1000);
|
|
97
|
+
}
|
|
98
|
+
}, [log, unmount]);
|
|
99
|
+
const handleAppShow = useCallback(() => {
|
|
100
|
+
log.info({
|
|
101
|
+
msg: 'hooks onAppShow'
|
|
102
|
+
});
|
|
103
|
+
log.info({
|
|
104
|
+
msg: `clear timer ${timer.current}`
|
|
105
|
+
});
|
|
106
|
+
isAppOnBackground.current = false;
|
|
107
|
+
timer.current && clearTimeout(timer.current);
|
|
108
|
+
setTimeout(() => {
|
|
109
|
+
var _ty$p2p$isP2PActiveSy, _ty$p2p, _ty$p2p$isP2PActiveSy2, _ty$p2p2;
|
|
110
|
+
log.info({
|
|
111
|
+
msg: `hooks onAppShow and after 500ms : ${isInit.current} isP2PActiveSync: ${(_ty$p2p$isP2PActiveSy = (_ty$p2p = ty.p2p).isP2PActiveSync) === null || _ty$p2p$isP2PActiveSy === void 0 ? void 0 : _ty$p2p$isP2PActiveSy.call(_ty$p2p, {
|
|
112
|
+
deviceId: devId
|
|
113
|
+
})}`
|
|
114
|
+
});
|
|
115
|
+
if ((!isInit.current || !((_ty$p2p$isP2PActiveSy2 = (_ty$p2p2 = ty.p2p).isP2PActiveSync) !== null && _ty$p2p$isP2PActiveSy2 !== void 0 && _ty$p2p$isP2PActiveSy2.call(_ty$p2p2, {
|
|
116
|
+
deviceId: devId
|
|
117
|
+
}))) && !SweeperP2pInstance.isConnecting) {
|
|
118
|
+
connectP2p();
|
|
119
|
+
}
|
|
120
|
+
}, 500);
|
|
121
|
+
}, [log, devId, connectP2p]);
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
if (logTag) {
|
|
124
|
+
log4js.setTag(logTag);
|
|
125
|
+
}
|
|
126
|
+
if (traceId) {
|
|
127
|
+
trace.traceId = traceId;
|
|
128
|
+
}
|
|
129
|
+
if (isIDE) {
|
|
130
|
+
log.warn({
|
|
131
|
+
msg: `You are using the IDE environment. To perform P2P and map debugging, please ensure the 'Robot Vacuum Debugger' plugin is installed.`
|
|
132
|
+
});
|
|
133
|
+
SweeperP2pInstance.onReceiveMapData = onReceiveMapData;
|
|
134
|
+
SweeperP2pInstance.onReceivePathData = onReceivePathData;
|
|
135
|
+
SweeperP2pInstance.onDefineStructuredMode = onDefineStructuredMode;
|
|
136
|
+
SweeperP2pInstance.registerP2pDownloadEvent();
|
|
137
|
+
SweeperP2pInstance.onLogger = onLogger;
|
|
138
|
+
return () => {
|
|
139
|
+
SweeperP2pInstance.removeP2pDownloadEvent();
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (devId.startsWith('vdevo')) {
|
|
143
|
+
log.warn({
|
|
144
|
+
msg: 'virtual device cannot use p2p'
|
|
145
|
+
});
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
SweeperP2pInstance.onLogger = onLogger;
|
|
149
|
+
SweeperP2pInstance.initP2pSdk(devId).then(() => {
|
|
150
|
+
connectP2p();
|
|
151
|
+
trace.pointFn({
|
|
152
|
+
devId,
|
|
153
|
+
eventName: 'initP2pSdk'
|
|
154
|
+
});
|
|
155
|
+
}).catch(() => {
|
|
156
|
+
trace.pointFn({
|
|
157
|
+
devId,
|
|
158
|
+
eventName: 'initP2pSdkFail'
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
ty.onAppHide(handleAppHide);
|
|
162
|
+
ty.onAppShow(handleAppShow);
|
|
163
|
+
}, [devId, logTag, traceId, isIDE, log, onLogger, connectP2p, handleAppHide, handleAppShow]);
|
|
164
|
+
usePageEvent('onUnload', () => {
|
|
165
|
+
unmount();
|
|
166
|
+
ty.offAppHide(handleAppHide);
|
|
167
|
+
ty.offAppShow(handleAppShow);
|
|
168
|
+
SweeperP2pInstance.deInitP2PSDK();
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
appendDownloadStreamDuringTask: SweeperP2pInstance.appendDownloadStreamDuringTask
|
|
172
|
+
};
|
|
173
|
+
};
|
package/lib/api/p2pApi.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ApiResponse, ApiErrorParams, AlbumFileIndexSuccess } from '../ttt';
|
|
1
2
|
/**
|
|
2
3
|
* P2P 工具类
|
|
3
4
|
*/
|
|
@@ -10,6 +11,24 @@ export default class P2pApi {
|
|
|
10
11
|
devId: string;
|
|
11
12
|
traceId: string;
|
|
12
13
|
constructor();
|
|
14
|
+
/**
|
|
15
|
+
* 便捷的日志记录方法
|
|
16
|
+
* 使用 getter 确保每次访问时都使用最新的 onLogger
|
|
17
|
+
*/
|
|
18
|
+
protected get log(): {
|
|
19
|
+
info: (params: {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
msg: string;
|
|
22
|
+
}) => void;
|
|
23
|
+
warn: (params: {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
msg: string;
|
|
26
|
+
}) => void;
|
|
27
|
+
error: (params: {
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
msg: string;
|
|
30
|
+
}) => void;
|
|
31
|
+
};
|
|
13
32
|
/**
|
|
14
33
|
* 设备断开之后的重连
|
|
15
34
|
*/
|
|
@@ -19,7 +38,7 @@ export default class P2pApi {
|
|
|
19
38
|
* @param id 用户Id
|
|
20
39
|
* @returns
|
|
21
40
|
*/
|
|
22
|
-
initP2pSdk: (devId: string) => Promise<
|
|
41
|
+
initP2pSdk: (devId: string) => Promise<ApiResponse<null, ApiErrorParams>>;
|
|
23
42
|
/**
|
|
24
43
|
* 连接设备
|
|
25
44
|
* @returns
|
|
@@ -29,7 +48,7 @@ export default class P2pApi {
|
|
|
29
48
|
* 断开P2P设备连接
|
|
30
49
|
* @returns
|
|
31
50
|
*/
|
|
32
|
-
disconnectDevice: () => Promise<
|
|
51
|
+
disconnectDevice: () => Promise<ApiResponse<null, ApiErrorParams>>;
|
|
33
52
|
/**
|
|
34
53
|
* 开始P2p流传输
|
|
35
54
|
* @param files
|
|
@@ -41,7 +60,7 @@ export default class P2pApi {
|
|
|
41
60
|
*/
|
|
42
61
|
downloadStream: (files: {
|
|
43
62
|
files: Array<string>;
|
|
44
|
-
}, albumName: string, successCb?: () => void, failedCb?: () => void) => Promise<
|
|
63
|
+
}, albumName: string, successCb?: () => void, failedCb?: () => void) => Promise<boolean>;
|
|
45
64
|
/**
|
|
46
65
|
* 在下载过程中加入下载文件,需要把之前下载中的文件名也一起带上
|
|
47
66
|
* @param files
|
|
@@ -52,7 +71,7 @@ export default class P2pApi {
|
|
|
52
71
|
*/
|
|
53
72
|
appendDownloadStream: (files: {
|
|
54
73
|
files: Array<string>;
|
|
55
|
-
}, albumName: string, successCb?: () => void, failedCb?: () => void) => Promise<boolean
|
|
74
|
+
}, albumName: string, successCb?: () => void, failedCb?: () => void) => Promise<boolean>;
|
|
56
75
|
/**
|
|
57
76
|
* 监听p2p传输数据流
|
|
58
77
|
* @param callback
|
|
@@ -65,7 +84,7 @@ export default class P2pApi {
|
|
|
65
84
|
*/
|
|
66
85
|
downloadFile: (files: {
|
|
67
86
|
files: Array<string>;
|
|
68
|
-
}, albumName: string, filePath: string, successCb?: () => void, failedCb?: () => void) => Promise<
|
|
87
|
+
}, albumName: string, filePath: string, successCb?: () => void, failedCb?: () => void) => Promise<boolean | null>;
|
|
69
88
|
/**
|
|
70
89
|
* 注册下载监听事件
|
|
71
90
|
* @param callback
|
|
@@ -93,16 +112,16 @@ export default class P2pApi {
|
|
|
93
112
|
* 取消进行下载
|
|
94
113
|
* @returns
|
|
95
114
|
*/
|
|
96
|
-
cancelDownloadTask: () => Promise<
|
|
115
|
+
cancelDownloadTask: () => Promise<ApiResponse<null, ApiErrorParams>>;
|
|
97
116
|
/**
|
|
98
117
|
* 查询设备相册文件列表
|
|
99
118
|
* @param albumName
|
|
100
119
|
* @returns
|
|
101
120
|
*/
|
|
102
|
-
queryAlbumFileIndexs: (albumName: string) => Promise<
|
|
121
|
+
queryAlbumFileIndexs: (albumName: string) => Promise<ApiResponse<AlbumFileIndexSuccess, ApiErrorParams>>;
|
|
103
122
|
/**
|
|
104
123
|
* P2p SDK 销毁
|
|
105
124
|
* @returns
|
|
106
125
|
*/
|
|
107
|
-
deInitP2PSDK: () => Promise<
|
|
126
|
+
deInitP2PSDK: () => Promise<ApiResponse<null, ApiErrorParams>>;
|
|
108
127
|
}
|