@ray-js/robot-data-stream 0.0.3 → 0.0.4
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/README.md +19 -26
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.js +1 -1
- package/lib/api/p2pApi.d.ts +0 -11
- package/lib/api/p2pApi.js +0 -37
- package/lib/api/sweeperP2p.d.ts +8 -26
- package/lib/api/sweeperP2p.js +26 -83
- package/lib/index.d.ts +3 -3
- package/lib/index.js +10 -7
- package/package.json +4 -6
package/README.md
CHANGED
|
@@ -26,43 +26,36 @@ yarn start:tuya
|
|
|
26
26
|
## Usage
|
|
27
27
|
|
|
28
28
|
```tsx
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
import React, { useEffect } from 'react';
|
|
30
31
|
import { View, Text } from '@ray-js/ray';
|
|
31
32
|
import { useP2PDataStream, StreamDataNotificationCenter } from '@ray-js/robot-data-stream';
|
|
32
33
|
import styles from './index.module.less';
|
|
33
34
|
|
|
34
35
|
const DemoBlock = ({ devId }) => {
|
|
36
|
+
|
|
35
37
|
const onReceiveMapData = (data: string) => {
|
|
36
|
-
StreamDataNotificationCenter.emit('receiveMapData', data)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const onReceivePathData = (data:
|
|
40
|
-
StreamDataNotificationCenter.emit('receivePathData', data)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const { appendDownloadStreamDuringTask } = useP2PDataStream(
|
|
52
|
-
devId,
|
|
53
|
-
onReceiveMapData,
|
|
54
|
-
onReceivePathData,
|
|
55
|
-
onReceiveAIPicData,
|
|
56
|
-
onReceiveAIPicHDData
|
|
57
|
-
);
|
|
38
|
+
StreamDataNotificationCenter.emit('receiveMapData', data)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const onReceivePathData = (data:string) => {
|
|
42
|
+
StreamDataNotificationCenter.emit('receivePathData', data)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
|
|
48
|
+
useP2PDataStream(devId, onReceiveMapData, onReceivePathData);
|
|
49
|
+
|
|
50
|
+
}, []);
|
|
58
51
|
|
|
59
52
|
return (
|
|
60
53
|
<View className={styles.demoBlock}>
|
|
61
54
|
<View className={styles.demoBlockTitle}>
|
|
62
55
|
<Text className={styles.demoBlockTitleText}>{devId}</Text>
|
|
63
56
|
</View>
|
|
64
|
-
|
|
65
|
-
)
|
|
57
|
+
</View>
|
|
58
|
+
)
|
|
66
59
|
};
|
|
67
60
|
|
|
68
61
|
export default function Home() {
|
|
@@ -72,5 +65,5 @@ export default function Home() {
|
|
|
72
65
|
</View>
|
|
73
66
|
);
|
|
74
67
|
}
|
|
68
|
+
```
|
|
75
69
|
|
|
76
|
-
```
|
package/lib/api/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import SweeperP2pInstance from
|
|
1
|
+
import SweeperP2pInstance from "./sweeperP2p";
|
|
2
2
|
export { SweeperP2pInstance };
|
package/lib/api/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import SweeperP2pInstance from
|
|
1
|
+
import SweeperP2pInstance from "./sweeperP2p";
|
|
2
2
|
export { SweeperP2pInstance };
|
package/lib/api/p2pApi.d.ts
CHANGED
|
@@ -39,17 +39,6 @@ export default class P2pApi {
|
|
|
39
39
|
downloadStream: (files: {
|
|
40
40
|
files: Array<string>;
|
|
41
41
|
}, albumName: string, successCb?: () => void, failedCb?: () => void) => Promise<unknown> | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* 在下载过程中加入下载文件,需要把之前下载中的文件名也一起带上
|
|
44
|
-
* @param files
|
|
45
|
-
* @param albumName
|
|
46
|
-
* @param successCb
|
|
47
|
-
* @param failedCb
|
|
48
|
-
* @returns
|
|
49
|
-
*/
|
|
50
|
-
appendDownloadStream: (files: {
|
|
51
|
-
files: Array<string>;
|
|
52
|
-
}, albumName: string, successCb?: () => void, failedCb?: () => void) => Promise<boolean> | undefined;
|
|
53
42
|
/**
|
|
54
43
|
* 监听p2p传输数据流
|
|
55
44
|
* @param callback
|
package/lib/api/p2pApi.js
CHANGED
|
@@ -164,43 +164,6 @@ export default class P2pApi {
|
|
|
164
164
|
}
|
|
165
165
|
};
|
|
166
166
|
|
|
167
|
-
/**
|
|
168
|
-
* 在下载过程中加入下载文件,需要把之前下载中的文件名也一起带上
|
|
169
|
-
* @param files
|
|
170
|
-
* @param albumName
|
|
171
|
-
* @param successCb
|
|
172
|
-
* @param failedCb
|
|
173
|
-
* @returns
|
|
174
|
-
*/
|
|
175
|
-
appendDownloadStream = (files, albumName, successCb, failedCb) => {
|
|
176
|
-
try {
|
|
177
|
-
if (this.isConnected) {
|
|
178
|
-
return new Promise(resolve => {
|
|
179
|
-
p2p.appendDownloadStream({
|
|
180
|
-
deviceId: this.devId,
|
|
181
|
-
albumName: albumName,
|
|
182
|
-
jsonfiles: JSON.stringify(files),
|
|
183
|
-
success: () => {
|
|
184
|
-
log4js.info('p2p appendDownloadStream success');
|
|
185
|
-
typeof successCb === 'function' && successCb();
|
|
186
|
-
resolve(true);
|
|
187
|
-
},
|
|
188
|
-
fail: params => {
|
|
189
|
-
log4js.warn('p2p appendDownloadStream failed ==>', params);
|
|
190
|
-
setTimeout(() => {
|
|
191
|
-
typeof failedCb === 'function' && failedCb();
|
|
192
|
-
}, 500);
|
|
193
|
-
resolve(false);
|
|
194
|
-
},
|
|
195
|
-
complete: () => {}
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
} catch (e) {
|
|
200
|
-
log4js.warn('p2p appendDownloadStream occur an error ==>', e);
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
|
|
204
167
|
/**
|
|
205
168
|
* 监听p2p传输数据流
|
|
206
169
|
* @param callback
|
package/lib/api/sweeperP2p.d.ts
CHANGED
|
@@ -24,18 +24,6 @@ declare const FILE_NAME_MAP: {
|
|
|
24
24
|
readonly 'cleanPath.bin.stream': {
|
|
25
25
|
readonly type: 1;
|
|
26
26
|
};
|
|
27
|
-
readonly 'ai.bin': {
|
|
28
|
-
readonly type: 4;
|
|
29
|
-
};
|
|
30
|
-
readonly 'ai.bin.stream': {
|
|
31
|
-
readonly type: 4;
|
|
32
|
-
};
|
|
33
|
-
readonly 'aiHD_XXXX_YYYY.bin': {
|
|
34
|
-
readonly type: 5;
|
|
35
|
-
};
|
|
36
|
-
readonly 'aiHD_XXXX_YYYY.bin.stream': {
|
|
37
|
-
readonly type: 5;
|
|
38
|
-
};
|
|
39
27
|
};
|
|
40
28
|
export declare class SweeperP2p extends P2pApi {
|
|
41
29
|
file: {
|
|
@@ -45,22 +33,24 @@ export declare class SweeperP2p extends P2pApi {
|
|
|
45
33
|
albumName: string;
|
|
46
34
|
streamFilePath: string;
|
|
47
35
|
dataFilePath: string;
|
|
36
|
+
mapBinData: string;
|
|
37
|
+
navPathBinData: string;
|
|
38
|
+
cleanPathBinData: string;
|
|
39
|
+
mapBinStream: string;
|
|
40
|
+
navPathBinStream: string;
|
|
41
|
+
cleanPathBinStream: string;
|
|
48
42
|
downloadType: number;
|
|
49
43
|
readingMap: boolean;
|
|
50
44
|
readingClean: boolean;
|
|
51
|
-
|
|
52
|
-
readingHD: boolean;
|
|
45
|
+
readingNav: boolean;
|
|
53
46
|
cacheDir: string;
|
|
54
47
|
fileIndex: number;
|
|
55
48
|
cacheData: any;
|
|
56
|
-
exitFiles: Array<string>;
|
|
57
49
|
packetDataCacheMap: Map<keyof typeof FILE_NAME_MAP, Map<number, string>>;
|
|
58
50
|
packetSerialNumberCacheMap: Map<keyof typeof FILE_NAME_MAP, number>;
|
|
59
51
|
packetTotalMap: Map<keyof typeof FILE_NAME_MAP, number>;
|
|
60
52
|
onReceiveMapData: (data: string) => void;
|
|
61
53
|
onReceivePathData: (data: string) => void;
|
|
62
|
-
onReceiveAIPicData: (data: string) => void;
|
|
63
|
-
onReceiveAIPicHDData: (data: string) => void;
|
|
64
54
|
offFileDownloadComplete: () => void;
|
|
65
55
|
offP2pStreamPacketReceive: () => void;
|
|
66
56
|
offDownLoadProgressUpdate: () => void;
|
|
@@ -116,15 +106,7 @@ export declare class SweeperP2p extends P2pApi {
|
|
|
116
106
|
* @param downloadType
|
|
117
107
|
* 0: 下载断开 1: 持续下载
|
|
118
108
|
*/
|
|
119
|
-
startObserverSweeperDataByP2P: (downloadType: number, devId: string, onReceiveMapData: (data: string) => void, onReceivePathData: (data: string) => void
|
|
120
|
-
/**
|
|
121
|
-
* 在下载过程中继续添加下载文件
|
|
122
|
-
* @param files
|
|
123
|
-
* @param successCb
|
|
124
|
-
* @param failCb
|
|
125
|
-
* @returns
|
|
126
|
-
*/
|
|
127
|
-
appendDownloadStreamDuringTask: (files: Array<string>, successCb?: () => void, failCb?: () => void) => Promise<boolean> | void;
|
|
109
|
+
startObserverSweeperDataByP2P: (downloadType: number, devId: string, onReceiveMapData: (data: string) => void, onReceivePathData: (data: string) => void) => Promise<void>;
|
|
128
110
|
/**
|
|
129
111
|
* 注册下载有关的监听
|
|
130
112
|
*/
|
package/lib/api/sweeperP2p.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-shadow */
|
|
2
2
|
import P2pApi from './p2pApi';
|
|
3
3
|
import Base64 from 'base64-js';
|
|
4
|
-
import { padStart
|
|
4
|
+
import { padStart } from 'lodash-es';
|
|
5
5
|
import log4js from '@ray-js/log4js';
|
|
6
6
|
/**
|
|
7
7
|
* 基于P2p工具类的扫地机扩展实现
|
|
@@ -19,18 +19,6 @@ const FILE_NAME_MAP = {
|
|
|
19
19
|
},
|
|
20
20
|
'cleanPath.bin.stream': {
|
|
21
21
|
type: 1
|
|
22
|
-
},
|
|
23
|
-
'ai.bin': {
|
|
24
|
-
type: 4
|
|
25
|
-
},
|
|
26
|
-
'ai.bin.stream': {
|
|
27
|
-
type: 4
|
|
28
|
-
},
|
|
29
|
-
'aiHD_XXXX_YYYY.bin': {
|
|
30
|
-
type: 5
|
|
31
|
-
},
|
|
32
|
-
'aiHD_XXXX_YYYY.bin.stream': {
|
|
33
|
-
type: 5
|
|
34
22
|
}
|
|
35
23
|
};
|
|
36
24
|
|
|
@@ -43,14 +31,20 @@ export class SweeperP2p extends P2pApi {
|
|
|
43
31
|
this.downloadType = 1;
|
|
44
32
|
this.fileIndex = -1; // -1 表示所有文件下载完成
|
|
45
33
|
this.albumName = 'ipc_sweeper_robot';
|
|
34
|
+
this.mapBinData = 'map.bin';
|
|
35
|
+
this.navPathBinData = 'navPath.bin';
|
|
36
|
+
this.cleanPathBinData = 'cleanPath.bin';
|
|
37
|
+
this.mapBinStream = 'map.bin.stream';
|
|
38
|
+
this.navPathBinStream = 'navPath.bin.stream';
|
|
39
|
+
this.cleanPathBinStream = 'cleanPath.bin.stream';
|
|
46
40
|
this.cacheDir = ty.env.USER_DATA_PATH;
|
|
47
41
|
this.readingMap = false;
|
|
48
42
|
this.readingClean = false;
|
|
43
|
+
this.readingNav = false;
|
|
49
44
|
this.cacheData = {};
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.packetDataCacheMap = new Map([['map.bin', new Map()], ['cleanPath.bin', new Map()], ['ai.bin', new Map()], ['aiHD_XXXX_YYYY.bin', new Map()], ['map.bin.stream', new Map()], ['cleanPath.bin.stream', new Map()], ['ai.bin.stream', new Map()], ['aiHD_XXXX_YYYY.bin.stream', new Map()]]);
|
|
45
|
+
this.packetTotalMap = new Map([['map.bin', -1], ['cleanPath.bin', -1], ['map.bin.stream', -1], ['cleanPath.bin.stream', -1]]);
|
|
46
|
+
this.packetSerialNumberCacheMap = new Map([['map.bin', -1], ['cleanPath.bin', -1], ['map.bin.stream', -1], ['cleanPath.bin.stream', -1]]);
|
|
47
|
+
this.packetDataCacheMap = new Map([['map.bin', new Map()], ['cleanPath.bin', new Map()], ['map.bin.stream', new Map()], ['cleanPath.bin.stream', new Map()]]);
|
|
54
48
|
}
|
|
55
49
|
setStreamFilePath = () => {
|
|
56
50
|
// this.streamFilePath = this.cacheDir + `/${this.albumName}/${devId}/stream`;
|
|
@@ -102,10 +96,10 @@ export class SweeperP2p extends P2pApi {
|
|
|
102
96
|
dirPath: filePath,
|
|
103
97
|
recursive: true
|
|
104
98
|
});
|
|
105
|
-
|
|
99
|
+
console.log('mkdirSync success: filePath ==>', filePath);
|
|
106
100
|
return true;
|
|
107
101
|
} catch (e) {
|
|
108
|
-
|
|
102
|
+
console.log('mkdirSync error ==>', e);
|
|
109
103
|
return false;
|
|
110
104
|
}
|
|
111
105
|
};
|
|
@@ -120,11 +114,11 @@ export class SweeperP2p extends P2pApi {
|
|
|
120
114
|
ty.getFileSystemManager().access({
|
|
121
115
|
path: filePath,
|
|
122
116
|
success(params) {
|
|
123
|
-
|
|
117
|
+
console.info('file access success ==>', params);
|
|
124
118
|
resolve(true);
|
|
125
119
|
},
|
|
126
120
|
fail(params) {
|
|
127
|
-
|
|
121
|
+
console.info('file access fail ==>', params);
|
|
128
122
|
resolve(false);
|
|
129
123
|
}
|
|
130
124
|
});
|
|
@@ -156,11 +150,8 @@ export class SweeperP2p extends P2pApi {
|
|
|
156
150
|
if (filename.indexOf('cleanPath') !== -1) {
|
|
157
151
|
return 1;
|
|
158
152
|
}
|
|
159
|
-
if (filename.indexOf('
|
|
160
|
-
return
|
|
161
|
-
}
|
|
162
|
-
if (filename.indexOf('aiHD') !== -1) {
|
|
163
|
-
return 5;
|
|
153
|
+
if (filename.indexOf('navPath') !== -1) {
|
|
154
|
+
return 3;
|
|
164
155
|
}
|
|
165
156
|
return 2;
|
|
166
157
|
};
|
|
@@ -194,7 +185,7 @@ export class SweeperP2p extends P2pApi {
|
|
|
194
185
|
* @param downloadType
|
|
195
186
|
* 0: 下载断开 1: 持续下载
|
|
196
187
|
*/
|
|
197
|
-
startObserverSweeperDataByP2P = async (downloadType, devId, onReceiveMapData, onReceivePathData
|
|
188
|
+
startObserverSweeperDataByP2P = async (downloadType, devId, onReceiveMapData, onReceivePathData) => {
|
|
198
189
|
var _this$file$items;
|
|
199
190
|
if (![0, 1].some(item => item === downloadType)) {
|
|
200
191
|
log4js.warn('download type must be 0 or 1');
|
|
@@ -202,8 +193,6 @@ export class SweeperP2p extends P2pApi {
|
|
|
202
193
|
}
|
|
203
194
|
this.onReceiveMapData = onReceiveMapData;
|
|
204
195
|
this.onReceivePathData = onReceivePathData;
|
|
205
|
-
this.onReceiveAIPicData = onReceiveAIPicData || (() => {});
|
|
206
|
-
this.onReceiveAIPicHDData = onReceiveAIPicHDData || (() => {});
|
|
207
196
|
log4js.info('startObserverSweeperDataByP2P ==>');
|
|
208
197
|
this.downloadType = downloadType;
|
|
209
198
|
this.setDataFilePath(devId);
|
|
@@ -212,14 +201,12 @@ export class SweeperP2p extends P2pApi {
|
|
|
212
201
|
this.removeP2pDownloadEvent();
|
|
213
202
|
this.registerP2pDownloadEvent();
|
|
214
203
|
if (!this.file) {
|
|
215
|
-
|
|
204
|
+
//@ts-ignore
|
|
216
205
|
this.file = await this.queryAlbumFileIndexs(this.albumName);
|
|
217
206
|
}
|
|
218
207
|
if (this.file && ((_this$file$items = this.file.items) === null || _this$file$items === void 0 ? void 0 : _this$file$items.length) > 0) {
|
|
219
208
|
if (this.downloadType === 0) {
|
|
220
209
|
const exitFiles = this.queryNeedFiles(this.file.items);
|
|
221
|
-
// 赋值
|
|
222
|
-
this.exitFiles = exitFiles;
|
|
223
210
|
if (exitFiles.length > 0) {
|
|
224
211
|
if (shouldDownloadStream) {
|
|
225
212
|
// 开启p2p流传输
|
|
@@ -234,8 +221,6 @@ export class SweeperP2p extends P2pApi {
|
|
|
234
221
|
}
|
|
235
222
|
} else if (this.downloadType === 1) {
|
|
236
223
|
const exitFiles = this.queryNeedFiles(this.file.items);
|
|
237
|
-
// 赋值
|
|
238
|
-
this.exitFiles = exitFiles;
|
|
239
224
|
if (exitFiles.length > 0) {
|
|
240
225
|
if (shouldDownloadStream) {
|
|
241
226
|
// 开启p2p流传输
|
|
@@ -253,19 +238,6 @@ export class SweeperP2p extends P2pApi {
|
|
|
253
238
|
}
|
|
254
239
|
};
|
|
255
240
|
|
|
256
|
-
/**
|
|
257
|
-
* 在下载过程中继续添加下载文件
|
|
258
|
-
* @param files
|
|
259
|
-
* @param successCb
|
|
260
|
-
* @param failCb
|
|
261
|
-
* @returns
|
|
262
|
-
*/
|
|
263
|
-
appendDownloadStreamDuringTask = (files, successCb, failCb) => {
|
|
264
|
-
return this.appendDownloadStream({
|
|
265
|
-
files: [...this.exitFiles, ...files]
|
|
266
|
-
}, this.albumName, successCb, failCb);
|
|
267
|
-
};
|
|
268
|
-
|
|
269
241
|
/**
|
|
270
242
|
* 注册下载有关的监听
|
|
271
243
|
*/
|
|
@@ -334,22 +306,12 @@ export class SweeperP2p extends P2pApi {
|
|
|
334
306
|
*/
|
|
335
307
|
p2pStreamPacketReceiveCallback = data => {
|
|
336
308
|
const {
|
|
309
|
+
fileName,
|
|
337
310
|
packetData,
|
|
338
311
|
fileSerialNumber,
|
|
339
312
|
packetIndex,
|
|
340
313
|
packetType
|
|
341
314
|
} = data;
|
|
342
|
-
let {
|
|
343
|
-
fileName
|
|
344
|
-
} = data;
|
|
345
|
-
|
|
346
|
-
// 因为XXXX_YYYYY会被替换为坐标值,所以这里需要替换一下
|
|
347
|
-
|
|
348
|
-
if (/^aiHD.*\.bin$/.test(fileName)) {
|
|
349
|
-
fileName = 'aiHD_XXXX_YYYY.bin';
|
|
350
|
-
} else if (/^aiHD.*\.bin.stream$/.test(fileName)) {
|
|
351
|
-
fileName = 'aiHD_XXXX_YYYY.bin.stream';
|
|
352
|
-
}
|
|
353
315
|
const cachePacketMap = this.packetDataCacheMap.get(fileName);
|
|
354
316
|
const cacheSerialNumber = this.packetSerialNumberCacheMap.get(fileName);
|
|
355
317
|
|
|
@@ -389,12 +351,6 @@ export class SweeperP2p extends P2pApi {
|
|
|
389
351
|
if (type === 1) {
|
|
390
352
|
this.onReceivePathData(hexValue);
|
|
391
353
|
}
|
|
392
|
-
if (type === 4) {
|
|
393
|
-
this.onReceiveAIPicData(hexValue);
|
|
394
|
-
}
|
|
395
|
-
if (type === 5) {
|
|
396
|
-
this.onReceiveAIPicHDData(hexValue);
|
|
397
|
-
}
|
|
398
354
|
this.cacheData[type] = hexValue;
|
|
399
355
|
}
|
|
400
356
|
}
|
|
@@ -432,7 +388,7 @@ export class SweeperP2p extends P2pApi {
|
|
|
432
388
|
success: params => {
|
|
433
389
|
this.resetReading(fileName);
|
|
434
390
|
const bytes = Base64.toByteArray(params.data);
|
|
435
|
-
const hexValue =
|
|
391
|
+
const hexValue = _(bytes).map(d => padStart(d.toString(16), 2, '0')).value().join('');
|
|
436
392
|
const type = this.getFileType(fileName);
|
|
437
393
|
if (this.cacheData[type] !== hexValue) {
|
|
438
394
|
if (hexValue.length === 0) {
|
|
@@ -445,12 +401,6 @@ export class SweeperP2p extends P2pApi {
|
|
|
445
401
|
if (type === 1) {
|
|
446
402
|
this.onReceivePathData(hexValue);
|
|
447
403
|
}
|
|
448
|
-
if (type === 4) {
|
|
449
|
-
this.onReceiveAIPicData(hexValue);
|
|
450
|
-
}
|
|
451
|
-
if (type === 5) {
|
|
452
|
-
this.onReceiveAIPicHDData(hexValue);
|
|
453
|
-
}
|
|
454
404
|
this.cacheData[type] = hexValue;
|
|
455
405
|
}
|
|
456
406
|
},
|
|
@@ -475,14 +425,9 @@ export class SweeperP2p extends P2pApi {
|
|
|
475
425
|
this.readingClean = true;
|
|
476
426
|
return true;
|
|
477
427
|
}
|
|
478
|
-
if (fileName.indexOf('
|
|
479
|
-
if (this.
|
|
480
|
-
this.
|
|
481
|
-
return true;
|
|
482
|
-
}
|
|
483
|
-
if (fileName.indexOf('aiHD') !== -1) {
|
|
484
|
-
if (this.readingHD === true) return false;
|
|
485
|
-
this.readingHD = true;
|
|
428
|
+
if (fileName.indexOf('navPath') !== -1) {
|
|
429
|
+
if (this.readingNav === true) return false;
|
|
430
|
+
this.readingNav = true;
|
|
486
431
|
return true;
|
|
487
432
|
}
|
|
488
433
|
return true;
|
|
@@ -492,10 +437,8 @@ export class SweeperP2p extends P2pApi {
|
|
|
492
437
|
this.readingMap = false;
|
|
493
438
|
} else if (fileName.indexOf('cleanPath') !== -1) {
|
|
494
439
|
this.readingClean = false;
|
|
495
|
-
} else if (fileName.indexOf('
|
|
496
|
-
this.
|
|
497
|
-
} else if (fileName.indexOf('aiHD') !== -1) {
|
|
498
|
-
this.readingHD = false;
|
|
440
|
+
} else if (fileName.indexOf('navPath') !== -1) {
|
|
441
|
+
this.readingNav = false;
|
|
499
442
|
}
|
|
500
443
|
};
|
|
501
444
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
declare const useP2PDataStream: (devId: string, onReceiveMapData: (data: string) => void, onReceivePathData: (data: string) => void,
|
|
2
|
-
|
|
3
|
-
};
|
|
1
|
+
declare const useP2PDataStream: (devId: string, onReceiveMapData: (data: string) => void, onReceivePathData: (data: string) => void, opt?: {
|
|
2
|
+
logTag?: string | undefined;
|
|
3
|
+
} | undefined) => void;
|
|
4
4
|
declare const StreamDataNotificationCenter: import("mitt").Emitter<Record<import("mitt").EventType, unknown>>;
|
|
5
5
|
export { useP2PDataStream, StreamDataNotificationCenter };
|
package/lib/index.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
/* eslint-disable consistent-return */
|
|
1
2
|
import { useEffect, useRef } from 'react';
|
|
2
3
|
import mitt from 'mitt';
|
|
3
4
|
import { SweeperP2pInstance } from './api';
|
|
4
5
|
import log4js from '@ray-js/log4js';
|
|
5
|
-
|
|
6
|
-
const
|
|
6
|
+
const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
|
|
7
|
+
const {
|
|
8
|
+
logTag
|
|
9
|
+
} = opt || {};
|
|
7
10
|
const isInit = useRef(null);
|
|
8
11
|
const offSessionStatusChange = useRef(null);
|
|
9
12
|
const isAppOnBackground = useRef(false);
|
|
10
13
|
const timer = useRef(null);
|
|
11
14
|
useEffect(() => {
|
|
15
|
+
if (logTag) {
|
|
16
|
+
log4js.setTag(logTag);
|
|
17
|
+
}
|
|
12
18
|
if (devId.startsWith('vdevo')) {
|
|
13
19
|
log4js.warn('virtual device cannot use p2p');
|
|
14
20
|
return;
|
|
@@ -31,11 +37,11 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, onReceiveA
|
|
|
31
37
|
if (isInit.current) {
|
|
32
38
|
SweeperP2pInstance.isConnecting = true;
|
|
33
39
|
SweeperP2pInstance.connectDevice(() => {
|
|
34
|
-
SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData
|
|
40
|
+
SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData);
|
|
35
41
|
offSessionStatusChange.current = SweeperP2pInstance.onSessionStatusChange(SweeperP2pInstance.sessionStatusCallback);
|
|
36
42
|
}, () => {
|
|
37
43
|
SweeperP2pInstance.reconnectP2p(() => {
|
|
38
|
-
SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData
|
|
44
|
+
SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData);
|
|
39
45
|
// 这里失败重连需要注册断开重连的事件
|
|
40
46
|
offSessionStatusChange.current = SweeperP2pInstance.onSessionStatusChange(SweeperP2pInstance.sessionStatusCallback);
|
|
41
47
|
});
|
|
@@ -90,9 +96,6 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, onReceiveA
|
|
|
90
96
|
}
|
|
91
97
|
});
|
|
92
98
|
};
|
|
93
|
-
return {
|
|
94
|
-
appendDownloadStreamDuringTask: sweeperP2pInstance.appendDownloadStreamDuringTask
|
|
95
|
-
};
|
|
96
99
|
};
|
|
97
100
|
const StreamDataNotificationCenter = mitt();
|
|
98
101
|
export { useP2PDataStream, StreamDataNotificationCenter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/robot-data-stream",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "扫地机P2P数据流标准化组件",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"files": [
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"release-it": "standard-version"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@ray-js/ray": "^1.5.0"
|
|
34
|
+
"@ray-js/ray": "^1.5.0",
|
|
35
|
+
"@ray-js/log4js": "^0.0.4"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@ray-js/log4js": "^0.0.3",
|
|
38
38
|
"clsx": "^1.2.1",
|
|
39
39
|
"lodash-es": "^4.17.21",
|
|
40
40
|
"mitt": "^3.0.1",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"@commitlint/cli": "^7.2.1",
|
|
45
45
|
"@commitlint/config-conventional": "^9.0.1",
|
|
46
46
|
"@ray-js/cli": "^1.5.20",
|
|
47
|
+
"@ray-js/log4js": "^0.0.4",
|
|
47
48
|
"@ray-js/ray": "^1.5.0",
|
|
48
49
|
"core-js": "^3.19.1",
|
|
49
50
|
"eslint-config-tuya-panel": "^0.4.2",
|
|
@@ -52,9 +53,6 @@
|
|
|
52
53
|
"patch-package": "^8.0.0",
|
|
53
54
|
"standard-version": "9.3.2"
|
|
54
55
|
},
|
|
55
|
-
"resolutions": {
|
|
56
|
-
"@ray-js/builder-mp": "1.4.15"
|
|
57
|
-
},
|
|
58
56
|
"husky": {
|
|
59
57
|
"hooks": {
|
|
60
58
|
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS --config commitlint.config.js",
|