A Service to check and handle network change.
$ 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();-
heartMode{ number } 2000 if it is undefined , it means useautomode. 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
Check if your network could work.
const isOnline = await NetworkHeartService.isOnline();Start or Stop the network check service.
this.networkHeartService = new NetworkHeartService({
heartMode: 'auto',
reconnect() {
console.log('TODO ...')
}
});
this.networkHeartService.start();
// this.networkHeartService.stop();Your contributions and suggestions are welcome 😄😄🌺🌺🎆🎆