本文介绍了在 setRemoteDescription 之后永远不会调用 onIceCandidate - webrtc - Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我遵循一些解释如何在 webrtc 中连接的流程.但我被阻止了:在我获得 sdpOffer 之后,我想调用 setRemoteDescrisption() 并且我有一个 onIceCandidate 的回调.但是我没有这个回调.如果你需要,我可以展示我的一段代码.

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.

感谢您的帮助

推荐答案

首先,我对 Android 上的 WebRTC 了解不多,但我想它会与 Web API 非常相似.我在下面的流程中使用了标准 js.

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.

onicecandidate 处理程序被调用,当您设置本地描述时参见 MDN onicecandidateevent.您需要设置本地描述以启动冰收集过程.原因之一是,收集到的候选冰将被添加到您的本地描述中,如果您没有本地描述可以将它们添加到其中,则它将不起作用.

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.

至于处理offer-answer-exchange的过程,尝试这样做(将A和B作为Peers,使用单独的RTCPeerConnection-Objects pcA和pcB),检查您的流程是否在某处有所不同:

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. 首先,您应该为 A 和 B 的传入冰候选设置处理程序,例如 signaller.on('ice',Candidate => pc.addIceCandidate(candidate))
  2. 然后您应该为 A 和 B 注册您的跟踪处理程序,例如 pcA.ontrack = track =>...(将其作为视频的 src 或其他内容)
  3. 将您的 MediaStreamTrack 添加到连接 pcA.addTrack(aTrack)

(从 A 的一侧开始...)

(Starting with A's side...)

  1. A 通过调用 offer = await pcA.createOffer()
  2. 生成报价
  3. A 将生成的报价设置为本地描述 await pcA.setLocalDescription(offer)
  4. A 通过信令通道发送生成的报价 signaller.sendTo('B','offer', offer),现在你的冰收集过程开始
  5. A 接收由 onicecandidate 处理程序生成的候选对象.pcA.oniceccandidate = e =>signaller.sendTo('B','ice', e.candidate)
  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)

(现在我们跳到 B 对事物的看法)

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

  1. B 收到报价并设置它 signaller.on('offer', async offer => { await pcB.setRemoteDescription(offer);//和下面的第 8 步到第 12 步})
  2. B 创建 sdp 答案 answer = await pcB.createAnswer()
  3. B 将答案设置为本地描述 await pcB.setLocalDescription(answer)
  4. 现在,B 的冰收集过程并行开始,应该像 7 一样处理.
  5. B 将答案发送给 A signaller.sendTo('A','answer', answer)

(回到A)

  1. A 收到答案 signaller.on('answer', async answer => await pcA.setRemoteDescription(answer); });
  2. 现在,呼叫应该完成,ice 候选交换和作为 ice state 的信令应该 stableconnected

如果这可行,请查看处理眩光,这是一个很好的来源.

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

这篇关于在 setRemoteDescription 之后永远不会调用 onIceCandidate - webrtc - Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 21:39