1.0.2 • Published 10 years ago
network-status v1.0.2
Network status
Allows checking the network status and re-connect.
Requires ES6 Promises
Install from npm
npm install network-status --saveNetwork status
From network networkStatus returns the current network state by giving a uri to ping e.g. favicon.ico.
networkStatus('/favicon.ico')
.then(isReachable)
.catch(notReachable);If the network connection is lost you can create a monitor for re-connection.
let networkStatusFavicon = () => networkStatus('/favicon.ico');
networkStatusFaviconIco()
.then(isReachable)
.catch(error => {
// update the UI to notify the user about lost network connection
return monitorForReConnect({
networkStatus: networkStatusFavicon,
maxRetries: 100});
})
.then(() => {
// update the UI, connection has been restored
})
.catch(error => {
// maximum retries reached
});networkStatusmust be a function without argumentsmaxRetriesif is set to 0 orundefinedit will try forever (default:undefined)delayhow long should be between network pings in milliseconds (default:2000)
1.0.2
10 years ago