network-heart-service

A Service to handle netowrk change.

Usage no npm install needed!

<script type="module">
  import networkHeartService from 'https://cdn.skypack.dev/network-heart-service';
</script>

README

Network heart service

CircleCI npm

A Service to check and handle network change.

How to use

Npm

$  npm install network-heart-service -save
// es6
import NetworkHeartService from 'network-heart-service';
this.networkHeartService = new NetworkHeartService({
  heartMode: 'auto',
  reconnect() {
    console.log('TODO ...')
  }
});
this.networkHeartService.start();

config

  • heartMode { number } 2000 if it is undefined , it means use auto mode. It will check the network in an incerasing timeout. But is is set with a number, it will check the network in speciy time.

  • lowSpeedNetwork { function }

    A function will be fire when your network could work but in low network bandwidth

  • reconnect { function }

    A function will be fire when your network could work.

  • offline { function }

    A function will be fire when your network go to offline

API

isOnline

Check if your network could work.

const isOnline = await NetworkHeartService.isOnline();

start() and stop()

Start or Stop the network check service.

this.networkHeartService = new NetworkHeartService({
  heartMode: 'auto',
  reconnect() {
    console.log('TODO ...')
  }
});
this.networkHeartService.start();

// this.networkHeartService.stop();

Contributions

Your contributions and suggestions are welcome πŸ˜„πŸ˜„πŸŒΊπŸŒΊπŸŽ†πŸŽ†

MIT License