UNPKG

3.08 kBTypeScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9export declare enum NetInfoStateType {
10 unknown = "unknown",
11 none = "none",
12 cellular = "cellular",
13 wifi = "wifi",
14 bluetooth = "bluetooth",
15 ethernet = "ethernet",
16 wimax = "wimax",
17 vpn = "vpn",
18 other = "other"
19}
20export declare enum NetInfoCellularGeneration {
21 '2g' = "2g",
22 '3g' = "3g",
23 '4g' = "4g",
24 '5g' = "5g"
25}
26export interface NetInfoConnectedDetails {
27 isConnectionExpensive: boolean;
28}
29interface NetInfoConnectedState<T extends NetInfoStateType, D extends Record<string, unknown> = Record<string, unknown>> {
30 type: T;
31 isConnected: true;
32 isInternetReachable: boolean | null;
33 details: D & NetInfoConnectedDetails;
34 isWifiEnabled?: boolean;
35}
36interface NetInfoDisconnectedState<T extends NetInfoStateType> {
37 type: T;
38 isConnected: false;
39 isInternetReachable: false;
40 details: null;
41}
42export interface NetInfoUnknownState {
43 type: NetInfoStateType.unknown;
44 isConnected: boolean | null;
45 isInternetReachable: null;
46 details: null;
47}
48export declare type NetInfoNoConnectionState = NetInfoDisconnectedState<NetInfoStateType.none>;
49export declare type NetInfoDisconnectedStates = NetInfoUnknownState | NetInfoNoConnectionState;
50export declare type NetInfoCellularState = NetInfoConnectedState<NetInfoStateType.cellular, {
51 cellularGeneration: NetInfoCellularGeneration | null;
52 carrier: string | null;
53}>;
54export declare type NetInfoWifiState = NetInfoConnectedState<NetInfoStateType.wifi, {
55 ssid: string | null;
56 bssid: string | null;
57 strength: number | null;
58 ipAddress: string | null;
59 subnet: string | null;
60 frequency: number | null;
61}>;
62export declare type NetInfoBluetoothState = NetInfoConnectedState<NetInfoStateType.bluetooth>;
63export declare type NetInfoEthernetState = NetInfoConnectedState<NetInfoStateType.ethernet, {
64 ipAddress: string | null;
65 subnet: string | null;
66}>;
67export declare type NetInfoWimaxState = NetInfoConnectedState<NetInfoStateType.wimax>;
68export declare type NetInfoVpnState = NetInfoConnectedState<NetInfoStateType.vpn>;
69export declare type NetInfoOtherState = NetInfoConnectedState<NetInfoStateType.other>;
70export declare type NetInfoConnectedStates = NetInfoCellularState | NetInfoWifiState | NetInfoBluetoothState | NetInfoEthernetState | NetInfoWimaxState | NetInfoVpnState | NetInfoOtherState;
71export declare type NetInfoState = NetInfoDisconnectedStates | NetInfoConnectedStates;
72export declare type NetInfoChangeHandler = (state: NetInfoState) => void;
73export declare type NetInfoSubscription = () => void;
74export interface NetInfoConfiguration {
75 reachabilityUrl: string;
76 reachabilityTest: (response: Response) => Promise<boolean>;
77 reachabilityLongTimeout: number;
78 reachabilityShortTimeout: number;
79 reachabilityRequestTimeout: number;
80 reachabilityShouldRun: () => boolean;
81}
82export {};