Skip to content

xiscodev/connection-checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A simple library to know the state of internet connection.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published