@ray-js/robot-data-stream 0.0.12-beta-12 → 0.0.12-beta-14

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/p2pApi.js CHANGED
@@ -74,6 +74,8 @@ export default class P2pApi {
74
74
  initP2pSdk = async devId => {
75
75
  return new Promise((resolve, reject) => {
76
76
  try {
77
+ // 初始化p2pSDK时,将trace的开始时间戳记录下来
78
+ trace.initTimeStamps = Date.now();
77
79
  this.devId = devId;
78
80
  p2p.P2PSDKInit({
79
81
  success: () => {
@@ -200,7 +202,7 @@ export default class P2pApi {
200
202
  logger('info', {
201
203
  msg: 'p2p downloadStream success'
202
204
  }, this.onLogger);
203
- trace.pointFn('p2p', {
205
+ trace.pointFn({
204
206
  devId: this.devId,
205
207
  eventName: 'downloadStream'
206
208
  });
@@ -212,7 +214,7 @@ export default class P2pApi {
212
214
  msg: 'p2p downloadStream failed===>',
213
215
  params
214
216
  }, this.onLogger);
215
- trace.pointFn('p2pFail', {
217
+ trace.pointFn({
216
218
  devId: this.devId,
217
219
  eventName: 'downloadStream'
218
220
  });
@@ -251,7 +251,7 @@ export class SweeperP2p extends P2pApi {
251
251
  logger('info', {
252
252
  msg: 'startObserverSweeperDataByP2P ==>'
253
253
  }, this.onLogger);
254
- trace.pointFn('p2p', {
254
+ trace.pointFn({
255
255
  devId,
256
256
  eventName: 'startObserverSweeperDataByP2P'
257
257
  });
@@ -495,7 +495,7 @@ export class SweeperP2p extends P2pApi {
495
495
  logger('info', {
496
496
  msg: `receive first full package, cost time: ${packageTime} ms, fileName: ${fileName}`
497
497
  }, this.onLogger);
498
- trace.pointFn('p2p', {
498
+ trace.pointFn({
499
499
  devId: this.devId,
500
500
  eventName: 'receiveFirstFullPackage'
501
501
  });
package/lib/index.d.ts CHANGED
@@ -7,6 +7,7 @@ declare const useP2PDataStream: (devId: string, onReceiveMapData: (data: string)
7
7
  onReceiveAIPicHDData?: ((data: string) => void) | undefined;
8
8
  onLogger?: TOnLogger | undefined;
9
9
  onDefineStructuredMode?: ((isStructured: boolean) => void) | undefined;
10
+ traceId?: string | undefined;
10
11
  } | undefined) => {
11
12
  appendDownloadStreamDuringTask: (files: Array<string>, successCb?: () => void, failedCb?: () => void) => Promise<boolean> | void;
12
13
  };
package/lib/index.js CHANGED
@@ -13,7 +13,8 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
13
13
  onReceiveAIPicData,
14
14
  onReceiveAIPicHDData,
15
15
  onLogger,
16
- onDefineStructuredMode
16
+ onDefineStructuredMode,
17
+ traceId
17
18
  } = opt || {};
18
19
  const isInit = useRef(false);
19
20
  const offSessionStatusChange = useRef(null);
@@ -62,6 +63,9 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
62
63
  if (logTag) {
63
64
  log4js.setTag(logTag);
64
65
  }
66
+ if (traceId) {
67
+ trace.traceId = traceId;
68
+ }
65
69
  if (isIDE) {
66
70
  logger('warn', {
67
71
  msg: `You are using the IDE environment. To perform P2P and map debugging, please ensure the 'Robot Vacuum Debugger' plugin is installed.`
@@ -84,14 +88,14 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
84
88
  SweeperP2pInstance.onLogger = onLogger;
85
89
  SweeperP2pInstance.initP2pSdk(devId).then(() => {
86
90
  connectP2p();
87
- trace.pointFn('p2p', {
91
+ trace.pointFn({
88
92
  devId,
89
93
  eventName: 'initP2pSdk'
90
94
  });
91
95
  }).catch(() => {
92
- trace.pointFn('p2pFail', {
96
+ trace.pointFn({
93
97
  devId,
94
- eventName: 'initP2pSdk'
98
+ eventName: 'initP2pSdkFail'
95
99
  });
96
100
  });
97
101
  ty.onAppHide(handleAppHide);
@@ -112,7 +116,7 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
112
116
  msg: 'hooks has been started connectP2p'
113
117
  }, onLogger);
114
118
  SweeperP2pInstance.connectDevice(() => {
115
- trace.pointFn('p2p', {
119
+ trace.pointFn({
116
120
  devId,
117
121
  eventName: 'connectDevice'
118
122
  });
@@ -120,13 +124,13 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
120
124
  SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData, onDefineStructuredMode);
121
125
  offSessionStatusChange.current = SweeperP2pInstance.onSessionStatusChange(SweeperP2pInstance.sessionStatusCallback);
122
126
  }, () => {
123
- trace.pointFn('p2pFail', {
127
+ trace.pointFn({
124
128
  devId,
125
- eventName: 'connectDevice'
129
+ eventName: 'connectDeviceFail'
126
130
  });
127
131
  SweeperP2pInstance.reconnectP2p(() => {
128
132
  isInit.current = true;
129
- trace.pointFn('p2p', {
133
+ trace.pointFn({
130
134
  devId,
131
135
  eventName: 'reconnectP2p'
132
136
  });
@@ -1,5 +1,5 @@
1
1
  import { PromiseWithRejection } from './promise';
2
- type TRequestPassword = () => PromiseWithRejection;
2
+ type TRequestPassword = () => PromiseWithRejection | Promise<void>;
3
3
  type TSetPassword = (params: {
4
4
  password: string;
5
5
  oldPassword?: string;
@@ -17,7 +17,7 @@ export const usePassword = devId => {
17
17
 
18
18
  return {
19
19
  requestPassword: () => {
20
- if (!useMqtt) return null;
20
+ if (!useMqtt) return Promise.reject(new Error('useMqtt is not used'));
21
21
  const params = createSetCommonParams({
22
22
  deviceId: devId,
23
23
  reqType: PasswordEnum.query
@@ -15,7 +15,7 @@ export const useRoomProperty = devId => {
15
15
 
16
16
  return {
17
17
  requestRoomProperty: () => {
18
- if (!useMqtt) return null;
18
+ if (!useMqtt) return Promise.reject(new Error('useMqtt is not used'));
19
19
  const params = createSetCommonParams({
20
20
  deviceId: devId,
21
21
  reqType: RoomPropertyEnum.query
@@ -1,12 +1,11 @@
1
1
  export declare const PointEventConfig: {
2
2
  p2p: string;
3
- p2pFail: string;
4
3
  };
5
4
  export declare class Trace {
6
5
  initTimeStamps: number;
7
6
  traceId: string;
8
7
  constructor();
9
- pointFn: (type: 'p2p' | 'p2pFail', options: {
8
+ pointFn: (options: {
10
9
  devId: string;
11
10
  eventName: string;
12
11
  }) => void;
@@ -1,32 +1,32 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- const _excluded = ["devId"];
4
1
  import { event } from '@ray-js/ray';
5
- import { uniqueId } from 'lodash-es';
6
2
 
7
3
  // 事件埋点编码
8
4
  export const PointEventConfig = {
9
- p2p: 'ty_QEsvYl97I7pGNwUlqR2ARB7F8uqTAtht',
10
- p2pFail: 'ty_YB0xgyLYCy3LDCCUh8zykbDDxMMCGWU5'
5
+ p2p: 'ty_QEsvYl97I7pGNwUlqR2ARB7F8uqTAtht'
11
6
  };
12
7
  export class Trace {
13
8
  constructor() {
14
9
  this.initTimeStamps = Date.now();
15
- this.traceId = uniqueId('p2p_trace_');
16
10
  }
17
- pointFn = (type, options) => {
11
+ pointFn = options => {
18
12
  const {
19
- devId
20
- } = options,
21
- rest = _objectWithoutProperties(options, _excluded);
13
+ devId,
14
+ eventName
15
+ } = options;
22
16
  event({
23
- eventId: type === 'p2p' ? PointEventConfig.p2p : PointEventConfig.p2pFail,
24
- event: _objectSpread({
17
+ eventId: PointEventConfig.p2p,
18
+ event: {
19
+ // 设备id
25
20
  devId,
26
- timeStamp: Date.now(),
27
- traceId: this.traceId,
28
- costTime: Date.now() - this.initTimeStamps
29
- }, rest)
21
+ // 时间戳
22
+ time: Date.now(),
23
+ // 追踪id
24
+ traceId: this.traceId || '',
25
+ // 耗时(当前的时间戳 - initP2PSDK的时间戳)
26
+ costTime: Date.now() - this.initTimeStamps,
27
+ // 事件名称
28
+ eventName
29
+ }
30
30
  });
31
31
  };
32
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/robot-data-stream",
3
- "version": "0.0.12-beta-12",
3
+ "version": "0.0.12-beta-14",
4
4
  "description": "扫地机P2P数据流标准化组件",
5
5
  "main": "lib/index",
6
6
  "files": [