new JsonRpcClientFactory(options)
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Connection options for the factory class Properties
|
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
protocol |
Object | Instance of JsonRpcClientProtocol to use for managing client connections |
pcolInstance |
class | The JsonRpcClientProtocol instance |
timeouts |
object | Key value pairs of request IDs to |
requestTimeout |
number | Same as |
remainingRetries |
number | Same as |
connectionTimeout |
number | Same as |
server |
object | Object of host and port |
Requires:
- module:events
Extends
- EventEmitter
Requires
- module:events
Members
-
<static> http :HttpClientFactory
-
HTTP client constructor
Type:
- Source:
-
<static> tcp :TcpClientFactory
-
TCP client constructor
Type:
- Source:
-
<static> ws :WsClientFactory
-
WebSocket client constructor
Type:
- Source:
Methods
-
batch(requests)
-
Calls
batch()method on protocol instanceParameters:
Name Type Description requestsArray.<JSON> Valid JSON-RPC batch request array
- Source:
-
<abstract> buildProtocol()
-
Set the
pcolInstancefor the client factory- Source:
Example
1
this.pcolInstance = new JsonRpcClientProtocol() -
cleanUp(ids)
-
Clears pending timeouts kept in
timeoutsproperty for the provided request IDs.Parameters:
Name Type Description idsArray.<string> | Array.<number> Array of request IDs
- Source:
-
connect()
-
Calls
buildProtocolmethod.Calls
connect()on protocol instance- Source:
-
<abstract> end()
-
Calls
end()on protocol instance- Source:
-
message(method, params [, id])
-
Calls
message()on the protocol instanceParameters:
Name Type Argument Description methodstring Name of the method to use in the request
paramsArray | JSON Params to send
idboolean <optional>
If true it will use instances
message_idfor the request id, if false will generate a notification request- Source:
Example
-
notify(method, params)
-
Calls
notify()method on protocol instancePromise will resolve if the request was sucessfully sent, and reject if there was an error sending the request.
Parameters:
Name Type Description methodstring Name of the method to use in the notification
paramsArray | JSON Params to send
- Source:
Returns:
Promise
Example
1
client.notify("hello", ["world"]) -
request()
-
Calls
request()method on protocol instancePlans to deprecate this in future versions.
- Source:
-
send(method, params)
-
Calls
send()method on protocol instancePromise 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
requestTimeoutParameters:
Name Type Description methodstring Name of the method to use in the request
paramsArray | JSON Params to send
- Source:
Returns:
Promise
Example
1
client.send("hello", {"foo": "bar"}) -
serverDisconnected(cb)
-
Listens for a
serverDisconnectedevent, passing the callback functionParameters:
Name Type Description cbfunction - Source:
-
<abstract> subscribe(method, cb)
-
Subscribe the function to the given event name
Parameters:
Name Type Description methodstring Method name to subscribe to
cbfunction Name of callback function to invoke on event
- Source:
-
<abstract> unsubscribe(method, cb)
-
Unsubscribe the function from the given event name
Parameters:
Name Type Description methodstring Method to unsubscribe from
cbfunction Name of function to remove
- Source:
-
<abstract> unsubscribeAll(method)
-
Unsubscribe all functions from given event name
Parameters:
Name Type Description methodstring Method to unsubscribe all listeners from
- Source: