@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.
Files changed (58) hide show
  1. package/lib/api/index.d.ts +12 -2
  2. package/lib/api/index.js +172 -1
  3. package/lib/api/p2pApi.d.ts +27 -8
  4. package/lib/api/p2pApi.js +169 -271
  5. package/lib/api/sweeperP2p.d.ts +23 -49
  6. package/lib/api/sweeperP2p.js +248 -311
  7. package/lib/constant.d.ts +52 -0
  8. package/lib/constant.js +54 -0
  9. package/lib/index.d.ts +1 -10
  10. package/lib/index.js +2 -165
  11. package/lib/mqtt/createCommonOptions.d.ts +56 -15
  12. package/lib/mqtt/createCommonOptions.js +44 -8
  13. package/lib/mqtt/index.d.ts +2 -1
  14. package/lib/mqtt/index.js +2 -1
  15. package/lib/mqtt/mqttProvider.d.ts +23 -15
  16. package/lib/mqtt/mqttProvider.js +63 -26
  17. package/lib/mqtt/promise.js +8 -3
  18. package/lib/mqtt/type/index.d.ts +14 -0
  19. package/lib/mqtt/type/index.js +14 -0
  20. package/lib/mqtt/type/requestType.d.ts +8 -0
  21. package/lib/mqtt/type/requestType.js +10 -0
  22. package/lib/mqtt/useDevInfo.d.ts +2 -7
  23. package/lib/mqtt/useDevInfo.js +25 -9
  24. package/lib/mqtt/useHistoryMap.d.ts +13 -21
  25. package/lib/mqtt/useHistoryMap.js +82 -32
  26. package/lib/mqtt/usePartDivision.d.ts +5 -7
  27. package/lib/mqtt/usePartDivision.js +41 -16
  28. package/lib/mqtt/usePartMerge.d.ts +5 -7
  29. package/lib/mqtt/usePartMerge.js +36 -18
  30. package/lib/mqtt/usePassword.js +59 -28
  31. package/lib/mqtt/useQuiteHours.d.ts +9 -24
  32. package/lib/mqtt/useQuiteHours.js +95 -52
  33. package/lib/mqtt/useResetMap.d.ts +10 -7
  34. package/lib/mqtt/useResetMap.js +40 -11
  35. package/lib/mqtt/useRoomProperty.js +23 -16
  36. package/lib/mqtt/useSchedule.d.ts +17 -4
  37. package/lib/mqtt/useSchedule.js +101 -49
  38. package/lib/mqtt/useSelectRoomClean.d.ts +20 -16
  39. package/lib/mqtt/useSelectRoomClean.js +145 -49
  40. package/lib/mqtt/useSpotClean.d.ts +3 -3
  41. package/lib/mqtt/useSpotClean.js +72 -50
  42. package/lib/mqtt/useVirtualArea.d.ts +6 -9
  43. package/lib/mqtt/useVirtualArea.js +112 -42
  44. package/lib/mqtt/useVirtualWall.d.ts +13 -10
  45. package/lib/mqtt/useVirtualWall.js +97 -34
  46. package/lib/mqtt/useVoice.d.ts +3 -6
  47. package/lib/mqtt/useVoice.js +73 -33
  48. package/lib/mqtt/useWifiMap.d.ts +8 -0
  49. package/lib/mqtt/useWifiMap.js +53 -0
  50. package/lib/mqtt/useZoneClean.d.ts +13 -13
  51. package/lib/mqtt/useZoneClean.js +149 -76
  52. package/lib/ttt/index.d.ts +153 -0
  53. package/lib/ttt/index.js +458 -0
  54. package/lib/utils/index.d.ts +20 -1
  55. package/lib/utils/index.js +19 -0
  56. package/package.json +1 -1
  57. package/lib/mqtt/myError.d.ts +0 -4
  58. package/lib/mqtt/myError.js +0 -6
@@ -1,7 +1,7 @@
1
1
  import "core-js/modules/esnext.iterator.constructor.js";
2
2
  import "core-js/modules/esnext.iterator.for-each.js";
3
+ import "core-js/modules/esnext.iterator.map.js";
3
4
  // 划区清扫
4
-
5
5
  import { isArray } from 'lodash-es';
6
6
  import { createSetCommonParams } from './createCommonOptions';
7
7
  import { normalResolve } from './promise';
@@ -10,9 +10,19 @@ import { useContext } from 'react';
10
10
  import { SingletonContext } from './mqttProvider';
11
11
  import { encodeZoneClean0x3a, requestZoneClean0x3b } from '@ray-js/robot-protocol';
12
12
  import { pointsToString } from '../utils';
13
+
14
+ // 划区清扫响应类型
15
+
16
+ // 设置划区清扫参数类型
17
+
18
+ // 请求划区清扫函数类型定义
19
+
20
+ // 设置划区清扫函数类型定义
21
+
13
22
  /**
14
- * 划区清扫
15
- * @returns
23
+ * 自定义 Hook,用于划区清扫
24
+ * @param devId 设备ID
25
+ * @returns 包含 requestZoneClean 和 setZoneClean 函数的对象
16
26
  */
17
27
  export const useZoneClean = devId => {
18
28
  const {
@@ -21,95 +31,158 @@ export const useZoneClean = devId => {
21
31
  devices
22
32
  } = useContext(SingletonContext);
23
33
 
24
- // 请求划区清扫信息
34
+ /**
35
+ * 请求划区清扫信息
36
+ * @returns Promise<ZoneCleanResponse> 响应结果
37
+ */
25
38
 
26
- // 设置划区清扫
39
+ /**
40
+ * 设置划区清扫
41
+ * @param params 包含划区清扫设置参数的对象
42
+ * @param params.zones 区域数组
43
+ * @param params.origin 原点坐标
44
+ * @returns Promise<ZoneCleanResponse> 响应结果
45
+ */
27
46
 
28
47
  return {
29
48
  requestZoneClean: () => {
30
- if (useMqtt) {
31
- const params = createSetCommonParams({
32
- deviceId: devId,
33
- reqType: ZoneCleanEnum.query
49
+ try {
50
+ if (useMqtt) {
51
+ const params = createSetCommonParams({
52
+ deviceId: devId,
53
+ reqType: ZoneCleanEnum.query
54
+ });
55
+ ty.device.sendMqttMessage(params);
56
+ const {
57
+ taskId
58
+ } = params.message;
59
+ return normalResolve(ZoneCleanEnum.query, taskId);
60
+ }
61
+
62
+ // 非 MQTT 模式:使用命令传输
63
+ devices.common.model.actions.command_trans.set(requestZoneClean0x3b({
64
+ version: commandVersion
65
+ }));
66
+
67
+ // 非 MQTT 模式下无法立即获取响应数据,返回默认响应
68
+ return Promise.resolve({
69
+ success: true,
70
+ errCode: 0,
71
+ reqType: ZoneCleanEnum.query,
72
+ version: commandVersion,
73
+ taskId: `${Date.now()}`,
74
+ polygons: [],
75
+ names: []
34
76
  });
35
- ty.device.sendMqttMessage(params);
36
- return normalResolve(ZoneCleanEnum.query, params.message.taskId);
77
+ } catch (error) {
78
+ return Promise.reject(error instanceof Error ? error : new Error('Failed to request zone clean'));
37
79
  }
38
- return devices.common.model.actions.command_trans.set(requestZoneClean0x3b({
39
- version: commandVersion
40
- }));
41
80
  },
42
- setZoneClean: message => {
81
+ setZoneClean: params => {
43
82
  const {
44
83
  zones,
45
84
  origin
46
- } = message;
47
- if (useMqtt) {
48
- if (!isArray(zones) || isArray(zones) && zones.length === 0) {
49
- return Promise.reject(new Error('message is required'));
50
- }
51
- const num = zones.length;
52
- const {
53
- suctions = new Array(num).fill(''),
54
- cisterns = new Array(num).fill(''),
55
- cleanCounts = new Array(num).fill(1),
56
- yMops = new Array(num).fill(-1),
57
- sweepMopModes = new Array(num).fill('only_sweep')
58
- } = message;
59
- if (suctions && !isArray(suctions)) {
60
- return Promise.reject(new Error('suctions is illegal'));
61
- }
62
- if (cisterns && !isArray(cisterns)) {
63
- return Promise.reject(new Error('cisterns is illegal'));
64
- }
65
- if (cleanCounts && !isArray(cleanCounts)) {
66
- return Promise.reject(new Error('cleanCounts is illegal'));
67
- }
68
- if (yMops && !isArray(yMops)) {
69
- return Promise.reject(new Error('yMops is illegal'));
70
- }
71
- if (sweepMopModes && !isArray(sweepMopModes)) {
72
- return Promise.reject(new Error('sweepMopModes is illegal'));
73
- }
74
- if (num !== suctions.length || num !== cisterns.length || num !== cleanCounts.length || num !== yMops.length || num !== sweepMopModes.length) {
75
- return Promise.reject(new Error('The length of the parameters is inconsistent'));
85
+ } = params;
86
+
87
+ // 参数验证
88
+ if (!isArray(zones) || zones.length === 0) {
89
+ throw new Error('zones is required and must be a non-empty array');
90
+ }
91
+ if (!origin || typeof origin.x !== 'number' || typeof origin.y !== 'number') {
92
+ throw new Error('origin is required and must be a valid Point object with x and y properties');
93
+ }
94
+ try {
95
+ if (useMqtt) {
96
+ const num = zones.length;
97
+ const {
98
+ suctions = new Array(num).fill(''),
99
+ cisterns = new Array(num).fill(''),
100
+ cleanCounts = new Array(num).fill(1),
101
+ yMops = new Array(num).fill(-1),
102
+ sweepMopModes = new Array(num).fill('only_sweep')
103
+ } = params;
104
+ if (suctions && !isArray(suctions)) {
105
+ throw new Error('suctions is illegal');
106
+ }
107
+ if (cisterns && !isArray(cisterns)) {
108
+ throw new Error('cisterns is illegal');
109
+ }
110
+ if (cleanCounts && !isArray(cleanCounts)) {
111
+ throw new Error('cleanCounts is illegal');
112
+ }
113
+ if (yMops && !isArray(yMops)) {
114
+ throw new Error('yMops is illegal');
115
+ }
116
+ if (sweepMopModes && !isArray(sweepMopModes)) {
117
+ throw new Error('sweepMopModes is illegal');
118
+ }
119
+ if (num !== suctions.length || num !== cisterns.length || num !== cleanCounts.length || num !== yMops.length || num !== sweepMopModes.length) {
120
+ throw new Error('The length of the parameters is inconsistent');
121
+ }
122
+ const polygons = [];
123
+ const names = [];
124
+ zones.forEach(_ref => {
125
+ let {
126
+ points,
127
+ name
128
+ } = _ref;
129
+ polygons.push(pointsToString(points, origin));
130
+ names.push(name || '');
131
+ });
132
+ const mqttParams = createSetCommonParams({
133
+ deviceId: devId,
134
+ reqType: ZoneCleanEnum.set,
135
+ message: {
136
+ num: zones.length,
137
+ switchGo: true,
138
+ polygons,
139
+ suctions,
140
+ cisterns,
141
+ cleanCounts,
142
+ yMops,
143
+ sweepMopModes,
144
+ names
145
+ }
146
+ });
147
+ ty.device.sendMqttMessage(mqttParams);
148
+ const {
149
+ taskId
150
+ } = mqttParams.message;
151
+ return normalResolve(ZoneCleanEnum.query, taskId);
76
152
  }
77
- const polygons = [];
78
- const names = [];
79
- zones.forEach(_ref => {
153
+
154
+ // MQTT 模式:使用命令传输
155
+ const command = encodeZoneClean0x3a({
156
+ protocolVersion: 1,
157
+ version: commandVersion,
158
+ origin,
159
+ zones
160
+ });
161
+ devices.common.model.actions.command_trans.set(command);
162
+ const polygons = zones.map(_ref2 => {
163
+ let {
164
+ points
165
+ } = _ref2;
166
+ return pointsToString(points, origin);
167
+ });
168
+ const names = zones.map(_ref3 => {
80
169
  let {
81
- points,
82
170
  name
83
- } = _ref;
84
- polygons.push(pointsToString(points, origin));
85
- names.push(name || '');
171
+ } = _ref3;
172
+ return name || '';
86
173
  });
87
- const params = createSetCommonParams({
88
- deviceId: devId,
89
- reqType: ZoneCleanEnum.set,
90
- message: {
91
- num: zones.length,
92
- switchGo: true,
93
- polygons,
94
- suctions,
95
- cisterns,
96
- cleanCounts,
97
- yMops,
98
- sweepMopModes,
99
- names
100
- }
174
+ return Promise.resolve({
175
+ success: true,
176
+ errCode: 0,
177
+ reqType: ZoneCleanEnum.query,
178
+ version: commandVersion,
179
+ taskId: `${Date.now()}`,
180
+ polygons,
181
+ names
101
182
  });
102
- ty.device.sendMqttMessage(params);
103
- return normalResolve(ZoneCleanEnum.query, params.message.taskId);
183
+ } catch (error) {
184
+ throw error instanceof Error ? error : new Error('Failed to set zone clean');
104
185
  }
105
- const command = encodeZoneClean0x3a({
106
- protocolVersion: 1,
107
- version: commandVersion,
108
- origin,
109
- zones
110
- });
111
- devices.common.model.actions.command_trans.set(command);
112
- return Promise.resolve();
113
186
  }
114
187
  };
115
188
  };
@@ -0,0 +1,153 @@
1
+ /**
2
+ * API 错误参数
3
+ */
4
+ export interface ApiErrorParams {
5
+ errorMsg?: string;
6
+ errorCode?: string | number;
7
+ innerError?: {
8
+ errorCode: string | number;
9
+ errorMsg: string;
10
+ };
11
+ [key: string]: any;
12
+ }
13
+ /**
14
+ * 通用 API 响应类型
15
+ * @template TSuccess 成功时的数据类型
16
+ * @template TError 失败时的错误类型,默认为 ApiErrorParams
17
+ */
18
+ export interface ApiResponse<TSuccess = any, TError = ApiErrorParams> {
19
+ /** 操作是否成功 */
20
+ success: boolean;
21
+ /** 响应数据(成功时为 TSuccess,失败时为 TError) */
22
+ data?: TSuccess | TError;
23
+ /** 响应参数(P2P API 使用,成功时为 TSuccess,失败时为 TError) */
24
+ params?: TSuccess | TError;
25
+ /** 错误信息(失败时使用) */
26
+ error?: TError;
27
+ }
28
+ /**
29
+ * 文件读取成功响应
30
+ */
31
+ export interface FileReadSuccess {
32
+ /** 文件内容(Base64 编码) */
33
+ data: string;
34
+ }
35
+ /**
36
+ * 相册文件索引查询成功响应
37
+ */
38
+ export interface AlbumFileIndexSuccess {
39
+ /** 文件数量 */
40
+ count: number;
41
+ /** 文件索引列表 */
42
+ items: ty.p2p.ThingP2PAlbumFileIndex[];
43
+ }
44
+ type TOnLogger = (type: 'warn' | 'error' | 'info', data: string) => void;
45
+ /**
46
+ * 创建文件路径(目录)
47
+ *
48
+ * @param filePath - 文件路径
49
+ * @returns Promise,成功时返回 true,失败时抛出错误
50
+ */
51
+ export declare const createFilePath: (filePath: string, onLogger: TOnLogger) => Promise<boolean>;
52
+ /**
53
+ * 检查目录是否存在
54
+ *
55
+ * @param filePath - 文件路径
56
+ * @returns Promise,返回检查结果
57
+ */
58
+ export declare const checkIfDirIsExist: (filePath: string) => Promise<boolean>;
59
+ /**
60
+ * 读取文件内容(Base64 编码)
61
+ *
62
+ * @param filePath - 文件路径
63
+ * @returns Promise,返回文件读取结果
64
+ */
65
+ export declare const readFile: (filePath: string, onLogger: TOnLogger) => Promise<ApiResponse<FileReadSuccess, ApiErrorParams>>;
66
+ /**
67
+ * 初始化 P2P SDK
68
+ *
69
+ * @returns Promise,返回初始化结果
70
+ */
71
+ export declare const initP2pSdk: (onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
72
+ /**
73
+ * 连接设备
74
+ *
75
+ * @param devId - 设备ID
76
+ * @returns Promise,返回连接结果
77
+ */
78
+ export declare const connectDevice: (devId: string, onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
79
+ /**
80
+ * 断开设备连接
81
+ *
82
+ * @param devId - 设备ID
83
+ * @returns Promise,返回断开连接结果
84
+ */
85
+ export declare const disconnectDevice: (devId: string, onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
86
+ /**
87
+ * 下载流数据
88
+ *
89
+ * @param devId - 设备ID
90
+ * @param albumName - 相册名称
91
+ * @param files - 文件列表
92
+ * @returns Promise,返回下载结果
93
+ */
94
+ export declare const downloadStream: (devId: string, albumName: string, files: string[], onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
95
+ /**
96
+ * 追加下载流数据
97
+ *
98
+ * @param devId - 设备ID
99
+ * @param albumName - 相册名称
100
+ * @param files - 文件列表
101
+ * @param onLogger - 日志回调函数
102
+ * @returns Promise,返回追加下载结果
103
+ */
104
+ export declare const appendDownloadStream: (devId: string, albumName: string, files: string[], onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
105
+ /**
106
+ * 下载文件
107
+ *
108
+ * @param devId - 设备ID
109
+ * @param albumName - 相册名称
110
+ * @param filePath - 文件保存路径
111
+ * @param files - 文件列表
112
+ * @returns Promise,返回下载结果
113
+ */
114
+ export declare const downloadFile: (devId: string, albumName: string, filePath: string, files: string[], onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
115
+ /**
116
+ * 取消下载任务
117
+ *
118
+ * @param devId - 设备ID
119
+ * @returns Promise,返回取消结果
120
+ */
121
+ export declare const cancelDownloadTask: (devId: string, onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
122
+ /**
123
+ * 查询相册文件索引
124
+ *
125
+ * @param devId - 设备ID
126
+ * @param albumName - 相册名称
127
+ * @returns Promise,返回查询结果
128
+ */
129
+ export declare const queryAlbumFileIndexs: (devId: string, albumName: string, onLogger: TOnLogger) => Promise<ApiResponse<AlbumFileIndexSuccess, ApiErrorParams>>;
130
+ /**
131
+ * 反初始化 P2P SDK
132
+ *
133
+ * @returns Promise,返回反初始化结果
134
+ */
135
+ export declare const deInitP2pSdk: (onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
136
+ /**
137
+ * TTT API 集合
138
+ */
139
+ export declare const apis: {
140
+ readonly createFilePath: (filePath: string, onLogger: TOnLogger) => Promise<boolean>;
141
+ readonly checkIfDirIsExist: (filePath: string) => Promise<boolean>;
142
+ readonly readFile: (filePath: string, onLogger: TOnLogger) => Promise<ApiResponse<FileReadSuccess, ApiErrorParams>>;
143
+ readonly initP2pSdk: (onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
144
+ readonly connectDevice: (devId: string, onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
145
+ readonly disconnectDevice: (devId: string, onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
146
+ readonly downloadStream: (devId: string, albumName: string, files: string[], onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
147
+ readonly appendDownloadStream: (devId: string, albumName: string, files: string[], onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
148
+ readonly downloadFile: (devId: string, albumName: string, filePath: string, files: string[], onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
149
+ readonly cancelDownloadTask: (devId: string, onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
150
+ readonly queryAlbumFileIndexs: (devId: string, albumName: string, onLogger: TOnLogger) => Promise<ApiResponse<AlbumFileIndexSuccess, ApiErrorParams>>;
151
+ readonly deInitP2pSdk: (onLogger: TOnLogger) => Promise<ApiResponse<null, ApiErrorParams>>;
152
+ };
153
+ export {};