new JsonRpcServerFactory(options)
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Properties
|
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
methods |
object | Key value pairs of server method to function call |
clients |
array | List of client connections which are instances of JsonRpcServerProtocol |
listening |
boolean | Inidicates if the server is currently listening |
protocol |
Object | Instance of JsonRpcServerProtocol to use for client connections |
Extends
- events
Members
-
<static> http :HttpServerFactory
-
HTTP server constructor
Type:
- Source:
-
<static> tcp :TcpServerFactory
-
TCP server constructor
Type:
- Source:
-
<static> ws :WsServerFactory
-
WS server constructor
Type:
- Source:
Methods
-
_removeFromArray(item, array)
-
Removes item from the given list
Parameters:
Name Type Description item* Any item in the list
arrayarray The array to remove the item from
- Source:
Returns:
Returns the item that was removed from the array or {error}
- Type
- * | error
-
<abstract> buildProtocol()
-
Establishes the client connection using the protocol instance and adds the newly connected client to
this.clients.Registers the event to call
clientDisconnectedwhen a client a closes the connection- Source:
Example
-
clientConnected(pcol)
-
Called when client receives a
connectionevent.Parameters:
Name Type Description pcolJsonRpcServerProtocol A JsonRpcServerProtocol instance
- Source:
Returns:
Returns a client for a given
JsonRpcServerProtocolinstance- Type
- JsonRpcServerProtocol.client
-
clientDisconnected(pcol)
-
Called when client disconnects from server.
If overwriting, its recommended to call JsonRpcServerFactory._removeFromArray manually to ensure
this.clientsis cleaned upCalls
this._removeFromArrayand removes disconnected client fromthis.clientslistParameters:
Name Type Description pcolJsonRpcServerProtocol A JsonRpcServerProtocol instance
- Source:
Returns:
Returns an object of {host, port} for the given protocol instance, or {error} if there was an error retrieving the client
- Type
- object | error
-
close()
-
Closes the server connection and kicks all connected clients.
Sets
listeningproperty tofalse.- Source:
Returns:
Will reject if any error was present
- Type
- Promise
-
listen()
-
Start listening for client connections to server.
Calls setServer and buildProtocol.
Establishes
errorandcloselisteners.- Source:
Returns:
Resolves host and port address for server.
- Type
- Promise
-
method(name, cb)
-
Register a method and associated function with the server.
The function will be called when a client makes a request to this method.
Parameters:
Name Type Description namestring Name of method
cbfunction Function to call when client makes request to method
- Source:
-
notify(notifications)
-
Parameters:
Name Type Description notificationsArray.<Array.<string, (Array|object)>> Array of notifications
- Source:
Returns:
Returns list of error objects if there was an error sending to any client. Returns true if the entire data was sent successfully Returns false if all or part of the data was not sent to the client.
- Type
- Array.<boolean> | Array.<Error>
Example
-
onNotify(method, cb)
-
Call function when notification with event name comes in.
Parameters:
Name Type Description methodstring Method name to listen for notification
cbfunction Name of callback function fired when method event comes in
- Source:
Example
-
removeAllOnNotify(method)
-
Remove all functions listening for notification.
Parameters:
Name Type Description methodstring Method name to remove events for
- Source:
-
removeOnNotify(method, cb)
-
Remove function name from listening for notifications.
Parameters:
Name Type Description methodstring Method name to remove
cbfunction Name of the callback function to remove
- Source:
Example
-
sendNotification(client, response)
-
Send notification to client
Parameters:
Name Type Description clientclass Client instance
responsestring Stringified JSON-RPC message to sent to client
- Source:
Throws:
Will throw an error if client is not defined
-
<abstract> setServer()
-
Set the
serverproperty for the server factory- Source:
Example
1
this.server = new net.Server()