不知道这个例子对不对
过程,调用new RTCPeerConnection()
然后调用createOffer()
然后调用setLocalDescription()
然后我等待 onicecandidate
获取它提供的内容,首先发送 offer
,然后通过 signal server
发送 icecandidates
给另一个同行
然后另一个节点将接收到的offer
放入setRemoteDescription(offer)
,然后将接收到的icecandidates
放入addIceCandidate(icecandidates)
然后调用 createAnswer()
这会给出一个 answer
放入 setLocalDescription(answer)
这会触发 onicecandidate
将这些 icecandidates
与 answer
=offer
一起发送给其他同行
另一个节点将 answer
放入 setRemoteDescription(answer)
然后将接收到的 icecandidates
放入 addIceCandidate(icecandidates)
我认为在这个例子中,连接在本地网络内部测试时可以工作,但如果因为它不是本地网络而不能工作怎么办,在这个例子中,API 将在哪个步骤调用 STUN 服务器,我还需要执行哪些其他功能调用STUN服务器还需要调用吗?
最佳答案
我发现生成 BIND 请求并立即发送到 STUN 服务器的一种方法是将配置中的 iceCandidatePoolSize 选项设置为 > 0。
config = {iceServers: [{urls:stun:stunserver.stunprotocol.org}], iceCandidatePoolSize: 1};
peerConnection = new RTCPeerConnection(config); // pretty much starts to resolve the DNS name and sends BIND requests right away.
希望这对您有所帮助。
还有:this link充满了解决 webrtc 连接问题的好建议。
关于javascript - 是什么触发 webRTC API 连接到 stun 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56062360/