I'm trying to make callkit work with webrtc on incoming call, but when I receive call and accept it from locked screen there are no sound untill I run the app in the foreground mode. I've configured audiosession send notification to RTCAudioSession, but it doesn't work. Do you have some workarounds?
func configureAudioSession() {
let sharedSession = AVAudioSession.sharedInstance()
do {
try sharedSession.setCategory(AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeVideoChat, options: .mixWithOthers)
try sharedSession.setMode(AVAudioSessionModeVideoChat)
// try sharedSession.setAggregatedIOPreference(AVAudioSessionIOType.aggregated)
} catch {
debugPrint("Failed to configure `AVAudioSession`")
}
}
func handleIncomingCall(spaceName:String) {
if callUUID != nil {
oldCallUUID = callUUID
}
callUUID = UUID()
print("CallManager handle uuid = \(callUUID?.description)")
let update = CXCallUpdate()
update.hasVideo = true
update.remoteHandle = CXHandle(type: .generic, value: spaceName)
self.configureAudioSession()
provider?.reportNewIncomingCall(with: callUUID!, update: update, completion: { error in
print("CallManager report new incoming call completion")
})
}
func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
print("CallManager didActivate")
RTCAudioSession.sharedInstance().audioSessionDidActivate(audioSession)
RTCAudioSession.sharedInstance().isAudioEnabled = true
self.callDelegate?.callIsAnswered()
}
func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
print("CallManager didDeactivate")
RTCAudioSession.sharedInstance().audioSessionDidDeactivate(audioSession)
RTCAudioSession.sharedInstance().isAudioEnabled = false
}
Okay, I've found what the cause of an issue. In IOS 12 there is a problem with webrtc, when you start webrtc from locked screen and trying to get access to camera - the output volume breaks, so the solution is to check if the screen is Active or not, and if not - do not request and add local RTCVideoTrack into your RTCStream.