@ray-js/robot-data-stream 0.0.12-beta-8 → 0.0.12-beta-10
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 +1 -1
- package/lib/api/p2pApi.js +38 -27
- package/lib/api/sweeperP2p.js +28 -10
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/lib/api/p2pApi.d.ts
CHANGED
package/lib/api/p2pApi.js
CHANGED
|
@@ -19,41 +19,46 @@ 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
|
|
26
26
|
* 并清除定时器
|
|
27
27
|
*/
|
|
28
|
-
this.isConnected = false;
|
|
29
|
-
if (
|
|
28
|
+
// this.isConnected = false;
|
|
29
|
+
if (this.isConnected || this.isConnecting) {
|
|
30
|
+
return logger('info', {
|
|
31
|
+
msg: 'p2p isConnected or isConnecting'
|
|
32
|
+
}, this.onLogger);
|
|
33
|
+
}
|
|
34
|
+
// if (!this.isConnected) {
|
|
35
|
+
logger('info', {
|
|
36
|
+
msg: `${source} start p2p reconnect ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
|
|
37
|
+
}, this.onLogger);
|
|
38
|
+
this.connectDevice(() => {
|
|
30
39
|
logger('info', {
|
|
31
|
-
msg:
|
|
40
|
+
msg: `${source} p2p reconnect success ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
|
|
32
41
|
}, this.onLogger);
|
|
33
|
-
this.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
logger('
|
|
45
|
-
msg:
|
|
42
|
+
this.isConnected = true;
|
|
43
|
+
if (this.isConnected) {
|
|
44
|
+
typeof successCb === 'function' && successCb();
|
|
45
|
+
}
|
|
46
|
+
}, () => {
|
|
47
|
+
//
|
|
48
|
+
}, () => {
|
|
49
|
+
logger('info', {
|
|
50
|
+
msg: `${source} reconnect complete ==> ${String(this.isConnected)}`
|
|
51
|
+
}, this.onLogger);
|
|
52
|
+
if (!this.isConnected) {
|
|
53
|
+
logger('warn', {
|
|
54
|
+
msg: `${source} p2p reconnect failed ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
|
|
46
55
|
}, this.onLogger);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}, 3000);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
this.reconnectP2p(successCb, '0000');
|
|
58
|
+
}, 6000);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
// }
|
|
57
62
|
};
|
|
58
63
|
|
|
59
64
|
/**
|
|
@@ -93,6 +98,8 @@ export default class P2pApi {
|
|
|
93
98
|
connectDevice = (successCb, failCb, completeCb) => {
|
|
94
99
|
return new Promise((resolve, reject) => {
|
|
95
100
|
try {
|
|
101
|
+
this.isConnecting = true;
|
|
102
|
+
this.isConnected = false;
|
|
96
103
|
p2p.connectDevice({
|
|
97
104
|
deviceId: this.devId,
|
|
98
105
|
timeout: 5000,
|
|
@@ -114,6 +121,7 @@ export default class P2pApi {
|
|
|
114
121
|
resolve(false);
|
|
115
122
|
},
|
|
116
123
|
complete: () => {
|
|
124
|
+
this.isConnecting = false;
|
|
117
125
|
typeof completeCb === 'function' && completeCb();
|
|
118
126
|
}
|
|
119
127
|
});
|
|
@@ -148,6 +156,9 @@ export default class P2pApi {
|
|
|
148
156
|
msg: 'p2p disconnectDevice failed'
|
|
149
157
|
}, this.onLogger);
|
|
150
158
|
resolve(false);
|
|
159
|
+
},
|
|
160
|
+
complete: () => {
|
|
161
|
+
this.isConnecting = false;
|
|
151
162
|
}
|
|
152
163
|
});
|
|
153
164
|
} catch (e) {
|
package/lib/api/sweeperP2p.js
CHANGED
|
@@ -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:
|
|
280
|
+
msg: `${downloadType} p2p downloadStream success===>`
|
|
281
281
|
}, this.onLogger);
|
|
282
282
|
}, () => {
|
|
283
283
|
logger('error', {
|
|
284
|
-
msg:
|
|
284
|
+
msg: `${downloadType} p2p downloadStream failed and try reConnect Device===>`
|
|
285
285
|
}, this.onLogger);
|
|
286
286
|
this.removeP2pDownloadEvent();
|
|
287
|
-
this.disconnectDevice()
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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
|
|