Skip to content

Commit

Permalink
Avoid logging activeDevice updates for undefined active devices (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO authored Oct 22, 2024
1 parent a1a2430 commit bdc52a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-rats-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/components-react": patch
---

Avoid logging activeDevice updates for undefined active devices
10 changes: 7 additions & 3 deletions packages/react/src/hooks/useMediaDeviceSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,20 @@ export function useMediaDeviceSelect({
);
const devices = useObservableState(deviceObserver, [] as MediaDeviceInfo[]);
// Active device management.
const [currentDeviceId, setCurrentDeviceId] = React.useState<string>('');
const [currentDeviceId, setCurrentDeviceId] = React.useState<string>(
roomContext?.getActiveDevice(kind) ?? '',
);
const { className, activeDeviceObservable, setActiveMediaDevice } = React.useMemo(
() => setupDeviceSelector(kind, room ?? roomContext, track),
[kind, room, roomContext, track],
);

React.useEffect(() => {
const listener = activeDeviceObservable.subscribe((deviceId) => {
log.info('setCurrentDeviceId', deviceId);
if (deviceId) setCurrentDeviceId(deviceId);
if (deviceId) {
log.info('setCurrentDeviceId', deviceId);
setCurrentDeviceId(deviceId);
}
});
return () => {
listener?.unsubscribe();
Expand Down

0 comments on commit bdc52a1

Please sign in to comment.