@ray-js/robot-data-stream 0.0.10 → 0.0.12-beta-1
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/sweeperP2p.d.ts +1 -12
- package/lib/api/sweeperP2p.js +15 -27
- package/package.json +1 -1
package/lib/api/sweeperP2p.d.ts
CHANGED
|
@@ -73,8 +73,7 @@ export declare class SweeperP2p extends P2pApi {
|
|
|
73
73
|
offDownLoadProgressUpdate: () => void;
|
|
74
74
|
offTotalDownLoadProgressUpdate: () => void;
|
|
75
75
|
onDefineStructuredMode: (isStructured: boolean) => void;
|
|
76
|
-
|
|
77
|
-
constructor(props: any);
|
|
76
|
+
constructor();
|
|
78
77
|
private setStreamFilePath;
|
|
79
78
|
private setDataFilePath;
|
|
80
79
|
/**
|
|
@@ -153,16 +152,6 @@ export declare class SweeperP2p extends P2pApi {
|
|
|
153
152
|
* @param downloadComplete
|
|
154
153
|
*/
|
|
155
154
|
private p2pStreamPacketReceiveCallback;
|
|
156
|
-
/**
|
|
157
|
-
* 单文件下载完成回调
|
|
158
|
-
* @param data
|
|
159
|
-
*/
|
|
160
|
-
private fileDownloadProgressCallback;
|
|
161
|
-
/**
|
|
162
|
-
* 多文件下载进度监听
|
|
163
|
-
* @param data
|
|
164
|
-
*/
|
|
165
|
-
private fileTotalDownloadProgressCallback;
|
|
166
155
|
/**
|
|
167
156
|
* 从指定的文件路径获取文件
|
|
168
157
|
* @param fileName
|
package/lib/api/sweeperP2p.js
CHANGED
|
@@ -4,7 +4,7 @@ import "core-js/modules/esnext.iterator.map.js";
|
|
|
4
4
|
/* eslint-disable no-shadow */
|
|
5
5
|
import P2pApi from './p2pApi';
|
|
6
6
|
import Base64 from 'base64-js';
|
|
7
|
-
import { padStart, join, map } from 'lodash-es';
|
|
7
|
+
import { padStart, join, map, once } from 'lodash-es';
|
|
8
8
|
import { logger } from '../utils';
|
|
9
9
|
import { trace } from '../trace';
|
|
10
10
|
/**
|
|
@@ -49,8 +49,8 @@ const FILE_NAME_MAP = {
|
|
|
49
49
|
// 走p2p流传输(新) or 读取bin文件(旧)
|
|
50
50
|
const shouldDownloadStream = Boolean(ty.p2p.downloadStream && ty.p2p.onStreamPacketReceive);
|
|
51
51
|
export class SweeperP2p extends P2pApi {
|
|
52
|
-
constructor(
|
|
53
|
-
super(
|
|
52
|
+
constructor() {
|
|
53
|
+
super();
|
|
54
54
|
this.file = undefined;
|
|
55
55
|
this.downloadType = 1;
|
|
56
56
|
this.fileIndex = -1; // -1 表示所有文件下载完成
|
|
@@ -61,7 +61,6 @@ export class SweeperP2p extends P2pApi {
|
|
|
61
61
|
this.cacheData = {};
|
|
62
62
|
this.exitFiles = [];
|
|
63
63
|
this.firstPackageTime = Date.now();
|
|
64
|
-
this.mapUpdateCount = 0;
|
|
65
64
|
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]]);
|
|
66
65
|
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]]);
|
|
67
66
|
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()]]);
|
|
@@ -359,9 +358,8 @@ export class SweeperP2p extends P2pApi {
|
|
|
359
358
|
[...this.packetDataCacheMap.keys()].forEach(key => {
|
|
360
359
|
this.packetDataCacheMap.set(key, new Map());
|
|
361
360
|
});
|
|
362
|
-
} else {
|
|
363
|
-
this.cacheData = {};
|
|
364
361
|
}
|
|
362
|
+
this.cacheData = {};
|
|
365
363
|
this.offFileDownloadComplete && this.offFileDownloadComplete();
|
|
366
364
|
this.offP2pStreamPacketReceive && this.offP2pStreamPacketReceive();
|
|
367
365
|
|
|
@@ -386,12 +384,11 @@ export class SweeperP2p extends P2pApi {
|
|
|
386
384
|
}
|
|
387
385
|
}
|
|
388
386
|
};
|
|
389
|
-
initStructuredMode =
|
|
390
|
-
if (this.mapUpdateCount > 1) return;
|
|
387
|
+
initStructuredMode = (() => once(isStructured => {
|
|
391
388
|
if (this.onDefineStructuredMode) {
|
|
392
|
-
this.onDefineStructuredMode(
|
|
389
|
+
this.onDefineStructuredMode(isStructured);
|
|
393
390
|
}
|
|
394
|
-
};
|
|
391
|
+
}))();
|
|
395
392
|
|
|
396
393
|
/**
|
|
397
394
|
* p2p数据流回调
|
|
@@ -427,6 +424,11 @@ export class SweeperP2p extends P2pApi {
|
|
|
427
424
|
return;
|
|
428
425
|
}
|
|
429
426
|
const cacheSerialNumber = this.packetSerialNumberCacheMap.get(fileName);
|
|
427
|
+
if (fileName.includes('cleanPath')) {
|
|
428
|
+
logger('info', {
|
|
429
|
+
msg: `receive a path package, ${fileSerialNumber}, ${packetIndex}, ${packetType}, ${cacheSerialNumber}}`
|
|
430
|
+
}, this.onLogger);
|
|
431
|
+
}
|
|
430
432
|
|
|
431
433
|
// 说明收到了过时包的数据
|
|
432
434
|
if (fileSerialNumber < cacheSerialNumber) return;
|
|
@@ -471,9 +473,11 @@ export class SweeperP2p extends P2pApi {
|
|
|
471
473
|
if (this.cacheData[type] !== hexValue) {
|
|
472
474
|
if (type === 0 || type === 6) {
|
|
473
475
|
this.onReceiveMapData(hexValue);
|
|
474
|
-
this.mapUpdateCount += 1;
|
|
475
476
|
}
|
|
476
477
|
if (type === 1) {
|
|
478
|
+
logger('info', {
|
|
479
|
+
msg: `push new path data`
|
|
480
|
+
}, this.onLogger);
|
|
477
481
|
this.onReceivePathData(hexValue);
|
|
478
482
|
}
|
|
479
483
|
if (type === 4) {
|
|
@@ -488,22 +492,6 @@ export class SweeperP2p extends P2pApi {
|
|
|
488
492
|
}
|
|
489
493
|
};
|
|
490
494
|
|
|
491
|
-
/**
|
|
492
|
-
* 单文件下载完成回调
|
|
493
|
-
* @param data
|
|
494
|
-
*/
|
|
495
|
-
fileDownloadProgressCallback = () => {
|
|
496
|
-
// console.log('fileDownloadProgressCallback', data);
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* 多文件下载进度监听
|
|
501
|
-
* @param data
|
|
502
|
-
*/
|
|
503
|
-
fileTotalDownloadProgressCallback = () => {
|
|
504
|
-
// console.log('fileTotalDownloadProgressCallback', data );
|
|
505
|
-
};
|
|
506
|
-
|
|
507
495
|
/**
|
|
508
496
|
* 从指定的文件路径获取文件
|
|
509
497
|
* @param fileName
|