Index · Object → JSONRPC

JSONRPC

A helper to handle dictionaries which look like JSONRPC documents.

Inherited by (1): GDScriptLanguageProtocol
Class Description

JSON-RPC is a standard which wraps a method call in a JSON object. The object has a particular structure and identifies which method is called, the parameters to that function, and carries an ID to keep track of responses. This class implements that standard on top of Dictionary; you will have to convert between a Dictionary and JSON with other functions.

Methods

func make_notification(method: String, params: Variant) -> Dictionary

Returns a dictionary in the form of a JSON-RPC notification. Notifications are one-shot messages which do not expect a response.

- method: Name of the method being called.

- params: An array or dictionary of parameters being passed to the method.

func make_request(method: String, params: Variant, id: Variant) -> Dictionary

Returns a dictionary in the form of a JSON-RPC request. Requests are sent to a server with the expectation of a response. The ID field is used for the server to specify which exact request it is responding to.

- method: Name of the method being called.

- params: An array or dictionary of parameters being passed to the method.

- id: Uniquely identifies this request. The server is expected to send a response with the same ID.

func make_response(result: Variant, id: Variant) -> Dictionary

When a server has received and processed a request, it is expected to send a response. If you did not want a response then you need to have sent a Notification instead.

- result: The return value of the function which was called.

- id: The ID of the request this response is targeted to.

func make_response_error(code: int, message: String, id: Variant = null) -> Dictionary

Creates a response which indicates a previous reply has failed in some way.

- code: The error code corresponding to what kind of error this is. See the ErrorCode constants.

- message: A custom message about this error.

- id: The request this error is a response to.

func process_action(action: Variant, recurse: bool = false) -> Variant

Given a Dictionary which takes the form of a JSON-RPC request: unpack the request and run it. Methods are resolved by looking at the field called "method" and looking for an equivalently named function in the JSONRPC object. If one is found that method is called.

To add new supported methods extend the JSONRPC class and call process_action() on your subclass.

action: The action to be run, as a Dictionary in the form of a JSON-RPC request or notification.

func process_string(action: String) -> String
func set_method(name: String, callback: Callable) -> void

Registers a callback for the given method name.

- name: The name that clients can use to access the callback.

- callback: The callback which will handle the specified method.

Inherited from Object (62)
func _get(property: StringName) -> Variant
func _get_property_list() -> Dictionary[]
func _init() -> void
func _iter_get(iter: Variant) -> Variant
func _iter_init(iter: Array) -> bool
func _iter_next(iter: Array) -> bool
func _notification(what: int) -> void
func _set(property: StringName, value: Variant) -> bool
func _to_string() -> String
func _validate_property(property: Dictionary) -> void
func add_user_signal(signal: String, arguments: Array = []) -> void
func call(method: StringName) -> Variant
func callv(method: StringName, arg_array: Array) -> Variant
func cancel_free() -> void
func connect(signal: StringName, callable: Callable, flags: int = 0) -> Error
func disconnect(signal: StringName, callable: Callable) -> void
func emit_signal(signal: StringName) -> Error
func free() -> void
func get(property: StringName) -> Variant
func get_class() -> String
func get_incoming_connections() -> Dictionary[]
func get_indexed(property_path: NodePath) -> Variant
func get_meta(name: StringName, default: Variant = null) -> Variant
func get_meta_list() -> StringName[]
func get_method_list() -> Dictionary[]
func get_property_list() -> Dictionary[]
func get_signal_connection_list(signal: StringName) -> Dictionary[]
func get_signal_list() -> Dictionary[]
func has_meta(name: StringName) -> bool
func has_method(method: StringName) -> bool
func has_signal(signal: StringName) -> bool
func is_class(class: StringName) -> bool
func is_connected(signal: StringName, callable: Callable) -> bool
func notification(what: int, reversed: bool = false) -> void
func remove_meta(name: StringName) -> void
func remove_user_signal(signal: StringName) -> void
func set(property: StringName, value: Variant) -> void
func set_block_signals(enable: bool) -> void
func set_deferred(property: StringName, value: Variant) -> void
func set_indexed(property_path: NodePath, value: Variant) -> void
func set_message_translation(enable: bool) -> void
func set_meta(name: StringName, value: Variant) -> void
func set_script(script: Variant) -> void
func set_translation_domain(domain: StringName) -> void
func to_string() -> String
func tr(message: StringName, context: StringName = &"") -> String
func tr_n(message: StringName, plural_message: StringName, n: int, context: StringName = &"") -> String

Signals

Inherited from Object (2)

Enums & Constants

enum ErrorCode
PARSE_ERROR = -32700

The request could not be parsed as it was not valid by JSON standard (JSON.parse() failed).

INVALID_REQUEST = -32600

A method call was requested but the request's format is not valid.

METHOD_NOT_FOUND = -32601

A method call was requested but no function of that name existed in the JSONRPC subclass.

INVALID_PARAMS = -32602

A method call was requested but the given method parameters are not valid. Not used by the built-in JSONRPC.

INTERNAL_ERROR = -32603

An internal error occurred while processing the request. Not used by the built-in JSONRPC.