fix(voice): refresh camera capture when the device changes (#2383)

This commit is contained in:
Hampus authored and GitHub committed 2026-09-02 17:32:43 +02:00
1 parent 1772b3aad0
commit 475f5a7dae
1 file changed
+16 -4
@@ -106,7 +106,7 @@ const CAMERA_BACKGROUND_REFRESH_KEYS: Array<keyof VoiceSettingsPatch> = [
'backgroundBlurStrength', 'backgroundBlurStrength',
'mirrorCamera', 'mirrorCamera',
]; ];
const CAMERA_CAPTURE_REFRESH_KEYS: Array<keyof VoiceSettingsPatch> = ['cameraResolution']; const CAMERA_CAPTURE_REFRESH_KEYS: Array<keyof VoiceSettingsPatch> = ['cameraResolution', 'videoDeviceId'];
const SCREEN_SHARE_CODEC_REFRESH_KEYS: Array<keyof VoiceSettingsPatch> = [ const SCREEN_SHARE_CODEC_REFRESH_KEYS: Array<keyof VoiceSettingsPatch> = [
'preferredScreenShareCodec', 'preferredScreenShareCodec',
'screenShareAv1OptIn', 'screenShareAv1OptIn',
@@ -138,8 +138,19 @@ function shouldRefreshCameraBackground(settings: VoiceSettingsPatch): boolean {
return CAMERA_BACKGROUND_REFRESH_KEYS.some((key) => settings[key] !== undefined); return CAMERA_BACKGROUND_REFRESH_KEYS.some((key) => settings[key] !== undefined);
} }
function shouldRefreshCameraCapture(settings: VoiceSettingsPatch): boolean { function readCameraCaptureRefreshValues(): VoiceSettingsPatch {
return CAMERA_CAPTURE_REFRESH_KEYS.some((key) => settings[key] !== undefined); return {
cameraResolution: VoiceSettings.cameraResolution,
videoDeviceId: VoiceSettings.videoDeviceId,
};
}
function shouldRefreshCameraCapture(
settings: VoiceSettingsPatch,
before: VoiceSettingsPatch,
after: VoiceSettingsPatch,
): boolean {
return CAMERA_CAPTURE_REFRESH_KEYS.some((key) => settings[key] !== undefined && before[key] !== after[key]);
} }
function shouldRefreshScreenShareCodecNegotiation(settings: VoiceSettingsPatch): boolean { function shouldRefreshScreenShareCodecNegotiation(settings: VoiceSettingsPatch): boolean {
@@ -155,6 +166,7 @@ function applyUpdatedVoiceSettings(
refreshInput: boolean, refreshInput: boolean,
options: VoiceSettingsUpdateOptions = {}, options: VoiceSettingsUpdateOptions = {},
): void { ): void {
const cameraCaptureBefore = readCameraCaptureRefreshValues();
VoiceSettings.updateSettings(settings); VoiceSettings.updateSettings(settings);
if (settings.muteStreamAudio !== undefined) { if (settings.muteStreamAudio !== undefined) {
MediaEngine.setScreenShareAudioMuted(settings.muteStreamAudio); MediaEngine.setScreenShareAudioMuted(settings.muteStreamAudio);
@@ -180,7 +192,7 @@ function applyUpdatedVoiceSettings(
if (options.refreshCameraBackground !== false && shouldRefreshCameraBackground(settings)) { if (options.refreshCameraBackground !== false && shouldRefreshCameraBackground(settings)) {
refreshCameraBackground(); refreshCameraBackground();
} }
if (shouldRefreshCameraCapture(settings)) { if (shouldRefreshCameraCapture(settings, cameraCaptureBefore, readCameraCaptureRefreshValues())) {
refreshCameraCapture(); refreshCameraCapture();
} }
if (shouldRefreshScreenShareCodecNegotiation(settings)) { if (shouldRefreshScreenShareCodecNegotiation(settings)) {