@ray-js/robot-data-stream 0.0.10-beta-5 → 0.0.10-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.
@@ -52,7 +52,6 @@ export declare class SweeperP2p extends P2pApi {
52
52
  streamFilePath: string;
53
53
  dataFilePath: string;
54
54
  downloadType: number;
55
- useStructuredMode: boolean;
56
55
  readingMap: boolean;
57
56
  readingClean: boolean;
58
57
  readingAI: boolean;
@@ -124,7 +123,7 @@ export declare class SweeperP2p extends P2pApi {
124
123
  * @param downloadType
125
124
  * 0: 下载断开 1: 持续下载
126
125
  */
127
- startObserverSweeperDataByP2P: (downloadType: number, useStructuredMode: boolean, devId: string, onReceiveMapData: (data: string) => void, onReceivePathData: (data: string) => void, onReceiveAIPicData?: ((data: string) => void) | undefined, onReceiveAIPicHDData?: ((data: string) => void) | undefined) => Promise<void>;
126
+ startObserverSweeperDataByP2P: (downloadType: number, devId: string, onReceiveMapData: (data: string) => void, onReceivePathData: (data: string) => void, onReceiveAIPicData?: ((data: string) => void) | undefined, onReceiveAIPicHDData?: ((data: string) => void) | undefined) => Promise<void>;
128
127
  /**
129
128
  * 在下载过程中继续添加下载文件
130
129
  * @param files
@@ -50,7 +50,6 @@ export class SweeperP2p extends P2pApi {
50
50
  super();
51
51
  this.file = undefined;
52
52
  this.downloadType = 1;
53
- this.useStructuredMode = false;
54
53
  this.fileIndex = -1; // -1 表示所有文件下载完成
55
54
  this.albumName = 'ipc_sweeper_robot';
56
55
  this.cacheDir = ty.env.USER_DATA_PATH;
@@ -195,7 +194,7 @@ export class SweeperP2p extends P2pApi {
195
194
  if (!this.isConnecting) {
196
195
  this.reconnectP2p(() => {
197
196
  // 重连之后重新开启文件下载, 这里的成功不需要注册断开事件
198
- this.startObserverSweeperDataByP2P(this.downloadType, this.useStructuredMode, this.devId, this.onReceiveMapData, this.onReceivePathData, this.onReceiveAIPicData, this.onReceiveAIPicHDData);
197
+ this.startObserverSweeperDataByP2P(this.downloadType, this.devId, this.onReceiveMapData, this.onReceivePathData, this.onReceiveAIPicData, this.onReceiveAIPicHDData);
199
198
  });
200
199
  } else {
201
200
  log4js.warn('receive disconnect notice, but connectDevice is connecting');
@@ -209,7 +208,7 @@ export class SweeperP2p extends P2pApi {
209
208
  * @param downloadType
210
209
  * 0: 下载断开 1: 持续下载
211
210
  */
212
- startObserverSweeperDataByP2P = async (downloadType, useStructuredMode, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData) => {
211
+ startObserverSweeperDataByP2P = async (downloadType, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData) => {
213
212
  var _this$file$items;
214
213
  if (![0, 1].some(item => item === downloadType)) {
215
214
  log4js.warn('download type must be 0 or 1');
@@ -224,7 +223,6 @@ export class SweeperP2p extends P2pApi {
224
223
  // do nothing
225
224
  });
226
225
  log4js.info('startObserverSweeperDataByP2P ==>');
227
- this.useStructuredMode = useStructuredMode;
228
226
  this.downloadType = downloadType;
229
227
  this.setDataFilePath(devId);
230
228
  this.setStreamFilePath(devId);
@@ -559,10 +557,6 @@ export class SweeperP2p extends P2pApi {
559
557
  }
560
558
  }
561
559
  });
562
- // 如果是使用结构化的数据,则直接把map. 相关的文件过滤掉
563
- if (this.useStructuredMode) {
564
- return exitFiles.filter(item => item.indexOf('map.') === -1);
565
- }
566
560
  return exitFiles;
567
561
  };
568
562
 
package/lib/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  declare const useP2PDataStream: (devId: string, onReceiveMapData: (data: string) => void, onReceivePathData: (data: string) => void, opt?: {
2
2
  logTag?: string | undefined;
3
- useStructuredMode?: boolean | undefined;
4
3
  onReceiveAIPicData?: ((data: string) => void) | undefined;
5
4
  onReceiveAIPicHDData?: ((data: string) => void) | undefined;
6
5
  } | undefined) => {
package/lib/index.js CHANGED
@@ -1,14 +1,13 @@
1
1
  /* eslint-disable consistent-return */
2
- import { useEffect, useRef } from 'react';
2
+ import { useEffect, useRef, useCallback } from 'react';
3
3
  import mitt from 'mitt';
4
4
  import log4js from '@ray-js/log4js';
5
5
  import { SweeperP2pInstance } from './api';
6
6
  import sweeperP2pInstance from './api/sweeperP2p';
7
- import { getSystemInfoSync, usePageEvent } from '@ray-js/ray';
7
+ import { getSystemInfoSync } from '@ray-js/ray';
8
8
  const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
9
9
  const {
10
10
  logTag,
11
- useStructuredMode = false,
12
11
  onReceiveAIPicData,
13
12
  onReceiveAIPicHDData
14
13
  } = opt || {};
@@ -17,6 +16,33 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
17
16
  const isAppOnBackground = useRef(false);
18
17
  const timer = useRef(null);
19
18
  const isIDE = getSystemInfoSync().brand === 'devtools';
19
+ const handleAppHide = useCallback(() => {
20
+ log4js.info('hooks onAppHide');
21
+ isAppOnBackground.current = true;
22
+ if (isInit.current) {
23
+ // 判断进入后台之后,维持定时器,如果进入后台超过2分钟, 则断开P2P
24
+ timer.current = setTimeout(() => {
25
+ log4js.info('background timer has been exe');
26
+ if (isAppOnBackground.current) {
27
+ unmount();
28
+ }
29
+ clearTimeout(timer.current);
30
+ timer.current = null;
31
+ }, 10 * 1000);
32
+ }
33
+ }, []);
34
+ const handleAppShow = useCallback(() => {
35
+ log4js.info('hooks onAppShow');
36
+ timer.current && clearTimeout(timer.current);
37
+ setTimeout(() => {
38
+ var _ty$p2p$isP2PActiveSy, _ty$p2p;
39
+ if (!isInit.current || !((_ty$p2p$isP2PActiveSy = (_ty$p2p = ty.p2p).isP2PActiveSync) !== null && _ty$p2p$isP2PActiveSy !== void 0 && _ty$p2p$isP2PActiveSy.call(_ty$p2p, {
40
+ deviceId: devId
41
+ }))) {
42
+ connectP2p();
43
+ }
44
+ }, 500);
45
+ }, []);
20
46
  useEffect(() => {
21
47
  if (logTag) {
22
48
  log4js.setTag(logTag);
@@ -37,13 +63,17 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
37
63
  SweeperP2pInstance.initP2pSdk(devId).then(() => {
38
64
  connectP2p();
39
65
  });
40
- onEnterBackground();
41
- onEnterForeground();
66
+ ty.onAppHide(handleAppHide);
67
+ ty.onAppShow(handleAppShow);
42
68
  }, []);
43
- usePageEvent('onUnload', () => {
69
+ ty.onAppClose(() => {
70
+ // 退出被拦截了,可以在此处理一些逻辑,如果允许退出则调用
71
+ // ty.exitMiniProgram 进行,否则当前小程序无法退出
44
72
  unmount();
45
73
  SweeperP2pInstance.deInitP2PSDK();
46
- timer && clearInterval(timer);
74
+ ty.offAppHide(handleAppHide);
75
+ ty.offAppShow(handleAppShow);
76
+ ty.exitMiniProgram();
47
77
  });
48
78
 
49
79
  /**
@@ -54,39 +84,18 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
54
84
  SweeperP2pInstance.isConnecting = true;
55
85
  SweeperP2pInstance.connectDevice(() => {
56
86
  isInit.current = true;
57
- SweeperP2pInstance.startObserverSweeperDataByP2P(1, useStructuredMode, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData);
87
+ SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData);
58
88
  offSessionStatusChange.current = SweeperP2pInstance.onSessionStatusChange(SweeperP2pInstance.sessionStatusCallback);
59
89
  }, () => {
60
90
  SweeperP2pInstance.reconnectP2p(() => {
61
91
  isInit.current = true;
62
- SweeperP2pInstance.startObserverSweeperDataByP2P(1, useStructuredMode, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData);
92
+ SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData);
63
93
  // 这里失败重连需要注册断开重连的事件
64
94
  offSessionStatusChange.current = SweeperP2pInstance.onSessionStatusChange(SweeperP2pInstance.sessionStatusCallback);
65
95
  });
66
96
  });
67
97
  };
68
98
 
69
- /**
70
- * 进入后台时断开P2P连接
71
- */
72
- const onEnterBackground = () => {
73
- ty.onAppHide(() => {
74
- log4js.info('hooks onAppHide');
75
- isAppOnBackground.current = true;
76
- if (isInit.current) {
77
- // 判断进入后台之后,维持定时器,如果进入后台超过2分钟, 则断开P2P
78
- timer.current = setTimeout(() => {
79
- log4js.info('background timer has been exe');
80
- if (isAppOnBackground.current) {
81
- unmount();
82
- }
83
- clearTimeout(timer.current);
84
- timer.current = null;
85
- }, 10 * 1000);
86
- }
87
- });
88
- };
89
-
90
99
  /**
91
100
  * p2p断开
92
101
  */
@@ -99,24 +108,6 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
99
108
  }
100
109
  SweeperP2pInstance.stopObserverSweeperDataByP2P();
101
110
  };
102
-
103
- /**
104
- * 进入前台时开启P2P连接
105
- */
106
- const onEnterForeground = () => {
107
- ty.onAppShow(() => {
108
- log4js.info('hooks onAppShow');
109
- timer.current && clearTimeout(timer.current);
110
- setTimeout(() => {
111
- var _ty$p2p$isP2PActiveSy, _ty$p2p;
112
- if (!isInit.current || !((_ty$p2p$isP2PActiveSy = (_ty$p2p = ty.p2p).isP2PActiveSync) !== null && _ty$p2p$isP2PActiveSy !== void 0 && _ty$p2p$isP2PActiveSy.call(_ty$p2p, {
113
- deviceId: devId
114
- }))) {
115
- connectP2p();
116
- }
117
- }, 500);
118
- });
119
- };
120
111
  return {
121
112
  appendDownloadStreamDuringTask: sweeperP2pInstance.appendDownloadStreamDuringTask
122
113
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/robot-data-stream",
3
- "version": "0.0.10-beta-5",
3
+ "version": "0.0.10-beta-7",
4
4
  "description": "扫地机P2P数据流标准化组件",
5
5
  "main": "lib/index",
6
6
  "files": [