gpt4 book ai didi

javascript - WebRTC 如何决定使用哪些 TURN 服务器

转载 作者:数据小太阳 更新时间:2023-10-29 04:40:28 25 4
gpt4 key购买 nike

分支这个问题 WebRTC - How many STUN/TURN servers do I need to specify?

当提供多个 TURN 服务器时,WebRTC 如何确定使用哪个 TURN 服务器?

最佳答案

每个 Ice 候选者在收集时都会被赋予优先级。它是多种因素的混合体,我相信每个平台(Chrome、FireFox 等)都有自己的偏好。

这是一个link to the RFC解释如何产生优先级。每个优先级都保证是唯一的,因为候选 ID 应该是唯一的(如果遵循 RFC)。所以,你永远不应该在优先级上有联系。首先尝试优先级较高的那些,如果无法与它们建立连接,则使用下一个队列。

引用自 RFC 关于优先级:

When using the formula, an agent computes the priority by determininga preference for each type of candidate (server reflexive, peer
reflexive, relayed, and host), and, when the agent is multihomed,
choosing a preference for its IP addresses. These two preferences
are then combined to compute the priority for a candidate. That
priority is computed using the following formula:

    priority = (2^24)*(type preference) +
(2^8)*(local preference) +
(2^0)*(256 - component ID)

The type preference MUST be an integer from 0 to 126 inclusive, andrepresents the preference for the type of the candidate (where the
types are local, server reflexive, peer reflexive, and relayed). A
126 is the highest preference, and a 0 is the lowest. Setting the
value to a 0 means that candidates of this type will only be used as
a last resort. The type preference MUST be identical for all
candidates of the same type and MUST be different for candidates of
different types. The type preference for peer reflexive candidates
MUST be higher than that of server reflexive candidates. Note that
candidates gathered based on the procedures of Section 4.1.1 will
never be peer reflexive candidates; candidates of these type are
learned from the connectivity checks performed by ICE.

The local preference MUST be an integer from 0 to 65535 inclusive.It represents a preference for the particular IP address from which
the candidate was obtained, in cases where an agent is multihomed.
65535 represents the highest preference, and a zero, the lowest.
When there is only a single IP address, this value SHOULD be set to65535. More generally, if there are multiple candidates for a particular component for a particular media stream that have the sametype, the local preference MUST be unique for each one. In this
specification, this only happens for multihomed hosts. If a host is
multihomed because it is dual stack, the local preference SHOULD be
set equal to the precedence value for IP addresses described in RFC
3484 [RFC3484].

The component ID is the component ID for the candidate, and MUST bebetween 1 and 256 inclusive.

你可以看到转服务器ip和端口显示在中继候选中。以下来源于the RFC page 82webrtc hacks .

a=candidate:2157334355<ID> 2<Component> udp<NetType> 33562367<Prioirty> 180.6.6.6<NAT pub IP> 54278<NAT pub Port> typ relay<Means it needs to be relayed through Turn> raddr 46.2.2.2<Relay address of turn> rport 38135<relay port of turn> generation 0

关于javascript - WebRTC 如何决定使用哪些 TURN 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26342589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com