Skip to content

Monitoring for network status and for re-connect

License

Notifications You must be signed in to change notification settings

mybuilder/network-status

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Network status

Allows checking the network status and re-connect.

Requires ES6 Promises

Build Status

Install from npm

npm install network-status --save

Network 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
    });
  • networkStatus must be a function without arguments
  • maxRetries if is set to 0 or undefined it will try forever (default: undefined)
  • delay how long should be between network pings in milliseconds (default: 2000)

About

Monitoring for network status and for re-connect

Resources

License

Stars

Watchers

Forks

Packages

No packages published