@ray-js/robot-data-stream 0.0.13-beta-7 → 0.0.13-beta-8

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.
Files changed (55) hide show
  1. package/lib/api/index.d.ts +2 -12
  2. package/lib/api/index.js +1 -172
  3. package/lib/api/p2pApi.d.ts +8 -27
  4. package/lib/api/p2pApi.js +271 -169
  5. package/lib/api/sweeperP2p.d.ts +54 -21
  6. package/lib/api/sweeperP2p.js +324 -245
  7. package/lib/constant.d.ts +0 -52
  8. package/lib/constant.js +0 -54
  9. package/lib/index.d.ts +11 -1
  10. package/lib/index.js +166 -2
  11. package/lib/mqtt/createCommonOptions.d.ts +15 -56
  12. package/lib/mqtt/createCommonOptions.js +8 -44
  13. package/lib/mqtt/mqttProvider.d.ts +15 -23
  14. package/lib/mqtt/mqttProvider.js +26 -63
  15. package/lib/mqtt/myError.d.ts +4 -0
  16. package/lib/mqtt/myError.js +6 -0
  17. package/lib/mqtt/promise.js +3 -8
  18. package/lib/mqtt/type/index.d.ts +0 -9
  19. package/lib/mqtt/type/index.js +0 -8
  20. package/lib/mqtt/type/requestType.d.ts +0 -3
  21. package/lib/mqtt/type/requestType.js +0 -4
  22. package/lib/mqtt/useDevInfo.d.ts +7 -2
  23. package/lib/mqtt/useDevInfo.js +9 -25
  24. package/lib/mqtt/useHistoryMap.d.ts +21 -13
  25. package/lib/mqtt/useHistoryMap.js +32 -82
  26. package/lib/mqtt/usePartDivision.d.ts +7 -5
  27. package/lib/mqtt/usePartDivision.js +16 -41
  28. package/lib/mqtt/usePartMerge.d.ts +7 -5
  29. package/lib/mqtt/usePartMerge.js +18 -36
  30. package/lib/mqtt/usePassword.js +28 -59
  31. package/lib/mqtt/useQuiteHours.d.ts +24 -9
  32. package/lib/mqtt/useQuiteHours.js +52 -95
  33. package/lib/mqtt/useResetMap.d.ts +7 -10
  34. package/lib/mqtt/useResetMap.js +11 -40
  35. package/lib/mqtt/useRoomProperty.js +16 -23
  36. package/lib/mqtt/useSchedule.d.ts +4 -17
  37. package/lib/mqtt/useSchedule.js +49 -101
  38. package/lib/mqtt/useSelectRoomClean.d.ts +16 -20
  39. package/lib/mqtt/useSelectRoomClean.js +49 -145
  40. package/lib/mqtt/useSpotClean.d.ts +3 -3
  41. package/lib/mqtt/useSpotClean.js +51 -71
  42. package/lib/mqtt/useVirtualArea.d.ts +9 -6
  43. package/lib/mqtt/useVirtualArea.js +42 -112
  44. package/lib/mqtt/useVirtualWall.d.ts +10 -13
  45. package/lib/mqtt/useVirtualWall.js +34 -97
  46. package/lib/mqtt/useVoice.d.ts +6 -3
  47. package/lib/mqtt/useVoice.js +33 -73
  48. package/lib/mqtt/useWifiMap.js +18 -34
  49. package/lib/mqtt/useZoneClean.d.ts +13 -13
  50. package/lib/mqtt/useZoneClean.js +76 -149
  51. package/lib/utils/index.d.ts +1 -20
  52. package/lib/utils/index.js +0 -19
  53. package/package.json +1 -1
  54. package/lib/ttt/index.d.ts +0 -153
  55. package/lib/ttt/index.js +0 -458
@@ -1,12 +1,2 @@
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 {};
1
+ import SweeperP2pInstance from './sweeperP2p';
2
+ export { SweeperP2pInstance };
package/lib/api/index.js CHANGED
@@ -1,173 +1,2 @@
1
1
  import SweeperP2pInstance from './sweeperP2p';
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
- };
2
+ export { SweeperP2pInstance };
@@ -1,4 +1,3 @@
1
- import { ApiResponse, ApiErrorParams, AlbumFileIndexSuccess } from '../ttt';
2
1
  /**
3
2
  * P2P 工具类
4
3
  */
@@ -11,24 +10,6 @@ export default class P2pApi {
11
10
  devId: string;
12
11
  traceId: string;
13
12
  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
- };
32
13
  /**
33
14
  * 设备断开之后的重连
34
15
  */
@@ -38,7 +19,7 @@ export default class P2pApi {
38
19
  * @param id 用户Id
39
20
  * @returns
40
21
  */
41
- initP2pSdk: (devId: string) => Promise<ApiResponse<null, ApiErrorParams>>;
22
+ initP2pSdk: (devId: string) => Promise<boolean>;
42
23
  /**
43
24
  * 连接设备
44
25
  * @returns
@@ -48,7 +29,7 @@ export default class P2pApi {
48
29
  * 断开P2P设备连接
49
30
  * @returns
50
31
  */
51
- disconnectDevice: () => Promise<ApiResponse<null, ApiErrorParams>>;
32
+ disconnectDevice: () => Promise<boolean>;
52
33
  /**
53
34
  * 开始P2p流传输
54
35
  * @param files
@@ -60,7 +41,7 @@ export default class P2pApi {
60
41
  */
61
42
  downloadStream: (files: {
62
43
  files: Array<string>;
63
- }, albumName: string, successCb?: () => void, failedCb?: () => void) => Promise<boolean>;
44
+ }, albumName: string, successCb?: () => void, failedCb?: () => void) => Promise<unknown> | undefined;
64
45
  /**
65
46
  * 在下载过程中加入下载文件,需要把之前下载中的文件名也一起带上
66
47
  * @param files
@@ -71,7 +52,7 @@ export default class P2pApi {
71
52
  */
72
53
  appendDownloadStream: (files: {
73
54
  files: Array<string>;
74
- }, albumName: string, successCb?: () => void, failedCb?: () => void) => Promise<boolean>;
55
+ }, albumName: string, successCb?: () => void, failedCb?: () => void) => Promise<boolean> | undefined;
75
56
  /**
76
57
  * 监听p2p传输数据流
77
58
  * @param callback
@@ -84,7 +65,7 @@ export default class P2pApi {
84
65
  */
85
66
  downloadFile: (files: {
86
67
  files: Array<string>;
87
- }, albumName: string, filePath: string, successCb?: () => void, failedCb?: () => void) => Promise<boolean | null>;
68
+ }, albumName: string, filePath: string, successCb?: () => void, failedCb?: () => void) => Promise<unknown> | null;
88
69
  /**
89
70
  * 注册下载监听事件
90
71
  * @param callback
@@ -112,16 +93,16 @@ export default class P2pApi {
112
93
  * 取消进行下载
113
94
  * @returns
114
95
  */
115
- cancelDownloadTask: () => Promise<ApiResponse<null, ApiErrorParams>>;
96
+ cancelDownloadTask: () => Promise<unknown>;
116
97
  /**
117
98
  * 查询设备相册文件列表
118
99
  * @param albumName
119
100
  * @returns
120
101
  */
121
- queryAlbumFileIndexs: (albumName: string) => Promise<ApiResponse<AlbumFileIndexSuccess, ApiErrorParams>>;
102
+ queryAlbumFileIndexs: (albumName: string) => Promise<unknown>;
122
103
  /**
123
104
  * P2p SDK 销毁
124
105
  * @returns
125
106
  */
126
- deInitP2PSDK: () => Promise<ApiResponse<null, ApiErrorParams>>;
107
+ deInitP2PSDK: () => Promise<boolean>;
127
108
  }