@ray-js/robot-data-stream 0.0.12-beta-7 → 0.0.12-beta-9

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.
@@ -13,7 +13,7 @@ export default class P2pApi {
13
13
  /**
14
14
  * 设备断开之后的重连
15
15
  */
16
- reconnectP2p: (successCb?: () => void) => void;
16
+ reconnectP2p: (successCb?: () => void, source?: string) => void;
17
17
  /**
18
18
  * 初始化P2P SDK
19
19
  * @param id 用户Id
package/lib/api/p2pApi.js CHANGED
@@ -19,7 +19,7 @@ export default class P2pApi {
19
19
  /**
20
20
  * 设备断开之后的重连
21
21
  */
22
- reconnectP2p = successCb => {
22
+ reconnectP2p = (successCb, source) => {
23
23
  /**
24
24
  * 监听到断开事件后
25
25
  * 连接成功后设置flag为true
@@ -28,11 +28,11 @@ export default class P2pApi {
28
28
  this.isConnected = false;
29
29
  if (!this.isConnected) {
30
30
  logger('info', {
31
- msg: `start p2p reconnect ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
31
+ msg: `${source} start p2p reconnect ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
32
32
  }, this.onLogger);
33
33
  this.connectDevice(() => {
34
34
  logger('info', {
35
- msg: `p2p reconnect success ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
35
+ msg: `${source} p2p reconnect success ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
36
36
  }, this.onLogger);
37
37
  this.isConnected = true;
38
38
  if (this.isConnected) {
@@ -42,15 +42,15 @@ export default class P2pApi {
42
42
  //
43
43
  }, () => {
44
44
  logger('info', {
45
- msg: `reconnect complete ==> ${String(this.isConnected)}`
45
+ msg: `${source} reconnect complete ==> ${String(this.isConnected)}`
46
46
  }, this.onLogger);
47
47
  if (!this.isConnected) {
48
48
  logger('warn', {
49
- msg: `p2p reconnect failed ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
49
+ msg: `${source} p2p reconnect failed ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
50
50
  }, this.onLogger);
51
51
  setTimeout(() => {
52
- this.reconnectP2p(successCb);
53
- }, 3000);
52
+ this.reconnectP2p(successCb, '0000');
53
+ }, 6000);
54
54
  }
55
55
  });
56
56
  }
@@ -216,7 +216,7 @@ export class SweeperP2p extends P2pApi {
216
216
  this.reconnectP2p(() => {
217
217
  // 重连之后重新开启文件下载, 这里的成功不需要注册断开事件
218
218
  this.startObserverSweeperDataByP2P(this.downloadType, this.devId, this.onReceiveMapData, this.onReceivePathData, this.onReceiveAIPicData, this.onReceiveAIPicHDData);
219
- });
219
+ }, '1111');
220
220
  } else {
221
221
  logger('warn', {
222
222
  msg: 'receive disconnect notice, but connectDevice is connecting'
@@ -277,19 +277,20 @@ export class SweeperP2p extends P2pApi {
277
277
  files: exitFiles
278
278
  }, this.albumName, () => {
279
279
  logger('info', {
280
- msg: 'p2p downloadStream success===>'
280
+ msg: `${downloadType} p2p downloadStream success===>`
281
281
  }, this.onLogger);
282
282
  }, () => {
283
283
  logger('error', {
284
- msg: 'p2p downloadStream failed and try reConnect Device===>'
284
+ msg: `${downloadType} p2p downloadStream failed and try reConnect Device===>`
285
285
  }, this.onLogger);
286
286
  this.removeP2pDownloadEvent();
287
- this.disconnectDevice();
288
- this.isConnected = false;
289
- this.isConnecting = false;
290
- this.reconnectP2p(() => {
291
- // 重连之后重新开启文件下载, 这里的成功不需要注册断开事件
292
- this.startObserverSweeperDataByP2P(this.downloadType, this.devId, this.onReceiveMapData, this.onReceivePathData, this.onReceiveAIPicData, this.onReceiveAIPicHDData);
287
+ this.disconnectDevice().then(() => {
288
+ this.isConnected = false;
289
+ this.isConnecting = false;
290
+ this.connectDevice(() => {
291
+ // 重连之后重新开启文件下载, 这里的成功不需要注册断开事件
292
+ this.startObserverSweeperDataByP2P(this.downloadType, this.devId, this.onReceiveMapData, this.onReceivePathData, this.onReceiveAIPicData, this.onReceiveAIPicHDData);
293
+ });
293
294
  });
294
295
  });
295
296
  } else if (await this.initFilePath(this.dataFilePath)) {
@@ -308,7 +309,24 @@ export class SweeperP2p extends P2pApi {
308
309
  // 开启p2p流传输
309
310
  await this.downloadStream({
310
311
  files: exitFiles
311
- }, this.albumName);
312
+ }, this.albumName, () => {
313
+ logger('info', {
314
+ msg: `${downloadType} p2p downloadStream success===>`
315
+ }, this.onLogger);
316
+ }, () => {
317
+ logger('error', {
318
+ msg: `${downloadType} p2p downloadStream failed and try reConnect Device===>`
319
+ }, this.onLogger);
320
+ this.removeP2pDownloadEvent();
321
+ this.disconnectDevice().then(() => {
322
+ this.isConnected = false;
323
+ this.isConnecting = false;
324
+ this.connectDevice(() => {
325
+ // 重连之后重新开启文件下载, 这里的成功不需要注册断开事件
326
+ this.startObserverSweeperDataByP2P(this.downloadType, this.devId, this.onReceiveMapData, this.onReceivePathData, this.onReceiveAIPicData, this.onReceiveAIPicHDData);
327
+ });
328
+ });
329
+ });
312
330
  } else if (await this.initFilePath(this.streamFilePath)) {
313
331
  // 每次要下载前都需要先检查文件目录是否存在 防止中间过程被删除掉文件目录
314
332
  await this.downloadFile({
package/lib/index.js CHANGED
@@ -134,7 +134,7 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
134
134
  SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData);
135
135
  // 这里失败重连需要注册断开重连的事件
136
136
  offSessionStatusChange.current = SweeperP2pInstance.onSessionStatusChange(SweeperP2pInstance.sessionStatusCallback);
137
- });
137
+ }, '22222');
138
138
  });
139
139
  };
140
140
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/robot-data-stream",
3
- "version": "0.0.12-beta-7",
3
+ "version": "0.0.12-beta-9",
4
4
  "description": "扫地机P2P数据流标准化组件",
5
5
  "main": "lib/index",
6
6
  "files": [