@ray-js/robot-data-stream 0.0.12-beta-13 → 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 +4 -2
- package/lib/api/sweeperP2p.js +2 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +12 -8
- package/lib/trace/index.d.ts +1 -2
- package/lib/trace/index.js +17 -17
- package/package.json +1 -1
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(
|
|
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(
|
|
217
|
+
trace.pointFn({
|
|
216
218
|
devId: this.devId,
|
|
217
219
|
eventName: 'downloadStream'
|
|
218
220
|
});
|
package/lib/api/sweeperP2p.js
CHANGED
|
@@ -251,7 +251,7 @@ export class SweeperP2p extends P2pApi {
|
|
|
251
251
|
logger('info', {
|
|
252
252
|
msg: 'startObserverSweeperDataByP2P ==>'
|
|
253
253
|
}, this.onLogger);
|
|
254
|
-
trace.pointFn(
|
|
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(
|
|
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(
|
|
91
|
+
trace.pointFn({
|
|
88
92
|
devId,
|
|
89
93
|
eventName: 'initP2pSdk'
|
|
90
94
|
});
|
|
91
95
|
}).catch(() => {
|
|
92
|
-
trace.pointFn(
|
|
96
|
+
trace.pointFn({
|
|
93
97
|
devId,
|
|
94
|
-
eventName: '
|
|
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(
|
|
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(
|
|
127
|
+
trace.pointFn({
|
|
124
128
|
devId,
|
|
125
|
-
eventName: '
|
|
129
|
+
eventName: 'connectDeviceFail'
|
|
126
130
|
});
|
|
127
131
|
SweeperP2pInstance.reconnectP2p(() => {
|
|
128
132
|
isInit.current = true;
|
|
129
|
-
trace.pointFn(
|
|
133
|
+
trace.pointFn({
|
|
130
134
|
devId,
|
|
131
135
|
eventName: 'reconnectP2p'
|
|
132
136
|
});
|
package/lib/trace/index.d.ts
CHANGED
|
@@ -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: (
|
|
8
|
+
pointFn: (options: {
|
|
10
9
|
devId: string;
|
|
11
10
|
eventName: string;
|
|
12
11
|
}) => void;
|
package/lib/trace/index.js
CHANGED
|
@@ -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 =
|
|
11
|
+
pointFn = options => {
|
|
18
12
|
const {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
devId,
|
|
14
|
+
eventName
|
|
15
|
+
} = options;
|
|
22
16
|
event({
|
|
23
|
-
eventId:
|
|
24
|
-
event:
|
|
17
|
+
eventId: PointEventConfig.p2p,
|
|
18
|
+
event: {
|
|
19
|
+
// 设备id
|
|
25
20
|
devId,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
}
|