Advanced WebSocket is a collection of lightweight (no dependencies) and simple components to build complex communication path over Websocket on the server and the browser.
All components are seen from the outside world like a WebSocket allowing you to integrate is on any existing project.
Examples
Waterfall
The waterfall is a simple compatible WebSocket with automatic reconnect support
The retry policy ermit a full customisation of the reconnection and a default exponential truncated backoff policy is provides by default.
;
Pipe
The Pipe allow you to multiplex string channels, add a pipe on a Websocket on both side and receive only the messages transmitted into this pipe.
;;;
Dam
Has you can split your WebSockets in different Pipes it become useful to be able to control an open or closed status, faking a connection. You can for example create a pipe to communicate and an other to authenticate and change the communication status according to the authentication status.
;;onLoginauthenticatedWebSocketr.status = "OPEN";onLogoutauthenticatedWebSocketr.status = "CLOSED";
Tank
Checking if a socket is open to be able to send your message, delaying
those messages for when the WebSocket is open is a repetitive task.
Wrap your socket in a Tank and you can use send
at anytime, if
the socket is closed, the messages will be buffered and has soon has the
websocket open they will be flushed in order.
;ws.send"I've send this message before the opening of the websocket";
Cable
Doing an RPC over a websocket should be trivial, the Cable provide a convenient way to register methods and to call them on both side of the connection.
// Client 1;cable.register"ping", ; cable.notify"hello", ; // Client 2 ; cable.register"hello", ; try catche
Advanced
A combination that use 5 components to create an authentication channel with rpc, a data channel (that can be used by any library expecting a regular websocket) and a robust websocket
;;;;; try catch
Roadmap
- Browser (WebSocket API compatible)
- Nodejs with ws (WebSocket API compatible)
- Waterfall - Reconnect (exponential truncated backoff by default, fully configurable)
- Pipe - Multiplexing, based on a string prefix
- Dam - Simulate open / close based on your logic, open a pipe after he 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
- Cable - Json rpc2 transport
- Split the project in different modules with yarn workspace and lerna
- Fizz - Wrap your WebSocket interface for more fun with
once
,on
,Promises
- Bottling - A json stream with filtering
- Url change (WIP)
- 100% test coverage
- Your idea here, send an issue, provide a PR
FAQ
Webpack
Webpack complain about the ws
implementation of WebSocket, the errors
are :
Can't resolve 'net'
and Can't resolve 'tls'
.
The solution consist in ignoring the ws module that can't be used in a browser (and not required), the polyfill will detect the browser implementation of the WebSocket and use it. To ignore the module, add a rule to your webpack config file :
{test: /[\/\\]node_modules[\/\\]ws[\/\\].+\.js$/, use: 'null-loader'},
Can't resolve 'ws'
If you're using this module on the client side webpack will warn you
with this message when you pack the module, if you're using this module
on the server side you need to install ws