registerRpcMethod

open override fun registerRpcMethod(method: String, handler: RpcHandler)

Establishes the participant as a receiver for calls of the specified RPC method. Will overwrite any existing callback for the same method.

Example:

room.registerRpcMethod("greet") { (requestId, callerIdentity, payload, responseTimeout) ->
Log.i("TAG", "Received greeting from ${callerIdentity}: ${payload}")

// Return a string
"Hello, ${callerIdentity}!"
}

The handler receives an RpcInvocationData with the following parameters:

  • requestId: A unique identifier for this RPC request

  • callerIdentity: The identity of the RemoteParticipant who initiated the RPC call

  • payload: The data sent by the caller (as a string)

  • responseTimeout: The maximum time available to return a response

The handler should return a string. If unable to respond within RpcInvocationData.responseTimeout, the request will result in an error on the caller's side.

You may throw errors of type RpcError with a string message in the handler, and they will be received on the caller's side with the message intact. Other errors thrown in your handler will not be transmitted as-is, and will instead arrive to the caller as 1500 ("Application Error").

Parameters

method

The name of the indicated RPC method

handler

Will be invoked when an RPC request for this method is received

See also

RpcInvocationData