@ohos-ports/expo-network 57.0.2-beta.0
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/CHANGELOG.md +391 -0
- package/LICENSE +21 -0
- package/README.md +44 -0
- package/android/build.gradle +27 -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 +281 -0
- package/android/src/main/java/expo/modules/network/NetworkUtils.kt +52 -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.web.d.ts +14 -0
- package/build/ExpoNetwork.web.d.ts.map +1 -0
- package/build/ExpoNetwork.web.js +47 -0
- package/build/ExpoNetwork.web.js.map +1 -0
- package/build/Network.d.ts +80 -0
- package/build/Network.d.ts.map +1 -0
- package/build/Network.js +111 -0
- package/build/Network.js.map +1 -0
- package/build/Network.types.d.ts +85 -0
- package/build/Network.types.d.ts.map +1 -0
- package/build/Network.types.js +55 -0
- package/build/Network.types.js.map +1 -0
- package/expo-module.config.json +15 -0
- package/ios/Exceptions.swift +7 -0
- package/ios/ExpoNetwork.podspec +28 -0
- package/ios/NetworkModule.swift +155 -0
- package/ios/NetworkType.swift +30 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2-sources.jar +0 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2-sources.jar.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2-sources.jar.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2-sources.jar.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2-sources.jar.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.aar +0 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.aar.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.aar.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.aar.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.aar.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.module +101 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.module.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.module.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.module.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.module.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.pom +59 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.pom.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.pom.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.pom.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/57.0.2/expo.modules.network-57.0.2.pom.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/maven-metadata.xml +13 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/maven-metadata.xml.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/maven-metadata.xml.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/maven-metadata.xml.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.network/maven-metadata.xml.sha512 +1 -0
- package/package.json +41 -0
- package/spm.config.json +37 -0
- package/src/ExpoNetwork.ts +3 -0
- package/src/ExpoNetwork.web.ts +52 -0
- package/src/Network.ts +123 -0
- package/src/Network.types.ts +90 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export type NetworkState = {
|
|
2
|
+
/**
|
|
3
|
+
* A [`NetworkStateType`](#networkstatetype) enum value that represents the current network
|
|
4
|
+
* connection type.
|
|
5
|
+
*/
|
|
6
|
+
type?: NetworkStateType;
|
|
7
|
+
/**
|
|
8
|
+
* If there is an active network connection. Note that this does not mean that internet is reachable.
|
|
9
|
+
* This field is `false` if the type is either `Network.NetworkStateType.NONE` or `Network.NetworkStateType.UNKNOWN`,
|
|
10
|
+
* `true` otherwise.
|
|
11
|
+
*/
|
|
12
|
+
isConnected?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* If the internet is reachable with the currently active network connection. On Android, this
|
|
15
|
+
* requires the active network to have internet capability (`NET_CAPABILITY_INTERNET`), confirmed
|
|
16
|
+
* internet access (`NET_CAPABILITY_VALIDATED`), and a usable connection state. VPN connections
|
|
17
|
+
* also require non-zero downstream bandwidth. On iOS, this value will always be the same as
|
|
18
|
+
* `isConnected`.
|
|
19
|
+
*/
|
|
20
|
+
isInternetReachable?: boolean;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* An enum of the different types of devices supported by Expo.
|
|
24
|
+
*/
|
|
25
|
+
export declare enum NetworkStateType {
|
|
26
|
+
/**
|
|
27
|
+
* No active network connection detected.
|
|
28
|
+
*/
|
|
29
|
+
NONE = "NONE",
|
|
30
|
+
/**
|
|
31
|
+
* The connection type could not be determined.
|
|
32
|
+
*/
|
|
33
|
+
UNKNOWN = "UNKNOWN",
|
|
34
|
+
/**
|
|
35
|
+
* Active network connection over mobile data or [`DUN-specific`](https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_MOBILE_DUN)
|
|
36
|
+
* mobile connection when setting an upstream connection for tethering.
|
|
37
|
+
* @platform android
|
|
38
|
+
* @platform ios
|
|
39
|
+
*/
|
|
40
|
+
CELLULAR = "CELLULAR",
|
|
41
|
+
/**
|
|
42
|
+
* Active network connection over Wi-Fi.
|
|
43
|
+
* @platform android
|
|
44
|
+
* @platform ios
|
|
45
|
+
*/
|
|
46
|
+
WIFI = "WIFI",
|
|
47
|
+
/**
|
|
48
|
+
* Active network connection over Bluetooth.
|
|
49
|
+
* @platform android
|
|
50
|
+
*/
|
|
51
|
+
BLUETOOTH = "BLUETOOTH",
|
|
52
|
+
/**
|
|
53
|
+
* Active network connection over Ethernet.
|
|
54
|
+
* @platform android
|
|
55
|
+
* @platform ios
|
|
56
|
+
*/
|
|
57
|
+
ETHERNET = "ETHERNET",
|
|
58
|
+
/**
|
|
59
|
+
* Active network connection over WiMAX.
|
|
60
|
+
* @platform android
|
|
61
|
+
*/
|
|
62
|
+
WIMAX = "WIMAX",
|
|
63
|
+
/**
|
|
64
|
+
* Active network connection over VPN.
|
|
65
|
+
* @platform android
|
|
66
|
+
*/
|
|
67
|
+
VPN = "VPN",
|
|
68
|
+
/**
|
|
69
|
+
* Active network connection over other network connection types.
|
|
70
|
+
* @platform android
|
|
71
|
+
*/
|
|
72
|
+
OTHER = "OTHER"
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Represents an event that provides the updated network state when there is a change in the network status.
|
|
76
|
+
* This is passed as the argument to listeners registered with [`addNetworkStateListener()`](#networkaddnetworkstatelistenerlistener).
|
|
77
|
+
*/
|
|
78
|
+
export type NetworkStateEvent = NetworkState;
|
|
79
|
+
/**
|
|
80
|
+
* @hidden
|
|
81
|
+
*/
|
|
82
|
+
export type NetworkEvents = {
|
|
83
|
+
onNetworkStateChanged(event: NetworkStateEvent): void;
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=Network.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Network.types.d.ts","sourceRoot":"","sources":["../src/Network.types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,YAAY,GAAG;IACzB;;;OAGG;IACH,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;OAMG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AAGF;;GAEG;AACH,oBAAY,gBAAgB;IAC1B;;OAEG;IACH,IAAI,SAAS;IACb;;OAEG;IACH,OAAO,YAAY;IACnB;;;;;OAKG;IACH,QAAQ,aAAa;IACrB;;;;OAIG;IACH,IAAI,SAAS;IACb;;;OAGG;IACH,SAAS,cAAc;IACvB;;;;OAIG;IACH,QAAQ,aAAa;IACrB;;;OAGG;IACH,KAAK,UAAU;IACf;;;OAGG;IACH,GAAG,QAAQ;IACX;;;OAGG;IACH,KAAK,UAAU;CAChB;AAGD;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,qBAAqB,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAAC;CACvD,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// @needsAudit
|
|
2
|
+
/**
|
|
3
|
+
* An enum of the different types of devices supported by Expo.
|
|
4
|
+
*/
|
|
5
|
+
export var NetworkStateType;
|
|
6
|
+
(function (NetworkStateType) {
|
|
7
|
+
/**
|
|
8
|
+
* No active network connection detected.
|
|
9
|
+
*/
|
|
10
|
+
NetworkStateType["NONE"] = "NONE";
|
|
11
|
+
/**
|
|
12
|
+
* The connection type could not be determined.
|
|
13
|
+
*/
|
|
14
|
+
NetworkStateType["UNKNOWN"] = "UNKNOWN";
|
|
15
|
+
/**
|
|
16
|
+
* Active network connection over mobile data or [`DUN-specific`](https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_MOBILE_DUN)
|
|
17
|
+
* mobile connection when setting an upstream connection for tethering.
|
|
18
|
+
* @platform android
|
|
19
|
+
* @platform ios
|
|
20
|
+
*/
|
|
21
|
+
NetworkStateType["CELLULAR"] = "CELLULAR";
|
|
22
|
+
/**
|
|
23
|
+
* Active network connection over Wi-Fi.
|
|
24
|
+
* @platform android
|
|
25
|
+
* @platform ios
|
|
26
|
+
*/
|
|
27
|
+
NetworkStateType["WIFI"] = "WIFI";
|
|
28
|
+
/**
|
|
29
|
+
* Active network connection over Bluetooth.
|
|
30
|
+
* @platform android
|
|
31
|
+
*/
|
|
32
|
+
NetworkStateType["BLUETOOTH"] = "BLUETOOTH";
|
|
33
|
+
/**
|
|
34
|
+
* Active network connection over Ethernet.
|
|
35
|
+
* @platform android
|
|
36
|
+
* @platform ios
|
|
37
|
+
*/
|
|
38
|
+
NetworkStateType["ETHERNET"] = "ETHERNET";
|
|
39
|
+
/**
|
|
40
|
+
* Active network connection over WiMAX.
|
|
41
|
+
* @platform android
|
|
42
|
+
*/
|
|
43
|
+
NetworkStateType["WIMAX"] = "WIMAX";
|
|
44
|
+
/**
|
|
45
|
+
* Active network connection over VPN.
|
|
46
|
+
* @platform android
|
|
47
|
+
*/
|
|
48
|
+
NetworkStateType["VPN"] = "VPN";
|
|
49
|
+
/**
|
|
50
|
+
* Active network connection over other network connection types.
|
|
51
|
+
* @platform android
|
|
52
|
+
*/
|
|
53
|
+
NetworkStateType["OTHER"] = "OTHER";
|
|
54
|
+
})(NetworkStateType || (NetworkStateType = {}));
|
|
55
|
+
//# sourceMappingURL=Network.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Network.types.js","sourceRoot":"","sources":["../src/Network.types.ts"],"names":[],"mappings":"AAuBA,cAAc;AACd;;GAEG;AACH,MAAM,CAAN,IAAY,gBAgDX;AAhDD,WAAY,gBAAgB;IAC1B;;OAEG;IACH,iCAAa,CAAA;IACb;;OAEG;IACH,uCAAmB,CAAA;IACnB;;;;;OAKG;IACH,yCAAqB,CAAA;IACrB;;;;OAIG;IACH,iCAAa,CAAA;IACb;;;OAGG;IACH,2CAAuB,CAAA;IACvB;;;;OAIG;IACH,yCAAqB,CAAA;IACrB;;;OAGG;IACH,mCAAe,CAAA;IACf;;;OAGG;IACH,+BAAW,CAAA;IACX;;;OAGG;IACH,mCAAe,CAAA;AACjB,CAAC,EAhDW,gBAAgB,KAAhB,gBAAgB,QAgD3B","sourcesContent":["// @needsAudit\nexport type NetworkState = {\n /**\n * A [`NetworkStateType`](#networkstatetype) enum value that represents the current network\n * connection type.\n */\n type?: NetworkStateType;\n /**\n * If there is an active network connection. Note that this does not mean that internet is reachable.\n * This field is `false` if the type is either `Network.NetworkStateType.NONE` or `Network.NetworkStateType.UNKNOWN`,\n * `true` otherwise.\n */\n isConnected?: boolean;\n /**\n * If the internet is reachable with the currently active network connection. On Android, this\n * requires the active network to have internet capability (`NET_CAPABILITY_INTERNET`), confirmed\n * internet access (`NET_CAPABILITY_VALIDATED`), and a usable connection state. VPN connections\n * also require non-zero downstream bandwidth. On iOS, this value will always be the same as\n * `isConnected`.\n */\n isInternetReachable?: boolean;\n};\n\n// @needsAudit\n/**\n * An enum of the different types of devices supported by Expo.\n */\nexport enum NetworkStateType {\n /**\n * No active network connection detected.\n */\n NONE = 'NONE',\n /**\n * The connection type could not be determined.\n */\n UNKNOWN = 'UNKNOWN',\n /**\n * Active network connection over mobile data or [`DUN-specific`](https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_MOBILE_DUN)\n * mobile connection when setting an upstream connection for tethering.\n * @platform android\n * @platform ios\n */\n CELLULAR = 'CELLULAR',\n /**\n * Active network connection over Wi-Fi.\n * @platform android\n * @platform ios\n */\n WIFI = 'WIFI',\n /**\n * Active network connection over Bluetooth.\n * @platform android\n */\n BLUETOOTH = 'BLUETOOTH',\n /**\n * Active network connection over Ethernet.\n * @platform android\n * @platform ios\n */\n ETHERNET = 'ETHERNET',\n /**\n * Active network connection over WiMAX.\n * @platform android\n */\n WIMAX = 'WIMAX',\n /**\n * Active network connection over VPN.\n * @platform android\n */\n VPN = 'VPN',\n /**\n * Active network connection over other network connection types.\n * @platform android\n */\n OTHER = 'OTHER',\n}\n\n// @needsAudit\n/**\n * Represents an event that provides the updated network state when there is a change in the network status.\n * This is passed as the argument to listeners registered with [`addNetworkStateListener()`](#networkaddnetworkstatelistenerlistener).\n */\nexport type NetworkStateEvent = NetworkState;\n\n/**\n * @hidden\n */\nexport type NetworkEvents = {\n onNetworkStateChanged(event: NetworkStateEvent): void;\n};\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"platforms": ["apple", "android", "web"],
|
|
3
|
+
"apple": {
|
|
4
|
+
"modules": ["NetworkModule"]
|
|
5
|
+
},
|
|
6
|
+
"android": {
|
|
7
|
+
"modules": ["expo.modules.network.NetworkModule"],
|
|
8
|
+
"publication": {
|
|
9
|
+
"groupId": "host.exp.exponent",
|
|
10
|
+
"artifactId": "expo.modules.network",
|
|
11
|
+
"version": "57.0.2",
|
|
12
|
+
"repository": "local-maven-repo"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'ExpoNetwork'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.description = package['description']
|
|
10
|
+
s.license = package['license']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.homepage = package['homepage']
|
|
13
|
+
s.platforms = {
|
|
14
|
+
:ios => '16.4',
|
|
15
|
+
:tvos => '16.4',
|
|
16
|
+
:osx => '13.4'
|
|
17
|
+
}
|
|
18
|
+
s.source = { git: 'https://github.com/expo/expo.git' }
|
|
19
|
+
s.static_framework = true
|
|
20
|
+
|
|
21
|
+
s.dependency 'ExpoModulesCore'
|
|
22
|
+
|
|
23
|
+
s.source_files = "**/*.{h,m,swift}"
|
|
24
|
+
s.pod_target_xcconfig = {
|
|
25
|
+
'DEFINES_MODULE' => 'YES',
|
|
26
|
+
'SWIFT_COMPILATION_MODE' => 'wholemodule'
|
|
27
|
+
}
|
|
28
|
+
end
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
import Network
|
|
3
|
+
|
|
4
|
+
let onNetworkStateChanged = "onNetworkStateChanged"
|
|
5
|
+
|
|
6
|
+
public final class NetworkModule: Module {
|
|
7
|
+
private let monitor = NWPathMonitor()
|
|
8
|
+
private let monitorQueue = DispatchQueue.global(qos: .default)
|
|
9
|
+
|
|
10
|
+
public func definition() -> ModuleDefinition {
|
|
11
|
+
Name("ExpoNetwork")
|
|
12
|
+
|
|
13
|
+
Events(onNetworkStateChanged)
|
|
14
|
+
|
|
15
|
+
OnStartObserving(onNetworkStateChanged) {
|
|
16
|
+
setupNetworkMonitoring()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
AsyncFunction("getIpAddressAsync") { () -> String? in
|
|
20
|
+
return try getIPAddress()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
AsyncFunction("getNetworkStateAsync") {
|
|
24
|
+
return getNetworkStateAsync()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
OnStopObserving(onNetworkStateChanged) {
|
|
28
|
+
monitor.cancel()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
OnDestroy {
|
|
32
|
+
monitor.cancel()
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private func setupNetworkMonitoring() {
|
|
37
|
+
monitor.pathUpdateHandler = { [weak self] path in
|
|
38
|
+
guard let self else {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
self.emitNetworkStateChange(path: path)
|
|
42
|
+
}
|
|
43
|
+
monitor.start(queue: monitorQueue)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private func emitNetworkStateChange(path: NWPath) {
|
|
47
|
+
let networkState = getNetworkStateAsync(path: path)
|
|
48
|
+
sendEvent(onNetworkStateChanged, networkState)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private func getIPAddress() throws -> String {
|
|
52
|
+
var address = "0.0.0.0"
|
|
53
|
+
var ifaddr: UnsafeMutablePointer<ifaddrs>?
|
|
54
|
+
|
|
55
|
+
let error = getifaddrs(&ifaddr)
|
|
56
|
+
|
|
57
|
+
guard error == 0 else {
|
|
58
|
+
throw IpAddressException(error)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
guard let firstAddr = ifaddr else {
|
|
62
|
+
return address
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for ifptr in sequence(first: firstAddr, next: { $0.pointee.ifa_next }) {
|
|
66
|
+
let temp = ifptr.pointee
|
|
67
|
+
let family = temp.ifa_addr.pointee.sa_family
|
|
68
|
+
|
|
69
|
+
if family == UInt8(AF_INET) {
|
|
70
|
+
let name = String(cString: temp.ifa_name)
|
|
71
|
+
if name.starts(with: "en") {
|
|
72
|
+
var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
|
|
73
|
+
getnameinfo(
|
|
74
|
+
temp.ifa_addr,
|
|
75
|
+
socklen_t(temp.ifa_addr.pointee.sa_len),
|
|
76
|
+
&hostname,
|
|
77
|
+
socklen_t(hostname.count),
|
|
78
|
+
nil,
|
|
79
|
+
socklen_t(0),
|
|
80
|
+
NI_NUMERICHOST)
|
|
81
|
+
address = String(cString: hostname)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
freeifaddrs(ifaddr)
|
|
87
|
+
return address
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private func getNetworkPathAsync() -> NWPath? {
|
|
91
|
+
// create a temporary monitor to avoid interfering with the module's monitor
|
|
92
|
+
// since we want to wait for the result to be updated once:
|
|
93
|
+
let tempMonitor = NWPathMonitor()
|
|
94
|
+
var tempPath: NWPath?
|
|
95
|
+
|
|
96
|
+
let semaphore = DispatchSemaphore(value: 0)
|
|
97
|
+
|
|
98
|
+
tempMonitor.pathUpdateHandler = { updatedPath in
|
|
99
|
+
tempPath = updatedPath
|
|
100
|
+
semaphore.signal() // Notify that we got the path
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
tempMonitor.start(queue: monitorQueue)
|
|
104
|
+
|
|
105
|
+
// Wait max 5 seconds to avoid any locking issues if the monitor
|
|
106
|
+
// doesn't get an update in time.
|
|
107
|
+
let result = semaphore.wait(timeout: .now() + 5)
|
|
108
|
+
tempMonitor.cancel()
|
|
109
|
+
|
|
110
|
+
if result == .timedOut {
|
|
111
|
+
// Handle the timeout case
|
|
112
|
+
print("Timeout waiting for network path.")
|
|
113
|
+
return nil
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return tempPath
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private func getNetworkStateAsync(path: NWPath? = nil) -> [String: Any] {
|
|
120
|
+
let currentPath = path ?? getNetworkPathAsync()
|
|
121
|
+
let isConnected = currentPath?.status == .satisfied
|
|
122
|
+
|
|
123
|
+
if !isConnected {
|
|
124
|
+
return [
|
|
125
|
+
"type": NetworkType.none.description,
|
|
126
|
+
"isConnected": isConnected,
|
|
127
|
+
"isInternetReachable": isConnected
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let connectionType = NWInterface
|
|
132
|
+
.InterfaceType
|
|
133
|
+
.allCases
|
|
134
|
+
.filter { currentPath?.usesInterfaceType($0) == true }
|
|
135
|
+
.first
|
|
136
|
+
|
|
137
|
+
var currentNetworkType = NetworkType.unknown
|
|
138
|
+
switch connectionType {
|
|
139
|
+
case .wifi:
|
|
140
|
+
currentNetworkType = .wifi
|
|
141
|
+
case .cellular:
|
|
142
|
+
currentNetworkType = .cellular
|
|
143
|
+
case .wiredEthernet:
|
|
144
|
+
currentNetworkType = .wiredEthernet
|
|
145
|
+
default:
|
|
146
|
+
currentNetworkType = .unknown
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return [
|
|
150
|
+
"type": currentNetworkType.description,
|
|
151
|
+
"isConnected": isConnected,
|
|
152
|
+
"isInternetReachable": isConnected
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Network
|
|
2
|
+
|
|
3
|
+
extension NWInterface.InterfaceType: CaseIterable {
|
|
4
|
+
public static var allCases: [NWInterface.InterfaceType] = [
|
|
5
|
+
.other,
|
|
6
|
+
.wifi,
|
|
7
|
+
.cellular,
|
|
8
|
+
.loopback,
|
|
9
|
+
.wiredEthernet
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
enum NetworkType: CustomStringConvertible {
|
|
14
|
+
case unknown, wifi, none, cellular, wiredEthernet
|
|
15
|
+
|
|
16
|
+
var description: String {
|
|
17
|
+
switch self {
|
|
18
|
+
case .wifi:
|
|
19
|
+
return "WIFI"
|
|
20
|
+
case .cellular:
|
|
21
|
+
return "CELLULAR"
|
|
22
|
+
case .wiredEthernet:
|
|
23
|
+
return "ETHERNET"
|
|
24
|
+
case .unknown:
|
|
25
|
+
return "UNKNOWN"
|
|
26
|
+
case .none:
|
|
27
|
+
return "NONE"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
27575b44500de7b7a54306c76e2e92c6
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1120869fc8c001fb9eeaa68263763b5551d6be2d
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
012f1dc241eafa35250a95774539d1018f0cd2dc0a309691938b8ba2b21ffc9f
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
743b63ffd72fd1933f210ab6c5d1fe07e068b45fd4dbb30aad632829e0c492b34407cc49483aceeda15f847ce7c5d7bd9c304a2ade1498b3ca4114c4ae5d3a99
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fd7ecf4c5e846531494a961499be570f
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0a9abad427021775e2af3bb616ca344e8636a6c3
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
d60008645cc2045cc850b1422bdf7aa357c4baf9a5b2578b87ca28b27ed6d2b3
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
6870b0ebade57761fe61e7533c54c275001356a7adbdbaf551ce9d81ec5926981f7bd64ba505419f4fe6de964501129b9c76824a0f7de1aa1d209f7e67e01545
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"formatVersion": "1.1",
|
|
3
|
+
"component": {
|
|
4
|
+
"group": "host.exp.exponent",
|
|
5
|
+
"module": "expo.modules.network",
|
|
6
|
+
"version": "57.0.2",
|
|
7
|
+
"attributes": {
|
|
8
|
+
"org.gradle.status": "release"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"createdBy": {
|
|
12
|
+
"gradle": {
|
|
13
|
+
"version": "9.3.1"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"variants": [
|
|
17
|
+
{
|
|
18
|
+
"name": "releaseVariantReleaseApiPublication",
|
|
19
|
+
"attributes": {
|
|
20
|
+
"org.gradle.category": "library",
|
|
21
|
+
"org.gradle.dependency.bundling": "external",
|
|
22
|
+
"org.gradle.libraryelements": "aar",
|
|
23
|
+
"org.gradle.usage": "java-api"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
{
|
|
27
|
+
"name": "expo.modules.network-57.0.2.aar",
|
|
28
|
+
"url": "expo.modules.network-57.0.2.aar",
|
|
29
|
+
"size": 22879,
|
|
30
|
+
"sha512": "6870b0ebade57761fe61e7533c54c275001356a7adbdbaf551ce9d81ec5926981f7bd64ba505419f4fe6de964501129b9c76824a0f7de1aa1d209f7e67e01545",
|
|
31
|
+
"sha256": "d60008645cc2045cc850b1422bdf7aa357c4baf9a5b2578b87ca28b27ed6d2b3",
|
|
32
|
+
"sha1": "0a9abad427021775e2af3bb616ca344e8636a6c3",
|
|
33
|
+
"md5": "fd7ecf4c5e846531494a961499be570f"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "releaseVariantReleaseRuntimePublication",
|
|
39
|
+
"attributes": {
|
|
40
|
+
"org.gradle.category": "library",
|
|
41
|
+
"org.gradle.dependency.bundling": "external",
|
|
42
|
+
"org.gradle.libraryelements": "aar",
|
|
43
|
+
"org.gradle.usage": "java-runtime"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": [
|
|
46
|
+
{
|
|
47
|
+
"group": "org.jetbrains.kotlin",
|
|
48
|
+
"module": "kotlin-stdlib-jdk7",
|
|
49
|
+
"version": {
|
|
50
|
+
"requires": "2.1.20"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"group": "org.jetbrains",
|
|
55
|
+
"module": "annotations",
|
|
56
|
+
"version": {
|
|
57
|
+
"requires": "23.0.0"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"group": "io.github.lukmccall.pika",
|
|
62
|
+
"module": "pika-api",
|
|
63
|
+
"version": {
|
|
64
|
+
"requires": "0.3.2"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"files": [
|
|
69
|
+
{
|
|
70
|
+
"name": "expo.modules.network-57.0.2.aar",
|
|
71
|
+
"url": "expo.modules.network-57.0.2.aar",
|
|
72
|
+
"size": 22879,
|
|
73
|
+
"sha512": "6870b0ebade57761fe61e7533c54c275001356a7adbdbaf551ce9d81ec5926981f7bd64ba505419f4fe6de964501129b9c76824a0f7de1aa1d209f7e67e01545",
|
|
74
|
+
"sha256": "d60008645cc2045cc850b1422bdf7aa357c4baf9a5b2578b87ca28b27ed6d2b3",
|
|
75
|
+
"sha1": "0a9abad427021775e2af3bb616ca344e8636a6c3",
|
|
76
|
+
"md5": "fd7ecf4c5e846531494a961499be570f"
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"name": "releaseVariantReleaseSourcePublication",
|
|
82
|
+
"attributes": {
|
|
83
|
+
"org.gradle.category": "documentation",
|
|
84
|
+
"org.gradle.dependency.bundling": "external",
|
|
85
|
+
"org.gradle.docstype": "sources",
|
|
86
|
+
"org.gradle.usage": "java-runtime"
|
|
87
|
+
},
|
|
88
|
+
"files": [
|
|
89
|
+
{
|
|
90
|
+
"name": "expo.modules.network-57.0.2-sources.jar",
|
|
91
|
+
"url": "expo.modules.network-57.0.2-sources.jar",
|
|
92
|
+
"size": 5575,
|
|
93
|
+
"sha512": "743b63ffd72fd1933f210ab6c5d1fe07e068b45fd4dbb30aad632829e0c492b34407cc49483aceeda15f847ce7c5d7bd9c304a2ade1498b3ca4114c4ae5d3a99",
|
|
94
|
+
"sha256": "012f1dc241eafa35250a95774539d1018f0cd2dc0a309691938b8ba2b21ffc9f",
|
|
95
|
+
"sha1": "1120869fc8c001fb9eeaa68263763b5551d6be2d",
|
|
96
|
+
"md5": "27575b44500de7b7a54306c76e2e92c6"
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
a6c62638bc0b29a676e7ff10322b1029
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
6a97283f9b82544ed474741a57e9722c0ceb5f21
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
d7dfa690d55c73b680d75bf378f745559dba16833496234db18705293f5fd681
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3d5d18c7f0c20193d81c57ec2f322c26503de5ee6c7206b8a75d3347e63d93ed92716ac31cb3f32a99b75a88f7886c41686cf82a4b6226b14c7c463b791381ec
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
|
3
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
4
|
+
<!-- This module was also published with a richer model, Gradle metadata, -->
|
|
5
|
+
<!-- which should be used instead. Do not delete the following line which -->
|
|
6
|
+
<!-- is to indicate to Gradle or any Gradle module metadata file consumer -->
|
|
7
|
+
<!-- that they should prefer consuming it instead. -->
|
|
8
|
+
<!-- do_not_remove: published-with-gradle-metadata -->
|
|
9
|
+
<modelVersion>4.0.0</modelVersion>
|
|
10
|
+
<groupId>host.exp.exponent</groupId>
|
|
11
|
+
<artifactId>expo.modules.network</artifactId>
|
|
12
|
+
<version>57.0.2</version>
|
|
13
|
+
<packaging>aar</packaging>
|
|
14
|
+
<name>expo.modules.network</name>
|
|
15
|
+
<url>https://github.com/expo/expo</url>
|
|
16
|
+
<organization>
|
|
17
|
+
<name>650 Industries, Inc. (“Expo”)</name>
|
|
18
|
+
<url>https://expo.dev/home</url>
|
|
19
|
+
</organization>
|
|
20
|
+
<licenses>
|
|
21
|
+
<license>
|
|
22
|
+
<name>MIT License</name>
|
|
23
|
+
<url>https://github.com/expo/expo/blob/main/LICENSE</url>
|
|
24
|
+
<distribution>https://github.com/expo/expo/blob/main/LICENSE</distribution>
|
|
25
|
+
</license>
|
|
26
|
+
</licenses>
|
|
27
|
+
<developers>
|
|
28
|
+
<developer>
|
|
29
|
+
<name>Expo Maintainers</name>
|
|
30
|
+
<email>support@expo.dev</email>
|
|
31
|
+
<url>https://github.com/orgs/expo/people</url>
|
|
32
|
+
</developer>
|
|
33
|
+
</developers>
|
|
34
|
+
<scm>
|
|
35
|
+
<connection>https://github.com/expo/expo.git</connection>
|
|
36
|
+
<developerConnection>https://github.com/expo/expo.git</developerConnection>
|
|
37
|
+
<url>https://github.com/expo/expo</url>
|
|
38
|
+
</scm>
|
|
39
|
+
<dependencies>
|
|
40
|
+
<dependency>
|
|
41
|
+
<groupId>org.jetbrains.kotlin</groupId>
|
|
42
|
+
<artifactId>kotlin-stdlib-jdk7</artifactId>
|
|
43
|
+
<version>2.1.20</version>
|
|
44
|
+
<scope>runtime</scope>
|
|
45
|
+
</dependency>
|
|
46
|
+
<dependency>
|
|
47
|
+
<groupId>org.jetbrains</groupId>
|
|
48
|
+
<artifactId>annotations</artifactId>
|
|
49
|
+
<version>23.0.0</version>
|
|
50
|
+
<scope>runtime</scope>
|
|
51
|
+
</dependency>
|
|
52
|
+
<dependency>
|
|
53
|
+
<groupId>io.github.lukmccall.pika</groupId>
|
|
54
|
+
<artifactId>pika-api</artifactId>
|
|
55
|
+
<version>0.3.2</version>
|
|
56
|
+
<scope>runtime</scope>
|
|
57
|
+
</dependency>
|
|
58
|
+
</dependencies>
|
|
59
|
+
</project>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ab48f53e433fa13cbedd6b1702c0023d
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
c55dad99ed83a455ce36317b37b7f3b2b7d40882
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3323fc13b71b6ada6f1a4700bf7bb825046c8cb7c30c8ae1b53ffe7580012b92
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ecf26bd3f69bf2380d5fbe9f2937d6c13dc56f9c91cd880a5f8cfdd4b58fb25bbf1c7d65277f36f5d3d1e983bcf9b0a4a8f310689e20c4dea6269a2bec35b291
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<metadata>
|
|
3
|
+
<groupId>host.exp.exponent</groupId>
|
|
4
|
+
<artifactId>expo.modules.network</artifactId>
|
|
5
|
+
<versioning>
|
|
6
|
+
<latest>57.0.2</latest>
|
|
7
|
+
<release>57.0.2</release>
|
|
8
|
+
<versions>
|
|
9
|
+
<version>57.0.2</version>
|
|
10
|
+
</versions>
|
|
11
|
+
<lastUpdated>20260911111646</lastUpdated>
|
|
12
|
+
</versioning>
|
|
13
|
+
</metadata>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
17adbbfac538f2470fc11a0a60a52ba5
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
08af64bbe735d0cec2649ba13330d98af8871246
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ab3002afa9f8c83050c7b31a1fc9654d1dce0aa35f8082eb4d290ddfa09c6e0e
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
444ac1e0102b883c89ffe1fd1f358eb82ea4d9bd1b4812a21445ae2524fb0690af31b15078aae20fe24fcd49302bef96fc3fe89a2c69cd53d228fd04e8c63d6f
|