new JsonRpcServerProtocol(factory, client, version, delimiter)
Parameters:
| Name | Type | Description |
|---|---|---|
factory |
class | Instance of JsonRpcServerFactory |
client |
class | Instance of |
version |
1 | 2 | JSON-RPC version to use |
delimiter |
string | Delimiter to use for |
- Source:
Properties:
| Name | Type | Default | Description |
|---|---|---|---|
messageBuffer |
class | Instance of MessageBuffer |
|
event |
string | "data" | The event name to listen for incoming data |
Methods
-
clientConnected()
-
Registers the
eventdata listener when client connects.Pushes received data into
messageBufferand calls _waitForData.- Source:
-
getResult(message)
-
Get the result for the request. Calls the function associated with the method and returns the result.
Parameters:
Name Type Description messageJSON Valid JSON-RPC message object
- Source:
Returns:
- Type
- Promise
-
gotBatchRequest(requests)
-
Attempts to get the result for all requests in the batch. Will send result to client if successful and error otherwise.
Parameters:
Name Type Description requestsArray.<JSON> Valid JSON-RPC batch request
- Source:
Returns:
- Type
- Array.<Promise>
-
gotError(error)
-
Writes error to the client. Will send a JSON-RPC error object if the passed error cannot be parsed.
Parameters:
Name Type Description errorError Errorobject instance where the message should be a JSON-RPC message object- Source:
-
gotNotification(message)
-
Calls
emiton factory with the event name beingmessage.methodand the date beingmessage.Parameters:
Name Type Description messagestring JSON-RPC message object
- Source:
-
gotRequest(message)
-
Attempts to get the result for the request object. Will send result to client if successful and will send an error otherwise.
Parameters:
Name Type Description messageJSON JSON-RPC message object
- Source:
Returns:
- Type
- Promise
-
validateMessage(message)
-
Validates if there are any issues with the incoming request
Parameters:
Name Type Description messageJSON Valid JSON-RPC request object
- Source:
Throws:
Will throw an error for any of the below reasons
Reason Type message is not an object Invalid Request the server does not have the required method Method Not Found the params are not an array or object Invalid Params the "jsonrpc" property was passed for a v1 server Invalid Request -
validateRequest(chunk)
-
Validate the request message
Parameters:
Name Type Description chunkstring - Source:
Throws:
Will throw an error with a JSON-RPC error object if chunk cannot be parsed
Returns:
- Type
- JSON
-
writeToClient(message)
-
Send message to the client
Parameters:
Name Type Description messagestring Stringified JSON-RPC message object
- Source: