Add audio track to existing stream/connection

Hi all,

I am working on a mobile app that uses React Native WebRTC (this particular issue is focused on iOS). There is a use case in the app where, while a WebRTC session is in progress, I need to temporarily take the microphone input away from WebRTC for another feature. Currently, when I go back to the WebRTC session after doing this, audio from the microphone is no longer heard on the other end of the connection. This makes sense, as the audio track was taken away. I’d like to readd the microphone without interrupting the rest of the connection (receiving audio and video, sending video). Is there a way to do this?

I think removing the track and create ing a new offer with offerToReceiveAudio set to true should work.

Then when you want the audio back, add the track again, and renegotiate.

Thanks for the response, @sagul! Would there be anyway to readd the audio track without a full renegotiation? Was hoping to not interrupt the rest of the WebRTC connection.

I don’t think so. Doing an O/A cycle shouldn’t disrupt your existing WebRTC connection, as it’s not re-established.

On that point, from my understanding so far… the latest addtracks functionality isn’t supported. https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addTrack

Instead still using the addstream functionality https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addStream

Can you speak at all about plans to support MediaStreamTrack or something similar that doesn’t require re-negotiation? I’d love to switch over the example project that I posted about to using tracks since addstream is deprecated on web.

Sorry if I’m very misinformed about what is/isn’t supported already

We will most likely skip the track APIs and go directly to transceivers. No ETA for that though.

There is an API replaceTrack but I could not find it in RNWebRTC, is this something that could be added? It sounds like this would solve this issue.

That function is part of the sensers API which is a prerequisite for transceivers. So yeah, we should be able to have it. When? I don’t know.