@ray-js/robot-data-stream 0.0.10-beta-19 → 0.0.10-beta-20
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.d.ts +2 -0
- package/lib/api/p2pApi.js +9 -0
- package/lib/api/sweeperP2p.d.ts +4 -1
- package/lib/api/sweeperP2p.js +22 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +29 -5
- package/lib/trace/index.d.ts +14 -0
- package/lib/trace/index.js +33 -0
- package/package.json +1 -1
package/lib/api/p2pApi.d.ts
CHANGED
|
@@ -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);
|
package/lib/api/sweeperP2p.d.ts
CHANGED
|
@@ -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
|
package/lib/api/sweeperP2p.js
CHANGED
|
@@ -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数据流回调
|
|
@@ -443,6 +458,10 @@ export class SweeperP2p extends P2pApi {
|
|
|
443
458
|
logger('info', {
|
|
444
459
|
msg: `receive first full package, cost time: ${packageTime} ms, fileName: ${fileName}`
|
|
445
460
|
}, this.onLogger);
|
|
461
|
+
trace.pointFn('p2p', {
|
|
462
|
+
devId: this.devId,
|
|
463
|
+
eventName: 'receiveFirstFullPackage'
|
|
464
|
+
});
|
|
446
465
|
this.firstPackageTime = 0;
|
|
447
466
|
}
|
|
448
467
|
const {
|
|
@@ -451,6 +470,8 @@ export class SweeperP2p extends P2pApi {
|
|
|
451
470
|
if (this.cacheData[type] !== hexValue) {
|
|
452
471
|
if (type === 0 || type === 6) {
|
|
453
472
|
this.onReceiveMapData(hexValue);
|
|
473
|
+
this.mapUpdateCount += 1;
|
|
474
|
+
this.initStructuredMode(type === 6);
|
|
454
475
|
}
|
|
455
476
|
if (type === 1) {
|
|
456
477
|
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 {
|
|
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 {
|
|
158
|
+
export { StreamDataNotificationCenter, useP2PDataStream };
|
|
@@ -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();
|