Skip to content

Commit 9cc0b7c

Browse files
authored
Only call onDeviceChange callback when changing to something other th… (#1172)
1 parent 287c29f commit 9cc0b7c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

.changeset/tough-flies-matter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@livekit/components-react": patch
3+
---
4+
5+
Only call onDeviceChange callback when non default device initially

packages/react/src/components/controls/MediaDeviceSelect.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const MediaDeviceSelect: (
6161
ref,
6262
) {
6363
const room = useMaybeRoomContext();
64+
const previousActiveDeviceId = React.useRef<string>('default');
6465
const handleError = React.useCallback(
6566
(e: Error) => {
6667
if (room) {
@@ -91,9 +92,10 @@ export const MediaDeviceSelect: (
9192
}, [onDeviceListChange, devices]);
9293

9394
React.useEffect(() => {
94-
if (activeDeviceId && activeDeviceId !== '') {
95+
if (activeDeviceId !== previousActiveDeviceId.current) {
9596
onActiveDeviceChange?.(activeDeviceId);
9697
}
98+
previousActiveDeviceId.current = activeDeviceId;
9799
}, [activeDeviceId]);
98100

99101
const handleActiveDeviceChange = async (deviceId: string) => {

0 commit comments

Comments
 (0)