diff --git a/.changeset/slow-rats-sneeze.md b/.changeset/slow-rats-sneeze.md new file mode 100644 index 000000000..3a25e1feb --- /dev/null +++ b/.changeset/slow-rats-sneeze.md @@ -0,0 +1,5 @@ +--- +"@livekit/components-react": patch +--- + +Avoid logging activeDevice updates for undefined active devices diff --git a/packages/react/src/hooks/useMediaDeviceSelect.ts b/packages/react/src/hooks/useMediaDeviceSelect.ts index 07e7a6b87..19d3dc44b 100644 --- a/packages/react/src/hooks/useMediaDeviceSelect.ts +++ b/packages/react/src/hooks/useMediaDeviceSelect.ts @@ -53,7 +53,9 @@ export function useMediaDeviceSelect({ ); const devices = useObservableState(deviceObserver, [] as MediaDeviceInfo[]); // Active device management. - const [currentDeviceId, setCurrentDeviceId] = React.useState(''); + const [currentDeviceId, setCurrentDeviceId] = React.useState( + roomContext?.getActiveDevice(kind) ?? '', + ); const { className, activeDeviceObservable, setActiveMediaDevice } = React.useMemo( () => setupDeviceSelector(kind, room ?? roomContext, track), [kind, room, roomContext, track], @@ -61,8 +63,10 @@ export function useMediaDeviceSelect({ 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();