Revert "Native calls: upgrade to LiveKit 2.15 + add CallKit audio-session coordination"
This reverts commit 455d16abcc.
This commit is contained in:
@@ -54,21 +54,16 @@ public class NativeCallPlugin: CAPPlugin, CAPBridgedPlugin, PKPushRegistryDelega
|
||||
registry.delegate = self
|
||||
registry.desiredPushTypes = [.voIP]
|
||||
pushRegistry = registry
|
||||
// CallKit audio coordination (needs LiveKit 2.15+, pinned in NativeCall.podspec). LiveKit's automatic
|
||||
// AVAudioSession configuration RACES CallKit's own activation → intermittent dead mic / no audio + the
|
||||
// output route only settling once audio flows ("speaker turns on late"). Fix: turn auto-config OFF and
|
||||
// keep the audio engine OFF; we configure the session and enable the engine ONLY in didActivate.
|
||||
AudioManager.shared.audioSession.isAutomaticConfigurationEnabled = false
|
||||
try? AudioManager.shared.setEngineAvailability(.none)
|
||||
// NOTE: the CallKit↔LiveKit audio-session coordination (AudioManager.audioSession /
|
||||
// setEngineAvailability) needs LiveKit 2.15+, but the build currently resolves an older 2.x that lacks
|
||||
// those symbols. So we rely on LiveKit's default audio handling for now and only configure the session
|
||||
// with plain AVFoundation in didActivate. Revisit once the pod is pinned/upgraded to 2.15+.
|
||||
}
|
||||
|
||||
// MARK: - LiveKit media
|
||||
|
||||
private func connectRoom(url: String, token: String) {
|
||||
guard !url.isEmpty, !token.isEmpty else { return }
|
||||
// Ask for mic permission now (we still connect MUTED). If it stays "undetermined", enabling the audio
|
||||
// engine in didActivate can block on first use — determining it up front avoids that.
|
||||
AVAudioSession.sharedInstance().requestRecordPermission { _ in }
|
||||
let old = room
|
||||
let r = Room()
|
||||
room = r
|
||||
@@ -290,20 +285,12 @@ public class NativeCallPlugin: CAPPlugin, CAPBridgedPlugin, PKPushRegistryDelega
|
||||
action.fulfill()
|
||||
}
|
||||
|
||||
// CallKit owns the AVAudioSession lifecycle. Since LiveKit auto-config is OFF, configure the session HERE —
|
||||
// when CallKit activates it — and enable LiveKit's audio engine. This is the fix for the intermittent
|
||||
// dead mic / no-audio and late speaker routing. Don't call setActive(true): CallKit already activated it.
|
||||
// Keep the last known-good audio behavior (rely on LiveKit's default session handling). We only report the
|
||||
// state to JS. The proper CallKit↔LiveKit session coordination is deferred until the pod is on 2.15+.
|
||||
public func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
|
||||
do {
|
||||
try audioSession.setCategory(.playAndRecord, mode: .voiceChat, options: [.mixWithOthers])
|
||||
try AudioManager.shared.setEngineAvailability(.default)
|
||||
notifyListeners("audioActivated", data: ["ok": true])
|
||||
} catch {
|
||||
notifyListeners("audioActivated", data: ["ok": false, "error": String(describing: error)])
|
||||
}
|
||||
notifyListeners("audioActivated", data: ["ok": true])
|
||||
}
|
||||
public func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
|
||||
try? AudioManager.shared.setEngineAvailability(.none) // keep the engine off until the next call activates
|
||||
notifyListeners("audioDeactivated", data: ["ok": true])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user