qaap-barge
(deprecated - please use rpc-websockets)
Barge wraps the "websockets/ws" library providing JSON RPC 2.0 support on top.
Installation
npm install qaap-barge
Examples
var Barge = // instantiate Barge and connect to an RPC servervar ws = 'ws://localhost:8080/rpc/1.0' ws
API
var Barge = var ws = 'ws://localhost:8080/rpc/1.0'
new Barge(address[, options]) -> Barge
Instantiate a Barge client.
Parameters:
address
{String}: The URL of the WebSocket server. Defaults to 'ws://localhost:8080/rpc/1.0'.options
{Object}: Client options that are also forwarded tows
.autoconnect
{Boolean}: Client autoconnect upon Barge class instantiation. Defaults totrue
.reconnect
{Boolean}: Whether client should reconnect automatically once the connection is down. Defaults totrue
.reconnect_interval
{Number}: Time between adjacent reconnects. Defaults to1000
.max_reconnects
{Number}: Maximum number of times the client should try to reconnect. Defaults to5
.
ws.call(method[, params]) -> Promise
Calls a registered RPC method on server. Resolves once the response is ready. Throws if an RPC error was received.
Parameters:
method
{String}: An RPC method name to run on server-side.params
{Object|Array}: Optional parameter(s) to be sent along the request.
ws.notify(method[, params])
Sends a JSON-RPC 2.0 notification to server.
Parameters:
method
{String}: An RPC method name to run on server-side.params
{Object|Array}: Optional parameter(s) to be sent along the request.
ws.subscribe(event) -> Promise
Subscribes for a defined event.
Parameters:
event
{String}: Event name.
ws.unsubscribe(event) -> Promise
Unsubscribes from a defined event.
Parameters:
event
{String}: Event name.
ws.close([code[, data]])
Closes a WebSocket connection gracefully.
Parameters:
code
{Number}: Socket close code.data
{String}: Optional data to be sent to socket before closing.
Event: 'open'
Emits when the connection is opened and ready for use.
Event: 'error'
- <Error>
Emits when a socket error is raised.
Event: 'close'
Emits when the connection is closed.
Event: <Notification>
- <Object>
Emits a notification event a client has subscribed to once the server sends it.
Example:
ws ws