Extends
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
- Inherited From:
- Overrides:
- Source:
Returns:
Returns the item that was removed from the array or {error}
- Type
- * | error
-
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- Inherited From:
- Overrides:
- Source:
Example
-
clientConnected(pcol)
-
Called when client receives a
connectionevent.Parameters:
Name Type Description pcolJsonRpcServerProtocol A JsonRpcServerProtocol instance
- Inherited From:
- Overrides:
- 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
- Inherited From:
- Overrides:
- 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.- Inherited From:
- Overrides:
- 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.- Inherited From:
- Overrides:
- 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
- Inherited From:
- Overrides:
- Source:
-
notify(notifications)
-
Parameters:
Name Type Description notificationsArray.<Array.<string, (Array|object)>> Array of notifications
- Inherited From:
- Overrides:
- 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
- Inherited From:
- Overrides:
- Source:
Example
-
removeAllOnNotify(method)
-
Remove all functions listening for notification.
Parameters:
Name Type Description methodstring Method name to remove events for
- Inherited From:
- Overrides:
- 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
- Inherited From:
- Overrides:
- 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
- Inherited From:
- Overrides:
- Source:
Throws:
Will throw an error if client is not defined
-
setServer()
-
Set the
serverproperty for the server factory- Inherited From:
- Overrides:
- Source:
Example
1
this.server = new net.Server()