UNPKG

2.81 kBPlain TextView 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 */
9
10export enum NetInfoStateType {
11 unknown = 'unknown',
12 none = 'none',
13 cellular = 'cellular',
14 wifi = 'wifi',
15 bluetooth = 'bluetooth',
16 ethernet = 'ethernet',
17 wimax = 'wimax',
18 vpn = 'vpn',
19 other = 'other',
20}
21
22export enum NetInfoCellularGeneration {
23 '2g' = '2g',
24 '3g' = '3g',
25 '4g' = '4g',
26}
27
28export interface NetInfoConnectedDetails {
29 isConnectionExpensive: boolean;
30}
31
32interface NetInfoConnectedState<
33 T extends NetInfoStateType,
34 D extends object = {}
35> {
36 type: T;
37 isConnected: true;
38 isInternetReachable: boolean | null | undefined;
39 details: D & NetInfoConnectedDetails;
40 isWifiEnabled?: boolean;
41}
42
43interface NetInfoDisconnectedState<T extends NetInfoStateType> {
44 type: T;
45 isConnected: false;
46 isInternetReachable: false;
47 details: null;
48}
49
50export type NetInfoUnknownState = NetInfoDisconnectedState<
51 NetInfoStateType.unknown
52>;
53export type NetInfoNoConnectionState = NetInfoDisconnectedState<
54 NetInfoStateType.none
55>;
56export type NetInfoDisconnectedStates =
57 | NetInfoUnknownState
58 | NetInfoNoConnectionState;
59
60export type NetInfoCellularState = NetInfoConnectedState<
61 NetInfoStateType.cellular,
62 {
63 cellularGeneration: NetInfoCellularGeneration | null;
64 carrier: string | null;
65 }
66>;
67export type NetInfoWifiState = NetInfoConnectedState<
68 NetInfoStateType.wifi,
69 {
70 ssid: string | null;
71 bssid: string | null;
72 strength: number | null;
73 ipAddress: string | null;
74 subnet: string | null;
75 frequency: number | null;
76 }
77>;
78export type NetInfoBluetoothState = NetInfoConnectedState<
79 NetInfoStateType.bluetooth
80>;
81export type NetInfoEthernetState = NetInfoConnectedState<
82 NetInfoStateType.ethernet,
83 {
84 ipAddress: string | null;
85 subnet: string | null;
86 }
87>;
88export type NetInfoWimaxState = NetInfoConnectedState<NetInfoStateType.wimax>;
89export type NetInfoVpnState = NetInfoConnectedState<NetInfoStateType.vpn>;
90export type NetInfoOtherState = NetInfoConnectedState<NetInfoStateType.other>;
91export type NetInfoConnectedStates =
92 | NetInfoCellularState
93 | NetInfoWifiState
94 | NetInfoBluetoothState
95 | NetInfoEthernetState
96 | NetInfoWimaxState
97 | NetInfoVpnState
98 | NetInfoOtherState;
99
100export type NetInfoState = NetInfoDisconnectedStates | NetInfoConnectedStates;
101
102export type NetInfoChangeHandler = (state: NetInfoState) => void;
103export type NetInfoSubscription = () => void;
104
105export interface NetInfoConfiguration {
106 reachabilityUrl: string;
107 reachabilityTest: (response: Response) => Promise<boolean>;
108 reachabilityLongTimeout: number;
109 reachabilityShortTimeout: number;
110 reachabilityRequestTimeout: number;
111}