Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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