1 | import { IHookStateInitAction } from './misc/hookState';
|
---|
2 | export interface INetworkInformation extends EventTarget {
|
---|
3 | readonly downlink: number;
|
---|
4 | readonly downlinkMax: number;
|
---|
5 | readonly effectiveType: 'slow-2g' | '2g' | '3g' | '4g';
|
---|
6 | readonly rtt: number;
|
---|
7 | readonly saveData: boolean;
|
---|
8 | readonly type: 'bluetooth' | 'cellular' | 'ethernet' | 'none' | 'wifi' | 'wimax' | 'other' | 'unknown';
|
---|
9 | onChange: (event: Event) => void;
|
---|
10 | }
|
---|
11 | export interface IUseNetworkState {
|
---|
12 | /**
|
---|
13 | * @desc Whether browser connected to the network or not.
|
---|
14 | */
|
---|
15 | online: boolean | undefined;
|
---|
16 | /**
|
---|
17 | * @desc Previous value of `online` property. Helps to identify if browser
|
---|
18 | * just connected or lost connection.
|
---|
19 | */
|
---|
20 | previous: boolean | undefined;
|
---|
21 | /**
|
---|
22 | * @desc The {Date} object pointing to the moment when state change occurred.
|
---|
23 | */
|
---|
24 | since: Date | undefined;
|
---|
25 | /**
|
---|
26 | * @desc Effective bandwidth estimate in megabits per second, rounded to the
|
---|
27 | * nearest multiple of 25 kilobits per seconds.
|
---|
28 | */
|
---|
29 | downlink: INetworkInformation['downlink'] | undefined;
|
---|
30 | /**
|
---|
31 | * @desc Maximum downlink speed, in megabits per second (Mbps), for the
|
---|
32 | * underlying connection technology
|
---|
33 | */
|
---|
34 | downlinkMax: INetworkInformation['downlinkMax'] | undefined;
|
---|
35 | /**
|
---|
36 | * @desc Effective type of the connection meaning one of 'slow-2g', '2g', '3g', or '4g'.
|
---|
37 | * This value is determined using a combination of recently observed round-trip time
|
---|
38 | * and downlink values.
|
---|
39 | */
|
---|
40 | effectiveType: INetworkInformation['effectiveType'] | undefined;
|
---|
41 | /**
|
---|
42 | * @desc Estimated effective round-trip time of the current connection, rounded
|
---|
43 | * to the nearest multiple of 25 milliseconds
|
---|
44 | */
|
---|
45 | rtt: INetworkInformation['rtt'] | undefined;
|
---|
46 | /**
|
---|
47 | * @desc {true} if the user has set a reduced data usage option on the user agent.
|
---|
48 | */
|
---|
49 | saveData: INetworkInformation['saveData'] | undefined;
|
---|
50 | /**
|
---|
51 | * @desc The type of connection a device is using to communicate with the network.
|
---|
52 | * It will be one of the following values:
|
---|
53 | * - bluetooth
|
---|
54 | * - cellular
|
---|
55 | * - ethernet
|
---|
56 | * - none
|
---|
57 | * - wifi
|
---|
58 | * - wimax
|
---|
59 | * - other
|
---|
60 | * - unknown
|
---|
61 | */
|
---|
62 | type: INetworkInformation['type'] | undefined;
|
---|
63 | }
|
---|
64 | export default function useNetworkState(initialState?: IHookStateInitAction<IUseNetworkState>): IUseNetworkState;
|
---|