强制 UDP 用于 Webrtc 对等连接 [英] Force UDP for Webrtc peer connection

查看:45
本文介绍了强制 UDP 用于 Webrtc 对等连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Chrome 中使用 webrtc RtcPeerConnection API.

I am using webrtc RtcPeerConnection API in Chrome.

我当地的 SDP 报价是这样的

My local SDP offer is like this

a=candidate:0 1 UDP 2122252543 10.100.49.26 59882 typ host
a=candidate:1 1 TCP 2105524479 10.100.49.26 9 typ host tcptype active

我认为如果 UDP 不起作用,它会尝试使用 TCP.

I think if UDP is not working, it will try TCP.

但是!我不希望 TCP 和 TCP 连接会导致异常,如何从我的本地 SDP 报价中删除 TCP 线路?

But! I don't want TCP and TCP connection can cause exceptions, How can I remove the TCP line from my local SDP offer?

推荐答案

您可以在调用 setLocalDecription 之前删除包含 a=candidate TCP 行的行并发送给对等方.

You can just remove the line which contains the a=candidate TCP line, before calling the setLocalDecription and sending to the peer.

但是,chrome 默认支持 ICE 涓流以加快连接设置过程,并且不需要在发送 SDP 之前收集所有候选.因此,您可以在生成后立即设置 SDP,并在将它们发送到 onicecandidate 回调中的其他对等点之前轻松过滤掉不需要的候选者.

However, chrome by default supports ICE trickle to speed up the connection setup process and does not require to gather all the candidates before sending the SDP. So, you can set the SDP immediately after generation and easily filter out the unwanted candidates before sending them to the other peer in the onicecandidate callback.

rtcPeerConnection.onicecandidate = event => {
      if (event.candidate && event.candidate.protocol !== 'tcp') {
         // send to peer
      }
}

这篇关于强制 UDP 用于 Webrtc 对等连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆