diff --git a/README.md b/README.md index 8c02cdd4b..8a2f6f88b 100644 --- a/README.md +++ b/README.md @@ -176,29 +176,39 @@ For more audio related information see the [Audio guide](./Docs/audio.md). ### Integration with CallKit -To integrate with CallKit for background-triggered incoming calls, LiveKit's audio session must be synchronized with CallKit's audio session: +When integrating with CallKit, proper timing and coordination between `AVAudioSession` and the SDK’s audio engine is crucial. -1. Add `import LiveKitWebRTC` to your CallProvider file. -2. In your `CXProviderDelegate` implementation, add the following: +1. Disable the SDK’s automatic `AVAudioSession` configuration. also prevent the audio engine from starting outside CallKit’s `didActivate` and `didDeactivate` window. ```swift -func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession){ - LKRTCAudioSession.sharedInstance().audioSessionDidActivate(audioSession) - // ... -} -func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) { - LKRTCAudioSession.sharedInstance().audioSessionDidDeactivate(audioSession) - // ... -} +// As early as possible, before connecting to a Room. +AudioManager.shared.audioSession.isAutomaticConfigurationEnabled = false +try AudioManager.shared.setEngineAvailability(.none) ``` -You would also want to turn off automatic `AVAudioSession` configuration. +2. Coordinate audio engine availability with CallKit in your `CXProviderDelegate` implementation: ```swift -AudioManager.shared.audioSession.isAutomaticConfigurationEnabled = false +func provider(_: CXProvider, didActivate session: AVAudioSession) { + do { + try session.setCategory(.playAndRecord, mode: .voiceChat, options: [.mixWithOthers]) + try AudioManager.shared.setEngineAvailability(.default) + } catch { + // Error + } +} + +func provider(_: CXProvider, didDeactivate _: AVAudioSession) { + do { + try AudioManager.shared.setEngineAvailability(.none) + } catch { + // Error + } +} ``` -For more audio related information see the [Audio guide](./Docs/audio.md). +* See our [CallKit example](https://github.com/livekit-examples/swift-example-collection/tree/main/callkit) for full details. +* For additional audio-related information, see the [Audio guide](./Docs/audio.md). ### iOS Simulator limitations