It will Create a toast notification to notify if Internet is Down or not based on ping request to google.com/yahoo.com
The package can be used as a standalone app or can be included in your app using require
or import
-
- Clone the Repository
$ git clone [email protected]:legndery/internet-notifier.git
- NPM install dependencies
$ cd internet-notifier $ npm i
- Run it
$ npm start # optionally you can make it a background process by # $ npm start &
- Clone the Repository
-
- NPM install from Git
$ npm i -g legndery/internet-notifier.git
- Run the package
$ inotifier # or internet-notifier
- NPM install from Git
- NPM install it as a module
$ npm i legndery/internet-notifier.git
- Import the class in your script and use it.
const InternetStateChangeNotifier = require('internet-notifier'); const customHandler = (data) => { console.log(data); } new InternetStateChangeNotifier(customHandler).run()
which checks with ping or dns if a remote host is reachable or not and emits an event called internet_state_changed
with data { alive: boolean }
Create the notifier class instance with params. Every Param is optional
Param | Type | Description |
---|---|---|
handler | function | boolean |
Handler for the internet_state_changed event. When false there will be no handler, if true it will use the default handler i.e the notification handler, if function will use the given function as the custom handler |
emitter | EventEmitter |
An EventEmitter instance. If none provided a new Event.EventEmitter() is created, getEmitter() returns the emitter instance, if any EventEmitter is provided it will use that EventEmitter |
_config | Object |
A configuration object for the class |
_config.host | String |
Default: '8.8.8.8' , A host or IP which is pinged or resolved |
_config.interval | Number |
Default: 1000 , Probing the Host every _config.interval ms |
_config.debounce_time | Number |
Default: 4 , How many consecutive same status requests are returned before internet state change is determined, i.e if atleast 4 consecutive dead or alive responses gets returned then we determine internet is down or up |
_config.check_method | String |
Default: "PING" , Possible Value: "DNS" , Determines if it will Ping or Lookup the Host |
runs the notification service
returns the EventEmitter instance