@ray-js/robot-data-stream 0.1.0 → 0.1.2

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.
@@ -5,6 +5,7 @@ import { VirtualWallEnum } from './type';
5
5
  import { SingletonContext } from './mqttProvider';
6
6
  import { encodeVirtualWall0x12, requestVirtualWall0x13 } from '@ray-js/robot-protocol';
7
7
  import { pointsToString } from '../utils';
8
+ import { createVirtualWallPayload } from './virtualWall';
8
9
  import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
9
10
  /**
10
11
  * 自定义 Hook,用于虚拟墙管理
@@ -73,11 +74,10 @@ export const useVirtualWall = () => {
73
74
  origin
74
75
  } = params;
75
76
  if (useMqtt) {
76
- sendStructuredMessage(VirtualWallEnum.set, {
77
- points: data.map(points => pointsToString(points, origin)),
78
- num: data.length,
79
- mode: new Array(data.length).fill('0')
80
- }, resolve, error => reject(handleMqttError(error, 'Failed to set virtual wall')), {
77
+ sendStructuredMessage(VirtualWallEnum.set, createVirtualWallPayload({
78
+ data,
79
+ origin
80
+ }), resolve, error => reject(handleMqttError(error, 'Failed to set virtual wall')), {
81
81
  responseType: VirtualWallEnum.query
82
82
  } // 响应类型是 query,不是 set
83
83
  );
@@ -0,0 +1,7 @@
1
+ import type { SetVirtualWallData } from './type/protocols/virtualWallProtocol';
2
+ export declare const createVirtualWallPayload: ({ data, origin }: SetVirtualWallData) => {
3
+ points: string[];
4
+ num: number;
5
+ modes: number[];
6
+ mode: string[];
7
+ };
@@ -0,0 +1,15 @@
1
+ import "core-js/modules/esnext.iterator.map.js";
2
+ import { pointsToString } from '../utils';
3
+ export const createVirtualWallPayload = _ref => {
4
+ let {
5
+ data,
6
+ origin
7
+ } = _ref;
8
+ return {
9
+ points: data.map(points => pointsToString(points, origin)),
10
+ num: data.length,
11
+ modes: new Array(data.length).fill(0),
12
+ // 历史兼容字段,避免存量非标固件依赖旧键名 mode;标准协议字段为 modes
13
+ mode: new Array(data.length).fill('0')
14
+ };
15
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/robot-data-stream",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "扫地机P2P数据流标准化组件",
5
5
  "main": "lib/index",
6
6
  "files": [