Network connection JavaScript utility module
JavaScript HTML
Latest commit 8ed772f Dec 10, 2016 @ryanve 0.7.0
Failed to load latest commit information.
.gitignore Add @ 0.1.0 Dec 14, 2013
index.html convert test.html into index.html Dec 10, 2016
vendor.js correct dependency Dec 10, 2016


Network connection JavaScript module with online/offline events


$ npm install cxn --save
var cxn = require('cxn')

API true if online

cxn.offline(listener?)boolean true if offline

cxn.line(listener?)cxn listen to online and offline

cxn.unline(listener?)cxn unlisten to online and offline

cxn.stable()boolean true if initial connection state persists

cxn.unstable()number times connection state changed

cxn.elapsed()number ms since runtime

cxn.interim()number ms at current state ms at current offline state (0 if online) ms at current online state (0 if offline)

cxn.late()number ms to first go online, Infinity if not yet, 0 if started online

cxn.bandwidth()number MB/s (0 if offline)

cxn.metered()boolean true if data usage is metered

cxn.wire(event, listener?)cxn listen

cxn.unwire(event, listener?)cxn unlisten

cxn.listeners(event)Array listeners

cxn.emit(event)number listeners fired


html[data-cxn] reports states

[data-cxn~="stable"] { border-top:4px solid blue }
[data-cxn~="unstable"] { border-top:4px dotted yellow }
[data-cxn~="online"] { border-top-color:green }
[data-cxn~="offline"] { border-top-color:red }