From 1e45f7d58c83e640ef7df8b9982cfe99e9a7d50b Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Tue, 22 Mar 2022 18:00:53 +0100 Subject: [PATCH] Prevent crash when toggling speaker out of call --- Classes/Swift/Voip/AudioRouteUtils.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Classes/Swift/Voip/AudioRouteUtils.swift b/Classes/Swift/Voip/AudioRouteUtils.swift index 91944d7e9..4f0158ad7 100644 --- a/Classes/Swift/Voip/AudioRouteUtils.swift +++ b/Classes/Swift/Voip/AudioRouteUtils.swift @@ -90,16 +90,16 @@ import linphonesw } static private func routeAudioTo( call: Call?, types: [AudioDeviceType]) { - let currentCall = call != nil ? call : core.currentCall != nil ? core.currentCall : core.calls[0] - if (call != nil || currentCall != nil) { - let callToUse = call != nil ? call : currentCall - applyAudioRouteChange(call: callToUse, types: types) - changeCaptureDeviceToMatchAudioRoute(call: callToUse, types: types) - } else { - applyAudioRouteChange(call: call, types: types) - changeCaptureDeviceToMatchAudioRoute(call: call, types: types) - } + let currentCall = call != nil ? call : core.currentCall != nil ? core.currentCall : (core.callsNb > 0 ? core.calls[0] : nil) + if (call != nil || currentCall != nil) { + let callToUse = call != nil ? call : currentCall + applyAudioRouteChange(call: callToUse, types: types) + changeCaptureDeviceToMatchAudioRoute(call: callToUse, types: types) + } else { + applyAudioRouteChange(call: call, types: types) + changeCaptureDeviceToMatchAudioRoute(call: call, types: types) } + } static func routeAudioToEarpiece(call: Call? = nil) { routeAudioTo(call: call, types: [AudioDeviceType.Microphone]) // on iOS Earpiece = Microphone