@ray-js/robot-data-stream 0.0.12-beta-5 → 0.0.12-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/sweeperP2p.js +1 -1
- package/lib/index.js +8 -3
- package/lib/mqtt/usePartDivision.js +15 -11
- package/lib/utils/index.js +14 -9
- package/package.json +1 -1
package/lib/api/sweeperP2p.js
CHANGED
|
@@ -3,7 +3,7 @@ import "core-js/modules/esnext.iterator.for-each.js";
|
|
|
3
3
|
import "core-js/modules/esnext.iterator.map.js";
|
|
4
4
|
/* eslint-disable no-shadow */
|
|
5
5
|
import Base64 from 'base64-js';
|
|
6
|
-
import { join, map, padStart } from 'lodash-es';
|
|
6
|
+
import { join, map, padStart, once } from 'lodash-es';
|
|
7
7
|
import { trace } from '../trace';
|
|
8
8
|
import { logger } from '../utils';
|
|
9
9
|
import P2pApi from './p2pApi';
|
package/lib/index.js
CHANGED
|
@@ -29,7 +29,7 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
|
|
|
29
29
|
// 判断进入后台之后,维持定时器,如果进入后台超过2分钟, 则断开P2P
|
|
30
30
|
timer.current = setTimeout(() => {
|
|
31
31
|
logger('info', {
|
|
32
|
-
msg:
|
|
32
|
+
msg: `background timer has been exe,isAppOnBackground: ${isAppOnBackground.current}`
|
|
33
33
|
}, onLogger);
|
|
34
34
|
if (isAppOnBackground.current) {
|
|
35
35
|
unmount();
|
|
@@ -45,8 +45,13 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
|
|
|
45
45
|
}, onLogger);
|
|
46
46
|
timer.current && clearTimeout(timer.current);
|
|
47
47
|
setTimeout(() => {
|
|
48
|
-
var _ty$p2p$isP2PActiveSy, _ty$p2p;
|
|
49
|
-
|
|
48
|
+
var _ty$p2p$isP2PActiveSy, _ty$p2p, _ty$p2p$isP2PActiveSy2, _ty$p2p2;
|
|
49
|
+
logger('info', {
|
|
50
|
+
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, {
|
|
51
|
+
deviceId: devId
|
|
52
|
+
})}`
|
|
53
|
+
}, onLogger);
|
|
54
|
+
if (!isInit.current || !((_ty$p2p$isP2PActiveSy2 = (_ty$p2p2 = ty.p2p).isP2PActiveSync) !== null && _ty$p2p$isP2PActiveSy2 !== void 0 && _ty$p2p$isP2PActiveSy2.call(_ty$p2p2, {
|
|
50
55
|
deviceId: devId
|
|
51
56
|
}))) {
|
|
52
57
|
connectP2p();
|
|
@@ -32,17 +32,21 @@ export const usePartDivision = devId => {
|
|
|
32
32
|
return {
|
|
33
33
|
setPartDivision: (points, roomId, origin) => {
|
|
34
34
|
if (useMqtt) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
try {
|
|
36
|
+
const pointStr = pointsToString(points, origin);
|
|
37
|
+
const params = createSetCommonParams({
|
|
38
|
+
deviceId: devId,
|
|
39
|
+
reqType: PartDivisionEnum.set,
|
|
40
|
+
message: {
|
|
41
|
+
lines: [pointStr],
|
|
42
|
+
ids: [roomId]
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
ty.device.sendMqttMessage(params);
|
|
46
|
+
return normalResolve(PartDivisionEnum.query, params.message.taskId);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
throw new Error('房间分隔失败');
|
|
49
|
+
}
|
|
46
50
|
}
|
|
47
51
|
const command = encodePartitionDivision0x1c({
|
|
48
52
|
version: commandVersion,
|
package/lib/utils/index.js
CHANGED
|
@@ -7,15 +7,20 @@ const pointToString = point => {
|
|
|
7
7
|
};
|
|
8
8
|
export const pointsToString = (points, origin) => {
|
|
9
9
|
let newPoints = [];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
try {
|
|
11
|
+
const ox = origin.x;
|
|
12
|
+
const oy = origin.y;
|
|
13
|
+
newPoints = map(points, i => {
|
|
14
|
+
return {
|
|
15
|
+
x: floor(i.x - ox, 0),
|
|
16
|
+
y: floor(-(i.y - oy), 0)
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
return join(map(newPoints, pointToString), ',');
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.error('pointsToString error', e);
|
|
22
|
+
throw new Error('pointsToString error');
|
|
23
|
+
}
|
|
19
24
|
};
|
|
20
25
|
export const isJSONString = str => {
|
|
21
26
|
if (typeof str !== 'string') {
|