@ray-js/robot-data-stream 0.0.14 → 0.0.15-beta.10
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/sweeperP2p.js +1 -1
- package/lib/mqtt/createCommonOptions.d.ts +4 -2
- package/lib/mqtt/createCommonOptions.js +10 -5
- package/lib/mqtt/hooks/useStructuredMessage.d.ts +17 -0
- package/lib/mqtt/hooks/useStructuredMessage.js +206 -0
- package/lib/mqtt/mqttProvider.d.ts +28 -1
- package/lib/mqtt/mqttProvider.js +72 -9
- package/lib/mqtt/promise.d.ts +57 -4
- package/lib/mqtt/promise.js +115 -36
- package/lib/mqtt/type/fun.d.ts +233 -0
- package/lib/mqtt/type/fun.js +145 -0
- package/lib/mqtt/type/index.d.ts +0 -7
- package/lib/mqtt/type/index.js +0 -1
- package/lib/mqtt/type/protocols/base.d.ts +21 -0
- package/lib/mqtt/type/protocols/base.js +32 -0
- package/lib/mqtt/type/protocols/carpetCleanProtocol.d.ts +14 -0
- package/lib/mqtt/type/protocols/carpetCleanProtocol.js +14 -0
- package/lib/mqtt/type/protocols/carpetProtocol.d.ts +102 -0
- package/lib/mqtt/type/protocols/carpetProtocol.js +202 -0
- package/lib/mqtt/type/protocols/devInfoProtocol.d.ts +11 -0
- package/lib/mqtt/type/protocols/devInfoProtocol.js +10 -0
- package/lib/mqtt/type/protocols/deviceModelProtocol.d.ts +31 -0
- package/lib/mqtt/type/protocols/deviceModelProtocol.js +32 -0
- package/lib/mqtt/type/protocols/furnitureModelProtocol.d.ts +27 -0
- package/lib/mqtt/type/protocols/furnitureModelProtocol.js +27 -0
- package/lib/mqtt/type/protocols/historyMapProtocol.d.ts +39 -0
- package/lib/mqtt/type/protocols/historyMapProtocol.js +37 -0
- package/lib/mqtt/type/protocols/index.d.ts +20 -0
- package/lib/mqtt/type/protocols/index.js +20 -0
- package/lib/mqtt/type/protocols/partDivisionProtocol.d.ts +20 -0
- package/lib/mqtt/type/protocols/partDivisionProtocol.js +12 -0
- package/lib/mqtt/type/protocols/partMergeProtocol.d.ts +13 -0
- package/lib/mqtt/type/protocols/partMergeProtocol.js +12 -0
- package/lib/mqtt/type/protocols/passwordProtocol.d.ts +24 -0
- package/lib/mqtt/type/protocols/passwordProtocol.js +25 -0
- package/lib/mqtt/type/protocols/quietHoursProtocol.d.ts +29 -0
- package/lib/mqtt/type/protocols/quietHoursProtocol.js +35 -0
- package/lib/mqtt/type/protocols/resetMapProtocol.d.ts +4 -0
- package/lib/mqtt/type/protocols/resetMapProtocol.js +1 -0
- package/lib/mqtt/type/protocols/roomPropertyProtocol.d.ts +42 -0
- package/lib/mqtt/type/protocols/roomPropertyProtocol.js +113 -0
- package/lib/mqtt/type/protocols/scheduleProtocol.d.ts +62 -0
- package/lib/mqtt/type/protocols/scheduleProtocol.js +100 -0
- package/lib/mqtt/type/protocols/selectRoomCleanProtocol.d.ts +27 -0
- package/lib/mqtt/type/protocols/selectRoomCleanProtocol.js +40 -0
- package/lib/mqtt/type/protocols/spotCleanProtocol.d.ts +38 -0
- package/lib/mqtt/type/protocols/spotCleanProtocol.js +72 -0
- package/lib/mqtt/type/protocols/virtualAreaProtocol.d.ts +32 -0
- package/lib/mqtt/type/protocols/virtualAreaProtocol.js +36 -0
- package/lib/mqtt/type/protocols/virtualWallProtocol.d.ts +27 -0
- package/lib/mqtt/type/protocols/virtualWallProtocol.js +25 -0
- package/lib/mqtt/type/protocols/voiceProtocol.d.ts +21 -0
- package/lib/mqtt/type/protocols/voiceProtocol.js +23 -0
- package/lib/mqtt/type/protocols/wifiMapProtocol.d.ts +16 -0
- package/lib/mqtt/type/protocols/wifiMapProtocol.js +14 -0
- package/lib/mqtt/type/protocols/zoneCleanProtocol.d.ts +47 -0
- package/lib/mqtt/type/protocols/zoneCleanProtocol.js +49 -0
- package/lib/mqtt/useCarpet.d.ts +7 -67
- package/lib/mqtt/useCarpet.js +101 -181
- package/lib/mqtt/useCarpetClean.d.ts +2 -11
- package/lib/mqtt/useCarpetClean.js +26 -50
- package/lib/mqtt/useDevInfo.d.ts +8 -6
- package/lib/mqtt/useDevInfo.js +44 -36
- package/lib/mqtt/useDeviceModel.d.ts +6 -19
- package/lib/mqtt/useDeviceModel.js +31 -42
- package/lib/mqtt/useFurnitureModel.d.ts +6 -18
- package/lib/mqtt/useFurnitureModel.js +31 -43
- package/lib/mqtt/useHistoryMap.d.ts +2 -18
- package/lib/mqtt/useHistoryMap.js +102 -119
- package/lib/mqtt/usePartDivision.d.ts +2 -9
- package/lib/mqtt/usePartDivision.js +48 -57
- package/lib/mqtt/usePartMerge.d.ts +2 -8
- package/lib/mqtt/usePartMerge.js +34 -49
- package/lib/mqtt/usePassword.d.ts +6 -13
- package/lib/mqtt/usePassword.js +84 -74
- package/lib/mqtt/useQuiteHours.d.ts +4 -37
- package/lib/mqtt/useQuiteHours.js +66 -100
- package/lib/mqtt/useResetMap.d.ts +2 -8
- package/lib/mqtt/useResetMap.js +27 -34
- package/lib/mqtt/useRoomProperty.d.ts +8 -9
- package/lib/mqtt/useRoomProperty.js +67 -65
- package/lib/mqtt/useSchedule.d.ts +3 -23
- package/lib/mqtt/useSchedule.js +72 -101
- package/lib/mqtt/useSelectRoomClean.d.ts +3 -24
- package/lib/mqtt/useSelectRoomClean.js +107 -133
- package/lib/mqtt/useSpotClean.d.ts +5 -15
- package/lib/mqtt/useSpotClean.js +68 -121
- package/lib/mqtt/useVirtualArea.d.ts +6 -17
- package/lib/mqtt/useVirtualArea.js +109 -119
- package/lib/mqtt/useVirtualWall.d.ts +2 -18
- package/lib/mqtt/useVirtualWall.js +69 -90
- package/lib/mqtt/useVoice.d.ts +2 -16
- package/lib/mqtt/useVoice.js +48 -68
- package/lib/mqtt/useWifiMap.d.ts +6 -5
- package/lib/mqtt/useWifiMap.js +43 -42
- package/lib/mqtt/useZoneClean.d.ts +2 -21
- package/lib/mqtt/useZoneClean.js +125 -137
- package/lib/myLib/zod/mini/index.d.cts +1 -0
- package/lib/myLib/zod/mini/index.d.ts +1 -0
- package/lib/myLib/zod/mini/index.js +1 -0
- package/lib/myLib/zod/mini/package.json +6 -0
- package/lib/myLib/zod/src/mini/index.d.ts +1 -0
- package/lib/myLib/zod/src/mini/index.js +1 -0
- package/lib/myLib/zod/src/v4/core/api.d.ts +306 -0
- package/lib/myLib/zod/src/v4/core/api.js +1256 -0
- package/lib/myLib/zod/src/v4/core/checks.d.ts +278 -0
- package/lib/myLib/zod/src/v4/core/checks.js +816 -0
- package/lib/myLib/zod/src/v4/core/config.d.ts +9 -0
- package/lib/myLib/zod/src/v4/core/config.js +5 -0
- package/lib/myLib/zod/src/v4/core/core.d.ts +70 -0
- package/lib/myLib/zod/src/v4/core/core.js +95 -0
- package/lib/myLib/zod/src/v4/core/doc.d.ts +14 -0
- package/lib/myLib/zod/src/v4/core/doc.js +42 -0
- package/lib/myLib/zod/src/v4/core/errors.d.ts +220 -0
- package/lib/myLib/zod/src/v4/core/errors.js +232 -0
- package/lib/myLib/zod/src/v4/core/index.d.ts +15 -0
- package/lib/myLib/zod/src/v4/core/index.js +15 -0
- package/lib/myLib/zod/src/v4/core/json-schema-generator.d.ts +65 -0
- package/lib/myLib/zod/src/v4/core/json-schema-generator.js +120 -0
- package/lib/myLib/zod/src/v4/core/json-schema-processors.d.ts +49 -0
- package/lib/myLib/zod/src/v4/core/json-schema-processors.js +593 -0
- package/lib/myLib/zod/src/v4/core/json-schema.d.ts +88 -0
- package/lib/myLib/zod/src/v4/core/json-schema.js +1 -0
- package/lib/myLib/zod/src/v4/core/parse.d.ts +49 -0
- package/lib/myLib/zod/src/v4/core/parse.js +147 -0
- package/lib/myLib/zod/src/v4/core/regexes.d.ts +78 -0
- package/lib/myLib/zod/src/v4/core/regexes.js +146 -0
- package/lib/myLib/zod/src/v4/core/registries.d.ts +35 -0
- package/lib/myLib/zod/src/v4/core/registries.js +51 -0
- package/lib/myLib/zod/src/v4/core/schemas.d.ts +1136 -0
- package/lib/myLib/zod/src/v4/core/schemas.js +2745 -0
- package/lib/myLib/zod/src/v4/core/standard-schema.d.ts +126 -0
- package/lib/myLib/zod/src/v4/core/standard-schema.js +1 -0
- package/lib/myLib/zod/src/v4/core/to-json-schema.d.ts +114 -0
- package/lib/myLib/zod/src/v4/core/to-json-schema.js +488 -0
- package/lib/myLib/zod/src/v4/core/util.d.ts +199 -0
- package/lib/myLib/zod/src/v4/core/util.js +656 -0
- package/lib/myLib/zod/src/v4/core/versions.d.ts +5 -0
- package/lib/myLib/zod/src/v4/core/versions.js +5 -0
- package/lib/myLib/zod/src/v4/core/zsf.d.ts +91 -0
- package/lib/myLib/zod/src/v4/core/zsf.js +1 -0
- package/lib/myLib/zod/src/v4/mini/checks.d.ts +1 -0
- package/lib/myLib/zod/src/v4/mini/checks.js +1 -0
- package/lib/myLib/zod/src/v4/mini/coerce.d.ts +7 -0
- package/lib/myLib/zod/src/v4/mini/coerce.js +27 -0
- package/lib/myLib/zod/src/v4/mini/external.d.ts +11 -0
- package/lib/myLib/zod/src/v4/mini/external.js +16 -0
- package/lib/myLib/zod/src/v4/mini/index.d.ts +530 -0
- package/lib/myLib/zod/src/v4/mini/index.js +30 -0
- package/lib/myLib/zod/src/v4/mini/iso.d.ts +22 -0
- package/lib/myLib/zod/src/v4/mini/iso.js +46 -0
- package/lib/myLib/zod/src/v4/mini/parse.d.ts +1 -0
- package/lib/myLib/zod/src/v4/mini/parse.js +1 -0
- package/lib/myLib/zod/src/v4/mini/schemas.js +1244 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +2 -1
- package/package.json +5 -3
|
@@ -2,27 +2,32 @@ import "core-js/modules/esnext.iterator.constructor.js";
|
|
|
2
2
|
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
3
|
import "core-js/modules/esnext.iterator.map.js";
|
|
4
4
|
// 添加禁区
|
|
5
|
-
import { useContext } from 'react';
|
|
6
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
7
|
-
import { normalResolve } from './promise';
|
|
8
|
-
import { VirtualAreaEnum } from './type';
|
|
9
|
-
import { SingletonContext } from './mqttProvider';
|
|
10
5
|
import { encodeVirtualArea0x1a, requestVirtualArea0x1b } from '@ray-js/robot-protocol';
|
|
6
|
+
import { useContext } from 'react';
|
|
11
7
|
import { pointsToString } from '../utils';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
import { handleMqttError, useStructuredMessage } from './hooks/useStructuredMessage';
|
|
9
|
+
import { SingletonContext } from './mqttProvider';
|
|
10
|
+
import { VirtualAreaEnum } from './type';
|
|
11
|
+
import { validator } from './type/fun';
|
|
15
12
|
// 禁区
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
/**
|
|
15
|
+
* 自定义 Hook,用于虚拟区域(禁区)管理
|
|
16
|
+
* @returns 包含 requestVirtualArea 和 setVirtualArea 函数的对象
|
|
17
|
+
*/
|
|
18
|
+
export const useVirtualArea = () => {
|
|
18
19
|
const {
|
|
19
20
|
useMqtt,
|
|
20
21
|
commandVersion,
|
|
21
22
|
devices
|
|
22
23
|
} = useContext(SingletonContext);
|
|
24
|
+
const {
|
|
25
|
+
sendStructuredMessage
|
|
26
|
+
} = useStructuredMessage();
|
|
23
27
|
|
|
24
28
|
/**
|
|
25
29
|
* 请求虚拟区域数据
|
|
30
|
+
* @param data 可选参数(目前为空对象)
|
|
26
31
|
* @returns Promise<VirtualAreaResponse> 响应结果
|
|
27
32
|
*/
|
|
28
33
|
|
|
@@ -36,125 +41,110 @@ export const useVirtualArea = devId => {
|
|
|
36
41
|
|
|
37
42
|
return {
|
|
38
43
|
requestVirtualArea: () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
ty.device.sendMqttMessage(params);
|
|
46
|
-
const {
|
|
47
|
-
taskId
|
|
48
|
-
} = params.message;
|
|
49
|
-
return normalResolve(VirtualAreaEnum.query, taskId);
|
|
50
|
-
}
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
try {
|
|
46
|
+
if (useMqtt) {
|
|
47
|
+
sendStructuredMessage(VirtualAreaEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request virtual area')));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
// 非 MQTT 模式:使用命令传输
|
|
52
|
+
devices.common.model.actions.command_trans.set(requestVirtualArea0x1b({
|
|
53
|
+
version: commandVersion
|
|
54
|
+
}));
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
} catch (error) {
|
|
71
|
-
return Promise.reject(error instanceof Error ? error : new Error('Failed to request virtual area'));
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
setVirtualArea: _ref => {
|
|
75
|
-
let {
|
|
76
|
-
data,
|
|
77
|
-
origin
|
|
78
|
-
} = _ref;
|
|
79
|
-
// 参数验证
|
|
80
|
-
if (!Array.isArray(data)) {
|
|
81
|
-
throw new Error('data is required and must be a non-empty array');
|
|
82
|
-
}
|
|
83
|
-
if (!origin || typeof origin.x !== 'number' || typeof origin.y !== 'number') {
|
|
84
|
-
throw new Error('origin is required and must be a valid Point object with x and y properties');
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
if (useMqtt) {
|
|
88
|
-
const names = [];
|
|
89
|
-
const modes = [];
|
|
90
|
-
const polygons = [];
|
|
91
|
-
data.forEach(_ref2 => {
|
|
92
|
-
let {
|
|
93
|
-
points,
|
|
94
|
-
name,
|
|
95
|
-
mode
|
|
96
|
-
} = _ref2;
|
|
97
|
-
names.push(name);
|
|
98
|
-
modes.push(mode);
|
|
99
|
-
polygons.push(pointsToString(points, origin));
|
|
56
|
+
// 非 MQTT 模式下无法立即获取响应数据,返回默认响应
|
|
57
|
+
resolve({
|
|
58
|
+
success: true,
|
|
59
|
+
errCode: 0,
|
|
60
|
+
reqType: VirtualAreaEnum.query,
|
|
61
|
+
version: commandVersion,
|
|
62
|
+
taskId: `${Date.now()}`,
|
|
63
|
+
num: 0,
|
|
64
|
+
modes: [],
|
|
65
|
+
polygons: [],
|
|
66
|
+
names: [],
|
|
67
|
+
mapId: 0
|
|
100
68
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
69
|
+
} catch (error) {
|
|
70
|
+
reject(handleMqttError(error, 'Failed to request virtual area'));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
setVirtualArea: message => {
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
try {
|
|
77
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
78
|
+
const validatedData = validator.validate('set_virtual_area', message);
|
|
79
|
+
const {
|
|
80
|
+
data,
|
|
81
|
+
origin
|
|
82
|
+
} = validatedData;
|
|
83
|
+
if (useMqtt) {
|
|
84
|
+
const names = [];
|
|
85
|
+
const modes = [];
|
|
86
|
+
const polygons = [];
|
|
87
|
+
data.forEach(_ref => {
|
|
88
|
+
let {
|
|
89
|
+
points,
|
|
90
|
+
name,
|
|
91
|
+
mode
|
|
92
|
+
} = _ref;
|
|
93
|
+
names.push(name);
|
|
94
|
+
modes.push(mode);
|
|
95
|
+
polygons.push(pointsToString(points, origin));
|
|
96
|
+
});
|
|
97
|
+
sendStructuredMessage(VirtualAreaEnum.set, {
|
|
105
98
|
polygons,
|
|
106
99
|
num: data.length,
|
|
107
100
|
modes: modes,
|
|
108
101
|
names: names
|
|
109
|
-
}
|
|
102
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to set virtual area')), VirtualAreaEnum.query // 响应类型是 query,不是 set
|
|
103
|
+
);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 非 MQTT 模式:使用命令传输
|
|
108
|
+
const command = encodeVirtualArea0x1a({
|
|
109
|
+
version: commandVersion,
|
|
110
|
+
origin,
|
|
111
|
+
virtualAreas: data
|
|
110
112
|
});
|
|
111
|
-
|
|
112
|
-
const {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
devices.common.model.actions.command_trans.set(command);
|
|
114
|
+
const names = data.map(_ref2 => {
|
|
115
|
+
let {
|
|
116
|
+
name
|
|
117
|
+
} = _ref2;
|
|
118
|
+
return name;
|
|
119
|
+
});
|
|
120
|
+
const modes = data.map(_ref3 => {
|
|
121
|
+
let {
|
|
122
|
+
mode
|
|
123
|
+
} = _ref3;
|
|
124
|
+
return mode;
|
|
125
|
+
});
|
|
126
|
+
const polygons = data.map(_ref4 => {
|
|
127
|
+
let {
|
|
128
|
+
points
|
|
129
|
+
} = _ref4;
|
|
130
|
+
return pointsToString(points, origin);
|
|
131
|
+
});
|
|
132
|
+
resolve({
|
|
133
|
+
success: true,
|
|
134
|
+
errCode: 0,
|
|
135
|
+
reqType: VirtualAreaEnum.query,
|
|
136
|
+
version: commandVersion,
|
|
137
|
+
taskId: `${Date.now()}`,
|
|
138
|
+
num: data.length,
|
|
139
|
+
modes,
|
|
140
|
+
polygons,
|
|
141
|
+
names,
|
|
142
|
+
mapId: 0
|
|
143
|
+
});
|
|
144
|
+
} catch (error) {
|
|
145
|
+
reject(handleMqttError(error, 'Failed to set virtual area'));
|
|
116
146
|
}
|
|
117
|
-
|
|
118
|
-
// 非 MQTT 模式:使用命令传输
|
|
119
|
-
const command = encodeVirtualArea0x1a({
|
|
120
|
-
version: commandVersion,
|
|
121
|
-
origin,
|
|
122
|
-
virtualAreas: data
|
|
123
|
-
});
|
|
124
|
-
devices.common.model.actions.command_trans.set(command);
|
|
125
|
-
const names = data.map(_ref3 => {
|
|
126
|
-
let {
|
|
127
|
-
name
|
|
128
|
-
} = _ref3;
|
|
129
|
-
return name;
|
|
130
|
-
});
|
|
131
|
-
const modes = data.map(_ref4 => {
|
|
132
|
-
let {
|
|
133
|
-
mode
|
|
134
|
-
} = _ref4;
|
|
135
|
-
return mode;
|
|
136
|
-
});
|
|
137
|
-
const polygons = data.map(_ref5 => {
|
|
138
|
-
let {
|
|
139
|
-
points
|
|
140
|
-
} = _ref5;
|
|
141
|
-
return pointsToString(points, origin);
|
|
142
|
-
});
|
|
143
|
-
return Promise.resolve({
|
|
144
|
-
success: true,
|
|
145
|
-
errCode: 0,
|
|
146
|
-
reqType: VirtualAreaEnum.query,
|
|
147
|
-
version: commandVersion,
|
|
148
|
-
taskId: `${Date.now()}`,
|
|
149
|
-
num: data.length,
|
|
150
|
-
modes,
|
|
151
|
-
polygons,
|
|
152
|
-
names,
|
|
153
|
-
mapId: 0
|
|
154
|
-
});
|
|
155
|
-
} catch (error) {
|
|
156
|
-
throw error instanceof Error ? error : new Error('Failed to set virtual area');
|
|
157
|
-
}
|
|
147
|
+
});
|
|
158
148
|
}
|
|
159
149
|
};
|
|
160
150
|
};
|
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Point } from '@ray-js/robot-protocol';
|
|
3
|
-
interface VirtualWallResponse extends BaseResponse {
|
|
4
|
-
reqType: VirtualWallEnum.query;
|
|
5
|
-
modes: number[];
|
|
6
|
-
num: number;
|
|
7
|
-
mapId: number;
|
|
8
|
-
points: string[];
|
|
9
|
-
}
|
|
10
|
-
interface SetVirtualWallParams {
|
|
11
|
-
data: Point[][];
|
|
12
|
-
origin: Point;
|
|
13
|
-
}
|
|
14
|
-
type TRequestVirtualWall = () => Promise<VirtualWallResponse>;
|
|
15
|
-
type TSetVirtualWall = (params: SetVirtualWallParams) => Promise<VirtualWallResponse>;
|
|
1
|
+
import { type TRequestVirtualWall, type TSetVirtualWall } from './type/protocols';
|
|
16
2
|
/**
|
|
17
3
|
* 自定义 Hook,用于虚拟墙管理
|
|
18
|
-
* @param devId 设备ID
|
|
19
4
|
* @returns 包含 requestVirtualWall 和 setVirtualWall 函数的对象
|
|
20
5
|
*/
|
|
21
|
-
export declare const useVirtualWall: (
|
|
6
|
+
export declare const useVirtualWall: () => {
|
|
22
7
|
requestVirtualWall: TRequestVirtualWall;
|
|
23
8
|
setVirtualWall: TSetVirtualWall;
|
|
24
9
|
};
|
|
25
|
-
export {};
|
|
@@ -1,35 +1,29 @@
|
|
|
1
1
|
import "core-js/modules/esnext.iterator.map.js";
|
|
2
2
|
// 虚拟墙数据
|
|
3
3
|
import { useContext } from 'react';
|
|
4
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
5
|
-
import { normalResolve } from './promise';
|
|
6
4
|
import { VirtualWallEnum } from './type';
|
|
7
5
|
import { SingletonContext } from './mqttProvider';
|
|
8
6
|
import { encodeVirtualWall0x12, requestVirtualWall0x13 } from '@ray-js/robot-protocol';
|
|
9
7
|
import { pointsToString } from '../utils';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// 设置虚拟墙参数类型
|
|
14
|
-
|
|
15
|
-
// 请求虚拟墙函数类型定义
|
|
16
|
-
|
|
17
|
-
// 设置虚拟墙函数类型定义
|
|
18
|
-
|
|
8
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
9
|
+
import { validator } from './type/fun';
|
|
19
10
|
/**
|
|
20
11
|
* 自定义 Hook,用于虚拟墙管理
|
|
21
|
-
* @param devId 设备ID
|
|
22
12
|
* @returns 包含 requestVirtualWall 和 setVirtualWall 函数的对象
|
|
23
13
|
*/
|
|
24
|
-
export const useVirtualWall =
|
|
14
|
+
export const useVirtualWall = () => {
|
|
25
15
|
const {
|
|
26
16
|
useMqtt,
|
|
27
17
|
commandVersion,
|
|
28
18
|
devices
|
|
29
19
|
} = useContext(SingletonContext);
|
|
20
|
+
const {
|
|
21
|
+
sendStructuredMessage
|
|
22
|
+
} = useStructuredMessage();
|
|
30
23
|
|
|
31
24
|
/**
|
|
32
25
|
* 请求虚拟墙数据
|
|
26
|
+
* @param data 可选参数(目前为空对象)
|
|
33
27
|
* @returns Promise<VirtualWallResponse> 响应结果
|
|
34
28
|
*/
|
|
35
29
|
|
|
@@ -43,91 +37,76 @@ export const useVirtualWall = devId => {
|
|
|
43
37
|
|
|
44
38
|
return {
|
|
45
39
|
requestVirtualWall: () => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
ty.device.sendMqttMessage(params);
|
|
53
|
-
const {
|
|
54
|
-
taskId
|
|
55
|
-
} = params.message;
|
|
56
|
-
return normalResolve(VirtualWallEnum.query, taskId);
|
|
57
|
-
}
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
try {
|
|
42
|
+
if (useMqtt) {
|
|
43
|
+
sendStructuredMessage(VirtualWallEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request virtual wall')));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
58
46
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
47
|
+
// 非 MQTT 模式:使用命令传输
|
|
48
|
+
devices.common.model.actions.command_trans.set(requestVirtualWall0x13({
|
|
49
|
+
version: commandVersion
|
|
50
|
+
}));
|
|
63
51
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
52
|
+
// 非 MQTT 模式下无法立即获取响应数据,返回默认响应
|
|
53
|
+
resolve({
|
|
54
|
+
success: true,
|
|
55
|
+
errCode: 0,
|
|
56
|
+
reqType: VirtualWallEnum.query,
|
|
57
|
+
version: commandVersion,
|
|
58
|
+
taskId: `${Date.now()}`,
|
|
59
|
+
num: 0,
|
|
60
|
+
modes: [],
|
|
61
|
+
points: [],
|
|
62
|
+
mapId: 0
|
|
63
|
+
});
|
|
64
|
+
} catch (error) {
|
|
65
|
+
reject(handleMqttError(error, 'Failed to request virtual wall'));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
79
68
|
},
|
|
80
|
-
setVirtualWall:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
if (useMqtt) {
|
|
94
|
-
const params = createSetCommonParams({
|
|
95
|
-
deviceId: devId,
|
|
96
|
-
reqType: VirtualWallEnum.set,
|
|
97
|
-
message: {
|
|
69
|
+
setVirtualWall: params => {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
try {
|
|
72
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
73
|
+
const validatedData = validator.validate('set_virtual_wall', params);
|
|
74
|
+
const {
|
|
75
|
+
data,
|
|
76
|
+
origin
|
|
77
|
+
} = validatedData;
|
|
78
|
+
if (useMqtt) {
|
|
79
|
+
sendStructuredMessage(VirtualWallEnum.set, {
|
|
98
80
|
points: data.map(points => pointsToString(points, origin)),
|
|
99
81
|
num: data.length,
|
|
100
82
|
mode: new Array(data.length).fill('0')
|
|
101
|
-
}
|
|
83
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to set virtual wall')), VirtualWallEnum.query // 响应类型是 query,不是 set
|
|
84
|
+
);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 非 MQTT 模式:使用命令传输
|
|
89
|
+
const command = encodeVirtualWall0x12({
|
|
90
|
+
version: commandVersion,
|
|
91
|
+
origin,
|
|
92
|
+
walls: data
|
|
102
93
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
94
|
+
devices.common.model.actions.command_trans.set(command);
|
|
95
|
+
resolve({
|
|
96
|
+
success: true,
|
|
97
|
+
errCode: 0,
|
|
98
|
+
reqType: VirtualWallEnum.query,
|
|
99
|
+
version: commandVersion,
|
|
100
|
+
taskId: `${Date.now()}`,
|
|
101
|
+
num: data.length,
|
|
102
|
+
modes: new Array(data.length).fill(0),
|
|
103
|
+
points: data.map(points => pointsToString(points, origin)),
|
|
104
|
+
mapId: 0
|
|
105
|
+
});
|
|
106
|
+
} catch (error) {
|
|
107
|
+
reject(handleMqttError(error, 'Failed to set virtual wall'));
|
|
108
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
|
|
127
|
-
});
|
|
128
|
-
} catch (error) {
|
|
129
|
-
throw error instanceof Error ? error : new Error('Failed to set virtual wall');
|
|
130
|
-
}
|
|
109
|
+
});
|
|
131
110
|
}
|
|
132
111
|
};
|
|
133
112
|
};
|
package/lib/mqtt/useVoice.d.ts
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
interface VoiceLanguageResponse extends BaseResponse {
|
|
3
|
-
reqType: VoiceLanguageEnum.query;
|
|
4
|
-
id: number;
|
|
5
|
-
schedule: number;
|
|
6
|
-
status: number;
|
|
7
|
-
}
|
|
8
|
-
type TSetVoice = (message: {
|
|
9
|
-
id: number;
|
|
10
|
-
url: string;
|
|
11
|
-
md5: string;
|
|
12
|
-
}) => Promise<VoiceLanguageResponse>;
|
|
13
|
-
type TRequestVoiceInUse = () => Promise<VoiceLanguageResponse>;
|
|
1
|
+
import { type TSetVoice, type TRequestVoiceInUse } from './type/protocols';
|
|
14
2
|
/**
|
|
15
3
|
* 自定义 Hook,用于语音语言设置
|
|
16
|
-
* @param devId 设备ID
|
|
17
4
|
* @returns 包含 requestAllVoices, requestVoiceInUse 和 setVoice 函数的对象
|
|
18
5
|
*/
|
|
19
|
-
export declare const useVoice: (
|
|
6
|
+
export declare const useVoice: () => {
|
|
20
7
|
requestAllVoices: () => Promise<ty.GetVoiceListResponse>;
|
|
21
8
|
requestVoiceInUse: TRequestVoiceInUse;
|
|
22
9
|
setVoice: TSetVoice;
|
|
23
10
|
};
|
|
24
|
-
export {};
|
package/lib/mqtt/useVoice.js
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import { getVoiceList } from '@ray-js/ray';
|
|
3
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
4
|
-
import { normalResolve } from './promise';
|
|
5
3
|
import { VoiceLanguageEnum } from './type';
|
|
6
4
|
import { useContext } from 'react';
|
|
7
5
|
import { SingletonContext } from './mqttProvider';
|
|
8
6
|
import { encodeVoice0x34 } from '@ray-js/robot-protocol';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// 设置语音语言函数类型定义
|
|
13
|
-
|
|
14
|
-
// 请求当前使用的机器语音
|
|
15
|
-
|
|
7
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
8
|
+
import { validator } from './type/fun';
|
|
16
9
|
/**
|
|
17
10
|
* 自定义 Hook,用于语音语言设置
|
|
18
|
-
* @param devId 设备ID
|
|
19
11
|
* @returns 包含 requestAllVoices, requestVoiceInUse 和 setVoice 函数的对象
|
|
20
12
|
*/
|
|
21
|
-
export const useVoice =
|
|
13
|
+
export const useVoice = () => {
|
|
22
14
|
const {
|
|
23
15
|
useMqtt,
|
|
24
16
|
devices,
|
|
25
17
|
commandVersion
|
|
26
18
|
} = useContext(SingletonContext);
|
|
19
|
+
const {
|
|
20
|
+
sendStructuredMessage
|
|
21
|
+
} = useStructuredMessage();
|
|
22
|
+
const {
|
|
23
|
+
devId
|
|
24
|
+
} = devices.common.getDevInfo();
|
|
27
25
|
/**
|
|
28
26
|
* 请求所有语音语言
|
|
29
27
|
* @returns Promise<ty.GetVoiceListResponse> 响应结果
|
|
@@ -31,6 +29,7 @@ export const useVoice = devId => {
|
|
|
31
29
|
|
|
32
30
|
/**
|
|
33
31
|
* 请求当前使用的语音语言
|
|
32
|
+
* @param data 可选参数(目前为空对象)
|
|
34
33
|
* @returns Promise<VoiceLanguageResponse> 响应结果
|
|
35
34
|
*/
|
|
36
35
|
|
|
@@ -54,67 +53,48 @@ export const useVoice = devId => {
|
|
|
54
53
|
}
|
|
55
54
|
},
|
|
56
55
|
requestVoiceInUse: () => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
ty.device.sendMqttMessage(params);
|
|
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
|
-
}
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
try {
|
|
58
|
+
if (!useMqtt) {
|
|
59
|
+
reject(new Error('useMqtt is not used'));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
sendStructuredMessage(VoiceLanguageEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request voice in use')));
|
|
63
|
+
} catch (error) {
|
|
64
|
+
reject(handleMqttError(error, 'Failed to request voice in use'));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
73
67
|
},
|
|
74
68
|
setVoice: message => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
try {
|
|
71
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
72
|
+
const validatedData = validator.validate('set_voice', message);
|
|
73
|
+
if (useMqtt) {
|
|
74
|
+
const sendData = _objectSpread(_objectSpread({}, validatedData), {}, {
|
|
75
|
+
urlLen: validatedData.url.length
|
|
76
|
+
});
|
|
77
|
+
sendStructuredMessage(VoiceLanguageEnum.set, sendData, resolve, error => reject(handleMqttError(error, 'Failed to set voice')), VoiceLanguageEnum.query);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 非 MQTT 模式:使用命令传输
|
|
82
|
+
const command = encodeVoice0x34(validatedData);
|
|
83
|
+
devices.common.model.actions.voice_data.set(command);
|
|
84
|
+
resolve({
|
|
85
|
+
success: true,
|
|
86
|
+
errCode: 0,
|
|
87
|
+
reqType: VoiceLanguageEnum.query,
|
|
88
|
+
version: commandVersion,
|
|
89
|
+
taskId: `${Date.now()}`,
|
|
90
|
+
id: validatedData.id,
|
|
91
|
+
schedule: 0,
|
|
92
|
+
status: 0
|
|
94
93
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
taskId
|
|
98
|
-
} = params.message;
|
|
99
|
-
return normalResolve(VoiceLanguageEnum.query, taskId);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
reject(handleMqttError(error, 'Failed to set voice'));
|
|
100
96
|
}
|
|
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');
|
|
117
|
-
}
|
|
97
|
+
});
|
|
118
98
|
}
|
|
119
99
|
};
|
|
120
100
|
};
|
package/lib/mqtt/useWifiMap.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { type TRequestWifiMap, type TSetWifiMap } from './type/protocols';
|
|
2
|
+
/**
|
|
3
|
+
* 自定义 Hook,用于 WiFi 地图管理
|
|
4
|
+
* @returns 包含 requestWifiMap 和 setWifiMap 函数的对象
|
|
5
|
+
*/
|
|
6
|
+
export declare const useWifiMap: () => {
|
|
5
7
|
requestWifiMap: TRequestWifiMap;
|
|
6
8
|
setWifiMap: TSetWifiMap;
|
|
7
9
|
};
|
|
8
|
-
export {};
|