@ray-js/robot-data-stream 0.0.12-beta-9 → 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.js +37 -26
- package/package.json +1 -1
package/lib/api/p2pApi.js
CHANGED
|
@@ -25,35 +25,40 @@ export default class P2pApi {
|
|
|
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: `${source}
|
|
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: `${source} reconnect
|
|
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
|
-
}, 6000);
|
|
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) {
|