UNPKG

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