-
Notifications
You must be signed in to change notification settings - Fork 121
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
base: main
Are you sure you want to change the base?
Conversation
This allows the microphone preconnect audio buffer to be used
…nnect in series Context around why this is important: #1197
|
size-limit report 📦
|
|
||
/** | ||
* 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>; | ||
|
There was a problem hiding this comment.
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.
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