Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mybuilder/network-status
Monitoring for network status and for re-connect
https://github.com/mybuilder/network-status
Last synced: about 1 month ago
JSON representation
Monitoring for network status and for re-connect
- Host: GitHub
- URL: https://github.com/mybuilder/network-status
- Owner: mybuilder
- License: mit
- Created: 2015-12-08T14:18:06.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-01-11T12:08:12.000Z (almost 2 years ago)
- Last Synced: 2024-10-31T19:47:49.189Z (about 2 months ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 1
- Watchers: 13
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Network status
--------------Allows checking the network status and re-connect.
Requires ES6 Promises
[![Build Status](https://travis-ci.org/mybuilder/network-status.svg?branch=master)](https://travis-ci.org/mybuilder/network-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`.
```javascript
networkStatus('/favicon.ico')
.then(isReachable)
.catch(notReachable);
```If the network connection is lost you can create a monitor for re-connection.
```javascript
let networkStatusFavicon = () => networkStatus('/favicon.ico');networkStatusFaviconIco()
.then(isReachable)
.catch(error => {
// update the UI to notify the user about lost network connectionreturn 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`)