Skip to content

JackPu/network-heart-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 increasing timeout. But it is set with a number, it will check the network in specify 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

About

A Service to Handle Network Change

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published