Skip to content

Commit ee8bb72

Browse files
authored
Update CallKit doc (#854)
1 parent a927415 commit ee8bb72

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

README.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,29 +176,39 @@ For more audio related information see the [Audio guide](./Docs/audio.md).
176176

177177
### Integration with CallKit
178178

179-
To integrate with CallKit for background-triggered incoming calls, LiveKit's audio session must be synchronized with CallKit's audio session:
179+
When integrating with CallKit, proper timing and coordination between `AVAudioSession` and the SDK’s audio engine is crucial.
180180

181-
1. Add `import LiveKitWebRTC` to your CallProvider file.
182-
2. In your `CXProviderDelegate` implementation, add the following:
181+
1. Disable the SDK’s automatic `AVAudioSession` configuration. also prevent the audio engine from starting outside CallKit’s `didActivate` and `didDeactivate` window.
183182

184183
```swift
185-
func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession){
186-
LKRTCAudioSession.sharedInstance().audioSessionDidActivate(audioSession)
187-
// ...
188-
}
189-
func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
190-
LKRTCAudioSession.sharedInstance().audioSessionDidDeactivate(audioSession)
191-
// ...
192-
}
184+
// As early as possible, before connecting to a Room.
185+
AudioManager.shared.audioSession.isAutomaticConfigurationEnabled = false
186+
try AudioManager.shared.setEngineAvailability(.none)
193187
```
194188

195-
You would also want to turn off automatic `AVAudioSession` configuration.
189+
2. Coordinate audio engine availability with CallKit in your `CXProviderDelegate` implementation:
196190

197191
```swift
198-
AudioManager.shared.audioSession.isAutomaticConfigurationEnabled = false
192+
func provider(_: CXProvider, didActivate session: AVAudioSession) {
193+
do {
194+
try session.setCategory(.playAndRecord, mode: .voiceChat, options: [.mixWithOthers])
195+
try AudioManager.shared.setEngineAvailability(.default)
196+
} catch {
197+
// Error
198+
}
199+
}
200+
201+
func provider(_: CXProvider, didDeactivate _: AVAudioSession) {
202+
do {
203+
try AudioManager.shared.setEngineAvailability(.none)
204+
} catch {
205+
// Error
206+
}
207+
}
199208
```
200209

201-
For more audio related information see the [Audio guide](./Docs/audio.md).
210+
* See our [CallKit example](https://github.com/livekit-examples/swift-example-collection/tree/main/callkit) for full details.
211+
* For additional audio-related information, see the [Audio guide](./Docs/audio.md).
202212

203213
### iOS Simulator limitations
204214

0 commit comments

Comments
 (0)