Skip to content

Commit f2f3077

Browse files
🔊 fix: conditionally capture audio stream based on audioSource existence
Refines audio capture logic by ensuring an audio source is selected before attempting to capture the audio stream. This change enhances application stability by preventing unnecessary errors and aligns with best practices for media stream handling. - Ensures audio capture attempts are made only when an explicit audio source is provided, thereby avoiding potential issues in scenarios where no audio source is selected. - Improves user experience by eliminating the possibility of encountering errors related to audio capture when no audio source is selected, ensuring the application behaves predictably and efficiently under all conditions.
1 parent 9af8f73 commit f2f3077

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

‎apps/desktop/src/components/Recorder.tsx‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,16 @@ export function Recorder({
234234
});
235235
setScreenStream(screenStream);
236236

237-
const audioStream = await navigator.mediaDevices.getUserMedia({
238-
audio: {
239-
deviceId: audioSource?.deviceId,
240-
echoCancellation: true,
241-
noiseSuppression: true,
242-
},
243-
});
244-
setAudioStream(audioStream);
237+
if (audioSource) {
238+
const audioStream = await navigator.mediaDevices.getUserMedia({
239+
audio: {
240+
deviceId: audioSource?.deviceId,
241+
echoCancellation: true,
242+
noiseSuppression: true,
243+
},
244+
});
245+
setAudioStream(audioStream);
246+
}
245247

246248
// Capture the camera stream
247249
if (cameraSource) {
@@ -262,7 +264,7 @@ export function Recorder({
262264
const combinedStream = new MediaStream([
263265
screenStream.getVideoTracks()[0],
264266
]);
265-
if (audioSource) {
267+
if (audioSource && audioStream) {
266268
combinedStream.addTrack(audioStream.getAudioTracks()[0]);
267269
}
268270

0 commit comments

Comments
 (0)