bulky-wall-61623
09/08/2025, 2:10 PMtall-airline-16756
09/08/2025, 2:10 PMtall-airline-16756
09/08/2025, 2:11 PMregisterRpcMethod. Here’s an example:
room.localParticipant?.registerRpcMethod(
'getUserLocation',
async (data) => {
console.log(`Request from ${data.callerIdentity}: ${data.payload}`);
// Do something here, like get the device location
return `Response data`;
}
);
Step 2: Perform the RPC Call (from the caller)
Then, the agent or another participant can call that method using performRpc. Check this out:
const result = await room.localParticipant.performRpc({
destinationIdentity: 'user-123',
method: 'getUserLocation',
payload: JSON.stringify({ highAccuracy: true }),
});
Just a few things to keep in mind:
• The payload needs to be a string (like JSON) and can’t be bigger than 15KiB.
• Make sure both participants are connected to the same room.
• Don’t forget to handle errors in performRpc using try/catch or .catch().
If you run into any issues or want to chat about specific use cases, just give me a shout—I’m here to help!
Sources: packages/livekit-rtc/README.md | complex-agents/role-playing/role_playing_frontend/components/character-port... | examples/rpc/rpc-demo.ts | Tool definition and use | LiveKit Docs | Tool definition and use | LiveKit Docsbulky-wall-61623
09/08/2025, 2:13 PMtall-airline-16756
09/08/2025, 2:14 PMdestinationIdentity. Thanks!bulky-wall-61623
09/08/2025, 8:29 PMtall-airline-16756
09/08/2025, 8:29 PMroom.localParticipant.performRpc worked out, you can handle it just like any other async operation. This method returns a promise that either resolves if everything goes well or rejects if something goes wrong.
Here’s a quick example:
try {
const response = await room.localParticipant.performRpc({
destinationIdentity: 'remote-participant',
method: 'greet',
payload: 'Hello!',
});
console.log('RPC successful, response:', response); // Got a successful response!
} catch (error) {
if (error instanceof RpcError) {
console.error('RPC failed with code:', error.code, 'message:', error.message);
} else {
console.error('Unexpected error:', error);
}
}
Some common reasons it might fail:
• `RESPONSE_TIMEOUT`: No response came back in time.
• `CONNECTION_TIMEOUT`: There were connectivity problems during the call.
• `UNSUPPORTED_METHOD`: The recipient doesn’t recognize that method.
• `RECIPIENT_DISCONNECTED`: The other participant disconnected.
So, if the promise resolves, that means success, and if it throws an error, something went wrong. Feel free to ask if you want me to walk you through any part of this!
Sources: livekit-android-sdk/src/main/java/io/livekit/android/room/participant/Local... | livekit/src/room/participant/local_participant.rs | localparticipant.go | examples/rpc/rpc-demo.ts | lib/src/participant/local.dartbulky-wall-61623
09/08/2025, 8:30 PMtall-airline-16756
09/08/2025, 8:31 PMroom.localParticipant.performRpc isn’t returning anything, it might mean there’s a hiccup in the RPC flow. No worries though—here are some friendly steps to help you troubleshoot:
• Check Method Registration: Make sure the destination participant has registered the method using registerRpcMethod. If it’s not registered, the call won’t go through.
• Verify Server Version: Double-check that your LiveKit server version is at least 1.8.0, since earlier versions don’t support RPC.
• Payload Size: Keep an eye on the payload size—it shouldn’t be bigger than 15KiB.
• Timeouts: Sometimes calls hang if the response or connection timeout isn’t set right. Take a look at the responseTimeout parameter and confirm the remote participant is online.
• Connection Issues: If the remote participant disconnects during the call, it will fail. So, make sure both participants have a stable connection.
Also, it’s a good idea to wrap performRpc in a try/catch block to catch any errors smoothly. Here’s a quick example:
try {
const response = await room.localParticipant.performRpc({
destinationIdentity: 'remote-identity',
method: 'yourMethod',
payload: 'yourPayload'
});
console.log('Success:', response);
} catch (error) {
console.error('RPC failed:', error.message, error.code);
}
If you’re still stuck after this, just give me a shout—I’m here to help you dig in and figure it out together!
Sources: Remote method calls (RPC) | LiveKit Docs | packages/livekit-rtc/src/participant.ts | examples/rpc/rpc-demo.ts | livekit-android-sdk/src/main/java/io/livekit/android/room/participant/Local... | lib/src/participant/local.dart