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