Skip to content

Commit 1787a5a

Browse files
committed
fix(ui): ensure video error handling is working
This commit fixes some bugs that were introduced in #10.
1 parent 9045ade commit 1787a5a

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

ui/src/components/settings.tsx

+13-8
Original file line numberDiff line numberDiff line change
@@ -158,50 +158,54 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
158158
const videoDevices = [
159159
{ deviceId: "none", label: "No Video" },
160160
...devices
161-
.filter((device) => device.kind === "videoinput")
161+
.filter((device) => device.kind === "videoinput" && device.deviceId)
162162
.map((device) => ({
163163
deviceId: device.deviceId,
164164
label: device.label || `Camera ${device.deviceId.slice(0, 5)}...`,
165165
}))
166166
];
167-
168167
setVideoDevices(videoDevices);
168+
169169
// Set default to first available camera if no selection yet
170170
if (!selectedDevice && videoDevices.length > 1) {
171171
setSelectedDevice(videoDevices[1].deviceId); // Index 1 because 0 is "No Video"
172172
}
173173
} catch (err) {
174174
console.error("Failed to get video devices");
175175
// If we can't access video devices, still provide the None option
176-
const videoDevices = [{ deviceId: "none", label: "No Video" }];
177-
setVideoDevices(videoDevices);
176+
setVideoDevices([{ deviceId: "none", label: "No Video" }]);
178177
setSelectedDevice("none");
179178
}
180179
}, [selectedDevice]);
181180

181+
/**
182+
* Retrieves the list of audio devices available on the user's device.
183+
*/
182184
const getAudioDevices = useCallback(async () => {
183185
try {
184186
const devices = await navigator.mediaDevices.enumerateDevices();
185187
const audioDevices = [
186188
{ deviceId: "none", label: "No Audio" },
187189
...devices
188-
.filter((device) => device.kind === "audioinput")
190+
.filter((device) => device.kind === "audioinput" && device.deviceId)
189191
.map((device) => ({
190192
deviceId: device.deviceId,
191193
label: device.label || `Microphone ${device.deviceId.slice(0, 5)}...`,
192194
}))
193195
];
194-
195196
setAudioDevices(audioDevices);
197+
196198
// Set default to first available microphone if no selection yet
197199
if (!selectedAudioDevice && audioDevices.length > 1) {
198200
setSelectedAudioDevice(audioDevices[0].deviceId); // Default to "No Audio" for now
201+
} else {
202+
setAudioDevices([{ deviceId: "none", label: "No Audio" }]);
203+
setSelectedAudioDevice("none");
199204
}
200205
} catch (err) {
201206
console.error("Failed to get audio devices");
202207
// If we can't access audio devices, still provide the None option
203-
const audioDevices = [{ deviceId: "none", label: "No Audio" }];
204-
setAudioDevices(audioDevices);
208+
setAudioDevices([{ deviceId: "none", label: "No Audio" }]);
205209
setSelectedAudioDevice("none");
206210
}
207211
}, [selectedAudioDevice]);
@@ -346,6 +350,7 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
346350
accept=".json"
347351
multiple
348352
onChange={handlePromptsChange}
353+
required={true}
349354
/>
350355
</div>
351356

0 commit comments

Comments
 (0)