1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export 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 |
|
22 | export enum NetInfoCellularGeneration {
|
23 | '2g' = '2g',
|
24 | '3g' = '3g',
|
25 | '4g' = '4g',
|
26 | }
|
27 |
|
28 | export interface NetInfoConnectedDetails {
|
29 | isConnectionExpensive: boolean;
|
30 | }
|
31 |
|
32 | interface 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 |
|
43 | interface NetInfoDisconnectedState<T extends NetInfoStateType> {
|
44 | type: T;
|
45 | isConnected: false;
|
46 | isInternetReachable: false;
|
47 | details: null;
|
48 | }
|
49 |
|
50 | export type NetInfoUnknownState = NetInfoDisconnectedState<
|
51 | NetInfoStateType.unknown
|
52 | >;
|
53 | export type NetInfoNoConnectionState = NetInfoDisconnectedState<
|
54 | NetInfoStateType.none
|
55 | >;
|
56 | export type NetInfoDisconnectedStates =
|
57 | | NetInfoUnknownState
|
58 | | NetInfoNoConnectionState;
|
59 |
|
60 | export type NetInfoCellularState = NetInfoConnectedState<
|
61 | NetInfoStateType.cellular,
|
62 | {
|
63 | cellularGeneration: NetInfoCellularGeneration | null;
|
64 | carrier: string | null;
|
65 | }
|
66 | >;
|
67 | export 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 | >;
|
78 | export type NetInfoBluetoothState = NetInfoConnectedState<
|
79 | NetInfoStateType.bluetooth
|
80 | >;
|
81 | export type NetInfoEthernetState = NetInfoConnectedState<
|
82 | NetInfoStateType.ethernet,
|
83 | {
|
84 | ipAddress: string | null;
|
85 | subnet: string | null;
|
86 | }
|
87 | >;
|
88 | export type NetInfoWimaxState = NetInfoConnectedState<NetInfoStateType.wimax>;
|
89 | export type NetInfoVpnState = NetInfoConnectedState<NetInfoStateType.vpn>;
|
90 | export type NetInfoOtherState = NetInfoConnectedState<NetInfoStateType.other>;
|
91 | export type NetInfoConnectedStates =
|
92 | | NetInfoCellularState
|
93 | | NetInfoWifiState
|
94 | | NetInfoBluetoothState
|
95 | | NetInfoEthernetState
|
96 | | NetInfoWimaxState
|
97 | | NetInfoVpnState
|
98 | | NetInfoOtherState;
|
99 |
|
100 | export type NetInfoState = NetInfoDisconnectedStates | NetInfoConnectedStates;
|
101 |
|
102 | export type NetInfoChangeHandler = (state: NetInfoState) => void;
|
103 | export type NetInfoSubscription = () => void;
|
104 |
|
105 | export interface NetInfoConfiguration {
|
106 | reachabilityUrl: string;
|
107 | reachabilityTest: (response: Response) => Promise<boolean>;
|
108 | reachabilityLongTimeout: number;
|
109 | reachabilityShortTimeout: number;
|
110 | reachabilityRequestTimeout: number;
|
111 | }
|