react-native-webrtc / react-native-incall-manager

Handling media-routes/sensors/events during a audio/video chat on React Native
ISC License
555 stars 193 forks source link

[IOS] Audio sometimes doesn't work when used with WebRTC connection #152

Open kjhyun824 opened 3 years ago

kjhyun824 commented 3 years ago

HI.

I'm building an app and have some issue. Here is my scenario.

// Establish WebRTC Connection
InCallManager.start({ media: 'video', auto: true });
// Communicate through RTC Connection

// After all communications done
InCallManager.stop();

// Re-establish WebRTC Connection 
InCallManager.start({ media: 'video', auto: true });

Here is problem. When I re-establish the connection and start InCallManager again, the Audio doesn't works at all, i.e. Mic input and Speaker output.

My assumption is due to IOS AVAudioSession, because WebRTC assumes that it's the only one controls AVAudioSession which is implemented as a singleton.

Am I right? and how can I fix it? (or do you have any plan for fixing it?)

React-Native-IncallManager Version : v3.3.0 libWebRTC : M84

tgreco commented 3 years ago

I'm not 100% sure what solved it for me but what I did was got got it working with video and audio on. I included onicecandidate handlers to handle those messages as I was missing those before. Then once it was all perfect I removed the video parameter and it is still working great.

tgreco commented 3 years ago

So I take back what I said, this only works if I am on the same WiFi for some reason.

kjhyun824 commented 3 years ago

@tgreco What did you handled on onicecandidate function? (i.e. which one was missing?) I also have tested on the same WIFI but it doesn't work for me... T.T

tgreco commented 3 years ago

@kjhyun824

When the ICE candidates are received I use websockets to so send them over to the other user.

onIceCandidate(evt)
  {
    console.log('On Ice Candidate', evt.candidate);
    if(evt.candidate !== null)
    {
      WebsocketClient.GetInstance().sendIceCandidate(evt.candidate, WebRtcClient.#instance.#partnerUserId.toString());
    }
  }

Then when the websocket message is received on the other client side:

peerConnection.addIceCandidate(new RTCIceCandidate(candidate));

jsellam commented 3 years ago

I have the same issue. When I start a second call after close the first, I don't have sound...

flhember commented 3 years ago

Same, only on ios, android works perfectly, if you have a solution share it here :)

kjhyun824 commented 3 years ago

@tgreco Sorry for my late reply. In my case, I use Open WebRTC Toolkit(a.k.a. OWT) which offers WebRTC gateway and SDKs for implementing client-side application. And in the Client-side SDK, I have found the implementation that you have mentioned above. Moreover, if the ice connection was a problem, the Android should not work too, but it works... :(

I think it's known issue for them, cause they mentioned on the TODO as "Fix iOS audio shared instance singleton conflict with internal webrtc." We should wait until they handle it TT

josefha commented 3 years ago

@jsellam we have exactly this problem as well, anyone has an update on solutions/workarounds?

kkureli commented 3 years ago

I have the same issue. When I start a second call after close the first, I don't have sound...

hi, could you solve it?

sagark1510 commented 3 years ago

@zxcpoiu any help on this? I'm also facing the same issue. And due to the same reason I can not call stop method at the moment.

kiprijonas commented 3 years ago

I solved it by manually managing RTCAudioSession. You can see a solution here: https://stackoverflow.com/a/55781328

flhember commented 2 years ago

Hi @kiprijonas , if you can give us more information on how to apply this solution please, thank you!

moigamijunior commented 2 years ago

Same problem. In my case, it does not work in any call. The microphone and video do, but the audio does not. In Android, it works perfectly. Some news? @saghul

ssimoe50 commented 1 year ago

I solved it by manually managing RTCAudioSession. You can see a solution here: https://stackoverflow.com/a/55781328

Hi @kiprijonas, I saw your comment, and also your solution, but I cannot seem to link both the situations together. Can you share some snippet please? which files you changed for example?

Thanks in advance!