@eohjsc/react-native-smart-city 0.3.53 → 0.3.54
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/package.json +2 -1
- package/src/Images/Common/loading-circle.json +1 -0
- package/src/commons/ActionGroup/index.js +6 -2
- package/src/commons/ButtonPopup/index.js +2 -0
- package/src/commons/DevMode/EmptyComponent.js +2 -2
- package/src/commons/Device/WaterQualitySensor/ListQualityIndicator.js +9 -6
- package/src/commons/FullLoading/__test__/index.test.js +43 -0
- package/src/commons/FullLoading/index.js +13 -3
- package/src/commons/Header/HeaderCustom.js +6 -1
- package/src/commons/Header/Styles/HeaderCustomStyles.js +4 -1
- package/src/commons/Processing/index.js +20 -18
- package/src/commons/Processing/styles.js +4 -3
- package/src/commons/StatusBox/index.js +23 -5
- package/src/commons/StatusBox/styles.js +7 -6
- package/src/configs/API.js +1 -1
- package/src/configs/AccessibilityLabel.js +1 -1
- package/src/configs/Colors.js +2 -0
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +22 -21
- package/src/hooks/IoT/useRemoteControl.js +8 -7
- package/src/iot/RemoteControl/Bluetooth.js +1 -1
- package/src/navigations/Main.js +3 -1
- package/src/screens/AddNewGateway/ConnectingModbusDevice.js +16 -19
- package/src/screens/AddNewGateway/ConnectingWifiGuide.js +139 -75
- package/src/screens/AddNewGateway/ConnectingWifiGuideStyles.js +8 -7
- package/src/screens/AddNewGateway/RenameNewDevices.js +147 -70
- package/src/screens/AddNewGateway/RenameNewDevicesStyles.js +35 -16
- package/src/screens/AddNewGateway/ShareWifiPassword.js +176 -107
- package/src/screens/AddNewGateway/ShareWifiPasswordStyles.js +14 -1
- package/src/screens/AddNewGateway/__test__/ConnectingWifiGuide.test.js +53 -7
- package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +44 -10
- package/src/screens/AddNewGateway/hooks/__Tests__/useStateAlertRename.test.js +57 -0
- package/src/screens/AddNewGateway/hooks/__Tests__/useWifiManage.test.js +22 -0
- package/src/screens/AddNewGateway/hooks/useWifiManage.js +29 -0
- package/src/screens/Device/__test__/detail.test.js +7 -1
- package/src/screens/Device/components/SensorDisplayItem.js +10 -2
- package/src/screens/Gateway/GatewayInfo/__test__/index.test.js +1 -1
- package/src/screens/Gateway/__test__/index.test.js +1 -1
- package/src/screens/Gateway/components/GatewayItem/index.js +1 -1
- package/src/screens/Gateway/components/GatewayItem/styles.js +4 -0
- package/src/screens/Gateway/components/Information/__test__/index.test.js +1 -1
- package/src/screens/Gateway/components/Information/index.js +5 -3
- package/src/screens/Gateway/components/Information/styles.js +3 -0
- package/src/screens/Gateway/components/TabPaneCT/index.js +31 -27
- package/src/screens/Gateway/components/TabPaneCT/styles.js +7 -1
- package/src/screens/Gateway/index.js +10 -10
- package/src/screens/Gateway/styles.js +3 -1
- package/src/screens/Notification/__test__/Notification.test.js +9 -1
- package/src/screens/Notification/index.js +7 -4
- package/src/screens/Template/EditTemplate.js +1 -1
- package/src/screens/Template/Styles/indexStyles.js +1 -1
- package/src/screens/Template/detail.js +26 -2
- package/src/screens/Template/index.js +1 -1
- package/src/screens/Unit/MoreMenu.js +56 -58
- package/src/screens/Unit/__test__/MoreMenu.test.js +59 -0
- package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +6 -3
- package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +7 -1
- package/src/utils/I18n/translations/en.json +8 -8
- package/src/utils/I18n/translations/vi.json +8 -7
package/src/configs/API.js
CHANGED
|
@@ -210,7 +210,7 @@ const API = {
|
|
|
210
210
|
DEV_MODE: {
|
|
211
211
|
GET_TEMPLATES: '/property_manager/iot_dashboard/dev_mode/templates/',
|
|
212
212
|
GET_WIDGETS: (templateId) =>
|
|
213
|
-
`/property_manager/iot_dashboard/dev_mode/templates/${templateId}/
|
|
213
|
+
`/property_manager/iot_dashboard/dev_mode/templates/${templateId}/widgets/`,
|
|
214
214
|
GATEWAY: {
|
|
215
215
|
LIST: () => '/chip_manager/developer_mode_chips/',
|
|
216
216
|
DETAIL: (id) => `/chip_manager/developer_mode_chips/${id}/`,
|
package/src/configs/Colors.js
CHANGED
|
@@ -7,14 +7,12 @@ import {
|
|
|
7
7
|
} from '../../../iot/RemoteControl/Bluetooth';
|
|
8
8
|
import { sendCommandOverHomeAssistant } from '../../../iot/RemoteControl/HomeAssistant';
|
|
9
9
|
import { sendCommandOverInternet } from '../../../iot/RemoteControl/Internet';
|
|
10
|
-
import { sendCommandOverLGThinq } from '../../../iot/RemoteControl/LG';
|
|
11
10
|
import { SCProvider } from '../../../context';
|
|
12
11
|
import { mockSCStore } from '../../../context/mockStore';
|
|
13
12
|
|
|
14
13
|
jest.mock('../../../iot/RemoteControl/Bluetooth');
|
|
15
14
|
jest.mock('../../../iot/RemoteControl/HomeAssistant');
|
|
16
15
|
jest.mock('../../../iot/RemoteControl/Internet');
|
|
17
|
-
jest.mock('../../../iot/RemoteControl/LG');
|
|
18
16
|
|
|
19
17
|
const mockedSetAction = jest.fn();
|
|
20
18
|
|
|
@@ -34,7 +32,6 @@ describe('Test useRemoteControl', () => {
|
|
|
34
32
|
sendCommandOverBluetooth.mockClear();
|
|
35
33
|
sendCommandOverHomeAssistant.mockClear();
|
|
36
34
|
sendCommandOverInternet.mockClear();
|
|
37
|
-
sendCommandOverLGThinq.mockClear();
|
|
38
35
|
|
|
39
36
|
sensor = {
|
|
40
37
|
id: 1,
|
|
@@ -59,11 +56,10 @@ describe('Test useRemoteControl', () => {
|
|
|
59
56
|
wrapper,
|
|
60
57
|
});
|
|
61
58
|
await act(async () => {
|
|
62
|
-
sendRemoteCommand.current(sensor, action, data, userId);
|
|
59
|
+
await sendRemoteCommand.current(sensor, action, data, userId);
|
|
63
60
|
});
|
|
64
61
|
expect(sendCommandOverInternet).not.toBeCalled();
|
|
65
62
|
expect(sendCommandOverHomeAssistant).not.toBeCalled();
|
|
66
|
-
expect(sendCommandOverLGThinq).not.toBeCalled();
|
|
67
63
|
expect(sendCommandOverBluetooth).not.toBeCalled();
|
|
68
64
|
});
|
|
69
65
|
|
|
@@ -74,7 +70,7 @@ describe('Test useRemoteControl', () => {
|
|
|
74
70
|
|
|
75
71
|
sendCommandOverBluetooth.mockImplementation(async () => true);
|
|
76
72
|
await act(async () => {
|
|
77
|
-
sendRemoteCommand.current(sensor, action, data, userId);
|
|
73
|
+
await sendRemoteCommand.current(sensor, action, data, userId);
|
|
78
74
|
});
|
|
79
75
|
expect(sendCommandOverBluetooth).toBeCalledWith(
|
|
80
76
|
sensor,
|
|
@@ -84,7 +80,6 @@ describe('Test useRemoteControl', () => {
|
|
|
84
80
|
);
|
|
85
81
|
expect(sendCommandOverInternet).not.toBeCalled();
|
|
86
82
|
expect(sendCommandOverHomeAssistant).not.toBeCalled();
|
|
87
|
-
expect(sendCommandOverLGThinq).not.toBeCalled();
|
|
88
83
|
});
|
|
89
84
|
|
|
90
85
|
it('test send remote command via bluetooth failed then send via internet', async () => {
|
|
@@ -99,7 +94,7 @@ describe('Test useRemoteControl', () => {
|
|
|
99
94
|
});
|
|
100
95
|
sendCommandOverInternet.mockImplementation(async () => true);
|
|
101
96
|
await act(async () => {
|
|
102
|
-
sendRemoteCommand.current(sensor, action, data, userId);
|
|
97
|
+
await sendRemoteCommand.current(sensor, action, data, userId);
|
|
103
98
|
});
|
|
104
99
|
expect(sendCommandOverBluetooth).toBeCalledWith(
|
|
105
100
|
sensor,
|
|
@@ -115,7 +110,6 @@ describe('Test useRemoteControl', () => {
|
|
|
115
110
|
);
|
|
116
111
|
expect(sendCommandOverInternet).toBeCalledTimes(1);
|
|
117
112
|
expect(sendCommandOverHomeAssistant).not.toBeCalled();
|
|
118
|
-
expect(sendCommandOverLGThinq).not.toBeCalled();
|
|
119
113
|
});
|
|
120
114
|
|
|
121
115
|
it('test send remote command via bluetooth failed throw unhandled error', async () => {
|
|
@@ -128,7 +122,11 @@ describe('Test useRemoteControl', () => {
|
|
|
128
122
|
});
|
|
129
123
|
sendCommandOverInternet.mockImplementation(async () => true);
|
|
130
124
|
await act(async () => {
|
|
131
|
-
|
|
125
|
+
try {
|
|
126
|
+
await sendRemoteCommand.current(sensor, action, data, userId);
|
|
127
|
+
} catch (err) {
|
|
128
|
+
expect(err).toBe('ANOTHER_ERROR');
|
|
129
|
+
}
|
|
132
130
|
});
|
|
133
131
|
expect(sendCommandOverBluetooth).toBeCalledWith(
|
|
134
132
|
sensor,
|
|
@@ -138,7 +136,6 @@ describe('Test useRemoteControl', () => {
|
|
|
138
136
|
);
|
|
139
137
|
expect(sendCommandOverInternet).not.toBeCalled();
|
|
140
138
|
expect(sendCommandOverHomeAssistant).not.toBeCalled();
|
|
141
|
-
expect(sendCommandOverLGThinq).not.toBeCalled();
|
|
142
139
|
});
|
|
143
140
|
|
|
144
141
|
it('test send remote command via internet', async () => {
|
|
@@ -150,7 +147,7 @@ describe('Test useRemoteControl', () => {
|
|
|
150
147
|
|
|
151
148
|
sendCommandOverInternet.mockImplementation(async () => true);
|
|
152
149
|
await act(async () => {
|
|
153
|
-
sendRemoteCommand.current(sensor, action, data, userId);
|
|
150
|
+
await sendRemoteCommand.current(sensor, action, data, userId);
|
|
154
151
|
});
|
|
155
152
|
expect(sendCommandOverInternet).toBeCalledWith(
|
|
156
153
|
sensor,
|
|
@@ -161,7 +158,6 @@ describe('Test useRemoteControl', () => {
|
|
|
161
158
|
expect(sendCommandOverInternet).toBeCalledTimes(1);
|
|
162
159
|
expect(sendCommandOverBluetooth).not.toBeCalled();
|
|
163
160
|
expect(sendCommandOverHomeAssistant).not.toBeCalled();
|
|
164
|
-
expect(sendCommandOverLGThinq).not.toBeCalled();
|
|
165
161
|
});
|
|
166
162
|
|
|
167
163
|
it('test send remote command via homeassistant', async () => {
|
|
@@ -173,7 +169,7 @@ describe('Test useRemoteControl', () => {
|
|
|
173
169
|
|
|
174
170
|
sendCommandOverHomeAssistant.mockImplementation(async () => true);
|
|
175
171
|
await act(async () => {
|
|
176
|
-
sendRemoteCommand.current(sensor, action, data, userId);
|
|
172
|
+
await sendRemoteCommand.current(sensor, action, data, userId);
|
|
177
173
|
});
|
|
178
174
|
expect(sendCommandOverHomeAssistant).toBeCalledWith(
|
|
179
175
|
{},
|
|
@@ -183,22 +179,27 @@ describe('Test useRemoteControl', () => {
|
|
|
183
179
|
);
|
|
184
180
|
expect(sendCommandOverBluetooth).not.toBeCalled();
|
|
185
181
|
expect(sendCommandOverInternet).not.toBeCalled();
|
|
186
|
-
expect(sendCommandOverLGThinq).not.toBeCalled();
|
|
187
182
|
});
|
|
188
183
|
|
|
189
|
-
it('test send remote command via
|
|
184
|
+
it('test send remote command action not prefer anything, trigger via internet', async () => {
|
|
190
185
|
action.command_prefer_over_bluetooth = false;
|
|
191
|
-
action.
|
|
186
|
+
action.command_prefer_over_googlehome = false;
|
|
187
|
+
action.command_prefer_over_internet = false;
|
|
192
188
|
const { result: sendRemoteCommand } = renderHook(() => useRemoteControl(), {
|
|
193
189
|
wrapper,
|
|
194
190
|
});
|
|
195
191
|
|
|
196
|
-
|
|
192
|
+
sendCommandOverInternet.mockImplementation(async () => true);
|
|
197
193
|
await act(async () => {
|
|
198
|
-
sendRemoteCommand.current(sensor, action, data, userId);
|
|
194
|
+
await sendRemoteCommand.current(sensor, action, data, userId);
|
|
199
195
|
});
|
|
200
|
-
expect(
|
|
196
|
+
expect(sendCommandOverInternet).toBeCalledWith(
|
|
197
|
+
sensor,
|
|
198
|
+
action,
|
|
199
|
+
data,
|
|
200
|
+
'internet'
|
|
201
|
+
);
|
|
201
202
|
expect(sendCommandOverHomeAssistant).not.toBeCalled();
|
|
202
|
-
expect(
|
|
203
|
+
expect(sendCommandOverBluetooth).not.toBeCalled();
|
|
203
204
|
});
|
|
204
205
|
});
|
|
@@ -27,9 +27,8 @@ const useRemoteControl = () => {
|
|
|
27
27
|
|
|
28
28
|
if (action.command_prefer_over_bluetooth) {
|
|
29
29
|
try {
|
|
30
|
-
|
|
30
|
+
return await sendCommandOverBluetooth(device, action, data, userId);
|
|
31
31
|
} catch (err) {
|
|
32
|
-
result = false;
|
|
33
32
|
if (err === SEND_COMMAND_OVER_BLUETOOTH_FAIL) {
|
|
34
33
|
result = await sendCommandOverInternet(
|
|
35
34
|
device,
|
|
@@ -37,14 +36,15 @@ const useRemoteControl = () => {
|
|
|
37
36
|
data,
|
|
38
37
|
'bluetooth'
|
|
39
38
|
);
|
|
39
|
+
return result;
|
|
40
40
|
} else {
|
|
41
41
|
throw err;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
if (action.command_prefer_over_internet
|
|
47
|
-
|
|
46
|
+
if (action.command_prefer_over_internet) {
|
|
47
|
+
return await sendCommandOverInternet(
|
|
48
48
|
device,
|
|
49
49
|
action,
|
|
50
50
|
data,
|
|
@@ -52,15 +52,16 @@ const useRemoteControl = () => {
|
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
if (action.command_prefer_over_googlehome
|
|
56
|
-
|
|
55
|
+
if (action.command_prefer_over_googlehome) {
|
|
56
|
+
return await sendCommandOverHomeAssistant(
|
|
57
57
|
homeAssistantConnections,
|
|
58
58
|
device,
|
|
59
59
|
action,
|
|
60
60
|
data
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
|
|
64
|
+
return await sendCommandOverInternet(device, action, data, 'internet');
|
|
64
65
|
},
|
|
65
66
|
[homeAssistantConnections]
|
|
66
67
|
);
|
|
@@ -85,7 +85,7 @@ export const sendCommandOverBluetooth = async (
|
|
|
85
85
|
data,
|
|
86
86
|
userID
|
|
87
87
|
) => {
|
|
88
|
-
const bluetooth = sensor
|
|
88
|
+
const bluetooth = sensor?.remote_control_options?.bluetooth;
|
|
89
89
|
let device = null;
|
|
90
90
|
if (bluetooth) {
|
|
91
91
|
device = getDeviceByName(bluetooth.address);
|
package/src/navigations/Main.js
CHANGED
|
@@ -36,6 +36,7 @@ import DetailConfigActionZigbee from '../screens/Gateway/DetailConfigActionZigbe
|
|
|
36
36
|
import DeviceModbusDetail from '../screens/Gateway/DeviceModbusDetail';
|
|
37
37
|
import DetailConfigActionModbus from '../screens/Gateway/DetailConfigActionModbus';
|
|
38
38
|
import DetailChildConfigActionModbus from '../screens/Gateway/DetailConfigActionModbus';
|
|
39
|
+
import { useBlockBackAndroid } from '../hooks/Common';
|
|
39
40
|
|
|
40
41
|
const Tab = createBottomTabNavigator();
|
|
41
42
|
const Drawer = createDrawerNavigator();
|
|
@@ -53,7 +54,7 @@ const MainDevMode = () => {
|
|
|
53
54
|
() => [
|
|
54
55
|
{
|
|
55
56
|
name: Routes.TemplateStack,
|
|
56
|
-
tabBarLabel: t('
|
|
57
|
+
tabBarLabel: t('dashboard'),
|
|
57
58
|
component: TemplateStack,
|
|
58
59
|
},
|
|
59
60
|
{
|
|
@@ -120,6 +121,7 @@ const MainDevMode = () => {
|
|
|
120
121
|
};
|
|
121
122
|
|
|
122
123
|
const DrawerScreen = () => {
|
|
124
|
+
useBlockBackAndroid();
|
|
123
125
|
return (
|
|
124
126
|
<Drawer.Navigator
|
|
125
127
|
backBehavior="none"
|
|
@@ -22,32 +22,21 @@ const ConnectingModbusDevice = ({ route }) => {
|
|
|
22
22
|
|
|
23
23
|
const { goBack } = useNavigation();
|
|
24
24
|
|
|
25
|
-
const addingModbusDeviceFail = useCallback(async (message, channelName) => {
|
|
26
|
-
const channel = getPusher().subscribe(channelName);
|
|
27
|
-
channel.bind('change_modbus_address_completed', (messageRes) => {
|
|
28
|
-
setIsChangeAddressSuccess(messageRes.success);
|
|
29
|
-
});
|
|
30
|
-
}, []);
|
|
31
|
-
|
|
32
25
|
const onReady = useCallback(
|
|
33
26
|
async (channelName) => {
|
|
34
27
|
setChannelNameTemp(channelName);
|
|
35
|
-
const { success,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
channel_name: channelName,
|
|
42
|
-
}
|
|
43
|
-
);
|
|
28
|
+
const { success, data } = await axiosPost(API.CHIP.SCAN_SENSOR(chipId), {
|
|
29
|
+
imei: qrData.imei,
|
|
30
|
+
unit: unitId,
|
|
31
|
+
station: subUnit?.id,
|
|
32
|
+
channel_name: channelName,
|
|
33
|
+
});
|
|
44
34
|
if (!success) {
|
|
45
|
-
addingModbusDeviceFail(JSON.stringify(problem || data), channelName);
|
|
46
35
|
return;
|
|
47
36
|
}
|
|
48
37
|
setSensorId(data.id);
|
|
49
38
|
},
|
|
50
|
-
[chipId,
|
|
39
|
+
[chipId, qrData, subUnit, unitId]
|
|
51
40
|
);
|
|
52
41
|
|
|
53
42
|
useEffect(() => {
|
|
@@ -63,12 +52,20 @@ const ConnectingModbusDevice = ({ route }) => {
|
|
|
63
52
|
}
|
|
64
53
|
}, [isRecallChipScan, channelNameTemp, onReady]);
|
|
65
54
|
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (channelNameTemp) {
|
|
57
|
+
const channel = getPusher().subscribe(channelNameTemp);
|
|
58
|
+
channel.bind('change_modbus_address_completed', (messageRes) => {
|
|
59
|
+
setIsChangeAddressSuccess(messageRes.success);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}, [channelNameTemp, setIsChangeAddressSuccess]);
|
|
63
|
+
|
|
66
64
|
return (
|
|
67
65
|
<ConnectingDevice
|
|
68
66
|
title={t('connect_device')}
|
|
69
67
|
initState={t('connecting_to_gateway')}
|
|
70
68
|
onReady={onReady}
|
|
71
|
-
fail={addingModbusDeviceFail}
|
|
72
69
|
unitId={unitId}
|
|
73
70
|
subUnit={subUnit}
|
|
74
71
|
chipId={chipId}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { useNavigation } from '@react-navigation/native';
|
|
1
|
+
import React, { useCallback, useEffect, useState, useMemo } from 'react';
|
|
2
|
+
import { Alert, Platform, View } from 'react-native';
|
|
3
|
+
import { useNavigation, useIsFocused } from '@react-navigation/native';
|
|
5
4
|
import _ from 'lodash';
|
|
6
5
|
import dgram from 'react-native-udp';
|
|
6
|
+
import LottieView from 'lottie-react-native';
|
|
7
|
+
import WifiManager from 'react-native-wifi-reborn';
|
|
7
8
|
|
|
8
|
-
import { ToastBottomHelper } from '../../utils/Utils';
|
|
9
9
|
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
10
|
+
import { ToastBottomHelper } from '../../utils/Utils';
|
|
10
11
|
import { HeaderCustom } from '../../commons/Header';
|
|
11
12
|
import Text from '../../commons/Text';
|
|
12
13
|
import Routes from '../../utils/Route';
|
|
@@ -14,31 +15,81 @@ import InteractSmartphoneIcon from '../../../assets/images/AddNewDevice/interact
|
|
|
14
15
|
import styles from './ConnectingWifiGuideStyles';
|
|
15
16
|
import BottomButtonView from '../../commons/BottomButtonView';
|
|
16
17
|
import AccessibilityLabel from '../../configs/AccessibilityLabel';
|
|
18
|
+
import LoadingCircle from '../../Images/Common/loading-circle.json';
|
|
19
|
+
import FullLoading from '../../commons/FullLoading';
|
|
20
|
+
import { useWifiManage } from './hooks/useWifiManage';
|
|
17
21
|
|
|
18
22
|
let intervalSend = null;
|
|
19
23
|
let socket;
|
|
20
|
-
|
|
21
24
|
const ConnectingWifiGuide = ({ route }) => {
|
|
22
25
|
const t = useTranslations();
|
|
23
|
-
const {
|
|
26
|
+
const {
|
|
27
|
+
qrData,
|
|
28
|
+
unitId,
|
|
29
|
+
subUnit,
|
|
30
|
+
addDeviceType,
|
|
31
|
+
stationId,
|
|
32
|
+
isBackFromOtherScreen,
|
|
33
|
+
} = route?.params || {};
|
|
24
34
|
const { navigate, goBack } = useNavigation();
|
|
35
|
+
const isFocused = useIsFocused();
|
|
36
|
+
const { getCurrentWifiSSID, disconnectWifi } = useWifiManage();
|
|
37
|
+
|
|
25
38
|
const [wifiList, setWifiList] = useState([]);
|
|
26
39
|
const [currentState, setCurrentState] = useState(0);
|
|
40
|
+
const [isDisabled, setIsDisabled] = useState(false);
|
|
41
|
+
const [isPressButton, setIsPressButton] = useState(false);
|
|
27
42
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const wifiPrefix = `${prefix.toLowerCase()}.`;
|
|
31
|
-
const buttons = [
|
|
43
|
+
const buttons = useMemo(
|
|
44
|
+
() => [
|
|
32
45
|
{
|
|
33
46
|
text: t('cancel'),
|
|
34
|
-
onPress:
|
|
47
|
+
onPress: () => {
|
|
48
|
+
socket?.close();
|
|
49
|
+
socket = null;
|
|
50
|
+
setIsDisabled(false);
|
|
51
|
+
goBack();
|
|
52
|
+
},
|
|
35
53
|
},
|
|
36
54
|
{
|
|
37
55
|
text: t('retry'),
|
|
38
56
|
onPress: connectToDeviceWifi,
|
|
39
57
|
},
|
|
40
|
-
]
|
|
58
|
+
],
|
|
59
|
+
[connectToDeviceWifi, goBack, t]
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const connectWifiSsid = useCallback(
|
|
63
|
+
async (wifiSsid = '', passWifi = 'Eoh@2021', isWep = false) => {
|
|
64
|
+
try {
|
|
65
|
+
if (Platform.OS === 'ios') {
|
|
66
|
+
await WifiManager.connectToProtectedSSIDPrefix(
|
|
67
|
+
wifiSsid,
|
|
68
|
+
passWifi,
|
|
69
|
+
isWep
|
|
70
|
+
);
|
|
71
|
+
} else {
|
|
72
|
+
await WifiManager.connectToProtectedSSID(wifiSsid, passWifi, isWep);
|
|
73
|
+
}
|
|
74
|
+
setIsDisabled(false);
|
|
75
|
+
setCurrentState(1);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
Alert.alert(
|
|
78
|
+
t('cannot_connect_to_device_wifi'),
|
|
79
|
+
t('try_to_turn_on_device_or_try_again'),
|
|
80
|
+
buttons
|
|
81
|
+
);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
[buttons, t]
|
|
86
|
+
);
|
|
41
87
|
|
|
88
|
+
const connectToDeviceWifi = useCallback(async () => {
|
|
89
|
+
setIsDisabled(true);
|
|
90
|
+
setIsPressButton(true);
|
|
91
|
+
const prefix = `${qrData.org_slug}.${qrData.prefix}`;
|
|
92
|
+
const wifiPrefix = `${prefix.toLowerCase()}.`;
|
|
42
93
|
if (Platform.OS === 'android') {
|
|
43
94
|
let phoneWifiList;
|
|
44
95
|
try {
|
|
@@ -50,8 +101,8 @@ const ConnectingWifiGuide = ({ route }) => {
|
|
|
50
101
|
const wifi = _.find(phoneWifiList, function (x) {
|
|
51
102
|
return x.SSID.indexOf(wifiPrefix) === 0;
|
|
52
103
|
});
|
|
53
|
-
|
|
54
104
|
if (!wifi) {
|
|
105
|
+
phoneWifiList = null;
|
|
55
106
|
Alert.alert(
|
|
56
107
|
t('fail_to_discover_device_wifi'),
|
|
57
108
|
t('try_to_turn_on_device_or_try_again'),
|
|
@@ -59,83 +110,78 @@ const ConnectingWifiGuide = ({ route }) => {
|
|
|
59
110
|
);
|
|
60
111
|
return;
|
|
61
112
|
}
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
await WifiManager.connectToProtectedSSID(wifi.SSID, 'Eoh@2021', false);
|
|
65
|
-
setCurrentState(1);
|
|
66
|
-
} catch (e) {
|
|
67
|
-
Alert.alert(
|
|
68
|
-
t('cannot_connect_to_device_wifi'),
|
|
69
|
-
t('try_to_turn_on_device_or_try_again'),
|
|
70
|
-
buttons
|
|
71
|
-
);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
113
|
+
await connectWifiSsid(wifi.SSID);
|
|
74
114
|
} else {
|
|
75
|
-
|
|
76
|
-
await WifiManager.connectToProtectedSSIDPrefix(
|
|
77
|
-
wifiPrefix,
|
|
78
|
-
'Eoh@2021',
|
|
79
|
-
false
|
|
80
|
-
);
|
|
81
|
-
setCurrentState(1);
|
|
82
|
-
} catch (e) {
|
|
83
|
-
Alert.alert(
|
|
84
|
-
t('cannot_connect_to_device_wifi'),
|
|
85
|
-
t('try_turn_on_device_or_try_again'),
|
|
86
|
-
buttons
|
|
87
|
-
);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
115
|
+
await connectWifiSsid(wifiPrefix);
|
|
90
116
|
}
|
|
91
117
|
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
socket.bind(54321);
|
|
118
|
+
if (intervalSend) {
|
|
119
|
+
clearInterval(intervalSend);
|
|
95
120
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
setWifiList(data.wifi);
|
|
101
|
-
setCurrentState(0);
|
|
102
|
-
clearInterval(intervalSend);
|
|
103
|
-
socket?.close();
|
|
104
|
-
socket = null;
|
|
121
|
+
try {
|
|
122
|
+
if (!socket) {
|
|
123
|
+
socket = dgram.createSocket({ type: 'udp4' });
|
|
124
|
+
socket.bind(54321);
|
|
105
125
|
}
|
|
106
|
-
});
|
|
107
126
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
127
|
+
socket.on('message', (msg, rinfo) => {
|
|
128
|
+
const data = JSON.parse(msg.toString());
|
|
129
|
+
if (Object.prototype.hasOwnProperty.call(data, 'wifi')) {
|
|
130
|
+
setWifiList(data.wifi);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
111
133
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
134
|
+
socket.on('error', () => {
|
|
135
|
+
ToastBottomHelper.error(t('fail_trigger_scan_wifi_on_device'));
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
intervalSend = setInterval(() => {
|
|
139
|
+
socket?.send(
|
|
140
|
+
JSON.stringify({ type: 'scan', data: { wifi: '' } }),
|
|
141
|
+
undefined,
|
|
142
|
+
undefined,
|
|
143
|
+
54321,
|
|
144
|
+
'192.168.27.1',
|
|
145
|
+
undefined
|
|
146
|
+
);
|
|
147
|
+
}, 5000); // workaround, todo Bang continue research
|
|
148
|
+
// eslint-disable-next-line no-empty
|
|
149
|
+
} catch (error) {}
|
|
150
|
+
setIsPressButton(false);
|
|
151
|
+
}, [buttons, connectWifiSsid, qrData?.org_slug, qrData?.prefix, t]);
|
|
115
152
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (isFocused) {
|
|
155
|
+
if (isBackFromOtherScreen) {
|
|
156
|
+
const currentConnectingWifi = getCurrentWifiSSID();
|
|
157
|
+
disconnectWifi(currentConnectingWifi);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return () => {
|
|
161
|
+
if (socket) {
|
|
162
|
+
socket?.close();
|
|
163
|
+
socket = null;
|
|
164
|
+
}
|
|
165
|
+
setIsDisabled(false);
|
|
166
|
+
};
|
|
167
|
+
}, [isFocused, isBackFromOtherScreen, getCurrentWifiSSID, disconnectWifi]);
|
|
127
168
|
|
|
128
169
|
useEffect(() => {
|
|
129
|
-
if (wifiList.length) {
|
|
170
|
+
if (wifiList.length > 0) {
|
|
171
|
+
setCurrentState(0);
|
|
172
|
+
clearInterval(intervalSend);
|
|
173
|
+
socket?.close();
|
|
174
|
+
socket = null;
|
|
130
175
|
navigate(Routes.ShareWifiPassword, {
|
|
131
176
|
unitId,
|
|
132
177
|
subUnit,
|
|
133
178
|
wifiList,
|
|
134
179
|
qrData: qrData,
|
|
135
180
|
addDeviceType,
|
|
181
|
+
stationId,
|
|
136
182
|
});
|
|
137
183
|
}
|
|
138
|
-
}, [addDeviceType, navigate, qrData, subUnit, unitId, wifiList]);
|
|
184
|
+
}, [addDeviceType, navigate, qrData, stationId, subUnit, unitId, wifiList]);
|
|
139
185
|
|
|
140
186
|
return (
|
|
141
187
|
<View style={styles.container}>
|
|
@@ -156,16 +202,34 @@ const ConnectingWifiGuide = ({ route }) => {
|
|
|
156
202
|
style={styles.bottomButtonView}
|
|
157
203
|
mainTitle={t('ok')}
|
|
158
204
|
onPressMain={connectToDeviceWifi}
|
|
159
|
-
typeMain={'primary'}
|
|
205
|
+
typeMain={isDisabled && isPressButton ? 'disabled' : 'primary'}
|
|
160
206
|
accessibilityLabelPrefix={
|
|
161
207
|
AccessibilityLabel.PREFIX.BUTTON_CONNECT_WIFI
|
|
162
208
|
}
|
|
163
209
|
/>
|
|
164
210
|
</>
|
|
165
211
|
) : (
|
|
166
|
-
<
|
|
212
|
+
<LottieView
|
|
213
|
+
source={LoadingCircle}
|
|
214
|
+
autoPlay
|
|
215
|
+
loop
|
|
216
|
+
style={styles.loading}
|
|
217
|
+
/>
|
|
167
218
|
)}
|
|
168
219
|
</View>
|
|
220
|
+
{isDisabled && isPressButton && (
|
|
221
|
+
<FullLoading
|
|
222
|
+
styleBackground={styles.backgroundLoading}
|
|
223
|
+
customIcon={
|
|
224
|
+
<LottieView
|
|
225
|
+
source={LoadingCircle}
|
|
226
|
+
autoPlay
|
|
227
|
+
loop
|
|
228
|
+
style={styles.loading}
|
|
229
|
+
/>
|
|
230
|
+
}
|
|
231
|
+
/>
|
|
232
|
+
)}
|
|
169
233
|
</View>
|
|
170
234
|
);
|
|
171
235
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Platform } from 'react-native';
|
|
2
1
|
import { Dimensions, StyleSheet } from 'react-native';
|
|
3
2
|
import { getBottomSpace } from 'react-native-iphone-x-helper';
|
|
4
3
|
import { Colors } from '../../configs';
|
|
@@ -58,11 +57,13 @@ export default StyleSheet.create({
|
|
|
58
57
|
lineHeight: 24,
|
|
59
58
|
},
|
|
60
59
|
bottomButtonView: {
|
|
61
|
-
marginBottom:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
marginBottom: getBottomSpace(),
|
|
61
|
+
},
|
|
62
|
+
loading: {
|
|
63
|
+
width: 40,
|
|
64
|
+
height: 40,
|
|
65
|
+
},
|
|
66
|
+
backgroundLoading: {
|
|
67
|
+
backgroundColor: Colors.Gray21,
|
|
67
68
|
},
|
|
68
69
|
});
|