@ray-js/robot-data-stream 0.0.13-beta-6 → 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 +21 -54
- package/lib/api/sweeperP2p.js +245 -324
- package/lib/constant.d.ts +52 -0
- package/lib/constant.js +54 -0
- package/lib/index.d.ts +1 -11
- package/lib/index.js +2 -166
- package/lib/mqtt/createCommonOptions.d.ts +56 -15
- package/lib/mqtt/createCommonOptions.js +44 -8
- 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 +9 -0
- package/lib/mqtt/type/index.js +8 -0
- package/lib/mqtt/type/requestType.d.ts +3 -0
- package/lib/mqtt/type/requestType.js +4 -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 +71 -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.js +34 -18
- 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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import "core-js/modules/esnext.iterator.map.js";
|
|
2
2
|
// 虚拟墙数据
|
|
3
|
-
|
|
4
3
|
import { useContext } from 'react';
|
|
5
4
|
import { createSetCommonParams } from './createCommonOptions';
|
|
6
5
|
import { normalResolve } from './promise';
|
|
@@ -8,6 +7,20 @@ import { VirtualWallEnum } from './type';
|
|
|
8
7
|
import { SingletonContext } from './mqttProvider';
|
|
9
8
|
import { encodeVirtualWall0x12, requestVirtualWall0x13 } from '@ray-js/robot-protocol';
|
|
10
9
|
import { pointsToString } from '../utils';
|
|
10
|
+
|
|
11
|
+
// 虚拟墙响应类型
|
|
12
|
+
|
|
13
|
+
// 设置虚拟墙参数类型
|
|
14
|
+
|
|
15
|
+
// 请求虚拟墙函数类型定义
|
|
16
|
+
|
|
17
|
+
// 设置虚拟墙函数类型定义
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 自定义 Hook,用于虚拟墙管理
|
|
21
|
+
* @param devId 设备ID
|
|
22
|
+
* @returns 包含 requestVirtualWall 和 setVirtualWall 函数的对象
|
|
23
|
+
*/
|
|
11
24
|
export const useVirtualWall = devId => {
|
|
12
25
|
const {
|
|
13
26
|
useMqtt,
|
|
@@ -15,56 +28,106 @@ export const useVirtualWall = devId => {
|
|
|
15
28
|
devices
|
|
16
29
|
} = useContext(SingletonContext);
|
|
17
30
|
|
|
18
|
-
|
|
31
|
+
/**
|
|
32
|
+
* 请求虚拟墙数据
|
|
33
|
+
* @returns Promise<VirtualWallResponse> 响应结果
|
|
34
|
+
*/
|
|
19
35
|
|
|
20
36
|
/**
|
|
21
37
|
* 设置虚拟墙数据
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
25
|
-
* @
|
|
26
|
-
* @returns Promise<Response> 响应结果
|
|
38
|
+
* @param params 包含虚拟墙设置参数的对象
|
|
39
|
+
* @param params.data 虚拟墙的点数组
|
|
40
|
+
* @param params.origin 原点坐标
|
|
41
|
+
* @returns Promise<VirtualWallResponse> 响应结果
|
|
27
42
|
*/
|
|
28
43
|
|
|
29
44
|
return {
|
|
30
45
|
requestVirtualWall: () => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
try {
|
|
47
|
+
if (useMqtt) {
|
|
48
|
+
const params = createSetCommonParams({
|
|
49
|
+
deviceId: devId,
|
|
50
|
+
reqType: VirtualWallEnum.query
|
|
51
|
+
});
|
|
52
|
+
ty.device.sendMqttMessage(params);
|
|
53
|
+
const {
|
|
54
|
+
taskId
|
|
55
|
+
} = params.message;
|
|
56
|
+
return normalResolve(VirtualWallEnum.query, taskId);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 非 MQTT 模式:使用命令传输
|
|
60
|
+
devices.common.model.actions.command_trans.set(requestVirtualWall0x13({
|
|
61
|
+
version: commandVersion
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
// 非 MQTT 模式下无法立即获取响应数据,返回默认响应
|
|
65
|
+
return Promise.resolve({
|
|
66
|
+
success: true,
|
|
67
|
+
errCode: 0,
|
|
68
|
+
reqType: VirtualWallEnum.query,
|
|
69
|
+
version: commandVersion,
|
|
70
|
+
taskId: `${Date.now()}`,
|
|
71
|
+
num: 0,
|
|
72
|
+
modes: [],
|
|
73
|
+
points: [],
|
|
74
|
+
mapId: 0
|
|
35
75
|
});
|
|
36
|
-
|
|
37
|
-
return
|
|
76
|
+
} catch (error) {
|
|
77
|
+
return Promise.reject(error instanceof Error ? error : new Error('Failed to request virtual wall'));
|
|
38
78
|
}
|
|
39
|
-
return devices.common.model.actions.command_trans.set(requestVirtualWall0x13({
|
|
40
|
-
version: commandVersion
|
|
41
|
-
}));
|
|
42
79
|
},
|
|
43
80
|
setVirtualWall: _ref => {
|
|
44
81
|
let {
|
|
45
82
|
data,
|
|
46
83
|
origin
|
|
47
84
|
} = _ref;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
85
|
+
// 参数验证
|
|
86
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
87
|
+
throw new Error('data is required and must be a non-empty array');
|
|
88
|
+
}
|
|
89
|
+
if (!origin || typeof origin.x !== 'number' || typeof origin.y !== 'number') {
|
|
90
|
+
throw new Error('origin is required and must be a valid Point object with x and y properties');
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
if (useMqtt) {
|
|
94
|
+
const params = createSetCommonParams({
|
|
95
|
+
deviceId: devId,
|
|
96
|
+
reqType: VirtualWallEnum.set,
|
|
97
|
+
message: {
|
|
98
|
+
points: data.map(points => pointsToString(points, origin)),
|
|
99
|
+
num: data.length,
|
|
100
|
+
mode: new Array(data.length).fill('0')
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
ty.device.sendMqttMessage(params);
|
|
104
|
+
const {
|
|
105
|
+
taskId
|
|
106
|
+
} = params.message;
|
|
107
|
+
return normalResolve(VirtualWallEnum.query, taskId);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 非 MQTT 模式:使用命令传输
|
|
111
|
+
const command = encodeVirtualWall0x12({
|
|
112
|
+
version: commandVersion,
|
|
113
|
+
origin,
|
|
114
|
+
walls: data
|
|
115
|
+
});
|
|
116
|
+
devices.common.model.actions.command_trans.set(command);
|
|
117
|
+
return Promise.resolve({
|
|
118
|
+
success: true,
|
|
119
|
+
errCode: 0,
|
|
120
|
+
reqType: VirtualWallEnum.query,
|
|
121
|
+
version: commandVersion,
|
|
122
|
+
taskId: `${Date.now()}`,
|
|
123
|
+
num: data.length,
|
|
124
|
+
modes: new Array(data.length).fill(0),
|
|
125
|
+
points: data.map(points => pointsToString(points, origin)),
|
|
126
|
+
mapId: 0
|
|
57
127
|
});
|
|
58
|
-
|
|
59
|
-
|
|
128
|
+
} catch (error) {
|
|
129
|
+
throw error instanceof Error ? error : new Error('Failed to set virtual wall');
|
|
60
130
|
}
|
|
61
|
-
const command = encodeVirtualWall0x12({
|
|
62
|
-
version: commandVersion,
|
|
63
|
-
origin,
|
|
64
|
-
walls: data
|
|
65
|
-
});
|
|
66
|
-
devices.common.model.actions.command_trans.set(command);
|
|
67
|
-
return Promise.resolve();
|
|
68
131
|
}
|
|
69
132
|
};
|
|
70
133
|
};
|
package/lib/mqtt/useVoice.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { BaseResponse, VoiceLanguageEnum } from './type';
|
|
2
|
+
interface VoiceLanguageResponse extends BaseResponse {
|
|
3
|
+
reqType: VoiceLanguageEnum.query;
|
|
4
4
|
id: number;
|
|
5
5
|
schedule: number;
|
|
6
6
|
status: number;
|
|
7
|
-
success: boolean;
|
|
8
|
-
errCode: number;
|
|
9
|
-
taskId: string;
|
|
10
7
|
}
|
|
11
8
|
type TSetVoice = (message: {
|
|
12
9
|
id: number;
|
package/lib/mqtt/useVoice.js
CHANGED
|
@@ -7,6 +7,8 @@ import { useContext } from 'react';
|
|
|
7
7
|
import { SingletonContext } from './mqttProvider';
|
|
8
8
|
import { encodeVoice0x34 } from '@ray-js/robot-protocol';
|
|
9
9
|
|
|
10
|
+
// 语音语言响应类型
|
|
11
|
+
|
|
10
12
|
// 设置语音语言函数类型定义
|
|
11
13
|
|
|
12
14
|
// 请求当前使用的机器语音
|
|
@@ -19,62 +21,100 @@ import { encodeVoice0x34 } from '@ray-js/robot-protocol';
|
|
|
19
21
|
export const useVoice = devId => {
|
|
20
22
|
const {
|
|
21
23
|
useMqtt,
|
|
22
|
-
devices
|
|
24
|
+
devices,
|
|
25
|
+
commandVersion
|
|
23
26
|
} = useContext(SingletonContext);
|
|
24
27
|
/**
|
|
25
28
|
* 请求所有语音语言
|
|
26
|
-
* @returns Promise<
|
|
29
|
+
* @returns Promise<ty.GetVoiceListResponse> 响应结果
|
|
27
30
|
*/
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
33
|
* 请求当前使用的语音语言
|
|
31
|
-
* @returns Promise<
|
|
34
|
+
* @returns Promise<VoiceLanguageResponse> 响应结果
|
|
32
35
|
*/
|
|
33
36
|
|
|
34
37
|
/**
|
|
35
38
|
* 设置语音语言
|
|
36
39
|
* @param message 包含语音语言设置参数的对象
|
|
37
|
-
* @returns Promise<
|
|
40
|
+
* @returns Promise<VoiceLanguageResponse> 响应结果
|
|
38
41
|
*/
|
|
39
42
|
|
|
40
43
|
return {
|
|
41
44
|
requestAllVoices: async () => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
try {
|
|
46
|
+
const res = await getVoiceList({
|
|
47
|
+
devId: devId,
|
|
48
|
+
offset: 0,
|
|
49
|
+
limit: 100
|
|
50
|
+
});
|
|
51
|
+
return res;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
throw error instanceof Error ? error : new Error('Failed to request all voices');
|
|
54
|
+
}
|
|
48
55
|
},
|
|
49
56
|
requestVoiceInUse: () => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const {
|
|
55
|
-
taskId
|
|
56
|
-
} = params.message;
|
|
57
|
-
ty.device.sendMqttMessage(params);
|
|
58
|
-
return normalResolve(VoiceLanguageEnum.query, taskId);
|
|
59
|
-
},
|
|
60
|
-
setVoice: message => {
|
|
61
|
-
if (useMqtt) {
|
|
62
|
-
const sendData = _objectSpread(_objectSpread({}, message), {}, {
|
|
63
|
-
urlLen: message.url.length
|
|
64
|
-
});
|
|
57
|
+
if (!useMqtt) {
|
|
58
|
+
return Promise.reject(new Error('useMqtt is not used'));
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
65
61
|
const params = createSetCommonParams({
|
|
66
62
|
deviceId: devId,
|
|
67
|
-
reqType: VoiceLanguageEnum.
|
|
68
|
-
message: sendData
|
|
63
|
+
reqType: VoiceLanguageEnum.query
|
|
69
64
|
});
|
|
65
|
+
const {
|
|
66
|
+
taskId
|
|
67
|
+
} = params.message;
|
|
70
68
|
ty.device.sendMqttMessage(params);
|
|
71
|
-
return normalResolve(VoiceLanguageEnum.query,
|
|
69
|
+
return normalResolve(VoiceLanguageEnum.query, taskId);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
return Promise.reject(error instanceof Error ? error : new Error('Failed to request voice in use'));
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
setVoice: message => {
|
|
75
|
+
// 参数验证
|
|
76
|
+
if (!message || typeof message.id !== 'number') {
|
|
77
|
+
throw new Error('message.id is required and must be a number');
|
|
78
|
+
}
|
|
79
|
+
if (!message.url || typeof message.url !== 'string') {
|
|
80
|
+
throw new Error('message.url is required and must be a string');
|
|
81
|
+
}
|
|
82
|
+
if (!message.md5 || typeof message.md5 !== 'string') {
|
|
83
|
+
throw new Error('message.md5 is required and must be a string');
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
if (useMqtt) {
|
|
87
|
+
const sendData = _objectSpread(_objectSpread({}, message), {}, {
|
|
88
|
+
urlLen: message.url.length
|
|
89
|
+
});
|
|
90
|
+
const params = createSetCommonParams({
|
|
91
|
+
deviceId: devId,
|
|
92
|
+
reqType: VoiceLanguageEnum.set,
|
|
93
|
+
message: sendData
|
|
94
|
+
});
|
|
95
|
+
ty.device.sendMqttMessage(params);
|
|
96
|
+
const {
|
|
97
|
+
taskId
|
|
98
|
+
} = params.message;
|
|
99
|
+
return normalResolve(VoiceLanguageEnum.query, taskId);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 非 MQTT 模式:使用命令传输
|
|
103
|
+
const command = encodeVoice0x34(message);
|
|
104
|
+
devices.common.model.actions.voice_data.set(command);
|
|
105
|
+
return Promise.resolve({
|
|
106
|
+
success: true,
|
|
107
|
+
errCode: 0,
|
|
108
|
+
reqType: VoiceLanguageEnum.query,
|
|
109
|
+
version: commandVersion,
|
|
110
|
+
taskId: `${Date.now()}`,
|
|
111
|
+
id: message.id,
|
|
112
|
+
schedule: 0,
|
|
113
|
+
status: 0
|
|
114
|
+
});
|
|
115
|
+
} catch (error) {
|
|
116
|
+
throw error instanceof Error ? error : new Error('Failed to set voice');
|
|
72
117
|
}
|
|
73
|
-
const command = encodeVoice0x34(message);
|
|
74
|
-
devices.common.model.actions.voice_data.set(command);
|
|
75
|
-
return Promise.resolve({
|
|
76
|
-
success: true
|
|
77
|
-
});
|
|
78
118
|
}
|
|
79
119
|
};
|
|
80
120
|
};
|
package/lib/mqtt/useWifiMap.js
CHANGED
|
@@ -8,30 +8,46 @@ export const useWifiMap = devId => {
|
|
|
8
8
|
useMqtt
|
|
9
9
|
} = useContext(SingletonContext);
|
|
10
10
|
|
|
11
|
-
//
|
|
11
|
+
// 请求 WiFi 地图状态
|
|
12
12
|
|
|
13
|
-
//
|
|
13
|
+
// 设置 WiFi 地图
|
|
14
14
|
|
|
15
15
|
return {
|
|
16
16
|
requestWifiMap: () => {
|
|
17
|
-
if (!useMqtt)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
if (!useMqtt) {
|
|
18
|
+
return Promise.reject(new Error('useMqtt is not used'));
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const params = createSetCommonParams({
|
|
22
|
+
deviceId: devId,
|
|
23
|
+
reqType: WifiMapEnum.query
|
|
24
|
+
});
|
|
25
|
+
ty.device.sendMqttMessage(params);
|
|
26
|
+
const {
|
|
27
|
+
taskId
|
|
28
|
+
} = params.message;
|
|
29
|
+
return normalResolve(WifiMapEnum.query, taskId);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
return Promise.reject(error instanceof Error ? error : new Error('Failed to request WiFi map'));
|
|
32
|
+
}
|
|
24
33
|
},
|
|
25
34
|
setWifiMap: () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
try {
|
|
36
|
+
const params = createSetCommonParams({
|
|
37
|
+
deviceId: devId,
|
|
38
|
+
reqType: WifiMapEnum.set,
|
|
39
|
+
message: {
|
|
40
|
+
taskId: String(Date.now())
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
ty.device.sendMqttMessage(params);
|
|
44
|
+
const {
|
|
45
|
+
taskId
|
|
46
|
+
} = params.message;
|
|
47
|
+
return normalResolve(WifiMapEnum.rst, taskId);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw error instanceof Error ? error : new Error('Failed to set WiFi map');
|
|
50
|
+
}
|
|
35
51
|
}
|
|
36
52
|
};
|
|
37
53
|
};
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { RoomPreference } from './type';
|
|
1
|
+
import { BaseResponse, ZoneCleanEnum, RoomPreference } from './type';
|
|
2
2
|
import { Point, Zone } from '@ray-js/robot-protocol';
|
|
3
|
-
|
|
4
|
-
reqType:
|
|
5
|
-
version: string;
|
|
6
|
-
success: boolean;
|
|
7
|
-
errCode: number;
|
|
8
|
-
taskId: string;
|
|
3
|
+
interface ZoneCleanResponse extends BaseResponse {
|
|
4
|
+
reqType: ZoneCleanEnum.query;
|
|
9
5
|
polygons: string[];
|
|
6
|
+
names?: string[];
|
|
10
7
|
suctions?: string[];
|
|
11
8
|
cisterns?: string[];
|
|
12
9
|
cleanCounts?: number[];
|
|
13
10
|
yMops?: number[];
|
|
14
11
|
sweepMopModes?: string[];
|
|
15
|
-
}
|
|
16
|
-
|
|
12
|
+
}
|
|
13
|
+
interface SetZoneCleanParams extends Partial<Pick<RoomPreference, 'suctions' | 'cisterns' | 'cleanCounts' | 'yMops' | 'sweepMopModes'>> {
|
|
17
14
|
zones: Zone[];
|
|
18
15
|
origin: Point;
|
|
19
|
-
}
|
|
16
|
+
}
|
|
17
|
+
type TRequestZoneClean = () => Promise<ZoneCleanResponse>;
|
|
18
|
+
type TSetZoneClean = (params: SetZoneCleanParams) => Promise<ZoneCleanResponse>;
|
|
20
19
|
/**
|
|
21
|
-
*
|
|
22
|
-
* @
|
|
20
|
+
* 自定义 Hook,用于划区清扫
|
|
21
|
+
* @param devId 设备ID
|
|
22
|
+
* @returns 包含 requestZoneClean 和 setZoneClean 函数的对象
|
|
23
23
|
*/
|
|
24
24
|
export declare const useZoneClean: (devId: string) => {
|
|
25
|
-
requestZoneClean:
|
|
25
|
+
requestZoneClean: TRequestZoneClean;
|
|
26
26
|
setZoneClean: TSetZoneClean;
|
|
27
27
|
};
|
|
28
28
|
export {};
|