npm.io
1.4.0 • Published 5 years ago

connection-checker

Licence
MIT
Version
1.4.0
Deps
2
Size
41 kB
Vulns
0
Weekly
0
Stars
3

Connection Checker

Why

Sometimes window.navigator.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

let { ConnectionEvent, startChecker } = require("connection-checker");

The import way

import { ConnectionEvent, checkOnDemand } from "connection-checker";

Then use it to know your state one time on demand

  window.addEventListener(ConnectionEvent.ON_NETWORK_CONNECTED, function() {
    // YOUR OWN CODE AND STUFF
  })

  checkOnDemand()

Or frequently (every 10 secs)

  window.addEventListener(ConnectionEvent.ON_NETWORK_CHANGED, function() {
    // YOUR OWN CODE AND STUFF
  })

  startChecker()

You can always refer to library documentation here

Powered by Deepertech