websocket-buffering
v0.0.2
Published
small wrapper around websocket that does message buffering and reconnects
Downloads
56
Readme
WebSocket-Buffering
small wrapper around websocket that does message buffering and reconnects
This is heavily inspired by stagas/websocket for the client side, but does the same wrapping for ws in node as well, to provide the same api.
Buffers messages and sends them once the connection has been established.
Also offers a .connect()
method to re-establish a broken connection.
Installation
$ npm install websocket-buffering
$ component install Swatinem/websocket-buffering
Usage
new WebSocketBuffering(url, [options])
Creates a new WebSocket connection to url
.
If options.connect
is set to false
, it will not automatically connect
If options.buffering
is set to false
, it will throw when sending on a closed
socket instead of buffering and sending once the socket is open.
ws.readyState
This is the readyState as defined by WebSocket. ws.OPEN
and so on.
ws.send(data)
Send data down the wire, or buffer it to be sent once the connection is actually open.
ws.connect()
This opens up a new connection when it is not open yet. Does nothing otherwise.
Event: 'open'
Event: 'error' (err)
Event: 'message' (message)
Event: 'close'
License
LGPLv3