Skip to content

Conversation

@pblazej
Copy link

@pblazej pblazej commented Dec 3, 2025

Also, a little change to useSession for the camera track...

@changeset-bot
Copy link

changeset-bot bot commented Dec 3, 2025

🦋 Changeset detected

Latest commit: f35d5a1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@livekit/component-example-next Patch
@livekit/components-react Patch
@livekit/components-js-docs Patch
@livekit/component-docs-storybook Patch
@livekit/components-docs-gen Patch

Not sure what this means? Click here to learn what changesets are.

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

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

size-limit report 📦

Path Size
LiveKitRoom only 6 KB (0%)
LiveKitRoom with VideoConference 32.46 KB (0%)
All exports 43.25 KB (-0.1% 🔽)

@pblazej pblazej marked this pull request as ready for review December 4, 2025 11:12
@pblazej pblazej requested review from 1egoman and lukasIO December 4, 2025 11:12
console.error('Failed to end session:', err);
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Contributor

Choose a reason for hiding this comment

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

thought(non-blocking): 😢

Copy link
Contributor

@1egoman 1egoman Dec 4, 2025

Choose a reason for hiding this comment

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

Also a thought:, but maybe it could make sense to destructure the session to get those start / end values out? I think you had said a few weeks back that does silence the warning?

);
};

session.internal.emitter.on(SessionEvent.MediaDevicesError, handleMediaDevicesError);
Copy link
Contributor

@lukasIO lukasIO Dec 4, 2025

Choose a reason for hiding this comment

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

thought: @1egoman maybe we should think about a cleaner high level helper for this.

using the internal emitters in the examples doesn't feel great.

Copy link
Contributor

Choose a reason for hiding this comment

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

There was a better way to do this proposed, useEvents, though it didn't get much discussion because I figured it was fairly non controversial - https://github.com/livekit/components-js/blob/main/packages/react/src/hooks/useEvents.ts#L5.

So the thinking is the above could be something like the below instead:

useEvents(session, SessionEvent.MediaDevicesError, handleMediaDevicesError);

roomName,
participantIdentity: userIdentity,
participantName: userIdentity,
room,
Copy link
Contributor

Choose a reason for hiding this comment

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

question: @1egoman is there anything ensuring that session is still "in charge" of the room connection cycle when users use this pattern?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not currently, no. It's an "escape hatch" you can use to provide a custom room and if the caller modifies the room's state extensively out of band it will definitely cause things to break. This definitely needs to be documented better than it currently is.

);
}

const VoiceAssistantExample: NextPage = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would be nice to rename this to agent example both in the method names and file

Comment on lines +22 to +24
const tokenSource = useMemo(() => {
return TokenSource.endpoint(process.env.NEXT_PUBLIC_LK_TOKEN_ENDPOINT!);
}, []);
Copy link
Contributor

@1egoman 1egoman Dec 4, 2025

Choose a reason for hiding this comment

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

suggestion: I think if at all possible, the examples (where it can be done) should define the TokenSource outside the component as a constant rather than in the component in a memoized fashion.

Making sure that the TokenSource doesn't change reference proved to be a challenge when Thom was porting over agent-starter-react to use these new apis, and I'd like to try to push people away from injecting local component state into TokenSources (configurable token sources should include all the metadata somebody would need in TokenSource.custom cases) unless you are doing something truly weird like agent-starter-react does to handle sandbox environments properly.

Comment on lines 33 to +44
const [room] = useState(new Room());

const tokenSource = useMemo(() => {
return TokenSource.endpoint(process.env.NEXT_PUBLIC_LK_TOKEN_ENDPOINT!);
}, []);

const session = useSession(tokenSource, {
roomName,
participantIdentity: userIdentity,
participantName: userIdentity,
room,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: I think you can get rid of the room parameter here since it is just new Room()?

@pblazej
Copy link
Author

pblazej commented Dec 5, 2025

Thank you for the feedback! I'll probably tackle that early next week to bring it to production standard.

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.

4 participants