Skip to content
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

Fix initial device selection when mounting useMediaDeviceSelect #1014

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/lemon-eggs-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@livekit/components-core": patch
"@livekit/components-react": patch
---

Fix initial device selection when mounting useMediaDeviceSelect
1 change: 0 additions & 1 deletion packages/core/src/observables/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ export function createActiveDeviceObservable(room: Room, kind: MediaDeviceKind)
log.debug('activeDeviceObservable | RoomEvent.ActiveDeviceChanged', { kind, deviceId });
return deviceId;
}),
startWith(room.getActiveDevice(kind)),
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 causes the active device to change whenever the useMediaDeviceSelect hook is mounted. Instead, shift the responsibility for initializing with the correct value into the hook's initial currentDeviceId state, which has been done already in https://github.com/livekit/components-js/pull/1012/files#diff-246daab5d71d5f9448a651e07a59775cbdccae8b7863e9f289fab063686772d1R57

);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/hooks/useMediaDeviceSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function useMediaDeviceSelect({

React.useEffect(() => {
const listener = activeDeviceObservable.subscribe((deviceId) => {
if (deviceId) {
if (deviceId && deviceId !== currentDeviceId) {
log.info('setCurrentDeviceId', deviceId);
setCurrentDeviceId(deviceId);
}
Expand Down