Skip to content

Commit 9af8f73

Browse files
🐛 fix: ensure camera source is checked before stream capture in Recorder
Refactors the camera stream capture logic to first check if a camera source is selected. This avoids unnecessary attempts to capture a camera stream when no camera source is selected, leading to a more efficient and error-free user experience. - Adds a condition to verify the existence of a camera source before attempting to capture the camera stream. - Ensures the application only attempts to capture from the camera when a valid camera source is provided, preventing potential errors or unexpected behaviors in the absence of a camera source.
1 parent 154dfa7 commit 9af8f73

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

apps/desktop/src/components/Recorder.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,20 @@ export function Recorder({
244244
setAudioStream(audioStream);
245245

246246
// Capture the camera stream
247-
const cameraStream = await navigator.mediaDevices.getUserMedia({
248-
video: {
249-
deviceId: cameraSource?.deviceId,
250-
width: 240,
251-
height: 180,
252-
aspectRatio: 1,
253-
facingMode: "user",
254-
frameRate: 60,
255-
},
256-
audio: false,
257-
});
258-
setCameraStream(cameraStream);
247+
if (cameraSource) {
248+
const cameraStream = await navigator.mediaDevices.getUserMedia({
249+
video: {
250+
deviceId: cameraSource?.deviceId,
251+
width: 240,
252+
height: 180,
253+
aspectRatio: 1,
254+
facingMode: "user",
255+
frameRate: 60,
256+
},
257+
audio: false,
258+
});
259+
setCameraStream(cameraStream);
260+
}
259261

260262
const combinedStream = new MediaStream([
261263
screenStream.getVideoTracks()[0],
@@ -274,7 +276,11 @@ export function Recorder({
274276
videoRef.current.srcObject = screenStream;
275277

276278
// Entire screen and a camera is selected
277-
if (selectedSource.sourceType === "window" && cameraSource) {
279+
if (
280+
selectedSource.sourceType === "window" &&
281+
cameraSource &&
282+
cameraStream
283+
) {
278284
const cameraRecorder = new MediaRecorder(cameraStream, {
279285
mimeType: "video/webm; codecs=vp9,opus",
280286
});

0 commit comments

Comments
 (0)