JsonRpcClient

Description

The JsonRpcClient object provides a JSON-RPC 2.0 compliant client which connects to the JSON-RPC server specified through the hostname property. Calls can be made through the call() method. Properties can be read and written using the getProperty() and setProperty() methods.

This object was introduced in InCore 2.2.

› Inherits:Object

Properties

debugRpcMessages

This property holds whether to log received and sent RPC messages to the console for debugging purposes.

› Type:Boolean
› Default:false
› Signal:debugRpcMessagesChanged()
› Attributes:Writable

hostname

This property holds the host name or address of the JSON-RPC server.

› Type:String
› Default:localhost
› Signal:hostnameChanged()
› Attributes:Writable

path

This property holds the URL path of the RPC endpoint.

› Type:String
› Default:/rpc
› Signal:pathChanged()
› Attributes:Writable

port

This property holds the port at which the JSON-RPC server is listening.

This property was introduced in InCore 2.5.

› Type:SignedInteger
› Signal:portChanged()
› Attributes:Writable

protocol

This property holds the protocol to use for sending the JSON-RPC requests. Valid values are http and https.

› Type:String
› Default:http
› Signal:protocolChanged()
› Attributes:Writable

serviceName

This property holds the server-side name of the service corresponding to property{JsonRpcService.serviceName}.

This property was introduced in InCore 2.5.

› Type:String
› Default:incore
› Signal:serviceNameChanged()
› Attributes:Writable

Methods

call(String name, List arguments, JSValue callback)

This method calls the method specified by parameter name with the arguments specified in parameter arguments. It returns true if the call request could be initiated succesfully. This does not neccessarily mean that the call itself was successful. Use the errorCodeReceived(), errorDataReceived() or errorMessageReceived() signals to detect and handle actual RPC errors. When the call succeeded, the return value will be passed to the given callback as the first argument.

› Returns:Boolean

getProperty(String name, JSValue callback)

This method wraps a call to the getProperty() method implemented by JsonRpcService. Whenever a property is received, the given callback is called with the result as the first argument.

› Returns:Boolean

setProperty(String name, Variant value)

This method wraps a call to the setProperty() method implemented by JsonRpcService.

› Returns:Boolean

Signals

errorCodeReceived(String name, SignedInteger errorCode)

This signal is emitted whenever an RPC error response with an error code other than 0 is received.

errorDataReceived(String name, Variant errorData)

This signal is emitted whenever an RPC error response with valid error data is received.

errorMessageReceived(String name, String errorMessage)

This signal is emitted whenever an RPC error response with a valid error message is received.

Example

See JsonRpcService example on how to use JsonRpcClient.