Skip to content

Commit 5208b71

Browse files
authored
Merge pull request #13360 from daily-co/hush/dailyReactRace
fix: preserve device selection after joining call CSDK-2860
2 parents abacd15 + d4a1b39 commit 5208b71

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/DailyDevices.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,24 @@ export const DailyDevices: React.FC<React.PropsWithChildren<unknown>> = ({
9191
device: {} | MediaDeviceInfo,
9292
d: MediaDeviceInfo,
9393
prevDevices: StatefulDevice[]
94-
) => ({
95-
device: d,
96-
selected: 'deviceId' in device && d.deviceId === device.deviceId,
97-
state:
98-
prevDevices.find((p) => p.device.deviceId === d.deviceId)
99-
?.state ?? 'granted',
100-
});
94+
) => {
95+
const prevDevice = prevDevices.find(
96+
(p) => p.device.deviceId === d.deviceId
97+
);
98+
// Determine if this device is selected
99+
// First, check if getInputDevices() returned a valid deviceId
100+
const isSelectedByDeviceId =
101+
'deviceId' in device && d.deviceId === device.deviceId;
102+
// If getInputDevices() returned an empty object, preserve the previous selection
103+
const isSelectedByPrevious =
104+
!('deviceId' in device) && prevDevice?.selected;
105+
106+
return {
107+
device: d,
108+
selected: isSelectedByDeviceId || Boolean(isSelectedByPrevious),
109+
state: prevDevice?.state ?? 'granted',
110+
};
111+
};
101112
const sortDeviceByLabel = (a: StatefulDevice, b: StatefulDevice) => {
102113
if (a.device.deviceId === 'default') return -1;
103114
if (b.device.deviceId === 'default') return 1;

0 commit comments

Comments
 (0)