Class: WsServerProtocol

WsServerProtocol

Creates instance of WsServerProtocol


new WsServerProtocol()

In addition to the params and properties for JsonRpcServerProtocol the WsServerProtocol has the following properties:

Properties:
Name Type Description
event string

HTTP response object

client.write object

Overrides client.write method to use client.send for Websocket

Source:

Extends

Methods


clientConnected()

Registers the event data listener when client connects.

Pushes received data into messageBuffer and calls _waitForData.

Inherited From:
Overrides:
Source:

getResult(message)

Get the result for the request. Calls the function associated with the method and returns the result.

Parameters:
Name Type Description
message JSON

Valid JSON-RPC message object

Inherited From:
Overrides:
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
requests Array.<JSON>

Valid JSON-RPC batch request

Inherited From:
Overrides:
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
error Error

Error object instance where the message should be a JSON-RPC message object

Inherited From:
Overrides:
Source:

gotNotification(message)

Calls emit on factory with the event name being message.method and the date being message.

Parameters:
Name Type Description
message string

JSON-RPC message object

Inherited From:
Overrides:
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
message JSON

JSON-RPC message object

Inherited From:
Overrides:
Source:
Returns:
Type
Promise

validateMessage(message)

Validates if there are any issues with the incoming request

Parameters:
Name Type Description
message JSON

Valid JSON-RPC request object

Inherited From:
Overrides:
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
chunk string
Inherited From:
Overrides:
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
message string

Stringified JSON-RPC message object

Inherited From:
Overrides:
Source: