Skip to content

Latest commit

 

History

History
89 lines (72 loc) · 3.41 KB

README.md

File metadata and controls

89 lines (72 loc) · 3.41 KB

WIP, release in december

Build Status devDependency Status Build Status Coveralls github branch Npm version Build Status

Support :

  • Browser (WebSocket API compatible)

  • Nodejs with ws (WebSocket API compatible)

  • Waterfall - Reconnect (exponential truncated backoff by default, fully configurable)

  • Pipe - Fake multiplexing, based on a string prefix - fake but working

  • Dam - Simulate open / close based on your logic, open a pipe after the authentication on an other one for example

  • Tank - No need to monitor the state of the communication the sent messages with be flushed when it open

  • Fizz - Wrap your WebSocket interface for more fun with once, on, Promises

  • Boat - Rpc transport

  • Bottling - A json stream with filtering

  • Url change (WIP)

  • 100% test coverage

  • Your idea here, send an issue, provide a PR

With strictly no dependencies

Greenkeeper badge

{
  "name": "advanced-websocket",
  ...
  "dependencies": null,
  ...
}

Examples:

A simple compatible WebSocket with automatic reconnect :

const ws = new Waterfall("wss://server", null, {
    connectionTimeout: 2000,
    retryPolicy: exponentialTruncatedBackoff(100, Number.MAX_VALUE)
});

Two channels (string messages only) api compatible with WebSocket on the same transport :

const ws = new WebSocket("wss://server");
const  channelA = new Pipe(ws, "A");
const  channelB = new Pipe(ws, "B");

Creating a WebSocket that send "open" "close", "messages" according to the transport layer and some logic :

const ws = new WebSocket("wss://server");
const  authentificationLayer = new Dam(ws);
onLogin(() => authenticationLayer.status = "OPEN");
onLogout(() => authenticationLayer.status = "CLOSED");

A combination that use the 3 objects to create an authentication channel, a data channel (that can be used by any library expecting a regular websocket) and a robust websocket

const ws = new Waterfall("wss://server", null, {
    connectionTimeout: 2000,
    retryPolicy: exponentialTruncatedBackoff(100, Number.MAX_VALUE)
});
const authChannel = new Pipe(ws, AUTH_CHANNEL);
const authFilter = new Dam(ws);
const shareDbChannel = new Pipe(authFilter, SHAREDB_CHANNEL);

authChannel.onopen = () => {
    authChannel.send(JSON.stringify(TOKEN));    
}
authChannel.onmessage = (message) => {
    if(message.data === "login") {
        authFilter.status = "OPEN";
    } else if(message.data === "logout") {
        authFilter.status = "CLOSED";
    }
}

const db = new ShareDb(shareDbChannel);