@amazon-devices/expo-network 2.0.1758683737
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/.eslintrc.js +2 -0
- package/CHANGELOG.md +156 -0
- package/CMakeLists.txt +50 -0
- package/LICENSE +7 -0
- package/README.kepler.md +104 -0
- package/README.md +44 -0
- package/THIRD_PARTY_NOTICES.txt +24 -0
- package/android/build.gradle +107 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/expo/modules/network/NetworkExceptions.kt +9 -0
- package/android/src/main/java/expo/modules/network/NetworkModule.kt +144 -0
- package/android/src/main/java/expo/modules/network/NetworkUtils.kt +7 -0
- package/build/ExpoNetwork.d.ts +3 -0
- package/build/ExpoNetwork.d.ts.map +1 -0
- package/build/ExpoNetwork.js +3 -0
- package/build/ExpoNetwork.js.map +1 -0
- package/build/ExpoNetwork.kepler.d.ts +9 -0
- package/build/ExpoNetwork.kepler.d.ts.map +1 -0
- package/build/ExpoNetwork.kepler.js +62 -0
- package/build/ExpoNetwork.kepler.js.map +1 -0
- package/build/ExpoNetwork.web.d.ts +7 -0
- package/build/ExpoNetwork.web.d.ts.map +1 -0
- package/build/ExpoNetwork.web.js +22 -0
- package/build/ExpoNetwork.web.js.map +1 -0
- package/build/Network.d.ts +50 -0
- package/build/Network.d.ts.map +1 -0
- package/build/Network.js +70 -0
- package/build/Network.js.map +1 -0
- package/build/Network.types.d.ts +62 -0
- package/build/Network.types.d.ts.map +1 -0
- package/build/Network.types.js +45 -0
- package/build/Network.types.js.map +1 -0
- package/expo-module.config.json +10 -0
- package/ios/Exceptions.swift +7 -0
- package/ios/ExpoNetwork.podspec +31 -0
- package/ios/NetworkModule.swift +102 -0
- package/ios/NetworkType.swift +28 -0
- package/kepler/ExpoNetwork.cpp +55 -0
- package/kepler/ExpoNetwork.h +24 -0
- package/kepler/KeplerInit.cpp +28 -0
- package/kepler/NetworkInterfaces.cpp +74 -0
- package/kepler/NetworkInterfaces.h +20 -0
- package/kepler/test/Network.cpp +147 -0
- package/package.json +1 -0
- package/react-native.config.js +21 -0
- package/src/ExpoNetwork.kepler.ts +80 -0
- package/src/ExpoNetwork.ts +2 -0
- package/src/ExpoNetwork.web.ts +21 -0
- package/src/Network.ts +74 -0
- package/src/Network.types.ts +64 -0
- package/tsconfig.json +9 -0
package/.eslintrc.js
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unpublished
|
|
4
|
+
|
|
5
|
+
### 🛠 Breaking changes
|
|
6
|
+
|
|
7
|
+
### 🎉 New features
|
|
8
|
+
|
|
9
|
+
### 🐛 Bug fixes
|
|
10
|
+
|
|
11
|
+
### 💡 Others
|
|
12
|
+
|
|
13
|
+
## 5.7.0 — 2023-10-17
|
|
14
|
+
|
|
15
|
+
### 🛠 Breaking changes
|
|
16
|
+
|
|
17
|
+
- Dropped support for Android SDK 21 and 22. ([#24201](https://github.com/expo/expo/pull/24201) by [@behenate](https://github.com/behenate))
|
|
18
|
+
|
|
19
|
+
### 🎉 New features
|
|
20
|
+
|
|
21
|
+
- Add Node.js support. ([#24505](https://github.com/expo/expo/pull/24505) by [@EvanBacon](https://github.com/EvanBacon))
|
|
22
|
+
|
|
23
|
+
### 💡 Others
|
|
24
|
+
|
|
25
|
+
- Remove deprecated `getMacAddressAsync` method. ([#24505](https://github.com/expo/expo/pull/24505) by [@EvanBacon](https://github.com/EvanBacon))
|
|
26
|
+
|
|
27
|
+
## 5.6.0 — 2023-09-04
|
|
28
|
+
|
|
29
|
+
### 🎉 New features
|
|
30
|
+
|
|
31
|
+
- Added support for React Native 0.73. ([#24018](https://github.com/expo/expo/pull/24018) by [@kudo](https://github.com/kudo))
|
|
32
|
+
|
|
33
|
+
## 5.5.0 — 2023-08-02
|
|
34
|
+
|
|
35
|
+
_This version does not introduce any user-facing changes._
|
|
36
|
+
|
|
37
|
+
## 5.4.0 — 2023-06-21
|
|
38
|
+
|
|
39
|
+
### 🐛 Bug fixes
|
|
40
|
+
|
|
41
|
+
- Fixed Android build warnings for Gradle version 8. ([#22537](https://github.com/expo/expo/pull/22537), [#22609](https://github.com/expo/expo/pull/22609) by [@kudo](https://github.com/kudo))
|
|
42
|
+
|
|
43
|
+
## 5.3.0 — 2023-05-08
|
|
44
|
+
|
|
45
|
+
_This version does not introduce any user-facing changes._
|
|
46
|
+
|
|
47
|
+
## 5.2.1 — 2023-02-09
|
|
48
|
+
|
|
49
|
+
_This version does not introduce any user-facing changes._
|
|
50
|
+
|
|
51
|
+
## 5.2.0 — 2023-02-03
|
|
52
|
+
|
|
53
|
+
### 💡 Others
|
|
54
|
+
|
|
55
|
+
- On Android bump `compileSdkVersion` and `targetSdkVersion` to `33`. ([#20721](https://github.com/expo/expo/pull/20721) by [@lukmccall](https://github.com/lukmccall))
|
|
56
|
+
|
|
57
|
+
## 5.1.0 — 2022-12-30
|
|
58
|
+
|
|
59
|
+
### 🎉 New features
|
|
60
|
+
|
|
61
|
+
- Migrated to Expo Modules API. ([#20083](https://github.com/expo/expo/pull/20083) and [#20303](https://github.com/expo/expo/pull/20303) by [@alanhughes](https://github.com/alanjhughes))
|
|
62
|
+
|
|
63
|
+
## 5.0.0 — 2022-10-25
|
|
64
|
+
|
|
65
|
+
### 🛠 Breaking changes
|
|
66
|
+
|
|
67
|
+
- Bumped iOS deployment target to 13.0 and deprecated support for iOS 12. ([#18873](https://github.com/expo/expo/pull/18873) by [@tsapeta](https://github.com/tsapeta))
|
|
68
|
+
|
|
69
|
+
## 4.3.0 — 2022-07-07
|
|
70
|
+
|
|
71
|
+
_This version does not introduce any user-facing changes._
|
|
72
|
+
|
|
73
|
+
## 4.2.0 — 2022-04-18
|
|
74
|
+
|
|
75
|
+
### ⚠️ Notices
|
|
76
|
+
|
|
77
|
+
- On Android bump `compileSdkVersion` to `31`, `targetSdkVersion` to `31` and `Java` version to `11`. ([#16941](https://github.com/expo/expo/pull/16941) by [@bbarthec](https://github.com/bbarthec))
|
|
78
|
+
|
|
79
|
+
## 4.1.1 - 2022-02-01
|
|
80
|
+
|
|
81
|
+
### 🐛 Bug fixes
|
|
82
|
+
|
|
83
|
+
- Fix `Plugin with id 'maven' not found` build error from Android Gradle 7. ([#16080](https://github.com/expo/expo/pull/16080) by [@kudo](https://github.com/kudo))
|
|
84
|
+
|
|
85
|
+
## 4.1.0 — 2021-12-03
|
|
86
|
+
|
|
87
|
+
_This version does not introduce any user-facing changes._
|
|
88
|
+
|
|
89
|
+
## 4.0.1 — 2021-10-01
|
|
90
|
+
|
|
91
|
+
_This version does not introduce any user-facing changes._
|
|
92
|
+
|
|
93
|
+
## 4.0.0 — 2021-09-28
|
|
94
|
+
|
|
95
|
+
### 🛠 Breaking changes
|
|
96
|
+
|
|
97
|
+
- Dropped support for iOS 11.0 ([#14383](https://github.com/expo/expo/pull/14383) by [@cruzach](https://github.com/cruzach))
|
|
98
|
+
|
|
99
|
+
### 🐛 Bug fixes
|
|
100
|
+
|
|
101
|
+
- Fix building errors from use_frameworks! in Podfile. ([#14523](https://github.com/expo/expo/pull/14523) by [@kudo](https://github.com/kudo))
|
|
102
|
+
|
|
103
|
+
### 💡 Others
|
|
104
|
+
|
|
105
|
+
- Migrated from `@unimodules/core` to `expo-modules-core`. ([#13757](https://github.com/expo/expo/pull/13757) by [@tsapeta](https://github.com/tsapeta))
|
|
106
|
+
- Rewrite Android code to Kotlin. ([#14474](https://github.com/expo/expo/pull/14474) by [@kkafar](https://github.com/kkafar))
|
|
107
|
+
|
|
108
|
+
## 3.2.0 — 2021-06-16
|
|
109
|
+
|
|
110
|
+
### 🐛 Bug fixes
|
|
111
|
+
|
|
112
|
+
- Enable kotlin in all modules. ([#12716](https://github.com/expo/expo/pull/12716) by [@wschurman](https://github.com/wschurman))
|
|
113
|
+
|
|
114
|
+
### 💡 Others
|
|
115
|
+
|
|
116
|
+
- Build Android code using Java 8 to fix Android instrumented test build error. ([#12939](https://github.com/expo/expo/pull/12939) by [@kudo](https://github.com/kudo))
|
|
117
|
+
|
|
118
|
+
## 3.1.1 — 2021-03-30
|
|
119
|
+
|
|
120
|
+
_This version does not introduce any user-facing changes._
|
|
121
|
+
|
|
122
|
+
## 3.1.0 — 2021-03-10
|
|
123
|
+
|
|
124
|
+
### 🎉 New features
|
|
125
|
+
|
|
126
|
+
- Updated Android build configuration to target Android 11 (added support for Android SDK 30). ([#11647](https://github.com/expo/expo/pull/11647) by [@bbarthec](https://github.com/bbarthec))
|
|
127
|
+
|
|
128
|
+
### 🐛 Bug fixes
|
|
129
|
+
|
|
130
|
+
- Remove peerDependencies and unimodulePeerDependencies from Expo modules. ([#11980](https://github.com/expo/expo/pull/11980) by [@brentvatne](https://github.com/brentvatne))
|
|
131
|
+
|
|
132
|
+
## 3.0.0 — 2021-01-15
|
|
133
|
+
|
|
134
|
+
### 🛠 Breaking changes
|
|
135
|
+
|
|
136
|
+
- Dropped support for iOS 10.0 ([#11344](https://github.com/expo/expo/pull/11344) by [@tsapeta](https://github.com/tsapeta))
|
|
137
|
+
|
|
138
|
+
### 🐛 Bug fixes
|
|
139
|
+
|
|
140
|
+
- Fixed issue on Android where apps would crash when calling `getIpAddressAsync` when using cellular data or on certain IP addresses.
|
|
141
|
+
|
|
142
|
+
## 2.4.0 — 2020-11-17
|
|
143
|
+
|
|
144
|
+
_This version does not introduce any user-facing changes._
|
|
145
|
+
|
|
146
|
+
## 2.3.0 — 2020-08-18
|
|
147
|
+
|
|
148
|
+
_This version does not introduce any user-facing changes._
|
|
149
|
+
|
|
150
|
+
## 2.2.1 — 2020-05-29
|
|
151
|
+
|
|
152
|
+
_This version does not introduce any user-facing changes._
|
|
153
|
+
|
|
154
|
+
## 2.2.0 — 2020-05-27
|
|
155
|
+
|
|
156
|
+
_This version does not introduce any user-facing changes._
|
package/CMakeLists.txt
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2023 Amazon.com, Inc. or its affiliates. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# AMAZON PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
#
|
|
6
|
+
# You may not use this file except in compliance with the terms and conditions
|
|
7
|
+
# set forth in the accompanying LICENSE.TXT file.
|
|
8
|
+
#
|
|
9
|
+
# THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY
|
|
10
|
+
# DISCLAIMS, WITH RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS,
|
|
11
|
+
# IMPLIED, OR STATUTORY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
|
12
|
+
# FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|
13
|
+
#
|
|
14
|
+
set(PACKAGE_NAME "expo-network")
|
|
15
|
+
set(AUTO_LINK_PACKAGE_NAME "${PACKAGE_NAME}-${KEPLER_REACT_NATIVE_MAJOR_VERSION}")
|
|
16
|
+
set(SOURCES_KEPLER
|
|
17
|
+
kepler/ExpoNetwork.cpp
|
|
18
|
+
kepler/NetworkInterfaces.cpp
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
add_library(${PACKAGE_NAME} STATIC ${SOURCES_KEPLER})
|
|
22
|
+
|
|
23
|
+
target_link_libraries(
|
|
24
|
+
${PACKAGE_NAME}
|
|
25
|
+
PUBLIC
|
|
26
|
+
keplerui::keplerscript-${KEPLER_REACT_NATIVE_MAJOR_VERSION}
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
add_library(${AUTO_LINK_PACKAGE_NAME} SHARED kepler/KeplerInit.cpp)
|
|
30
|
+
|
|
31
|
+
set_target_properties(${AUTO_LINK_PACKAGE_NAME} PROPERTIES SOVERSION ${KEPLER_REACT_NATIVE_MAJOR_VERSION}.${KEPLER_REACT_NATIVE_MINOR_VERSION})
|
|
32
|
+
|
|
33
|
+
target_link_libraries(
|
|
34
|
+
${AUTO_LINK_PACKAGE_NAME}
|
|
35
|
+
PRIVATE
|
|
36
|
+
keplerui::keplerscript-${KEPLER_REACT_NATIVE_MAJOR_VERSION}
|
|
37
|
+
${PACKAGE_NAME}
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# Helps in checking undefined references
|
|
41
|
+
add_executable(${AUTO_LINK_PACKAGE_NAME}_exe kepler/KeplerInit.cpp)
|
|
42
|
+
target_link_libraries(${AUTO_LINK_PACKAGE_NAME}_exe
|
|
43
|
+
PRIVATE
|
|
44
|
+
${AUTO_LINK_PACKAGE_NAME}
|
|
45
|
+
keplerui::keplerscript-${KEPLER_REACT_NATIVE_MAJOR_VERSION}
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
install(TARGETS ${AUTO_LINK_PACKAGE_NAME}
|
|
49
|
+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
50
|
+
)
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
|
|
2
|
+
|
|
3
|
+
These materials are licensed as "Program Materials" under the Program Materials License Agreement (the "Agreement"). The Agreement is available at https://developer.amazon.com/support/legal/pml. See the Agreement for the specific terms and conditions of the Agreement. Capitalized terms not defined in this file have the meanings given to them in the Agreement.
|
|
4
|
+
|
|
5
|
+
If you do not agree to the above terms and conditions, you may not use any file in this package.
|
|
6
|
+
|
|
7
|
+
YOUR USE OF THE PROGRAM MATERIALS IN OR ASSOCIATED WITH THIS PACKAGE IS AT YOUR SOLE RISK. IN NO EVENT WILL AMAZON BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION ANY DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL, INCIDENTAL, OR PUNITIVE DAMAGES (INCLUDING FOR ANY LOSS OF GOODWILL, BUSINESS INTERRUPTION, LOST PROFITS OR DATA, OR COMPUTER FAILURE OR MALFUNCTION) ARISING FROM OR RELATING TO SUCH PROGRAM MATERIALS, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, EVEN IF AMAZON HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS AND DISCLAIMERS APPLY EXCEPT TO THE EXTENT PROHIBITED BY APPLICABLE LAW.
|
package/README.kepler.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# @amazon-devices/expo-network
|
|
2
|
+
|
|
3
|
+
## Getting Started
|
|
4
|
+
|
|
5
|
+
`@amazon-devices/expo-network` provides useful information about the device's network such as its IP address, MAC address, and airplane mode status.
|
|
6
|
+
|
|
7
|
+
### Installation
|
|
8
|
+
|
|
9
|
+
1. Add the JavaScript library dependency in the `package.json` file:
|
|
10
|
+
```json
|
|
11
|
+
dependencies: {
|
|
12
|
+
...
|
|
13
|
+
"@amazon-devices/expo-network": "~2.0.0",
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
2. Reinstall dependencies using `npm install` command.
|
|
18
|
+
|
|
19
|
+
## Usage Examples
|
|
20
|
+
|
|
21
|
+
To test network features, you need to connect to the WiFi on your device shell. Replace NETWORK and PASSWORD with proper credentials.
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
> ace mw wifi add_network ssid=$NETWORK psk=$PASSWORD
|
|
25
|
+
> ace mw wifi connect $NETWORK
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Expo network example:
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import * as Network from '@amazon-devices/expo-network';
|
|
32
|
+
import React, {useEffect, useState} from 'react';
|
|
33
|
+
import {StyleSheet, Text, View} from 'react-native';
|
|
34
|
+
|
|
35
|
+
export const App = () => {
|
|
36
|
+
const [networkState, setNetworkState] = useState<Network.NetworkState>();
|
|
37
|
+
const [ipAddress, setIpAddress] = useState<string>();
|
|
38
|
+
const [airplaneModeEnabled, setAirplaneModeEnabled] = useState<boolean>();
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
(async () => {
|
|
42
|
+
setNetworkState(await Network.getNetworkStateAsync());
|
|
43
|
+
setIpAddress(await Network.getIpAddressAsync());
|
|
44
|
+
setAirplaneModeEnabled(await Network.isAirplaneModeEnabledAsync());
|
|
45
|
+
})();
|
|
46
|
+
}, []);
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<View style={styles.container}>
|
|
50
|
+
<Text style={styles.text}>
|
|
51
|
+
getNetworkStateAsync().type: {networkState?.type}
|
|
52
|
+
</Text>
|
|
53
|
+
<Text style={styles.text}>
|
|
54
|
+
getNetworkStateAsync().isConnected: {String(networkState?.isConnected)}
|
|
55
|
+
</Text>
|
|
56
|
+
<Text style={styles.text}>
|
|
57
|
+
getNetworkStateAsync().isInternetReachable:{' '}
|
|
58
|
+
{String(networkState?.isInternetReachable)}
|
|
59
|
+
</Text>
|
|
60
|
+
<Text style={styles.text}>getIpAddressAsync(): {ipAddress}</Text>
|
|
61
|
+
<Text style={styles.text}>
|
|
62
|
+
isAirplaneModeEnabledAsync(): {String(airplaneModeEnabled)}
|
|
63
|
+
</Text>
|
|
64
|
+
</View>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const styles = StyleSheet.create({
|
|
69
|
+
container: {
|
|
70
|
+
backgroundColor: 'white',
|
|
71
|
+
flex: 1,
|
|
72
|
+
},
|
|
73
|
+
text: {
|
|
74
|
+
color: 'black',
|
|
75
|
+
fontSize: 32,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## API Reference
|
|
83
|
+
|
|
84
|
+
Check out the dedicated documentation page for info about this library, API reference and more: [Official Expo documentation for expo-network](https://github.com/expo/expo/blob/sdk-49/docs/pages/versions/v49.0.0/sdk/network.mdx).
|
|
85
|
+
|
|
86
|
+
### Methods
|
|
87
|
+
|
|
88
|
+
| Name | Type | Description | Platform |
|
|
89
|
+
|------|------|-------------|----------|
|
|
90
|
+
| Network.getIpAddressAsync() | `Promise<string>` | Gets the device's current IPv4 address. Returns 0.0.0.0 if the IP address could not be retrieved. | All |
|
|
91
|
+
| Network.getNetworkStateAsync() | `Promise<NetworkState>` | Gets the device's current network connection state. | All |
|
|
92
|
+
| Network.isAirplaneModeEnabledAsync() | `Promise<boolean>` | Tells if the device is in airplane mode. On Kelper always return false. | Android, Kelper |
|
|
93
|
+
|
|
94
|
+
## Known Issues
|
|
95
|
+
|
|
96
|
+
* `Network.isAirplaneModeEnabledAsync()` - always returns false
|
|
97
|
+
* `Network.getNetworkStateAsync()` - `isInternetReachable` field is always missing
|
|
98
|
+
* `Network.getNetworkStateAsync()` - `type` field can only be either `NONE` or `WIFI`
|
|
99
|
+
|
|
100
|
+
## Supported Versions
|
|
101
|
+
|
|
102
|
+
| Package version | Based on | @amazon-devices/react-native-kepler version |
|
|
103
|
+
| ---------------- | -------- | --------------------------------- |
|
|
104
|
+
| 2.0.x | expo-network v5.7.0 | 2.0.x |
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<p>
|
|
2
|
+
<a href="https://docs.expo.dev/versions/latest/sdk/network/">
|
|
3
|
+
<img
|
|
4
|
+
src="../../.github/resources/expo-network.svg"
|
|
5
|
+
alt="expo-network"
|
|
6
|
+
height="64" />
|
|
7
|
+
</a>
|
|
8
|
+
</p>
|
|
9
|
+
Gets device's network information such as ip address, mac address and check for airplane mode.
|
|
10
|
+
|
|
11
|
+
See [Expo Network docs](https://docs.expo.dev/versions/latest/sdk/network/) for documentation of this universal module's API.
|
|
12
|
+
|
|
13
|
+
# API documentation
|
|
14
|
+
|
|
15
|
+
- [Documentation for the main branch](https://github.com/expo/expo/blob/main/docs/pages/versions/unversioned/sdk/network.mdx)
|
|
16
|
+
- [Documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/network/)
|
|
17
|
+
|
|
18
|
+
# Installation in managed Expo projects
|
|
19
|
+
|
|
20
|
+
For [managed](https://docs.expo.dev/archive/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/network/).
|
|
21
|
+
|
|
22
|
+
# Installation in bare React Native projects
|
|
23
|
+
|
|
24
|
+
For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
|
|
25
|
+
|
|
26
|
+
### Add the package to your npm dependencies
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
npx expo install expo-network
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Configure for Android
|
|
33
|
+
|
|
34
|
+
This module requires permissions to access the network and Wi-Fi state. The `ACCESS_NETWORK_STATE` and `ACCESS_WIFI_STATE` permissions are added automatically.
|
|
35
|
+
|
|
36
|
+
```xml
|
|
37
|
+
<!-- Added permissions -->
|
|
38
|
+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
|
39
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
# Contributing
|
|
43
|
+
|
|
44
|
+
Contributions are very welcome! Please refer to guidelines described in the [contributing guide](https://github.com/expo/expo#contributing).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
License from package.json:
|
|
2
|
+
==============================
|
|
3
|
+
|
|
4
|
+
The MIT License (MIT)
|
|
5
|
+
|
|
6
|
+
Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
apply plugin: 'kotlin-android'
|
|
3
|
+
apply plugin: 'maven-publish'
|
|
4
|
+
|
|
5
|
+
group = 'host.exp.exponent'
|
|
6
|
+
version = '5.7.0'
|
|
7
|
+
|
|
8
|
+
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
9
|
+
if (expoModulesCorePlugin.exists()) {
|
|
10
|
+
apply from: expoModulesCorePlugin
|
|
11
|
+
applyKotlinExpoModulesCorePlugin()
|
|
12
|
+
// Remove this check, but keep the contents after SDK49 support is dropped
|
|
13
|
+
if (safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
14
|
+
useExpoPublishing()
|
|
15
|
+
useCoreDependencies()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
buildscript {
|
|
20
|
+
// Simple helper that allows the root project to override versions declared by this library.
|
|
21
|
+
ext.safeExtGet = { prop, fallback ->
|
|
22
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Ensures backward compatibility
|
|
26
|
+
ext.getKotlinVersion = {
|
|
27
|
+
if (ext.has("kotlinVersion")) {
|
|
28
|
+
ext.kotlinVersion()
|
|
29
|
+
} else {
|
|
30
|
+
ext.safeExtGet("kotlinVersion", "1.8.10")
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
repositories {
|
|
35
|
+
mavenCentral()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
dependencies {
|
|
39
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
44
|
+
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
45
|
+
afterEvaluate {
|
|
46
|
+
publishing {
|
|
47
|
+
publications {
|
|
48
|
+
release(MavenPublication) {
|
|
49
|
+
from components.release
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
repositories {
|
|
53
|
+
maven {
|
|
54
|
+
url = mavenLocal().url
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
android {
|
|
62
|
+
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
63
|
+
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
64
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 33)
|
|
65
|
+
|
|
66
|
+
defaultConfig {
|
|
67
|
+
minSdkVersion safeExtGet("minSdkVersion", 23)
|
|
68
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 33)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
publishing {
|
|
72
|
+
singleVariant("release") {
|
|
73
|
+
withSourcesJar()
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
lintOptions {
|
|
78
|
+
abortOnError false
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
|
|
83
|
+
if (agpVersion.tokenize('.')[0].toInteger() < 8) {
|
|
84
|
+
compileOptions {
|
|
85
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
86
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
kotlinOptions {
|
|
90
|
+
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
namespace "expo.modules.network"
|
|
95
|
+
defaultConfig {
|
|
96
|
+
versionCode 11
|
|
97
|
+
versionName '5.7.0'
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
dependencies {
|
|
102
|
+
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
103
|
+
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
104
|
+
implementation project(':expo-modules-core')
|
|
105
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
package expo.modules.network
|
|
2
|
+
|
|
3
|
+
import expo.modules.kotlin.exception.CodedException
|
|
4
|
+
|
|
5
|
+
internal class NetworkAccessException(e: Exception) :
|
|
6
|
+
CodedException("Unable to access network information", e.cause)
|
|
7
|
+
|
|
8
|
+
internal class NetworkWifiException(e: Exception) :
|
|
9
|
+
CodedException("Wi-Fi information could not be acquired", e.cause)
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
package expo.modules.network
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.net.ConnectivityManager
|
|
5
|
+
import android.net.NetworkCapabilities
|
|
6
|
+
import android.net.NetworkInfo
|
|
7
|
+
import android.net.wifi.WifiInfo
|
|
8
|
+
import android.net.wifi.WifiManager
|
|
9
|
+
import android.os.Build
|
|
10
|
+
import android.os.Bundle
|
|
11
|
+
import android.provider.Settings
|
|
12
|
+
import android.util.Log
|
|
13
|
+
import expo.modules.kotlin.Promise
|
|
14
|
+
import expo.modules.kotlin.exception.Exceptions
|
|
15
|
+
import expo.modules.kotlin.modules.Module
|
|
16
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
17
|
+
import java.math.BigInteger
|
|
18
|
+
import java.net.InetAddress
|
|
19
|
+
import java.net.UnknownHostException
|
|
20
|
+
import java.nio.ByteOrder
|
|
21
|
+
|
|
22
|
+
private val TAG = NetworkModule::class.java.simpleName
|
|
23
|
+
|
|
24
|
+
class NetworkModule : Module() {
|
|
25
|
+
private val context: Context
|
|
26
|
+
get() = appContext.reactContext ?: throw Exceptions.ReactContextLost()
|
|
27
|
+
|
|
28
|
+
override fun definition() = ModuleDefinition {
|
|
29
|
+
Name("ExpoNetwork")
|
|
30
|
+
|
|
31
|
+
AsyncFunction("getNetworkStateAsync") { promise: Promise ->
|
|
32
|
+
val result = Bundle()
|
|
33
|
+
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
if (Build.VERSION.SDK_INT < 29) { // use getActiveNetworkInfo before api level 29
|
|
37
|
+
val netInfo = connectivityManager.activeNetworkInfo
|
|
38
|
+
val connectionType = getConnectionType(netInfo)
|
|
39
|
+
|
|
40
|
+
result.apply {
|
|
41
|
+
putBoolean("isInternetReachable", netInfo!!.isConnected)
|
|
42
|
+
putString("type", connectionType.value)
|
|
43
|
+
putBoolean("isConnected", connectionType.isDefined)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
promise.resolve(result)
|
|
47
|
+
} else {
|
|
48
|
+
val network = connectivityManager.activeNetwork
|
|
49
|
+
val isInternetReachable = network != null
|
|
50
|
+
|
|
51
|
+
val connectionType = if (isInternetReachable) {
|
|
52
|
+
val netCapabilities = connectivityManager.getNetworkCapabilities(network)
|
|
53
|
+
getConnectionType(netCapabilities)
|
|
54
|
+
} else {
|
|
55
|
+
null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
result.apply {
|
|
59
|
+
putString("type", connectionType?.value ?: NetworkStateType.NONE.value)
|
|
60
|
+
putBoolean("isInternetReachable", isInternetReachable)
|
|
61
|
+
putBoolean("isConnected", connectionType != null && connectionType.isDefined)
|
|
62
|
+
}
|
|
63
|
+
promise.resolve(result)
|
|
64
|
+
}
|
|
65
|
+
} catch (e: Exception) {
|
|
66
|
+
throw NetworkAccessException(e)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
AsyncFunction("getIpAddressAsync") {
|
|
71
|
+
return@AsyncFunction rawIpToString(wifiInfo.ipAddress)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
AsyncFunction("isAirplaneModeEnabledAsync") {
|
|
75
|
+
return@AsyncFunction Settings.Global.getInt(context.contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0) != 0
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
enum class NetworkStateType(val value: String) {
|
|
80
|
+
NONE("NONE"),
|
|
81
|
+
UNKNOWN("UNKNOWN"),
|
|
82
|
+
CELLULAR("CELLULAR"),
|
|
83
|
+
WIFI("WIFI"),
|
|
84
|
+
BLUETOOTH("BLUETOOTH"),
|
|
85
|
+
ETHERNET("ETHERNET"),
|
|
86
|
+
WIMAX("WIMAX"),
|
|
87
|
+
VPN("VPN"),
|
|
88
|
+
OTHER("OTHER");
|
|
89
|
+
|
|
90
|
+
val isDefined: Boolean
|
|
91
|
+
get() = this.value != "NONE" && this.value != "UNKNOWN"
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private val wifiInfo: WifiInfo
|
|
95
|
+
get() = try {
|
|
96
|
+
val manager = context.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
|
97
|
+
manager.connectionInfo
|
|
98
|
+
} catch (e: Exception) {
|
|
99
|
+
Log.e(TAG, e.message ?: "Wi-Fi information could not be acquired")
|
|
100
|
+
throw NetworkWifiException(e)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private fun getConnectionType(netInfo: NetworkInfo?): NetworkStateType = when (netInfo?.type) {
|
|
104
|
+
ConnectivityManager.TYPE_MOBILE,
|
|
105
|
+
ConnectivityManager.TYPE_MOBILE_DUN -> NetworkStateType.CELLULAR
|
|
106
|
+
ConnectivityManager.TYPE_WIFI -> NetworkStateType.WIFI
|
|
107
|
+
ConnectivityManager.TYPE_BLUETOOTH -> NetworkStateType.BLUETOOTH
|
|
108
|
+
ConnectivityManager.TYPE_ETHERNET -> NetworkStateType.ETHERNET
|
|
109
|
+
ConnectivityManager.TYPE_WIMAX -> NetworkStateType.WIMAX
|
|
110
|
+
ConnectivityManager.TYPE_VPN -> NetworkStateType.VPN
|
|
111
|
+
else -> NetworkStateType.UNKNOWN
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private fun getConnectionType(netCapabilities: NetworkCapabilities?): NetworkStateType =
|
|
115
|
+
when {
|
|
116
|
+
netCapabilities == null -> NetworkStateType.UNKNOWN
|
|
117
|
+
netCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> NetworkStateType.CELLULAR
|
|
118
|
+
netCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) || netCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI_AWARE) -> NetworkStateType.WIFI
|
|
119
|
+
netCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_BLUETOOTH) -> NetworkStateType.BLUETOOTH
|
|
120
|
+
netCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> NetworkStateType.ETHERNET
|
|
121
|
+
netCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN) -> NetworkStateType.VPN
|
|
122
|
+
else -> NetworkStateType.UNKNOWN
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private fun rawIpToString(ipAddress: Int): String {
|
|
126
|
+
// Convert little-endian to big-endian if needed
|
|
127
|
+
val ip = if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
|
|
128
|
+
Integer.reverseBytes(ipAddress)
|
|
129
|
+
} else {
|
|
130
|
+
ipAddress
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
var ipByteArray = BigInteger.valueOf(ip.toLong()).toByteArray()
|
|
134
|
+
if (ipByteArray.size < 4) {
|
|
135
|
+
ipByteArray = frontPadWithZeros(ipByteArray)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return try {
|
|
139
|
+
InetAddress.getByAddress(ipByteArray).hostAddress as String
|
|
140
|
+
} catch (e: UnknownHostException) {
|
|
141
|
+
"0.0.0.0"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpoNetwork.d.ts","sourceRoot":"","sources":["../src/ExpoNetwork.ts"],"names":[],"mappings":";AACA,wBAAkD"}
|