Network Information API is an experiment feature.
Is there any existing way to get network information (e.g. 4g/5g/wifi, uplink/downlink, rtt, latency)? I would like to show the info in my React component for all popular browsers (chrome, firefox, safari).
const [networkInformation, setNetworkInformation] = useState({});
useEffect(() => {
setInterval(() => {
setNetworkInformation({
networkType: getNetworkType(), // returns like 4g/5g/wifi,
uplink: getUplink(), // returns like 100 for 100kbps
downlink: getDownlink(), // same as uplink
rtt: getRtt(), // returns like 75 for 75ms
});
}, 2000);
}, []);
return (<div>{JSON.stringify(networkInformation)}</div>);
How to implement getNetworkType
, getUplink
, getDownlink
, getRtt
?