onIceCandidate is never call after setRemoteDescription - webrtc - Android

对着背影说爱祢 提交于 2021-01-29 13:00:45

问题


I follow some flow who explain how to connect in webrtc. But I m blocked : After I get the sdpOffer, I suppose to call setRemoteDescrisption() and I have a callback of onIceCandidate. But I don't have this callback. I can show piece of my code if you need it.

Thanks for helping


回答1:


First things first, I do not know much about WebRTC on Android, but I imagine that it will be very similar to the web API. I used the standard js in my flow below.

Regarding the onicecandidate-trigger:

the onicecandidate handler is called, when you set your local description, see MDN onicecandidateevent. You need to set a local description to start the ice gathering process. One of the reasons is, that the gathered ice candidates will be added to your local description and if you have no local description to add them to, it wouldn't work.

Regarding your flow (maybe to check):

As for the process of handling the offer-answer-exchange, try doing it like this (take A and B as Peers with seperate RTCPeerConnection-Objects pcA and pcB), check if your flow differs somewhere:

  1. First, you should set up a handler for incoming ice candidates for A and B, like signaller.on('ice', candidate => pc.addIceCandidate(candidate))
  2. Then you should register your track handlers for A and B, like pcA.ontrack = track => ... (put it as src of your video or whatever)
  3. add your MediaStreamTracks to the connections pcA.addTrack(aTrack)

(Starting with A's side...)

  1. A generates an offer by calling offer = await pcA.createOffer()
  2. A sets the generated offer as local description await pcA.setLocalDescription(offer)
  3. A sends the generated offer over the signalling channel signaller.sendTo('B','offer', offer), now your ice gathering process starts
  4. A receives generated candidates by the onicecandidate-handler. pcA.onicecandidate = e => signaller.sendTo('B','ice', e.candidate)

(Now we jump to B's view of the things)

  1. B receives the offer and sets it signaller.on('offer', async offer => { await pcB.setRemoteDescription(offer); // and the following steps 8 to 12 follow here })
  2. B creates an sdp answer answer = await pcB.createAnswer()
  3. B sets the answer as local description await pcB.setLocalDescription(answer)
  4. Now, B's ice gathering process starts in parallel and should be handled like in 7.
  5. B sends the answer to A signaller.sendTo('A','answer', answer)

(Back to A)

  1. A receives the answer signaller.on('answer', async answer => await pcA.setRemoteDescription(answer); });
  2. Now, the call should be complete, ice candidates exchange and the signaling as ice state should be stable or connected

If this works, have a look at handling glare, this is a good source.



来源:https://stackoverflow.com/questions/58429603/onicecandidate-is-never-call-after-setremotedescription-webrtc-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!