Gathering detailed insights and metrics for @rescript-react-native/netinfo
Gathering detailed insights and metrics for @rescript-react-native/netinfo
Gathering detailed insights and metrics for @rescript-react-native/netinfo
Gathering detailed insights and metrics for @rescript-react-native/netinfo
npm install @rescript-react-native/netinfo
26.8
Supply Chain
42
Quality
70.2
Maintenance
50
Vulnerability
95.3
License
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
9 Stars
1,156 Commits
2 Forks
4 Watching
5 Branches
71 Contributors
Updated on 03 Jun 2024
ReScript (92.51%)
JavaScript (7.49%)
Cumulative downloads
Total Downloads
Last day
5.3%
40
Compared to previous day
Last week
33.6%
203
Compared to previous week
Last month
80.4%
765
Compared to previous month
Last year
-29%
11,713
Compared to previous year
1
6
@rescript-react-native/netinfo
ReScript bindings for
@react-native-community/netinfo
.
Exposed as ReactNativeNetInfo
module.
@rescript-react-native/netinfo
X.y.* means it's compatible with
@react-native-community/netinfo
X.y.*
When
@react-native-community/netinfo
is properly installed & configured by following their installation instructions,
you can install the bindings:
1npm install @rescript-react-native/netinfo 2# or 3yarn add @rescript-react-native/netinfo
@rescript-react-native/netinfo
should be added to bs-dependencies
in your
bsconfig.json
:
1{ 2 //... 3 "bs-dependencies": [ 4 "@rescript/react", 5 "rescript-react-native", 6 // ... 7+ "@rescript-react-native/netinfo" 8 ], 9 //... 10}
netInfoConfiguration
To be used only when the platform does not natively supply information on internet reachability.
Property | Type | Description |
---|---|---|
reachabilityUrl | string | URL used to test if the internet is reachable. |
reachabilityTest | response => bool | A function to handle the response object returned when the reachability URL is called. It should return true if the response indicates that the internet is reachable. |
reachabilityShortTimeout | float | Number of seconds between internet reachability checks when the internet was not previously detected. |
reachabilityLongTimeout | float | Number of seconds between internet reachability checks when the internet was previously detected. |
reachabilityRequestTimeout | float | Number of milliseconds allowed before reachability check fails. |
netInfoStateType
Kind of the current network connection. Valid values are:
Value | Platforms | Connection State |
---|---|---|
none | Android, iOS, Windows | Not active |
unknown | Android, iOS, Windows | Undetermined |
cellular | Android, iOS, Windows | Active |
wifi | Android, iOS, Windows | Active |
bluetooth | Android | Active |
ethernet | Android, Windows | Active |
wimax | Android | Active |
vpn | Android | Active |
other | Android, iOS, Windows | Active |
netInfoCellularGeneration
Cellular generation of the current network connection. Valid values are:
Value | Notes |
---|---|
net2g | Inlined as "2g". Returned for CDMA, EDGE, GPRS and IDEN connections |
net3g | Inlined as "3g". Returned for EHRPD, EVDO, HSPA, HSUPA, HSDPA and UTMS connections. |
net4g | Inlined as "4g". Returned for HSPAP and LTE connections |
netInfoState
1type netInfoState = {
2 .
3 "_type": netInfoStateType,
4 "isConnected": bool,
5 "isInternetReachable": bool,
6 "isWifiEnabled": bool,
7 "details": Js.Null.t(details),
8};
isConnected
will be true
if there is an active connection (but not imply
that the internet is necessarily reachable).isInternetReachable
will be true
if the internet can be reached using the
active connectionisWifiEnabled
will be true
if WiFi is enabled on the device, and false
otherwise. Android only.details
key will have value Js.Null.empty
(null
) when _type
is null
or
unknown
.
details
details
depends on _type
given within netInfoState
. If
_type
is not null
or unknown
, details
is an object as below:
1type details = {
2 .
3 "isConnectionExpensive": bool,
4 "ssid": Js.Nullable.t(string),
5 "strength": Js.Nullable.t(int),
6 "ipAddress": Js.Nullable.t(string),
7 "subnet": Js.Nullable.t(string),
8 "cellularGeneration": Js.Nullable.t(netInfoCellularGeneration),
9 "carrier": Js.Nullable.t(string),
10};
Property | Platform | Type | Description |
---|---|---|---|
isConnectionExpensive | Android, iOS, Windows | bool | If network connection is considered expensive in either energy or monetary terms. |
Note that some keys may only exist in the JS object when _type
is wifi
or
cellular
. Accordingly, in Reason, keys may have values
Js.Nullable.undefined
.
ssid
, strength
, ipAddress
and subnet
will have value
Js.Nullable.undefined
unless _type
is wifi
.cellularGeneration
and carrier
will have value Js.Nullable.undefined
unless _type
is cellular._type
is wifi
Property | Platform | Type | Description |
---|---|---|---|
ssid | Android, iOS (not tvOS) | Js.Nullable.t(string) | SSID of the network. May have value Js.Nullable.undefined , Js.Nullable.null , or be an empty string if undetermined. On iOS, make sure your app meets at least one of the following requirements. On Android, make sure the ACCESS_FINE_LOCATION permission is listed in AndroidManifest.xml and accepted by the user. |
strength | Android | Js.Nullable.t(string) | If signal strength can be determined, will be an integer number from 0 to 5 . May have value Js.Nullable.undefined otherwise. |
ipAddress | Android, iOS | Js.Nullable.t(string) | External IP address. Can be in IPv4 or IPv6 format. May have value Js.Nullable.undefined if undetermined. |
subnet | Android, iOS | Js.Nullable.t(string) | The subnet mask in IPv4 format. May have value Js.Nullable.undefined if undetermined. |
type
is cellular
Property | Platform | Type | Description |
---|---|---|---|
cellularGeneration | Android, iOS, Windows | NetInfoCellularGeneration | Generation of cell network the user is connected to. This can give an indication of speed, but no guarantees. May have value Js.Nullable.null if generation cannot be determined. |
carrier | Android, iOS | string | The network carrier name. May have value Js.Nullable.undefined or may be empty if undetermined. |
configure
1configure: netInfoConfiguration => unit
fetch
To query state of the active connection, returns netInfoState
wrapped in a
Promise
.
1fetch: unit => Js.Promise.t(netInfoState)
Below example demonstrates determination of the cellular connection generation, using this method.
1React.useEffect0(() => {
2 Js.Promise.(
3 ReactNativeNetInfo.fetch()
4 |> then_(w =>
5 {
6 switch (w##details->Js.Null.toOption) {
7 | None => "Connection type is none or unknown"->Js.Console.warn
8 | Some(x) =>
9 let y = x##cellularGeneration;
10 switch (y->Js.Nullable.toOption) {
11 | None =>
12 if (y == Js.Nullable.undefined) {
13 "Connection type is wifi, bluetooth, ethernet, wimax, vpn or other"
14 ->Js.Console.warn;
15 } else {
16 "Connection generation unknown"->Js.Console.warn;
17 }
18 | Some(z) =>
19 if (z == ReactNativeNetInfo.net2G) {
20 "2G connection"->Js.Console.warn;
21 } else if (z == ReactNativeNetInfo.net3G) {
22 "3G connection"->Js.Console.warn;
23 } else {
24 "4G connection"->Js.Console.warn;
25 }
26 };
27 };
28 }
29 ->resolve
30 )
31 |> catch(err => "error"->Js.Console.warn->resolve)
32 |> ignore
33 );
34 None;
35});
fetchInterface
To query the connection state for a particular interface.
1fetchInterface: [ | `cellular | `ethernet | `wifi] => Js.Promise.t(netInfoState)
addEventListener
To subscribe to the connection state; accepts a listener of type
netInfoState => unit
and returns an unsubscribe method of type unit => unit
.
The listener will be called once following subscription and each time connection
state changes.
1addEventListener: (netInfoState => unit) => t
where
1type t = unit => unit
Below example demonstrates subscribing to changes in connection state:
1React.useEffect0(() => {
2 let remove =
3 ReactNativeNetInfo.addEventListener(w =>
4 (
5 switch (w##details->Js.Null.toOption) {
6 | None => "Connection type is none or unknown"
7 | Some(x) =>
8 let y = x##cellularGeneration;
9 switch (y->Js.Nullable.toOption) {
10 | None =>
11 if (y == Js.Nullable.undefined) {
12 "Connection type is wifi, bluetooth, ethernet, wimax, vpn or other";
13 } else {
14 "Connection generation unknown";
15 }
16 | Some(z) =>
17 if (z == ReactNativeNetInfo.net2G) {
18 "2G connection";
19 } else if (z == ReactNativeNetInfo.net3G) {
20 "3G connection";
21 } else {
22 "4G connection";
23 }
24 };
25 }
26 )
27 ->Js.Console.warn
28 );
29 Js.Console.warn(remove);
30 Some(() => remove());
31});
useNetInfo
This method returns a React Hook with type netInfoState
1useNetInfo: unit => netInfoState
Below example demonstrates its use within a Text
component:
1<Text>
2 (
3 switch (ReactNativeNetInfo.useNetInfo()##details->Js.Null.toOption) {
4 | None => "Connection type is none or unknown"
5 | Some(x) =>
6 let y = x##cellularGeneration;
7 switch (y->Js.Nullable.toOption) {
8 | None =>
9 if (y == Js.Nullable.undefined) {
10 "Connection type is wifi, bluetooth, ethernet, wimax, vpn or other";
11 } else {
12 "Connection generation unknown";
13 }
14 | Some(z) =>
15 if (z == ReactNativeNetInfo.net2G) {
16 "2G connection";
17 } else if (z == ReactNativeNetInfo.net3G) {
18 "3G connection";
19 } else {
20 "4G connection";
21 }
22 };
23 }
24 )
25 ->React.string
26</Text>
Check the changelog for more informations about recent releases.
Read the contribution guidelines before contributing.
We want this community to be friendly and respectful to each other. Please read our full code of conduct so that you can understand what actions will and will not be tolerated.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/28 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
15 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More