Class: WsBrowserClientFactory

WsBrowserClientFactory

Creates an instance of WsBrowserClientFactory.

For websocket client use in the browser.


new WsBrowserClientFactory(options)

Parameters:
Name Type Description
options Object

Connection options for the factory class

Properties
Name Type Argument Default Description
url string <optional>
"ws://127.0.0.1:8100"

IP of server to connect to

version number <optional>
2

JSON-RPC version to use (1|2)

delimiter string <optional>
"\n"

Delimiter to use for requests

timeout number <optional>
30

Timeout for request response

connectionTimeout number <optional>
5000

Timeout for connection to server

retries number <optional>
2

Number of connection retry attempts

Properties:
Name Type Description
pcolInstance class

The JsonRpcClientProtocol instance

timeouts object

Key value pairs of request IDs to setTimeout instance

requestTimeout number

Same as options.timeout

remainingRetries number

Same as options.retries

connectionTimeout number

Same as options.connectionTimeout

url string

Same as options.url

Source:

Extends

  • EventTarget

Methods


batch(requests)

Calls batch() method on protocol instance

Parameters:
Name Type Description
requests Array.<JSON>

Valid JSON-RPC batch request array

Source:

buildProtocol()

Set the pcolInstance for the client factory

Source:
Example
this.pcolInstance = new WsBrowserClientProtocol()

cleanUp(ids)

Clears pending timeouts kept in timeouts for the provided request IDs.

Parameters:
Name Type Description
ids Array.<string> | Array.<number>

Array of request IDs

Source:

connect()

Calls connect() on protocol instance.

Source:
Returns:

pcolInstance.connect()

Type
function

end()

Calls end() on protocol instance

Source:

getEventListeners(name)

Get the list of event listeners attached to the given event name.

Parameters:
Name Type Description
name string

The name of the event to retrieve listeners for

Source:
Returns:
Type
function | Array.<function()>

message(method, params [, id])

Calls message() on the protocol instance

Parameters:
Name Type Argument Description
method string

Name of the method to use in the request

params Array | JSON

Params to send

id boolean <optional>

If true it will use instances message_id for the request id, if false will generate a notification request

Source:
Example
client.message("hello", ["world"]) // returns {"jsonrpc": "2.0", "method": "hello", "params": ["world"], "id": 1}
client.message("hello", ["world"], false) // returns {"jsonrpc": "2.0", "method": "hello", "params": ["world"]}

notify(method, params)

Calls notify() method on protocol instance

Promise will resolve if the request was sucessfully sent, and reject if there was an error sending the request.

Parameters:
Name Type Description
method string

Name of the method to use in the notification

params Array | JSON

Params to send

Source:
Returns:

Promise

Example
client.notify("hello", ["world"])

request()

Calls request() method on protocol instance

Source:

send(method, params)

Calls send() method on protocol instance

Promise will resolve when a response has been received for the request.

Promise will reject if the server responds with an error object, or if the response is not received within the set requestTimeout

Parameters:
Name Type Description
method string

Name of the method to use in the request

params Array | JSON

Params to send

Source:
Returns:

Promise

Example
client.send("hello", {"foo": "bar"})

subscribe(method, cb)

Subscribe the function to the given event name

Parameters:
Name Type Description
method string

Method to subscribe to

cb function

Name of callback function to invoke on event

Source:

unsubscribe(method, cb)

Unsubscribe the function from the given event name

Parameters:
Name Type Description
method string

Method to unsubscribe from

cb function

Name of function to remove

Source:

unsubscribeAll(method)

Unsubscribe all functions from given event name

Parameters:
Name Type Description
method string

Method to unsubscribe all listeners from

Source: