Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryanve/cxn
Network connection JavaScript utility module
https://github.com/ryanve/cxn
javascript offline
Last synced: about 1 month ago
JSON representation
Network connection JavaScript utility module
- Host: GitHub
- URL: https://github.com/ryanve/cxn
- Owner: ryanve
- License: mit
- Created: 2013-12-13T23:55:12.000Z (almost 11 years ago)
- Default Branch: gh-pages
- Last Pushed: 2016-12-10T23:47:14.000Z (almost 8 years ago)
- Last Synced: 2024-09-14T14:37:24.158Z (about 2 months ago)
- Topics: javascript, offline
- Language: JavaScript
- Homepage: https://ryanve.github.io/cxn
- Size: 43.9 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
=cxn
Network connection JavaScript module with online/offline events- [Live Demo](http://ryanve.github.io/cxn/)
- [API](#api)
- [CSS](#css)## Setup
```sh
$ npm install cxn --save
``````js
var cxn = require('cxn')
```## API
#### `cxn.online(listener?)` ⇒ `boolean` 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
#### `cxn.gap()` ⇒ `number` ms at current offline state (0 if online)
#### `cxn.life()` ⇒ `number` 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## CSS
#### `html[data-cxn]` reports states
```css
[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 }
```