Skip to content

Commit 5f40fb5

Browse files
committed
fix(ui): ensure video error handling is working
This commit fixes some bugs that were introduced in yondonfu#10.
1 parent 4fbe1c9 commit 5f40fb5

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
@@ -159,14 +159,14 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
159159
const videoDevices = [
160160
{ deviceId: "none", label: "No Video" },
161161
...devices
162-
.filter((device) => device.kind === "videoinput")
162+
.filter((device) => device.kind === "videoinput" && device.deviceId)
163163
.map((device) => ({
164164
deviceId: device.deviceId,
165165
label: device.label || `Camera ${device.deviceId.slice(0, 5)}...`,
166166
}))
167167
];
168-
169168
setVideoDevices(videoDevices);
169+
170170
// Set default to first available camera if no selection yet
171171
if (!selectedDevice && videoDevices.length > 1) {
172172
setSelectedDevice(videoDevices[1].deviceId); // Index 1 because 0 is "No Video"
@@ -178,29 +178,34 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
178178
});
179179

180180
// If we can't access video devices, still provide the None option
181-
const videoDevices = [{ deviceId: "none", label: "No Video" }];
182-
setVideoDevices(videoDevices);
181+
setVideoDevices([{ deviceId: "none", label: "No Video" }]);
183182
setSelectedDevice("none");
184183
}
185184
}, [selectedDevice]);
186185

186+
/**
187+
* Retrieves the list of audio devices available on the user's device.
188+
*/
187189
const getAudioDevices = useCallback(async () => {
188190
try {
189191
const devices = await navigator.mediaDevices.enumerateDevices();
190192
const audioDevices = [
191193
{ deviceId: "none", label: "No Audio" },
192194
...devices
193-
.filter((device) => device.kind === "audioinput")
195+
.filter((device) => device.kind === "audioinput" && device.deviceId)
194196
.map((device) => ({
195197
deviceId: device.deviceId,
196198
label: device.label || `Microphone ${device.deviceId.slice(0, 5)}...`,
197199
}))
198200
];
199-
200201
setAudioDevices(audioDevices);
202+
201203
// Set default to first available microphone if no selection yet
202204
if (!selectedAudioDevice && audioDevices.length > 1) {
203205
setSelectedAudioDevice(audioDevices[0].deviceId); // Default to "No Audio" for now
206+
} else {
207+
setAudioDevices([{ deviceId: "none", label: "No Audio" }]);
208+
setSelectedAudioDevice("none");
204209
}
205210
} catch (error) {
206211
console.error("Failed to get audio devices: ", error);
@@ -209,8 +214,7 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
209214
});
210215

211216
// If we can't access audio devices, still provide the None option
212-
const audioDevices = [{ deviceId: "none", label: "No Audio" }];
213-
setAudioDevices(audioDevices);
217+
setAudioDevices([{ deviceId: "none", label: "No Audio" }]);
214218
setSelectedAudioDevice("none");
215219
}
216220
}, [selectedAudioDevice]);
@@ -358,6 +362,7 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
358362
accept=".json"
359363
multiple
360364
onChange={handlePromptsChange}
365+
required={true}
361366
/>
362367
</div>
363368

0 commit comments

Comments
 (0)