From 69ce39bbc3a6463f17cd89e0b6e1606d4f82e324 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Fri, 27 Sep 2024 09:58:27 +0300 Subject: [PATCH] Have ElementCall always default to the speaker; prevent the lock button from ending the call - previously handled in 81d669e5cef3b260fb7563e6bdeea21192030d4a - seems the default behavior changed and we now need to manually configure the AudioSession --- .../Services/ElementCall/ElementCallService.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ElementX/Sources/Services/ElementCall/ElementCallService.swift b/ElementX/Sources/Services/ElementCall/ElementCallService.swift index 980e9b5f3..9555d62e8 100644 --- a/ElementX/Sources/Services/ElementCall/ElementCallService.swift +++ b/ElementX/Sources/Services/ElementCall/ElementCallService.swift @@ -103,6 +103,17 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe } catch { MXLog.error("Failed requesting start call action with error: \(error)") } + + do { + // Have ElementCall default to the speaker so that the lock button doesn't end the call. + // Could also use `overrideOutputAudioPort` but the documentation is clear about it: + // `Sessions using PlayAndRecord category that always want to prefer the built-in + // speaker output over the receiver, should use AVAudioSessionCategoryOptionDefaultToSpeaker instead.`. + try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .videoChat, options: [.defaultToSpeaker]) + try AVAudioSession.sharedInstance().setActive(true, options: .notifyOthersOnDeactivation) + } catch { + MXLog.error("Failed setting up audio session with error: \(error)") + } } func tearDownCallSession() {