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

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.
Files changed (2) hide show
  1. package/lib/api/p2pApi.js +45 -26
  2. package/package.json +1 -1
package/lib/api/p2pApi.js CHANGED
@@ -25,35 +25,45 @@ export default class P2pApi {
25
25
  * 连接成功后设置flag为true
26
26
  * 并清除定时器
27
27
  */
28
- this.isConnected = false;
29
- if (!this.isConnected) {
28
+ // this.isConnected = false;
29
+ if (this.isConnected) {
30
+ return logger('info', {
31
+ msg: 'p2p isConnected or isConnecting'
32
+ }, this.onLogger);
33
+ }
34
+ if (this.isConnecting) {
35
+ return logger('info', {
36
+ msg: 'p2p isConnecting'
37
+ }, this.onLogger);
38
+ }
39
+ // if (!this.isConnected) {
40
+ logger('info', {
41
+ msg: `${source} start p2p reconnect ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
42
+ }, this.onLogger);
43
+ this.connectDevice(() => {
30
44
  logger('info', {
31
- msg: `${source} start p2p reconnect ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
45
+ msg: `${source} p2p reconnect success ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
32
46
  }, this.onLogger);
33
- this.connectDevice(() => {
34
- logger('info', {
35
- msg: `${source} p2p reconnect success ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
36
- }, this.onLogger);
37
- this.isConnected = true;
38
- if (this.isConnected) {
39
- typeof successCb === 'function' && successCb();
40
- }
41
- }, () => {
42
- //
43
- }, () => {
44
- logger('info', {
45
- msg: `${source} reconnect complete ==> ${String(this.isConnected)}`
47
+ this.isConnected = true;
48
+ if (this.isConnected) {
49
+ typeof successCb === 'function' && successCb();
50
+ }
51
+ }, () => {
52
+ //
53
+ }, () => {
54
+ logger('info', {
55
+ msg: `${source} reconnect complete ==> ${String(this.isConnected)}`
56
+ }, this.onLogger);
57
+ if (!this.isConnected) {
58
+ logger('warn', {
59
+ msg: `${source} p2p reconnect failed ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
46
60
  }, this.onLogger);
47
- if (!this.isConnected) {
48
- logger('warn', {
49
- msg: `${source} p2p reconnect failed ==> ${moment().format('YYYY-MM-DD HH:mm:ss')}`
50
- }, this.onLogger);
51
- setTimeout(() => {
52
- this.reconnectP2p(successCb, '0000');
53
- }, 6000);
54
- }
55
- });
56
- }
61
+ setTimeout(() => {
62
+ this.reconnectP2p(successCb, '0000');
63
+ }, 6000);
64
+ }
65
+ });
66
+ // }
57
67
  };
58
68
 
59
69
  /**
@@ -93,6 +103,8 @@ export default class P2pApi {
93
103
  connectDevice = (successCb, failCb, completeCb) => {
94
104
  return new Promise((resolve, reject) => {
95
105
  try {
106
+ this.isConnecting = true;
107
+ this.isConnected = false;
96
108
  p2p.connectDevice({
97
109
  deviceId: this.devId,
98
110
  timeout: 5000,
@@ -110,14 +122,18 @@ export default class P2pApi {
110
122
  logger('warn', {
111
123
  msg: `p2p connectDevice failed ==> ${JSON.stringify(params.innerError)}`
112
124
  }, this.onLogger);
125
+ this.isConnecting = false;
113
126
  typeof failCb === 'function' && failCb();
114
127
  resolve(false);
115
128
  },
116
129
  complete: () => {
130
+ this.isConnecting = false;
117
131
  typeof completeCb === 'function' && completeCb();
118
132
  }
119
133
  });
120
134
  } catch (e) {
135
+ this.isConnecting = false;
136
+ this.isConnected = false;
121
137
  logger('error', {
122
138
  msg: 'p2p connectDevice occur an error ==>',
123
139
  e
@@ -148,6 +164,9 @@ export default class P2pApi {
148
164
  msg: 'p2p disconnectDevice failed'
149
165
  }, this.onLogger);
150
166
  resolve(false);
167
+ },
168
+ complete: () => {
169
+ this.isConnecting = false;
151
170
  }
152
171
  });
153
172
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/robot-data-stream",
3
- "version": "0.0.12-beta-9",
3
+ "version": "0.0.12-beta-11",
4
4
  "description": "扫地机P2P数据流标准化组件",
5
5
  "main": "lib/index",
6
6
  "files": [