@ray-js/robot-data-stream 0.0.12 → 0.0.13-beta-2

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.
@@ -62,6 +62,7 @@ export declare class SweeperP2p extends P2pApi {
62
62
  exitFiles: Array<string>;
63
63
  packetDataCacheMap: Map<keyof typeof FILE_NAME_MAP, Map<number, string>>;
64
64
  packetSerialNumberCacheMap: Map<keyof typeof FILE_NAME_MAP, number>;
65
+ fileLengthCacheMap: Map<keyof typeof FILE_NAME_MAP, number>;
65
66
  packetTotalMap: Map<keyof typeof FILE_NAME_MAP, number>;
66
67
  firstPackageTime: number;
67
68
  onReceiveMapData: (data: string) => void;
@@ -63,6 +63,7 @@ export class SweeperP2p extends P2pApi {
63
63
  this.firstPackageTime = Date.now();
64
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]]);
65
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]]);
66
+ this.fileLengthCacheMap = 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
67
  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()]]);
67
68
  }
68
69
  setStreamFilePath = () => {
@@ -386,6 +387,9 @@ export class SweeperP2p extends P2pApi {
386
387
  [...this.packetSerialNumberCacheMap.keys()].forEach(key => {
387
388
  this.packetSerialNumberCacheMap.set(key, -1);
388
389
  });
390
+ [...this.fileLengthCacheMap.keys()].forEach(key => {
391
+ this.fileLengthCacheMap.set(key, -1);
392
+ });
389
393
  [...this.packetTotalMap.keys()].forEach(key => {
390
394
  this.packetTotalMap.set(key, -1);
391
395
  });
@@ -431,6 +435,7 @@ export class SweeperP2p extends P2pApi {
431
435
  p2pStreamPacketReceiveCallback = data => {
432
436
  const {
433
437
  packetData,
438
+ fileLength,
434
439
  fileSerialNumber,
435
440
  packetIndex,
436
441
  packetType
@@ -465,6 +470,7 @@ export class SweeperP2p extends P2pApi {
465
470
  // 说明收到了新的整包数据
466
471
  if (fileSerialNumber > cacheSerialNumber) {
467
472
  this.packetSerialNumberCacheMap.set(fileName, fileSerialNumber);
473
+ this.fileLengthCacheMap.set(fileName, fileLength);
468
474
  this.packetTotalMap.set(fileName, -1);
469
475
  cachePacketMap.clear();
470
476
  }
@@ -485,6 +491,13 @@ export class SweeperP2p extends P2pApi {
485
491
  let [index, data] = _ref;
486
492
  return data;
487
493
  }).join('');
494
+ const cacheFileLength = this.fileLengthCacheMap.get(fileName);
495
+ if (cacheFileLength > 0 && hexValue.length !== cacheFileLength * 2) {
496
+ logger('warn', {
497
+ msg: `p2pStreamPacketReceiveCallback: fileName : ${fileName} length mismatch, expected: ${cacheFileLength * 2}, received: ${hexValue.length}`
498
+ }, this.onLogger);
499
+ return;
500
+ }
488
501
  if (this.firstPackageTime > 0 && fileName.indexOf('map') !== -1) {
489
502
  const packageTime = Date.now() - this.firstPackageTime;
490
503
  logger('info', {
package/lib/index.js CHANGED
@@ -28,7 +28,6 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
28
28
  }, onLogger);
29
29
  isAppOnBackground.current = true;
30
30
  if (isInit.current) {
31
- // 判断进入后台之后,维持定时器,如果进入后台超过2分钟, 则断开P2P
32
31
  timer.current = setTimeout(() => {
33
32
  logger('info', {
34
33
  msg: `background timer has been exe,isAppOnBackground: ${isAppOnBackground.current}`
@@ -45,6 +44,10 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
45
44
  logger('info', {
46
45
  msg: 'hooks onAppShow'
47
46
  }, onLogger);
47
+ logger('info', {
48
+ msg: `clear timer ${timer.current}`
49
+ }, onLogger);
50
+ isAppOnBackground.current = false;
48
51
  timer.current && clearTimeout(timer.current);
49
52
  setTimeout(() => {
50
53
  var _ty$p2p$isP2PActiveSy, _ty$p2p, _ty$p2p$isP2PActiveSy2, _ty$p2p2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/robot-data-stream",
3
- "version": "0.0.12",
3
+ "version": "0.0.13-beta-2",
4
4
  "description": "扫地机P2P数据流标准化组件",
5
5
  "main": "lib/index",
6
6
  "files": [