npm.io
1.0.3 • Published 6 years ago

connectivity-events

Licence
MIT
Version
1.0.3
Deps
1
Size
4 kB
Vulns
0
Weekly
0
Stars
16

connectivity-events

Emits events on system wakeup or network status changes.

By default, the timer that's used for polling os.networkInterfaces() is unref'd, so it won't keep your process alive.

Installation

> npm i connectivity-events --save

Usage

const ConnectivityMonitor = require('connectivity-events')
const connectivity = new ConnectivityMonitor()

connectivity.on('change', () => { ... }) // Emitted whenever connectivity state changes.

// After you're done listening for events.
connectivity.destroy()
API
const monitor = new ConnectivityMonitor(opts = {})

Start listening for connectivity events.

Options include:

{
  interval: 10000 // The default polling interval.
  noUnref: false  // Don't unref the timer.
}
monitor.on('change', () => { ... })

Emitted whenever your computer's connectivity state has changed.

This will also be emitted when your computer wakes up after being suspended.

monitor.destroy()

Stop listening for network changes.

License

MIT

Keywords