big-controller-60015
05/12/2025, 1:44 PMtall-airline-16756
05/12/2025, 1:44 PMtall-airline-16756
05/12/2025, 1:44 PMregisterRpcMethod
function. For example:
room.localParticipant?.registerRpcMethod(
'greet', // method name
async (data: RpcInvocationData) => {
console.log(`Received greeting from ${data.callerIdentity}: ${data.payload}`);
return `Hello, ${data.callerIdentity}!`;
},
);
The handler receives the payload and a responseTimeout
parameter, which indicates the maximum time available to return a response.
Calling an RPC Method
To call an RPC method on another participant, use the performRpc
function. For example:
try {
const response = await room.localParticipant!.performRpc({
destinationIdentity: 'recipient-identity',
method: 'greet',
payload: 'Hello from RPC!',
});
console.log('RPC response:', response);
} catch (error) {
console.error('RPC call failed:', error);
}
You can also adjust the responseTimeout
parameter to specify how long to wait for a response.
Error Handling
In RPC method handlers, you can throw errors of type RpcError
with a string message, which will be received by the caller. Other error types will result in a generic "1500" ("Application Error").
If you have further questions or need additional clarification, feel free to ask!
Sources: LiveKit JS Client SDK - v2.8.1