@ray-js/robot-data-stream 0.0.10-beta-19 → 0.0.10-beta-21

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.
@@ -6,7 +6,9 @@ export default class P2pApi {
6
6
  isConnecting: boolean;
7
7
  offSessionStatusChange: () => void;
8
8
  onLogger: (type: 'warn' | 'error' | 'info', v: string) => void;
9
+ initTimeStamp: number;
9
10
  devId: string;
11
+ traceId: string;
10
12
  constructor(props: {
11
13
  onLogger: (type: 'warn' | 'error' | 'info', data: string) => void;
12
14
  });
package/lib/api/p2pApi.js CHANGED
@@ -4,6 +4,7 @@
4
4
  import { p2p } from '@ray-js/ray';
5
5
  import moment from 'moment';
6
6
  import { logger } from '../utils';
7
+ import { trace } from '../trace';
7
8
  /**
8
9
  * P2P 工具类
9
10
  */
@@ -184,6 +185,10 @@ export default class P2pApi {
184
185
  logger('info', {
185
186
  msg: 'p2p downloadStream success'
186
187
  }, this.onLogger);
188
+ trace.pointFn('p2p', {
189
+ devId: this.devId,
190
+ eventName: 'downloadStream'
191
+ });
187
192
  typeof successCb === 'function' && successCb();
188
193
  resolve(true);
189
194
  },
@@ -192,6 +197,10 @@ export default class P2pApi {
192
197
  msg: 'p2p downloadStream failed===>',
193
198
  params
194
199
  }, this.onLogger);
200
+ trace.pointFn('p2pFail', {
201
+ devId: this.devId,
202
+ eventName: 'downloadStream'
203
+ });
195
204
  setTimeout(() => {
196
205
  typeof failedCb === 'function' && failedCb();
197
206
  }, 500);
@@ -72,6 +72,8 @@ export declare class SweeperP2p extends P2pApi {
72
72
  offP2pStreamPacketReceive: () => void;
73
73
  offDownLoadProgressUpdate: () => void;
74
74
  offTotalDownLoadProgressUpdate: () => void;
75
+ onDefineStructuredMode: (isStructured: boolean) => void;
76
+ mapUpdateCount: number;
75
77
  constructor(props: {
76
78
  onLogger: (type: 'warn' | 'error' | 'info', data: string) => void;
77
79
  });
@@ -125,7 +127,7 @@ export declare class SweeperP2p extends P2pApi {
125
127
  * @param downloadType
126
128
  * 0: 下载断开 1: 持续下载
127
129
  */
128
- startObserverSweeperDataByP2P: (downloadType: number, devId: string, onReceiveMapData: (data: string) => void, onReceivePathData: (data: string) => void, onReceiveAIPicData?: ((data: string) => void) | undefined, onReceiveAIPicHDData?: ((data: string) => void) | undefined) => Promise<void>;
130
+ startObserverSweeperDataByP2P: (downloadType: number, devId: string, onReceiveMapData: (data: string) => void, onReceivePathData: (data: string) => void, onReceiveAIPicData?: ((data: string) => void) | undefined, onReceiveAIPicHDData?: ((data: string) => void) | undefined, onDefineStructuredMode?: ((isStructured: boolean) => void) | undefined) => Promise<void>;
129
131
  /**
130
132
  * 在下载过程中继续添加下载文件
131
133
  * @param files
@@ -147,6 +149,7 @@ export declare class SweeperP2p extends P2pApi {
147
149
  * @param downloadComplete
148
150
  */
149
151
  private fileDownloadCompleteCallback;
152
+ private initStructuredMode;
150
153
  /**
151
154
  * p2p数据流回调
152
155
  * @param downloadComplete
@@ -6,14 +6,17 @@ import P2pApi from './p2pApi';
6
6
  import Base64 from 'base64-js';
7
7
  import { padStart, join, map } from 'lodash-es';
8
8
  import { logger } from '../utils';
9
+ import { trace } from '../trace';
9
10
  /**
10
11
  * 基于P2p工具类的扫地机扩展实现
11
12
  */
12
13
 
13
14
  const FILE_NAME_MAP = {
15
+ // raw类型地图点数据
14
16
  'map.bin': {
15
17
  type: 0
16
18
  },
19
+ // 结构化点数据
17
20
  'map_structured.bin': {
18
21
  type: 6
19
22
  },
@@ -61,6 +64,7 @@ export class SweeperP2p extends P2pApi {
61
64
  this.cacheData = {};
62
65
  this.exitFiles = [];
63
66
  this.firstPackageTime = Date.now();
67
+ this.mapUpdateCount = 0;
64
68
  this.packetTotalMap = new Map([['map.bin', -1], ['map_structured.bin', -1], ['cleanPath.bin', -1], ['ai.bin', -1], ['aiHD_XXXX_YYYY.bin', -1], ['map.bin.stream', -1], ['map_structured.bin.stream', -1], ['cleanPath.bin.stream', -1], ['ai.bin.stream', -1], ['aiHD_XXXX_YYYY.bin.stream', -1]]);
65
69
  this.packetSerialNumberCacheMap = new Map([['map.bin', -1], ['map_structured.bin', -1], ['cleanPath.bin', -1], ['ai.bin', -1], ['aiHD_XXXX_YYYY.bin', -1], ['map.bin.stream', -1], ['map_structured.bin.stream', -1], ['cleanPath.bin.stream', -1], ['ai.bin.stream', -1], ['aiHD_XXXX_YYYY.bin.stream', -1]]);
66
70
  this.packetDataCacheMap = new Map([['map.bin', new Map()], ['map_structured.bin', new Map()], ['cleanPath.bin', new Map()], ['ai.bin', new Map()], ['aiHD_XXXX_YYYY.bin', new Map()], ['map.bin.stream', new Map()], ['map_structured.bin.stream', new Map()], ['cleanPath.bin.stream', new Map()], ['ai.bin.stream', new Map()], ['aiHD_XXXX_YYYY.bin.stream', new Map()]]);
@@ -231,7 +235,7 @@ export class SweeperP2p extends P2pApi {
231
235
  * @param downloadType
232
236
  * 0: 下载断开 1: 持续下载
233
237
  */
234
- startObserverSweeperDataByP2P = async (downloadType, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData) => {
238
+ startObserverSweeperDataByP2P = async (downloadType, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData, onDefineStructuredMode) => {
235
239
  var _this$file$items;
236
240
  if (![0, 1].some(item => item === downloadType)) {
237
241
  logger('warn', {
@@ -241,6 +245,7 @@ export class SweeperP2p extends P2pApi {
241
245
  }
242
246
  this.onReceiveMapData = onReceiveMapData;
243
247
  this.onReceivePathData = onReceivePathData;
248
+ this.onDefineStructuredMode = onDefineStructuredMode;
244
249
  this.onReceiveAIPicData = onReceiveAIPicData || (() => {
245
250
  // do nothing
246
251
  });
@@ -250,6 +255,10 @@ export class SweeperP2p extends P2pApi {
250
255
  logger('info', {
251
256
  msg: 'startObserverSweeperDataByP2P ==>'
252
257
  }, this.onLogger);
258
+ trace.pointFn('p2p', {
259
+ devId,
260
+ eventName: 'startObserverSweeperDataByP2P'
261
+ });
253
262
  this.downloadType = downloadType;
254
263
  this.setDataFilePath(devId);
255
264
  this.setStreamFilePath(devId);
@@ -380,6 +389,12 @@ export class SweeperP2p extends P2pApi {
380
389
  }
381
390
  }
382
391
  };
392
+ initStructuredMode = v => {
393
+ if (this.mapUpdateCount > 1) return;
394
+ if (this.onDefineStructuredMode) {
395
+ this.onDefineStructuredMode(v);
396
+ }
397
+ };
383
398
 
384
399
  /**
385
400
  * p2p数据流回调
@@ -395,6 +410,10 @@ export class SweeperP2p extends P2pApi {
395
410
  let {
396
411
  fileName
397
412
  } = data;
413
+ if (fileName.startsWith('map')) {
414
+ var _FILE_NAME_MAP$fileNa;
415
+ this.initStructuredMode(((_FILE_NAME_MAP$fileNa = FILE_NAME_MAP[fileName]) === null || _FILE_NAME_MAP$fileNa === void 0 ? void 0 : _FILE_NAME_MAP$fileNa.type) === 6);
416
+ }
398
417
 
399
418
  // 因为XXXX_YYYYY会被替换为坐标值,所以这里需要替换一下
400
419
 
@@ -443,6 +462,10 @@ export class SweeperP2p extends P2pApi {
443
462
  logger('info', {
444
463
  msg: `receive first full package, cost time: ${packageTime} ms, fileName: ${fileName}`
445
464
  }, this.onLogger);
465
+ trace.pointFn('p2p', {
466
+ devId: this.devId,
467
+ eventName: 'receiveFirstFullPackage'
468
+ });
446
469
  this.firstPackageTime = 0;
447
470
  }
448
471
  const {
@@ -451,6 +474,7 @@ export class SweeperP2p extends P2pApi {
451
474
  if (this.cacheData[type] !== hexValue) {
452
475
  if (type === 0 || type === 6) {
453
476
  this.onReceiveMapData(hexValue);
477
+ this.mapUpdateCount += 1;
454
478
  }
455
479
  if (type === 1) {
456
480
  this.onReceivePathData(hexValue);
package/lib/index.d.ts CHANGED
@@ -6,8 +6,9 @@ declare const useP2PDataStream: (devId: string, onReceiveMapData: (data: string)
6
6
  onReceiveAIPicData?: ((data: string) => void) | undefined;
7
7
  onReceiveAIPicHDData?: ((data: string) => void) | undefined;
8
8
  onLogger?: TOnLogger | undefined;
9
+ onDefineStructuredMode?: ((isStructured: boolean) => void) | undefined;
9
10
  } | undefined) => {
10
11
  appendDownloadStreamDuringTask: (files: Array<string>, successCb?: () => void, failedCb?: () => void) => Promise<boolean> | void;
11
12
  };
12
13
  declare const StreamDataNotificationCenter: import("mitt").Emitter<Record<import("mitt").EventType, unknown>>;
13
- export { useP2PDataStream, StreamDataNotificationCenter };
14
+ export { StreamDataNotificationCenter, useP2PDataStream };
package/lib/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  /* eslint-disable consistent-return */
2
- import { useEffect, useRef, useCallback } from 'react';
3
2
  import log4js from '@ray-js/log4js';
4
- import { SweeperP2p } from './api/sweeperP2p';
5
3
  import { getSystemInfoSync, usePageEvent } from '@ray-js/ray';
4
+ import { useCallback, useEffect, useRef } from 'react';
5
+ import { SweeperP2p } from './api/sweeperP2p';
6
+ import { trace } from './trace';
6
7
  import { emitter, logger } from './utils';
7
8
  export * from './mqtt';
8
9
  export * from './mqtt/type/requestType';
@@ -11,7 +12,8 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
11
12
  logTag,
12
13
  onReceiveAIPicData,
13
14
  onReceiveAIPicHDData,
14
- onLogger
15
+ onLogger,
16
+ onDefineStructuredMode
15
17
  } = opt || {};
16
18
  const isInit = useRef(false);
17
19
  const offSessionStatusChange = useRef(null);
@@ -64,6 +66,7 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
64
66
  }, onLogger);
65
67
  SweeperP2pInstance.onReceiveMapData = onReceiveMapData;
66
68
  SweeperP2pInstance.onReceivePathData = onReceivePathData;
69
+ SweeperP2pInstance.onDefineStructuredMode = onDefineStructuredMode;
67
70
  SweeperP2pInstance.registerP2pDownloadEvent();
68
71
  SweeperP2pInstance.onLogger = onLogger;
69
72
  return () => {
@@ -78,6 +81,15 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
78
81
  }
79
82
  SweeperP2pInstance.initP2pSdk(devId).then(() => {
80
83
  connectP2p();
84
+ trace.pointFn('p2p', {
85
+ devId,
86
+ eventName: 'initP2pSdk'
87
+ });
88
+ }).catch(() => {
89
+ trace.pointFn('p2pFail', {
90
+ devId,
91
+ eventName: 'initP2pSdk'
92
+ });
81
93
  });
82
94
  ty.onAppHide(handleAppHide);
83
95
  ty.onAppShow(handleAppShow);
@@ -99,12 +111,24 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
99
111
  }, onLogger);
100
112
  SweeperP2pInstance.isConnecting = true;
101
113
  SweeperP2pInstance.connectDevice(() => {
114
+ trace.pointFn('p2p', {
115
+ devId,
116
+ eventName: 'connectDevice'
117
+ });
102
118
  isInit.current = true;
103
- SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData);
119
+ SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData, onDefineStructuredMode);
104
120
  offSessionStatusChange.current = SweeperP2pInstance.onSessionStatusChange(SweeperP2pInstance.sessionStatusCallback);
105
121
  }, () => {
122
+ trace.pointFn('p2pFail', {
123
+ devId,
124
+ eventName: 'connectDevice'
125
+ });
106
126
  SweeperP2pInstance.reconnectP2p(() => {
107
127
  isInit.current = true;
128
+ trace.pointFn('p2p', {
129
+ devId,
130
+ eventName: 'reconnectP2p'
131
+ });
108
132
  SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData);
109
133
  // 这里失败重连需要注册断开重连的事件
110
134
  offSessionStatusChange.current = SweeperP2pInstance.onSessionStatusChange(SweeperP2pInstance.sessionStatusCallback);
@@ -131,4 +155,4 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
131
155
  };
132
156
  };
133
157
  const StreamDataNotificationCenter = emitter;
134
- export { useP2PDataStream, StreamDataNotificationCenter };
158
+ export { StreamDataNotificationCenter, useP2PDataStream };
@@ -1,21 +1,21 @@
1
1
  import React from 'react';
2
2
  export declare const SingletonContext: React.Context<{
3
- useStructuredMode: boolean;
3
+ useMqtt: boolean;
4
4
  commandVersion: '0' | '1';
5
5
  devices: {
6
6
  common: any;
7
7
  };
8
8
  }>;
9
9
  export declare function useMqtt(): {
10
- useStructuredMode: boolean;
10
+ useMqtt: boolean;
11
11
  commandVersion: "0" | "1";
12
12
  devices: {
13
13
  common: any;
14
14
  };
15
15
  };
16
- export declare function MqttProvider({ children, useStructuredMode, commandVersion, devices }: {
16
+ export declare function MqttProvider({ children, useMqtt, commandVersion, devices }: {
17
17
  children: any;
18
- useStructuredMode: any;
18
+ useMqtt: any;
19
19
  commandVersion: any;
20
20
  devices: any;
21
21
  }): React.JSX.Element;
@@ -17,7 +17,7 @@ export function useMqtt() {
17
17
  export function MqttProvider(_ref) {
18
18
  let {
19
19
  children,
20
- useStructuredMode,
20
+ useMqtt,
21
21
  commandVersion,
22
22
  devices
23
23
  } = _ref;
@@ -54,8 +54,8 @@ export function MqttProvider(_ref) {
54
54
  }
55
55
  });
56
56
  instanceRef.current = {
57
- // 是否结构化数据(mqtt)
58
- useStructuredMode,
57
+ // 是否走mqtt64/65通道
58
+ useMqtt,
59
59
  // 指令协议版本(1byte or 4bytes)
60
60
  commandVersion,
61
61
  // sdm
@@ -10,12 +10,12 @@ var DevInfoEnum = /*#__PURE__*/function (DevInfoEnum) {
10
10
  // 请求设备信息
11
11
  export const useDevInfo = devId => {
12
12
  const {
13
- useStructuredMode,
13
+ useMqtt,
14
14
  devices
15
15
  } = useContext(SingletonContext);
16
16
  return {
17
17
  requestDevInfo: () => {
18
- if (useStructuredMode) {
18
+ if (useMqtt) {
19
19
  const params = createSetCommonParams({
20
20
  deviceId: devId,
21
21
  reqType: DevInfoEnum.query,
@@ -17,7 +17,7 @@ import { encodeDeleteMap0x2c, encodeSaveMap0x2a, encodeUseMap0x2e } from '@ray-j
17
17
  */
18
18
  export const useHistoryMap = devId => {
19
19
  const {
20
- useStructuredMode,
20
+ useMqtt,
21
21
  devices
22
22
  } = useContext(SingletonContext);
23
23
  /**
@@ -45,7 +45,7 @@ export const useHistoryMap = devId => {
45
45
  return Promise.reject(new Error('mapId is required'));
46
46
  }
47
47
  await deleteMultipleMapFile(mapId, devId);
48
- if (useStructuredMode) {
48
+ if (useMqtt) {
49
49
  const params = createSetCommonParams({
50
50
  deviceId: devId,
51
51
  reqType: DeleteMapEnum.set,
@@ -70,7 +70,7 @@ export const useHistoryMap = devId => {
70
70
  },
71
71
  changeCurrentMap: async (mapId, url) => {
72
72
  try {
73
- if (useStructuredMode) {
73
+ if (useMqtt) {
74
74
  const sendData = {
75
75
  reqType: UseMapEnum.set,
76
76
  mapId,
@@ -99,7 +99,7 @@ export const useHistoryMap = devId => {
99
99
  }
100
100
  },
101
101
  saveMap: () => {
102
- if (useStructuredMode) {
102
+ if (useMqtt) {
103
103
  const params = createSetCommonParams({
104
104
  deviceId: devId,
105
105
  reqType: SaveCurrentMapEnum.set,
@@ -16,7 +16,7 @@ import { encodePartitionDivision0x1c } from '@ray-js/robot-protocol';
16
16
  */
17
17
  export const usePartDivision = devId => {
18
18
  const {
19
- useStructuredMode,
19
+ useMqtt,
20
20
  devices,
21
21
  commandVersion
22
22
  } = useContext(SingletonContext);
@@ -31,7 +31,7 @@ export const usePartDivision = devId => {
31
31
 
32
32
  return {
33
33
  setPartDivision: (points, roomId, origin) => {
34
- if (useStructuredMode) {
34
+ if (useMqtt) {
35
35
  const pointStr = pointsToString(points, origin);
36
36
  const params = createSetCommonParams({
37
37
  deviceId: devId,
@@ -17,7 +17,7 @@ import { encodePartitionMerge0x1e } from '@ray-js/robot-protocol';
17
17
  */
18
18
  export const usePartMerge = devId => {
19
19
  const {
20
- useStructuredMode,
20
+ useMqtt,
21
21
  devices,
22
22
  commandVersion
23
23
  } = useContext(SingletonContext);
@@ -35,7 +35,7 @@ export const usePartMerge = devId => {
35
35
  if (ids.some(id => typeof id !== 'number')) {
36
36
  return Promise.reject(new Error('ids must be an array of numbers'));
37
37
  }
38
- if (useStructuredMode) {
38
+ if (useMqtt) {
39
39
  const params = createSetCommonParams({
40
40
  deviceId: devId,
41
41
  reqType: PartMergeEnum.set,
@@ -6,7 +6,7 @@ import { useContext } from 'react';
6
6
  import { SingletonContext } from './mqttProvider';
7
7
  export const usePassword = devId => {
8
8
  const {
9
- useStructuredMode
9
+ useMqtt
10
10
  } = useContext(SingletonContext);
11
11
 
12
12
  // 请求密码状态
@@ -17,7 +17,7 @@ export const usePassword = devId => {
17
17
 
18
18
  return {
19
19
  requestPassword: () => {
20
- if (!useStructuredMode) return null;
20
+ if (!useMqtt) return null;
21
21
  const params = createSetCommonParams({
22
22
  deviceId: devId,
23
23
  reqType: PasswordEnum.query
@@ -18,7 +18,7 @@ import { encodeDoNotDisturb0x32 } from '@ray-js/robot-protocol';
18
18
  */
19
19
  export const useQuiteHours = devId => {
20
20
  const {
21
- useStructuredMode,
21
+ useMqtt,
22
22
  devices,
23
23
  commandVersion
24
24
  } = useContext(SingletonContext);
@@ -40,7 +40,7 @@ export const useQuiteHours = devId => {
40
40
  endTime
41
41
  } = message,
42
42
  others = _objectWithoutProperties(message, _excluded);
43
- if (useStructuredMode) {
43
+ if (useMqtt) {
44
44
  if (!startTime || !endTime) {
45
45
  throw new Error('Invalid time');
46
46
  }
@@ -6,7 +6,7 @@ import { SingletonContext } from './mqttProvider';
6
6
  import { encodeResetMap0x42 } from '@ray-js/robot-protocol';
7
7
  export const useResetMap = devId => {
8
8
  const {
9
- useStructuredMode,
9
+ useMqtt,
10
10
  devices,
11
11
  commandVersion
12
12
  } = useContext(SingletonContext);
@@ -14,7 +14,7 @@ export const useResetMap = devId => {
14
14
 
15
15
  return {
16
16
  setResetMap: () => {
17
- if (useStructuredMode) {
17
+ if (useMqtt) {
18
18
  const params = createSetCommonParams({
19
19
  deviceId: devId,
20
20
  reqType: ResetCurrMapEnum.set
@@ -6,7 +6,7 @@ import { useContext } from 'react';
6
6
  import { SingletonContext } from './mqttProvider';
7
7
  export const useRoomProperty = devId => {
8
8
  const {
9
- useStructuredMode
9
+ useMqtt
10
10
  } = useContext(SingletonContext);
11
11
 
12
12
  // 请求房间属性
@@ -15,7 +15,7 @@ export const useRoomProperty = devId => {
15
15
 
16
16
  return {
17
17
  requestRoomProperty: () => {
18
- if (!useStructuredMode) return null;
18
+ if (!useMqtt) return null;
19
19
  const params = createSetCommonParams({
20
20
  deviceId: devId,
21
21
  reqType: RoomPropertyEnum.query
@@ -12,7 +12,7 @@ import { CISTERN_MAP, CLEAN_MODE_MAP, SUCTION_MAP } from '../constant';
12
12
 
13
13
  export const useSchedule = devId => {
14
14
  const {
15
- useStructuredMode,
15
+ useMqtt,
16
16
  devices,
17
17
  commandVersion
18
18
  } = useContext(SingletonContext);
@@ -33,7 +33,7 @@ export const useSchedule = devId => {
33
33
  return normalResolve(ScheduleEnum.query, taskId);
34
34
  },
35
35
  setSchedule: message => {
36
- if (useStructuredMode) {
36
+ if (useMqtt) {
37
37
  const params = createSetCommonParams({
38
38
  deviceId: devId,
39
39
  reqType: ScheduleEnum.set,
@@ -10,7 +10,7 @@ import { SingletonContext } from './mqttProvider';
10
10
  import { encodeRoomClean0x14, requestRoomClean0x15 } from '@ray-js/robot-protocol';
11
11
  export const useSelectRoomClean = devId => {
12
12
  const {
13
- useStructuredMode,
13
+ useMqtt,
14
14
  commandVersion,
15
15
  devices
16
16
  } = useContext(SingletonContext);
@@ -22,7 +22,7 @@ export const useSelectRoomClean = devId => {
22
22
 
23
23
  return {
24
24
  requestSelectRoomClean: () => {
25
- if (useStructuredMode) {
25
+ if (useMqtt) {
26
26
  const params = createSetCommonParams({
27
27
  deviceId: devId,
28
28
  reqType: RoomCleanSetEnum.query
@@ -36,7 +36,7 @@ export const useSelectRoomClean = devId => {
36
36
  },
37
37
  setRoomClean: rooms => {
38
38
  var _rooms$0$cleanTimes, _rooms$;
39
- if (useStructuredMode) {
39
+ if (useMqtt) {
40
40
  const ids = [];
41
41
  const suctions = [];
42
42
  const cisterns = [];
@@ -14,7 +14,7 @@ import { pointsToString } from '../utils';
14
14
  */
15
15
  export const useSpotClean = devId => {
16
16
  const {
17
- useStructuredMode,
17
+ useMqtt,
18
18
  commandVersion,
19
19
  devices
20
20
  } = useContext(SingletonContext);
@@ -38,7 +38,7 @@ export const useSpotClean = devId => {
38
38
  spots,
39
39
  origin
40
40
  } = message;
41
- if (useStructuredMode) {
41
+ if (useMqtt) {
42
42
  if (!isArray(spots) || isArray(spots) && spots.length === 0) {
43
43
  return Promise.reject(new Error('message is required'));
44
44
  }
@@ -12,7 +12,7 @@ import { pointsToString } from '../utils';
12
12
 
13
13
  export const useVirtualArea = devId => {
14
14
  const {
15
- useStructuredMode,
15
+ useMqtt,
16
16
  commandVersion,
17
17
  devices
18
18
  } = useContext(SingletonContext);
@@ -34,7 +34,7 @@ export const useVirtualArea = devId => {
34
34
 
35
35
  return {
36
36
  requestVirtualArea: () => {
37
- if (useStructuredMode) {
37
+ if (useMqtt) {
38
38
  const params = createSetCommonParams({
39
39
  deviceId: devId,
40
40
  reqType: VirtualAreaEnum.query
@@ -51,7 +51,7 @@ export const useVirtualArea = devId => {
51
51
  data,
52
52
  origin
53
53
  } = _ref;
54
- if (useStructuredMode) {
54
+ if (useMqtt) {
55
55
  const names = [];
56
56
  const modes = [];
57
57
  const polygons = [];
@@ -10,7 +10,7 @@ import { encodeVirtualWall0x12, requestVirtualWall0x13 } from '@ray-js/robot-pro
10
10
  import { pointsToString } from '../utils';
11
11
  export const useVirtualWall = devId => {
12
12
  const {
13
- useStructuredMode,
13
+ useMqtt,
14
14
  commandVersion,
15
15
  devices
16
16
  } = useContext(SingletonContext);
@@ -28,7 +28,7 @@ export const useVirtualWall = devId => {
28
28
 
29
29
  return {
30
30
  requestVirtualWall: () => {
31
- if (useStructuredMode) {
31
+ if (useMqtt) {
32
32
  const params = createSetCommonParams({
33
33
  deviceId: devId,
34
34
  reqType: VirtualWallEnum.query
@@ -45,7 +45,7 @@ export const useVirtualWall = devId => {
45
45
  data,
46
46
  origin
47
47
  } = _ref;
48
- if (useStructuredMode) {
48
+ if (useMqtt) {
49
49
  const params = createSetCommonParams({
50
50
  deviceId: devId,
51
51
  reqType: VirtualWallEnum.set,
@@ -18,7 +18,7 @@ import { encodeVoice0x34 } from '@ray-js/robot-protocol';
18
18
  */
19
19
  export const useVoice = devId => {
20
20
  const {
21
- useStructuredMode,
21
+ useMqtt,
22
22
  devices
23
23
  } = useContext(SingletonContext);
24
24
  /**
@@ -58,7 +58,7 @@ export const useVoice = devId => {
58
58
  return normalResolve(VoiceLanguageEnum.query, taskId);
59
59
  },
60
60
  setVoice: message => {
61
- if (useStructuredMode) {
61
+ if (useMqtt) {
62
62
  const sendData = _objectSpread(_objectSpread({}, message), {}, {
63
63
  urlLen: message.url.length
64
64
  });
@@ -16,7 +16,7 @@ import { pointsToString } from '../utils';
16
16
  */
17
17
  export const useZoneClean = devId => {
18
18
  const {
19
- useStructuredMode,
19
+ useMqtt,
20
20
  commandVersion,
21
21
  devices
22
22
  } = useContext(SingletonContext);
@@ -27,7 +27,7 @@ export const useZoneClean = devId => {
27
27
 
28
28
  return {
29
29
  requestZoneClean: () => {
30
- if (useStructuredMode) {
30
+ if (useMqtt) {
31
31
  const params = createSetCommonParams({
32
32
  deviceId: devId,
33
33
  reqType: ZoneCleanEnum.query
@@ -44,7 +44,7 @@ export const useZoneClean = devId => {
44
44
  zones,
45
45
  origin
46
46
  } = message;
47
- if (useStructuredMode) {
47
+ if (useMqtt) {
48
48
  if (!isArray(zones) || isArray(zones) && zones.length === 0) {
49
49
  return Promise.reject(new Error('message is required'));
50
50
  }
@@ -0,0 +1,14 @@
1
+ export declare const PointEventConfig: {
2
+ p2p: string;
3
+ p2pFail: string;
4
+ };
5
+ export declare class Trace {
6
+ initTimeStamps: number;
7
+ traceId: string;
8
+ constructor();
9
+ pointFn: (type: 'p2p' | 'p2pFail', options: {
10
+ devId: string;
11
+ eventName: string;
12
+ }) => void;
13
+ }
14
+ export declare const trace: Trace;
@@ -0,0 +1,33 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ const _excluded = ["devId"];
4
+ import { event } from '@ray-js/ray';
5
+ import { uniqueId } from 'lodash-es';
6
+
7
+ // 事件埋点编码
8
+ export const PointEventConfig = {
9
+ p2p: 'ty_QEsvYl97I7pGNwUlqR2ARB7F8uqTAtht',
10
+ p2pFail: 'ty_YB0xgyLYCy3LDCCUh8zykbDDxMMCGWU5'
11
+ };
12
+ export class Trace {
13
+ constructor() {
14
+ this.initTimeStamps = Date.now();
15
+ this.traceId = uniqueId('p2p_trace_');
16
+ }
17
+ pointFn = (type, options) => {
18
+ const {
19
+ devId
20
+ } = options,
21
+ rest = _objectWithoutProperties(options, _excluded);
22
+ event({
23
+ eventId: type === 'p2p' ? PointEventConfig.p2p : PointEventConfig.p2pFail,
24
+ event: _objectSpread({
25
+ devId,
26
+ timeStamp: Date.now(),
27
+ traceId: this.traceId,
28
+ costTime: Date.now() - this.initTimeStamps
29
+ }, rest)
30
+ });
31
+ };
32
+ }
33
+ export const trace = new Trace();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/robot-data-stream",
3
- "version": "0.0.10-beta-19",
3
+ "version": "0.0.10-beta-21",
4
4
  "description": "扫地机P2P数据流标准化组件",
5
5
  "main": "lib/index",
6
6
  "files": [