RTCIceCandidate:protocol 属性
Baseline 2024Newly available
Since May 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
RTCIceCandidate
接口的 protocol
只读属性是一个用于指示候选者使用的传输协议是 UDP 还是 TCP 的字符串。
protocol
字段的值是通过传递给 RTCIceCandidate(candidateInfo)
构造函数的 candidateInfo
选项对象中设置的。你不能直接在选项对象中指定 protocol
的值,如果对象的 candidate
属性行(a-line)的格式正确,其值将自动从中提取。
如果在 SDP
中未正确指定 protocol
,则 protocol
默认为 null
。如果没有设置,在调用 RTCPeerConnection.addIceCandidate()
时将抛出异常。
值
使用说明
以下是 ICE 发送的候选者属性行的示例:
a=candidate:4234997325 1 udp 2043278322 192.0.2.172 44323 typ host
第三个字段 "udp"
是协议类型,表示候选者将使用 UDP 传输协议。
示例
此代码片段检查 protocol
的值以决定是否应查看 tcpType
的值,以查看它是否是同时打开(simultaneous-open,S-O)候选者。
js
if (candidate.protocol === "tcp") {
if (candidate.tcpType === "so") {
adjustForSimultaneousOpen(candidate);
}
}
规范
Specification |
---|
WebRTC: Real-Time Communication in Browsers # dom-rtcicecandidate-protocol |