#3372 - Stop setting up CallKit sessions when joining calls

- comes following the discussions on https://developer.apple.com/forums//thread/767949?answerId=812951022#812951022
- this removes the lock screen controls entirely and lets the rest of the app behave normally
This commit is contained in:
Stefan Ceriu 2024-11-07 16:57:17 +02:00
parent 4e880f1924
commit c42ef40aa4

View File

@ -99,26 +99,18 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
incomingCallID = nil incomingCallID = nil
ongoingCallID = callID ongoingCallID = callID
let handle = CXHandle(type: .generic, value: roomDisplayName) // Don't bother starting another CallKit session as it won't work properly
let startCallAction = CXStartCallAction(call: callID.callKitID, handle: handle) // https://developer.apple.com/forums//thread/767949?answerId=812951022#812951022
startCallAction.isVideo = true
do { // let handle = CXHandle(type: .generic, value: roomDisplayName)
try await callController.request(CXTransaction(action: startCallAction)) // let startCallAction = CXStartCallAction(call: callID.callKitID, handle: handle)
} catch { // startCallAction.isVideo = true
MXLog.error("Failed requesting start call action with error: \(error)")
}
do { // do {
// Have ElementCall default to the speaker so that the lock button doesn't end the call. // try await callController.request(CXTransaction(action: startCallAction))
// Could also use `overrideOutputAudioPort` but the documentation is clear about it: // } catch {
// `Sessions using PlayAndRecord category that always want to prefer the built-in // MXLog.error("Failed requesting start call action with error: \(error)")
// 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() { func tearDownCallSession() {
@ -222,6 +214,8 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
// Reporting the call as ended imediately after answering it works around that // Reporting the call as ended imediately after answering it works around that
// as EC gets access to media again and EX builds the right UI in `setupCallSession` // as EC gets access to media again and EX builds the right UI in `setupCallSession`
// //
// https://developer.apple.com/forums//thread/767949?answerId=812951022#812951022
//
// https://github.com/element-hq/element-x-ios/issues/3041 // https://github.com/element-hq/element-x-ios/issues/3041
// https://forums.developer.apple.com/forums/thread/685268 // https://forums.developer.apple.com/forums/thread/685268
// https://stackoverflow.com/questions/71483732/webrtc-running-from-wkwebview-avaudiosession-development-roadblock // https://stackoverflow.com/questions/71483732/webrtc-running-from-wkwebview-avaudiosession-development-roadblock