early-window-29567
11/10/2025, 3:05 PMtall-airline-16756
11/10/2025, 3:05 PMtall-airline-16756
11/10/2025, 3:06 PMregisterRpcMethod. You give it a method name and a handler function that will process incoming calls. The handler gets useful info like who called, the data sent, and how long to wait for a response. Here’s an example:
`room.localParticipant?.registerRpcMethod('greet', async (data) => {
console.log(Received greeting from ${data.callerIdentity}: ${data.payload});
return `Hello, ${data.callerIdentity}!;
});
• Performing an RPC Request: When you want to call a method on someone else, you use performRpc, specifying who you’re calling, the method name, and any data you want to send. Like this:
const response = await room.localParticipant!.performRpc({
destinationIdentity: 'recipient-identity',
method: 'greet',
payload: 'Hello from RPC!',
});
• If the participant you’re calling doesn’t respond in time, you’ll get an error — so it’s good to keep an eye on those timeouts.
Best Use Cases:
• Forwarding tool calls from AI agents to frontend apps: For example, an AI can trigger a function on the frontend, like asking for the user’s location through browser APIs.
• Keeping app states synchronized in real-time between participants.
• Requesting data from peers exactly when you need it.
• Building fun interactive features like greetings, games, or collaborative tools.
And the great news is, RPC works across various SDKs — JavaScript, Python, Unity, and Node.js — so you can easily connect participants on different platforms.
Sources: packages/livekit-rtc/README.md | Tool definition and use | LiveKit docs | README.md | README.md | Remote method calls | LiveKit docs