Skip to content

Commit 112e380

Browse files
authored
fix: ios callkit related audio inconsistencies (#1982)
### 💡 Overview There is a niche audio bug described below: 1. join a call with callkit. callmanager.start() 2. leave the call. callmanager.stop() 3. join the same call without callkit. callmanager.start() now the audio configuration for webrtc is not set. Mic cannot be activated. This is because callkit usage activates the audio session for webrtc. But if the next call doesnt use it, the SDK does not take care that it activates again. This is fixed in the PR ### 📝 Implementation notes We explicitly set the activation flag to false for webrtc in callmanager.stop() for consistency now. Just this change will fix it. But additionally on callmanager.start() we ensure we activate always because an integrator may have some other library that changes the audio session without stop(). failsafe. 🎫 Ticket: https://linear.app/stream/issue/RN-299
1 parent 21ab444 commit 112e380

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

packages/react-native-sdk/ios/StreamInCallManager.swift

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ class StreamInCallManager: RCTEventEmitter {
9696
if !audioManagerActivated {
9797
return
9898
}
99+
let session = RTCAudioSession.sharedInstance()
100+
session.lockForConfiguration()
101+
defer {
102+
session.unlockForConfiguration()
103+
}
104+
105+
do {
106+
try session.setActive(false)
107+
} catch {
108+
log("Error deactivating audio session: \(error.localizedDescription)")
109+
}
99110
if let prev = previousAudioSessionState {
100111
let session = AVAudioSession.sharedInstance()
101112
do {
@@ -155,32 +166,25 @@ class StreamInCallManager: RCTEventEmitter {
155166
RTCAudioSessionConfiguration.setWebRTC(rtcConfig)
156167
// END
157168

158-
// START: compare current audio session with intended, and update if different
169+
// START: activate the webrtc audio session
159170
let session = RTCAudioSession.sharedInstance()
160-
let currentCategory = session.category
161-
let currentMode = session.mode
162-
let currentOptions = session.categoryOptions
163-
let currentIsActive = session.isActive
164-
165-
if currentCategory != intendedCategory.rawValue || currentMode != intendedMode.rawValue || currentOptions != intendedOptions || !currentIsActive {
166-
session.lockForConfiguration()
171+
session.lockForConfiguration()
172+
defer {
173+
session.unlockForConfiguration()
174+
}
175+
do {
176+
try session.setCategory(intendedCategory, mode: intendedMode, options: intendedOptions)
177+
try session.setActive(true)
178+
log("configureAudioSession: setCategory success \(intendedCategory.rawValue) \(intendedMode.rawValue) \(intendedOptions.rawValue)")
179+
} catch {
180+
log("configureAudioSession: setCategory failed due to: \(error.localizedDescription)")
167181
do {
168-
try session.setCategory(intendedCategory, mode: intendedMode, options: intendedOptions)
182+
try session.setMode(intendedMode)
169183
try session.setActive(true)
170-
log("configureAudioSession: setCategory success \(intendedCategory.rawValue) \(intendedMode.rawValue) \(intendedOptions.rawValue)")
184+
log("configureAudioSession: setMode success \(intendedMode.rawValue)")
171185
} catch {
172-
log("configureAudioSession: setCategory failed due to: \(error.localizedDescription)")
173-
do {
174-
try session.setMode(intendedMode)
175-
try session.setActive(true)
176-
log("configureAudioSession: setMode success \(intendedMode.rawValue)")
177-
} catch {
178-
log("configureAudioSession: Error setting mode: \(error.localizedDescription)")
179-
}
186+
log("configureAudioSession: Error setting mode: \(error.localizedDescription)")
180187
}
181-
session.unlockForConfiguration()
182-
} else {
183-
log("configureAudioSession: no change needed")
184188
}
185189
// END
186190
}

0 commit comments

Comments
 (0)