In my app, I have integrated Callkit and Livekit accroding sample project here. I have a speaker toggle button in UI to let user enable/disable speaker. In button actions, I have added the following code to enable/disable speaker-
func enableSpeaker(_ enable: Bool) {
do {
try AVAudioSession.sharedInstance().overrideOutputAudioPort(enable ? .speaker : .none)
debugPrint("\(enable ? "enabled" : "disabled") speaker")
} catch {
debugPrint("failed to \(enable ? "enable" : "disable") speaker: \(error.localizedDescription)")
}
}
After this code is executed, audio input/output becomes disabled. There's no error thrown here though. How to enable speaker seamlessly keeping consistent with the callkit audio session flow in the sample project?