# js-flux

> Datagram send and receive over binary websocket

Latest version **2.0.1** (published 2018-07-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install js-flux
pnpm add js-flux
yarn add js-flux
bun add js-flux
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2018-07-24 |
| First published | 2018-05-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Peter Bjorklund |
| Maintainers | piot |

## Links

- npm: https://www.npmjs.com/package/js-flux
- Repository: https://github.com/Piot/flux-js
- npm.io page: https://npm.io/package/js-flux

## Recent versions

- 2.0.1 (latest) — 2018-07-24
- 2.0.0 — 2018-07-24
- 1.0.15 — 2018-07-24
- 1.0.14 — 2018-07-23
- 1.0.13 — 2018-07-22
- 1.0.12 — 2018-07-22
- 1.0.11 — 2018-07-22
- 1.0.10 — 2018-07-22
- 1.0.9 — 2018-07-22
- 1.0.8 — 2018-05-09
- 1.0.7 — 2018-05-07

## README

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [WebsocketConnection][1]
    -   [Parameters][2]
    -   [Examples][3]
    -   [onOpen][4]
    -   [onClose][5]
    -   [onError][6]
        -   [Parameters][7]
    -   [onMessage][8]
        -   [Parameters][9]
    -   [connect][10]
    -   [close][11]
    -   [send][12]
        -   [Parameters][13]

## WebsocketConnection

Encapsulates a websocket connection

Wraps a Websocket connection with a logger.

### Parameters

-   `host` **[string][14]** A websocket url, e.g. 'ws://demos.kaazing.com/echo'
-   `log` **Log** An object which has a `log()` function

### Examples

```javascript
import { WebsocketConnection } from 'js-flux';

class Log {
  log(x) {
   console.log('log: ' + x);
 }
}

let logger = new Log();
let connection = new WebsocketConnection('ws://demos.kaazing.com/echo', logger);

connection.onOpen = () => console.log('opened connection');
connection.onMessage = (message) => console.log('received message:', message);

connection.connect();
```

### onOpen

### onClose

Type: Callback

### onError

Type: Callback

#### Parameters

-   `e`  

### onMessage

Type: Callback

#### Parameters

-   `m`  

### connect

Starts the connection process

### close

Closes the current connection

### send

Sends a binary payload

#### Parameters

-   `payload` **([Uint8Array][15] \| [Blob][16])** 

[1]: #websocketconnection

[2]: #parameters

[3]: #examples

[4]: #onopen

[5]: #onclose

[6]: #onerror

[7]: #parameters-1

[8]: #onmessage

[9]: #parameters-2

[10]: #connect

[11]: #close

[12]: #send

[13]: #parameters-3

[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array

[16]: https://developer.mozilla.org/docs/Web/API/Blob

---
_Source: https://npm.io/package/js-flux · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
