Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 }
```