Skip to content

Update LiveKitRoom connection logic #1198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

1egoman
Copy link
Contributor

@1egoman 1egoman commented Aug 5, 2025

Initially, I made #1197, which aimed to create a react hook for managing a room connection. However, after some comments were left and I started digging in to the codebase a bit deeper, I noticed that there was already a mechanism in place to support this - LiveKitRoom / useLiveKitRoom. Embarrassingly, this is also called out right in the README... 🤦

So, ditch the old attempt and instead update this pre-existing abstraction to use the connection behavior from the previous change. In addition, it looks like there isn't a means to support the microphone preconnect audio buffer logic with the existing implementation, so add a mechanism to do that.

I ported agent-starter-react over to use this mechanism here: livekit-examples/agent-starter-react#225

1egoman added 2 commits August 5, 2025 11:46
This allows the microphone preconnect audio buffer to be used
…nnect in series

Context around why this is important: #1197
Copy link

changeset-bot bot commented Aug 5, 2025

⚠️ No Changeset found

Latest commit: 01a8fcd

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

Copy link
Contributor

github-actions bot commented Aug 5, 2025

size-limit report 📦

Path Size
LiveKitRoom only 6.06 KB (+1.11% 🔺)
LiveKitRoom with VideoConference 30.64 KB (+0.17% 🔺)
All exports 38.19 KB (+0.15% 🔺)

Comment on lines 80 to +86

/**
* Optional side effect to run in parallel with the connection process.
* This can be used to enable the microphone preconnect buffer / etc
*/
connectionSideEffect?: (room: Room) => Promise<void>;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new prop / parameter allows a user to inject in a side effect to run in parallel with the room.connect(...) call - an example of its use in agent-starter-react:

// Within a react component:
const enableMicrophonePreConnectBuffer = useCallback(async (room: Room) => {
  room.localParticipant.setMicrophoneEnabled(true, undefined, {
    preConnectBuffer: appConfig.isPreConnectBufferEnabled,
  });
}, []);

// (later on in the component)
return (
  <LiveKitRoom
    token="..."
    serverUrl="..."
    connectionSideEffect={enableMicrophonePreConnectBuffer}
  >
    {/* rest of application here */}
  </LiveKitRoom>
);

Note that I could see enableMicrophonePreConnectBuffer being extracted into the eventual agents sdk that has been discussed.

@1egoman 1egoman marked this pull request as ready for review August 5, 2025 16:41
@1egoman 1egoman requested a review from lukasIO August 5, 2025 16:41
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