@ray-js/robot-data-stream 0.0.13-beta-6 → 0.0.13-beta-7
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/index.d.ts +12 -2
- package/lib/api/index.js +172 -1
- package/lib/api/p2pApi.d.ts +27 -8
- package/lib/api/p2pApi.js +169 -271
- package/lib/api/sweeperP2p.d.ts +21 -54
- package/lib/api/sweeperP2p.js +245 -324
- package/lib/constant.d.ts +52 -0
- package/lib/constant.js +54 -0
- package/lib/index.d.ts +1 -11
- package/lib/index.js +2 -166
- package/lib/mqtt/createCommonOptions.d.ts +56 -15
- package/lib/mqtt/createCommonOptions.js +44 -8
- package/lib/mqtt/mqttProvider.d.ts +23 -15
- package/lib/mqtt/mqttProvider.js +63 -26
- package/lib/mqtt/promise.js +8 -3
- package/lib/mqtt/type/index.d.ts +9 -0
- package/lib/mqtt/type/index.js +8 -0
- package/lib/mqtt/type/requestType.d.ts +3 -0
- package/lib/mqtt/type/requestType.js +4 -0
- package/lib/mqtt/useDevInfo.d.ts +2 -7
- package/lib/mqtt/useDevInfo.js +25 -9
- package/lib/mqtt/useHistoryMap.d.ts +13 -21
- package/lib/mqtt/useHistoryMap.js +82 -32
- package/lib/mqtt/usePartDivision.d.ts +5 -7
- package/lib/mqtt/usePartDivision.js +41 -16
- package/lib/mqtt/usePartMerge.d.ts +5 -7
- package/lib/mqtt/usePartMerge.js +36 -18
- package/lib/mqtt/usePassword.js +59 -28
- package/lib/mqtt/useQuiteHours.d.ts +9 -24
- package/lib/mqtt/useQuiteHours.js +95 -52
- package/lib/mqtt/useResetMap.d.ts +10 -7
- package/lib/mqtt/useResetMap.js +40 -11
- package/lib/mqtt/useRoomProperty.js +23 -16
- package/lib/mqtt/useSchedule.d.ts +17 -4
- package/lib/mqtt/useSchedule.js +101 -49
- package/lib/mqtt/useSelectRoomClean.d.ts +20 -16
- package/lib/mqtt/useSelectRoomClean.js +145 -49
- package/lib/mqtt/useSpotClean.d.ts +3 -3
- package/lib/mqtt/useSpotClean.js +71 -50
- package/lib/mqtt/useVirtualArea.d.ts +6 -9
- package/lib/mqtt/useVirtualArea.js +112 -42
- package/lib/mqtt/useVirtualWall.d.ts +13 -10
- package/lib/mqtt/useVirtualWall.js +97 -34
- package/lib/mqtt/useVoice.d.ts +3 -6
- package/lib/mqtt/useVoice.js +73 -33
- package/lib/mqtt/useWifiMap.js +34 -18
- package/lib/mqtt/useZoneClean.d.ts +13 -13
- package/lib/mqtt/useZoneClean.js +149 -76
- package/lib/ttt/index.d.ts +153 -0
- package/lib/ttt/index.js +458 -0
- package/lib/utils/index.d.ts +20 -1
- package/lib/utils/index.js +19 -0
- package/package.json +1 -1
- package/lib/mqtt/myError.d.ts +0 -4
- package/lib/mqtt/myError.js +0 -6
package/lib/api/p2pApi.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
/* eslint-disable consistent-return */
|
|
2
|
-
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
3
|
-
/* eslint-disable prefer-promise-reject-errors */
|
|
4
1
|
import { p2p } from '@ray-js/ray';
|
|
5
2
|
import dayjs from 'dayjs';
|
|
6
|
-
import { logger } from '../utils';
|
|
7
3
|
import { trace } from '../trace';
|
|
4
|
+
import { apis } from '../ttt';
|
|
5
|
+
import { createLogger } from '../utils';
|
|
6
|
+
|
|
8
7
|
/**
|
|
9
8
|
* P2P 工具类
|
|
10
9
|
*/
|
|
@@ -16,6 +15,14 @@ export default class P2pApi {
|
|
|
16
15
|
this.isConnecting = false;
|
|
17
16
|
}
|
|
18
17
|
|
|
18
|
+
/**
|
|
19
|
+
* 便捷的日志记录方法
|
|
20
|
+
* 使用 getter 确保每次访问时都使用最新的 onLogger
|
|
21
|
+
*/
|
|
22
|
+
get log() {
|
|
23
|
+
return createLogger(this.onLogger);
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
/**
|
|
20
27
|
* 设备断开之后的重连
|
|
21
28
|
*/
|
|
@@ -27,23 +34,23 @@ export default class P2pApi {
|
|
|
27
34
|
*/
|
|
28
35
|
// this.isConnected = false;
|
|
29
36
|
if (this.isConnected) {
|
|
30
|
-
return
|
|
37
|
+
return this.log.info({
|
|
31
38
|
msg: 'p2p isConnected or isConnecting'
|
|
32
|
-
}
|
|
39
|
+
});
|
|
33
40
|
}
|
|
34
41
|
if (this.isConnecting) {
|
|
35
|
-
return
|
|
42
|
+
return this.log.info({
|
|
36
43
|
msg: 'p2p isConnecting'
|
|
37
|
-
}
|
|
44
|
+
});
|
|
38
45
|
}
|
|
39
46
|
// if (!this.isConnected) {
|
|
40
|
-
|
|
47
|
+
this.log.info({
|
|
41
48
|
msg: `${source} start p2p reconnect ==> ${dayjs().format('YYYY-MM-DD HH:mm:ss')}`
|
|
42
|
-
}
|
|
49
|
+
});
|
|
43
50
|
this.connectDevice(() => {
|
|
44
|
-
|
|
51
|
+
this.log.info({
|
|
45
52
|
msg: `${source} p2p reconnect success ==> ${dayjs().format('YYYY-MM-DD HH:mm:ss')}`
|
|
46
|
-
}
|
|
53
|
+
});
|
|
47
54
|
this.isConnected = true;
|
|
48
55
|
if (this.isConnected) {
|
|
49
56
|
typeof successCb === 'function' && successCb();
|
|
@@ -51,13 +58,13 @@ export default class P2pApi {
|
|
|
51
58
|
}, () => {
|
|
52
59
|
//
|
|
53
60
|
}, () => {
|
|
54
|
-
|
|
61
|
+
this.log.info({
|
|
55
62
|
msg: `${source} reconnect complete ==> ${String(this.isConnected)}`
|
|
56
|
-
}
|
|
63
|
+
});
|
|
57
64
|
if (!this.isConnected) {
|
|
58
|
-
|
|
65
|
+
this.log.warn({
|
|
59
66
|
msg: `${source} p2p reconnect failed ==> ${dayjs().format('YYYY-MM-DD HH:mm:ss')}`
|
|
60
|
-
}
|
|
67
|
+
});
|
|
61
68
|
setTimeout(() => {
|
|
62
69
|
this.reconnectP2p(successCb, '0000');
|
|
63
70
|
}, 6000);
|
|
@@ -72,111 +79,82 @@ export default class P2pApi {
|
|
|
72
79
|
* @returns
|
|
73
80
|
*/
|
|
74
81
|
initP2pSdk = async devId => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}, this.onLogger);
|
|
90
|
-
resolve(false);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
} catch (e) {
|
|
94
|
-
reject(false);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
82
|
+
try {
|
|
83
|
+
this.devId = devId;
|
|
84
|
+
const result = await apis.initP2pSdk(this.onLogger);
|
|
85
|
+
return result;
|
|
86
|
+
} catch (e) {
|
|
87
|
+
this.log.error({
|
|
88
|
+
msg: 'P2PSDKInit occur an error',
|
|
89
|
+
e
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
error: e
|
|
94
|
+
};
|
|
95
|
+
}
|
|
97
96
|
};
|
|
98
97
|
|
|
99
98
|
/**
|
|
100
99
|
* 连接设备
|
|
101
100
|
* @returns
|
|
102
101
|
*/
|
|
103
|
-
connectDevice = (successCb, failCb, completeCb) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
timeout: 5000,
|
|
111
|
-
mode: 0,
|
|
112
|
-
success: () => {
|
|
113
|
-
logger('info', {
|
|
114
|
-
msg: 'p2p connectDevice success'
|
|
115
|
-
}, this.onLogger);
|
|
116
|
-
this.isConnected = true;
|
|
117
|
-
this.isConnecting = false;
|
|
118
|
-
typeof successCb === 'function' && successCb();
|
|
119
|
-
resolve(true);
|
|
120
|
-
},
|
|
121
|
-
fail: params => {
|
|
122
|
-
logger('warn', {
|
|
123
|
-
msg: `p2p connectDevice failed ==> ${JSON.stringify(params.innerError)}`
|
|
124
|
-
}, this.onLogger);
|
|
125
|
-
this.isConnecting = false;
|
|
126
|
-
typeof failCb === 'function' && failCb();
|
|
127
|
-
resolve(false);
|
|
128
|
-
},
|
|
129
|
-
complete: () => {
|
|
130
|
-
this.isConnecting = false;
|
|
131
|
-
typeof completeCb === 'function' && completeCb();
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
} catch (e) {
|
|
102
|
+
connectDevice = async (successCb, failCb, completeCb) => {
|
|
103
|
+
try {
|
|
104
|
+
this.isConnecting = true;
|
|
105
|
+
this.isConnected = false;
|
|
106
|
+
const result = await apis.connectDevice(this.devId, this.onLogger);
|
|
107
|
+
if (result.success) {
|
|
108
|
+
this.isConnected = true;
|
|
135
109
|
this.isConnecting = false;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
110
|
+
typeof successCb === 'function' && successCb();
|
|
111
|
+
typeof completeCb === 'function' && completeCb();
|
|
112
|
+
return true;
|
|
113
|
+
} else {
|
|
114
|
+
result.params || result.error;
|
|
115
|
+
this.isConnecting = false;
|
|
116
|
+
typeof failCb === 'function' && failCb();
|
|
117
|
+
typeof completeCb === 'function' && completeCb();
|
|
118
|
+
return false;
|
|
142
119
|
}
|
|
143
|
-
})
|
|
120
|
+
} catch (e) {
|
|
121
|
+
this.isConnecting = false;
|
|
122
|
+
this.isConnected = false;
|
|
123
|
+
this.log.error({
|
|
124
|
+
msg: 'p2p connectDevice occur an error ==>',
|
|
125
|
+
e
|
|
126
|
+
});
|
|
127
|
+
typeof failCb === 'function' && failCb();
|
|
128
|
+
typeof completeCb === 'function' && completeCb();
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
144
131
|
};
|
|
145
132
|
|
|
146
133
|
/**
|
|
147
134
|
* 断开P2P设备连接
|
|
148
135
|
* @returns
|
|
149
136
|
*/
|
|
150
|
-
disconnectDevice = () => {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
msg: 'p2p disconnectDevice success'
|
|
159
|
-
}, this.onLogger);
|
|
160
|
-
resolve(true);
|
|
161
|
-
},
|
|
162
|
-
fail: () => {
|
|
163
|
-
logger('warn', {
|
|
164
|
-
msg: 'p2p disconnectDevice failed'
|
|
165
|
-
}, this.onLogger);
|
|
166
|
-
resolve(false);
|
|
167
|
-
},
|
|
168
|
-
complete: () => {
|
|
169
|
-
this.isConnecting = false;
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
} catch (e) {
|
|
173
|
-
logger('warn', {
|
|
174
|
-
msg: 'p2p disconnectDevice occur an error ==>',
|
|
175
|
-
e
|
|
176
|
-
}, this.onLogger);
|
|
177
|
-
reject(false);
|
|
137
|
+
disconnectDevice = async () => {
|
|
138
|
+
try {
|
|
139
|
+
const result = await apis.disconnectDevice(this.devId, this.onLogger);
|
|
140
|
+
if (result.success) {
|
|
141
|
+
this.isConnected = false;
|
|
142
|
+
this.isConnecting = false;
|
|
143
|
+
} else {
|
|
144
|
+
this.isConnecting = false;
|
|
178
145
|
}
|
|
179
|
-
|
|
146
|
+
return result;
|
|
147
|
+
} catch (e) {
|
|
148
|
+
this.isConnecting = false;
|
|
149
|
+
this.log.warn({
|
|
150
|
+
msg: 'p2p disconnectDevice occur an error ==>',
|
|
151
|
+
e
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
success: false,
|
|
155
|
+
error: e
|
|
156
|
+
};
|
|
157
|
+
}
|
|
180
158
|
};
|
|
181
159
|
|
|
182
160
|
/**
|
|
@@ -188,50 +166,33 @@ export default class P2pApi {
|
|
|
188
166
|
* @param failedCb
|
|
189
167
|
* @returns
|
|
190
168
|
*/
|
|
191
|
-
downloadStream = (files, albumName, successCb, failedCb) => {
|
|
169
|
+
downloadStream = async (files, albumName, successCb, failedCb) => {
|
|
192
170
|
try {
|
|
193
171
|
if (this.isConnected) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
success: () => {
|
|
200
|
-
logger('info', {
|
|
201
|
-
msg: 'p2p downloadStream success'
|
|
202
|
-
}, this.onLogger);
|
|
203
|
-
trace.pointFn({
|
|
204
|
-
devId: this.devId,
|
|
205
|
-
eventName: 'downloadStream'
|
|
206
|
-
});
|
|
207
|
-
typeof successCb === 'function' && successCb();
|
|
208
|
-
resolve(true);
|
|
209
|
-
},
|
|
210
|
-
fail: params => {
|
|
211
|
-
logger('warn', {
|
|
212
|
-
msg: 'p2p downloadStream failed===>',
|
|
213
|
-
params
|
|
214
|
-
}, this.onLogger);
|
|
215
|
-
trace.pointFn({
|
|
216
|
-
devId: this.devId,
|
|
217
|
-
eventName: 'downloadStreamFailed'
|
|
218
|
-
});
|
|
219
|
-
setTimeout(() => {
|
|
220
|
-
typeof failedCb === 'function' && failedCb();
|
|
221
|
-
}, 500);
|
|
222
|
-
resolve(false);
|
|
223
|
-
},
|
|
224
|
-
complete: () => {
|
|
225
|
-
//
|
|
226
|
-
}
|
|
172
|
+
const result = await apis.downloadStream(this.devId, albumName, files.files, this.onLogger);
|
|
173
|
+
if (result.success) {
|
|
174
|
+
trace.pointFn({
|
|
175
|
+
devId: this.devId,
|
|
176
|
+
eventName: 'downloadStream'
|
|
227
177
|
});
|
|
228
|
-
|
|
178
|
+
typeof successCb === 'function' && successCb();
|
|
179
|
+
} else {
|
|
180
|
+
trace.pointFn({
|
|
181
|
+
devId: this.devId,
|
|
182
|
+
eventName: 'downloadStreamFailed'
|
|
183
|
+
});
|
|
184
|
+
setTimeout(() => {
|
|
185
|
+
typeof failedCb === 'function' && failedCb();
|
|
186
|
+
}, 500);
|
|
187
|
+
}
|
|
188
|
+
return result.success;
|
|
229
189
|
}
|
|
230
190
|
} catch (e) {
|
|
231
|
-
|
|
191
|
+
this.log.warn({
|
|
232
192
|
msg: 'p2p downloadStream occur an error ==>',
|
|
233
193
|
e
|
|
234
|
-
}
|
|
194
|
+
});
|
|
195
|
+
return false;
|
|
235
196
|
}
|
|
236
197
|
};
|
|
237
198
|
|
|
@@ -243,42 +204,27 @@ export default class P2pApi {
|
|
|
243
204
|
* @param failedCb
|
|
244
205
|
* @returns
|
|
245
206
|
*/
|
|
246
|
-
appendDownloadStream = (files, albumName, successCb, failedCb) => {
|
|
207
|
+
appendDownloadStream = async (files, albumName, successCb, failedCb) => {
|
|
247
208
|
try {
|
|
248
209
|
if (this.isConnected) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
},
|
|
261
|
-
fail: params => {
|
|
262
|
-
logger('warn', {
|
|
263
|
-
msg: 'p2p appendDownloadStream failed===>',
|
|
264
|
-
params
|
|
265
|
-
}, this.onLogger);
|
|
266
|
-
setTimeout(() => {
|
|
267
|
-
typeof failedCb === 'function' && failedCb();
|
|
268
|
-
}, 500);
|
|
269
|
-
resolve(false);
|
|
270
|
-
},
|
|
271
|
-
complete: () => {
|
|
272
|
-
//
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
});
|
|
210
|
+
const {
|
|
211
|
+
success
|
|
212
|
+
} = await apis.appendDownloadStream(this.devId, albumName, files.files, this.onLogger);
|
|
213
|
+
if (success) {
|
|
214
|
+
typeof successCb === 'function' && successCb();
|
|
215
|
+
} else {
|
|
216
|
+
setTimeout(() => {
|
|
217
|
+
typeof failedCb === 'function' && failedCb();
|
|
218
|
+
}, 500);
|
|
219
|
+
}
|
|
220
|
+
return success;
|
|
276
221
|
}
|
|
277
222
|
} catch (e) {
|
|
278
|
-
|
|
223
|
+
this.log.warn({
|
|
279
224
|
msg: 'p2p appendDownloadStream failed===>',
|
|
280
225
|
e
|
|
281
|
-
}
|
|
226
|
+
});
|
|
227
|
+
return false;
|
|
282
228
|
}
|
|
283
229
|
};
|
|
284
230
|
|
|
@@ -299,43 +245,25 @@ export default class P2pApi {
|
|
|
299
245
|
* 开始下载文件
|
|
300
246
|
* files : {"files":["filesname1", "filesname2", "filesname3" ]}
|
|
301
247
|
*/
|
|
302
|
-
downloadFile = (files, albumName, filePath, successCb, failedCb) => {
|
|
248
|
+
downloadFile = async (files, albumName, filePath, successCb, failedCb) => {
|
|
303
249
|
try {
|
|
304
250
|
if (this.isConnected) {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
typeof successCb === 'function' && successCb();
|
|
316
|
-
resolve(true);
|
|
317
|
-
},
|
|
318
|
-
fail: params => {
|
|
319
|
-
logger('warn', {
|
|
320
|
-
msg: 'p2p downloadFile success',
|
|
321
|
-
params
|
|
322
|
-
}, this.onLogger);
|
|
323
|
-
setTimeout(() => {
|
|
324
|
-
typeof failedCb === 'function' && failedCb();
|
|
325
|
-
}, 500);
|
|
326
|
-
resolve(false);
|
|
327
|
-
},
|
|
328
|
-
complete: () => {
|
|
329
|
-
//
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
});
|
|
251
|
+
const result = await apis.downloadFile(this.devId, albumName, filePath, files.files, this.onLogger);
|
|
252
|
+
if (result.success) {
|
|
253
|
+
typeof successCb === 'function' && successCb();
|
|
254
|
+
return true;
|
|
255
|
+
} else {
|
|
256
|
+
setTimeout(() => {
|
|
257
|
+
typeof failedCb === 'function' && failedCb();
|
|
258
|
+
}, 500);
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
333
261
|
}
|
|
334
262
|
} catch (e) {
|
|
335
|
-
|
|
263
|
+
this.log.error({
|
|
336
264
|
msg: 'p2p downloadFile occur an error ==>',
|
|
337
265
|
e
|
|
338
|
-
}
|
|
266
|
+
});
|
|
339
267
|
}
|
|
340
268
|
return null;
|
|
341
269
|
};
|
|
@@ -396,26 +324,20 @@ export default class P2pApi {
|
|
|
396
324
|
* 取消进行下载
|
|
397
325
|
* @returns
|
|
398
326
|
*/
|
|
399
|
-
cancelDownloadTask = () => {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
msg: 'cancelDownloadTask occur an error',
|
|
414
|
-
e
|
|
415
|
-
}, this.onLogger);
|
|
416
|
-
reject(false);
|
|
417
|
-
}
|
|
418
|
-
});
|
|
327
|
+
cancelDownloadTask = async () => {
|
|
328
|
+
try {
|
|
329
|
+
const result = await apis.cancelDownloadTask(this.devId, this.onLogger);
|
|
330
|
+
return result;
|
|
331
|
+
} catch (e) {
|
|
332
|
+
this.log.error({
|
|
333
|
+
msg: 'cancelDownloadTask occur an error',
|
|
334
|
+
e
|
|
335
|
+
});
|
|
336
|
+
return {
|
|
337
|
+
success: false,
|
|
338
|
+
error: e
|
|
339
|
+
};
|
|
340
|
+
}
|
|
419
341
|
};
|
|
420
342
|
|
|
421
343
|
/**
|
|
@@ -423,27 +345,17 @@ export default class P2pApi {
|
|
|
423
345
|
* @param albumName
|
|
424
346
|
* @returns
|
|
425
347
|
*/
|
|
426
|
-
queryAlbumFileIndexs = albumName => {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
params
|
|
435
|
-
}, this.onLogger);
|
|
436
|
-
resolve(params);
|
|
437
|
-
},
|
|
438
|
-
fail: params => {
|
|
439
|
-
logger('warn', {
|
|
440
|
-
msg: 'queryAlbumFileIndexs failed ==>',
|
|
441
|
-
params
|
|
442
|
-
}, this.onLogger);
|
|
443
|
-
resolve(null);
|
|
444
|
-
}
|
|
348
|
+
queryAlbumFileIndexs = async albumName => {
|
|
349
|
+
try {
|
|
350
|
+
const result = await apis.queryAlbumFileIndexs(this.devId, albumName, this.onLogger);
|
|
351
|
+
return result;
|
|
352
|
+
} catch (e) {
|
|
353
|
+
this.log.error({
|
|
354
|
+
msg: 'queryAlbumFileIndexs occur an error',
|
|
355
|
+
e
|
|
445
356
|
});
|
|
446
|
-
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
447
359
|
};
|
|
448
360
|
|
|
449
361
|
/**
|
|
@@ -451,32 +363,18 @@ export default class P2pApi {
|
|
|
451
363
|
* @returns
|
|
452
364
|
*/
|
|
453
365
|
deInitP2PSDK = async () => {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
resolve(false);
|
|
468
|
-
},
|
|
469
|
-
complete: () => {
|
|
470
|
-
resolve(true);
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
|
-
} catch (e) {
|
|
474
|
-
logger('error', {
|
|
475
|
-
msg: 'deInitP2pSDK occur an error ==>',
|
|
476
|
-
e
|
|
477
|
-
}, this.onLogger);
|
|
478
|
-
reject(false);
|
|
479
|
-
}
|
|
480
|
-
});
|
|
366
|
+
try {
|
|
367
|
+
const result = await apis.deInitP2pSdk(this.onLogger);
|
|
368
|
+
return result;
|
|
369
|
+
} catch (e) {
|
|
370
|
+
this.log.error({
|
|
371
|
+
msg: 'deInitP2pSDK occur an error ==>',
|
|
372
|
+
e
|
|
373
|
+
});
|
|
374
|
+
return {
|
|
375
|
+
success: false,
|
|
376
|
+
error: e
|
|
377
|
+
};
|
|
378
|
+
}
|
|
481
379
|
};
|
|
482
380
|
}
|
package/lib/api/sweeperP2p.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FileNameEnum } from '../constant';
|
|
1
2
|
import P2pApi from './p2pApi';
|
|
2
3
|
/**
|
|
3
4
|
* 基于P2p工具类的扫地机扩展实现
|
|
@@ -11,44 +12,6 @@ interface FileInfo {
|
|
|
11
12
|
idx: number;
|
|
12
13
|
type: number;
|
|
13
14
|
}
|
|
14
|
-
declare const FILE_NAME_MAP: {
|
|
15
|
-
readonly 'map.bin': {
|
|
16
|
-
readonly type: 0;
|
|
17
|
-
};
|
|
18
|
-
readonly 'map_structured.bin': {
|
|
19
|
-
readonly type: 6;
|
|
20
|
-
};
|
|
21
|
-
readonly 'cleanPath.bin': {
|
|
22
|
-
readonly type: 1;
|
|
23
|
-
};
|
|
24
|
-
readonly 'map.bin.stream': {
|
|
25
|
-
readonly type: 0;
|
|
26
|
-
};
|
|
27
|
-
readonly 'map_structured.bin.stream': {
|
|
28
|
-
readonly type: 6;
|
|
29
|
-
};
|
|
30
|
-
readonly 'cleanPath.bin.stream': {
|
|
31
|
-
readonly type: 1;
|
|
32
|
-
};
|
|
33
|
-
readonly 'ai.bin': {
|
|
34
|
-
readonly type: 4;
|
|
35
|
-
};
|
|
36
|
-
readonly 'ai.bin.stream': {
|
|
37
|
-
readonly type: 4;
|
|
38
|
-
};
|
|
39
|
-
readonly 'aiHD_XXXX_YYYY.bin': {
|
|
40
|
-
readonly type: 5;
|
|
41
|
-
};
|
|
42
|
-
readonly 'aiHD_XXXX_YYYY.bin.stream': {
|
|
43
|
-
readonly type: 5;
|
|
44
|
-
};
|
|
45
|
-
readonly 'wifi_map.bin': {
|
|
46
|
-
readonly type: 7;
|
|
47
|
-
};
|
|
48
|
-
readonly 'wifi_map.bin.stream': {
|
|
49
|
-
readonly type: 7;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
15
|
export declare class SweeperP2p extends P2pApi {
|
|
53
16
|
file: {
|
|
54
17
|
items: Array<FileInfo>;
|
|
@@ -66,10 +29,10 @@ export declare class SweeperP2p extends P2pApi {
|
|
|
66
29
|
fileIndex: number;
|
|
67
30
|
cacheData: any;
|
|
68
31
|
exitFiles: Array<string>;
|
|
69
|
-
packetDataCacheMap: Map<
|
|
70
|
-
packetSerialNumberCacheMap: Map<
|
|
71
|
-
fileLengthCacheMap: Map<
|
|
72
|
-
packetTotalMap: Map<
|
|
32
|
+
packetDataCacheMap: Map<FileNameEnum, Map<number, string>>;
|
|
33
|
+
packetSerialNumberCacheMap: Map<FileNameEnum, number>;
|
|
34
|
+
fileLengthCacheMap: Map<FileNameEnum, number>;
|
|
35
|
+
packetTotalMap: Map<FileNameEnum, number>;
|
|
73
36
|
firstPackageTime: number;
|
|
74
37
|
onReceiveMapData: (data: string) => void;
|
|
75
38
|
onReceivePathData: (data: string) => void;
|
|
@@ -96,18 +59,6 @@ export declare class SweeperP2p extends P2pApi {
|
|
|
96
59
|
* @returns
|
|
97
60
|
*/
|
|
98
61
|
private getDataFilePath;
|
|
99
|
-
/**
|
|
100
|
-
* 创建文件路径文件夹
|
|
101
|
-
* @param filePath
|
|
102
|
-
* @returns
|
|
103
|
-
*/
|
|
104
|
-
private createFilePath;
|
|
105
|
-
/**
|
|
106
|
-
* 检查当前文件目录是否存在
|
|
107
|
-
* @param filePath
|
|
108
|
-
* @returns
|
|
109
|
-
*/
|
|
110
|
-
private checkIfDirIsExist;
|
|
111
62
|
/**
|
|
112
63
|
* 初始化文件目录
|
|
113
64
|
* @param filePath
|
|
@@ -119,6 +70,10 @@ export declare class SweeperP2p extends P2pApi {
|
|
|
119
70
|
* @param filename
|
|
120
71
|
*/
|
|
121
72
|
private getFileType;
|
|
73
|
+
/**
|
|
74
|
+
* 根据文件类型处理数据并调用相应的回调函数
|
|
75
|
+
*/
|
|
76
|
+
private handleDataByType;
|
|
122
77
|
/**
|
|
123
78
|
* 设备连接状态发生改变
|
|
124
79
|
* @param data
|
|
@@ -127,6 +82,14 @@ export declare class SweeperP2p extends P2pApi {
|
|
|
127
82
|
deviceId: string;
|
|
128
83
|
status: number;
|
|
129
84
|
}) => void;
|
|
85
|
+
/**
|
|
86
|
+
* 创建下载失败时的重连回调函数
|
|
87
|
+
*/
|
|
88
|
+
private createReconnectCallback;
|
|
89
|
+
/**
|
|
90
|
+
* 执行文件下载逻辑
|
|
91
|
+
*/
|
|
92
|
+
private executeDownload;
|
|
130
93
|
/**
|
|
131
94
|
* 开始进行文件下载
|
|
132
95
|
* @param downloadType
|
|
@@ -166,6 +129,10 @@ export declare class SweeperP2p extends P2pApi {
|
|
|
166
129
|
* @param filePath
|
|
167
130
|
*/
|
|
168
131
|
private readFileFromPath;
|
|
132
|
+
/**
|
|
133
|
+
* 根据文件名获取对应的 reading 状态标志
|
|
134
|
+
*/
|
|
135
|
+
private getReadingFlag;
|
|
169
136
|
private setReading;
|
|
170
137
|
private resetReading;
|
|
171
138
|
/**
|