We are using WebRTC M110 with iOS 16.5 for an audio call application and would like to allow our users to mute their audio such that the orange indicator provided by the operating system disappears. We have not found a solution that works.
We initialize the audio session like this
RTCAudioSession.sharedInstance().useManualAudio = true
RTCAudioSession.sharedInstance().lockForConfiguration()
try! RTCAudioSession.sharedInstance().setCategory(
AVAudioSession.Category.playAndRecord.rawValue,
with: []
)
try! RTCAudioSession.sharedInstance().setMode(AVAudioSession.Mode.voiceChat.rawValue)
try! RTCAudioSession.sharedInstance().setActive(true)
RTCAudioSession.sharedInstance().unlockForConfiguration()
RTCAudioSession.sharedInstance().isAudioEnabled = true
In order to mute and unmute our audio stream we set isEnabled
to the current mute state as set by the user
peerConnection.transceivers.compactMap { $0.sender.track as? RTCAudioTrack }
.forEach { $0.isEnabled = isEnabled }
This seems to be the general solution to this problem and is for example described on StackOverflow [1] [2] and is used in example projects where it also doesn't work. After this no more audio is being sent but the orange microphone indicator is still being shown. This is not standard in other apps such as Signal and we would like to have the orange microphone indicator not be shown as well. How do we achieve that?
Additionally we have tried the following:
We have tried to change the audio session and set the category to
AVAudioSession.Category.playAndRecord.rawValue
when disabling the audio track. However this doesn't work and AVAudioSession throws errors unless we do it before enabling the audio session. Disabling and subsequently enabling the audio session withRTCAudioSession.sharedInstance().isAudioEnabled = false
does not work either.We had a look at Signals RingRTC and it looks like they are doing just the same and are simply setting
isEnabled
to false when muting the call (github.com/signalapp/ringrtc/). However with their implementation the orange microphone indicator disappears almost instantly.We have tried to remove the tracks directly on the peer connection. But that doesn't change anything either.