UNPKG

3.35 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 type NetInfoMethodType = 'HEAD' | 'GET';
21export declare enum NetInfoCellularGeneration {
22 '2g' = "2g",
23 '3g' = "3g",
24 '4g' = "4g",
25 '5g' = "5g"
26}
27export interface NetInfoConnectedDetails {
28 isConnectionExpensive: boolean;
29}
30interface NetInfoConnectedState<T extends NetInfoStateType, D extends Record<string, unknown> = Record<string, unknown>> {
31 type: T;
32 isConnected: true;
33 isInternetReachable: boolean | null;
34 details: D & NetInfoConnectedDetails;
35 isWifiEnabled?: boolean;
36}
37interface NetInfoDisconnectedState<T extends NetInfoStateType> {
38 type: T;
39 isConnected: false;
40 isInternetReachable: false;
41 details: null;
42}
43export interface NetInfoUnknownState {
44 type: NetInfoStateType.unknown;
45 isConnected: boolean | null;
46 isInternetReachable: null;
47 details: null;
48}
49export declare type NetInfoNoConnectionState = NetInfoDisconnectedState<NetInfoStateType.none>;
50export declare type NetInfoDisconnectedStates = NetInfoUnknownState | NetInfoNoConnectionState;
51export declare type NetInfoCellularState = NetInfoConnectedState<NetInfoStateType.cellular, {
52 cellularGeneration: NetInfoCellularGeneration | null;
53 carrier: string | null;
54}>;
55export declare type NetInfoWifiState = NetInfoConnectedState<NetInfoStateType.wifi, {
56 ssid: string | null;
57 bssid: string | null;
58 strength: number | null;
59 ipAddress: string | null;
60 subnet: string | null;
61 frequency: number | null;
62 linkSpeed: number | null;
63 rxLinkSpeed: number | null;
64 txLinkSpeed: number | null;
65}>;
66export declare type NetInfoBluetoothState = NetInfoConnectedState<NetInfoStateType.bluetooth>;
67export declare type NetInfoEthernetState = NetInfoConnectedState<NetInfoStateType.ethernet, {
68 ipAddress: string | null;
69 subnet: string | null;
70}>;
71export declare type NetInfoWimaxState = NetInfoConnectedState<NetInfoStateType.wimax>;
72export declare type NetInfoVpnState = NetInfoConnectedState<NetInfoStateType.vpn>;
73export declare type NetInfoOtherState = NetInfoConnectedState<NetInfoStateType.other>;
74export declare type NetInfoConnectedStates = NetInfoCellularState | NetInfoWifiState | NetInfoBluetoothState | NetInfoEthernetState | NetInfoWimaxState | NetInfoVpnState | NetInfoOtherState;
75export declare type NetInfoState = NetInfoDisconnectedStates | NetInfoConnectedStates;
76export declare type NetInfoChangeHandler = (state: NetInfoState) => void;
77export declare type NetInfoSubscription = () => void;
78export interface NetInfoConfiguration {
79 reachabilityUrl: string;
80 reachabilityMethod?: NetInfoMethodType;
81 reachabilityTest: (response: Response) => Promise<boolean>;
82 reachabilityLongTimeout: number;
83 reachabilityShortTimeout: number;
84 reachabilityRequestTimeout: number;
85 reachabilityShouldRun: () => boolean;
86 shouldFetchWiFiSSID: boolean;
87 useNativeReachability: boolean;
88}
89export {};