Skip to content

Commit 193487e

Browse files
committed
Fix to pre-built work on Android web view
1 parent 5e76649 commit 193487e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/hooks/useDevices.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ export const useDevices = () => {
5757
const micDevices = useRecoilValue(microphoneDevicesState);
5858
const speakerDevices = useRecoilValue(speakerDevicesState);
5959

60+
const createDefaultLabelIfEmpty = (
61+
devices: MediaDeviceInfo[],
62+
defaultLabel: string
63+
) => {
64+
for (let i = 0; i < devices.length; i++) {
65+
const device = devices[i];
66+
if (!device.label) {
67+
const label = `${defaultLabel} - ${i + 1}`;
68+
devices[i] = Object.assign(device, { label });
69+
}
70+
}
71+
};
72+
6073
/**
6174
* Refreshes list of available devices using enumerateDevices.
6275
* Previous device states are kept in place, otherwise states are initialized as 'granted'.
@@ -80,18 +93,25 @@ export const useDevices = () => {
8093

8194
try {
8295
const { devices } = await daily.enumerateDevices();
96+
8397
/**
8498
* Filter out "empty" devices for when device access has not been granted (yet).
8599
*/
86100
const cams = devices.filter(
87101
(d) => d.kind === 'videoinput' && d.deviceId !== ''
88102
);
103+
createDefaultLabelIfEmpty(cams, 'Camera');
104+
89105
const mics = devices.filter(
90106
(d) => d.kind === 'audioinput' && d.deviceId !== ''
91107
);
108+
createDefaultLabelIfEmpty(mics, 'Microphone');
109+
92110
const speakers = devices.filter(
93111
(d) => d.kind === 'audiooutput' && d.deviceId !== ''
94112
);
113+
createDefaultLabelIfEmpty(speakers, 'Speaker');
114+
95115
const { camera, mic, speaker } = await daily.getInputDevices();
96116

97117
const mapDevice = (

0 commit comments

Comments
 (0)