I have an audio streaming app based on WebRTC, so there are rooms with speakers and listeners. Those listeners can be moved to be speakers, or speakers could be moved to be listeners.
Now, iOS 14 has this orange indicator when microphone is in use and it's enabled for both listeners and speakers, but should be only for speakers.
I can take control over it by setting AVAudioSession category in a way that if user is a speaker, I set .playAndRecord, and if user is only listener I set .playback.
The problem is, when listener gets upgraded to be a speaker I need that record category, so I try to change category from .playback to .playAndRecord and everything gets changed successfully, but it doesn't work.
So:
If I join the stream as speaker .playAndRecord works fine. Mic works and there is the orange indicator.
If I join the stream as listener .playback works fine. Mic doesn't work and there is no orange indicator.
If I join the stream as listener and get upgraded to speaker mic doesn't work and there is no orange indicator, but it should work.
Also if I join the stream as speaker and get downgraded to listener, it doesn't work.
I'm using this method for configuring it:
func configureAudioSession(clientMode: ClientMode) {
let audioConfiguration = RTCAudioSessionConfiguration()
audioConfiguration.category = clientMode == .listener ?
AVAudioSession.Category.playback.rawValue : AVAudioSession.Category.playAndRecord.rawValue
audioConfiguration.mode = clientMode == .listener ?
AVAudioSession.Mode.moviePlayback.rawValue : AVAudioSession.Mode.voiceChat.rawValue
audioConfiguration.categoryOptions = AVAudioSession.CategoryOptions(rawValue: AVAudioSession.CategoryOptions.mixWithOthers.rawValue)
self.rtcAudioSession.lockForConfiguration()
do {
try self.rtcAudioSession.setConfiguration(audioConfiguration, active: true)
} catch let error {
self.errorHandler.onNext(error)
}
self.rtcAudioSession.unlockForConfiguration()
}
rtcAudioSession is just:
let rtcAudioSession = RTCAudioSession.sharedInstance()
But behind it is ofc iOS AVAudioSession object.