Skip to content

(WIP) Add new useRpc hook prototype#1314

Draft
1egoman wants to merge 5 commits intomainfrom
use-rpc-hook-prototype
Draft

(WIP) Add new useRpc hook prototype#1314
1egoman wants to merge 5 commits intomainfrom
use-rpc-hook-prototype

Conversation

@1egoman
Copy link
Copy Markdown
Contributor

@1egoman 1egoman commented Mar 25, 2026

Overview

A prototype of a new useRpc hook aiming to simplify both sending and responding to rpc messages.

A snapshot build was published on npm, run the below to give it a shot locally:

$ npm install --save @livekit/components-react@rpc-prototype

Example usage:

// "Server" end of RPC
const { performRpc } = useRpc(session, {
  getUserLocation: rpc.json(async (payload: { highAccuracy: boolean }, data) => {
    const position = await new Promise<GeolocationPosition>((resolve, reject) => {
      navigator.geolocation.getCurrentPosition(resolve, reject, {
        enableHighAccuracy: payload.highAccuracy,
        timeout: data.responseTimeout * 1000,
      });
    });
    return {
      latitude: position.coords.latitude,
      longitude: position.coords.longitude,
    };
  }),
});

// "Client" end of RPC
const result = await performRpc(rpc.json<{ highAccuracy: boolean }, { latitude: number; longitude: number }>({
  destinationIdentity: participantIdentity,
  method: 'getUserLocation',
  payload: { highAccuracy: true },
}));

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 25, 2026

size-limit report 📦

Path Size
LiveKitRoom only 6.01 KB (0%)
LiveKitRoom with VideoConference 32.25 KB (+0.06% 🔺)
All exports 43.83 KB (+1.79% 🔺)

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
components-js-storybook-5kld Ready Ready Preview, Comment Mar 27, 2026 4:29pm

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 27, 2026

⚠️ No Changeset found

Latest commit: 43501ca

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant