From 35fc0544a00c3b059cd1581b7e8ab4f9629884fd Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Tue, 8 Oct 2024 21:57:33 +0700 Subject: [PATCH] ui: do not enable speaker in calls when contact turned on video (#4998) --- apps/ios/Shared/Views/Call/ActiveCallView.swift | 6 +++--- .../chat/simplex/common/views/call/CallView.android.kt | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/ios/Shared/Views/Call/ActiveCallView.swift b/apps/ios/Shared/Views/Call/ActiveCallView.swift index ec0873a634..1f9f0739b6 100644 --- a/apps/ios/Shared/Views/Call/ActiveCallView.swift +++ b/apps/ios/Shared/Views/Call/ActiveCallView.swift @@ -434,12 +434,12 @@ struct ActiveCallOverlay: View { audioDevicePickerButton() } } - .onChange(of: call.hasVideo) { hasVideo in + .onChange(of: call.localMediaSources.hasVideo) { hasVideo in let current = AVAudioSession.sharedInstance().currentRoute.outputs.first?.portType let speakerEnabled = current == .builtInSpeaker let receiverEnabled = current == .builtInReceiver - // react automatically only when speaker or receiver were selected, otherwise keep an external device selected - if hasVideo != speakerEnabled && (speakerEnabled || receiverEnabled) { + // react automatically only when receiver were selected, otherwise keep an external device selected + if !speakerEnabled && hasVideo && receiverEnabled { client.setSpeakerEnabledAndConfigureSession(!speakerEnabled, skipExternalDevice: true) call.speakerEnabled = !speakerEnabled } diff --git a/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/views/call/CallView.android.kt b/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/views/call/CallView.android.kt index dbcd05b3c7..37bf8d1330 100644 --- a/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/views/call/CallView.android.kt +++ b/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/views/call/CallView.android.kt @@ -226,8 +226,9 @@ actual fun ActiveCallView() { ActiveCallOverlay(call, chatModel, callAudioDeviceManager) } } - KeyChangeEffect(call?.hasVideo) { - if (call != null) { + KeyChangeEffect(call?.localMediaSources?.hasVideo) { + if (call != null && call.hasVideo && callAudioDeviceManager.currentDevice.value?.type == AudioDeviceInfo.TYPE_BUILTIN_EARPIECE) { + // enabling speaker on user action (peer action ignored) and not disabling it again callAudioDeviceManager.selectLastExternalDeviceOrDefault(call.hasVideo, true) } }