Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xiscodev/connection-checker
A simple library to know the state of internet connection.
https://github.com/xiscodev/connection-checker
checker connection javascript library network
Last synced: about 18 hours ago
JSON representation
A simple library to know the state of internet connection.
- Host: GitHub
- URL: https://github.com/xiscodev/connection-checker
- Owner: xiscodev
- Created: 2020-02-23T10:47:54.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-27T23:07:30.000Z (almost 4 years ago)
- Last Synced: 2024-04-26T10:42:08.963Z (7 months ago)
- Topics: checker, connection, javascript, library, network
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/connection-checker
- Size: 52.7 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
Connection Checker
## Why
Sometimes [window.navigator.onLine](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine.onLine) API is not available and we need a good way to check if we got internet connection.## What is this?
A simple library to know the state of internet connection.## How to use it?
First you need to import it in your project_The require way_
```js
let { ConnectionEvent, startChecker } = require("connection-checker");
```_The import way_
```js
import { ConnectionEvent, checkOnDemand } from "connection-checker";
```Then use it to know your state one time on demand
```js
window.addEventListener(ConnectionEvent.ON_NETWORK_CONNECTED, function() {
// YOUR OWN CODE AND STUFF
})checkOnDemand()
```Or frequently (every 10 secs)
```js
window.addEventListener(ConnectionEvent.ON_NETWORK_CHANGED, function() {
// YOUR OWN CODE AND STUFF
})startChecker()
```
You can always refer to library documentation [here](api.md)Powered by Deepertech