RTCIceCandidate interface's read-only 协议 property is a string which indicates whether the candidate uses UDP or TCP as its transport protocol. 协议 is null by default if not specified properly in the SDP, but this is an error condition and will result in a thrown exception when you call RTCPeerConnection.addIceCandidate() .

协议 property's value is set when the RTCIceCandidate() constructor is used. The value is automatically extracted from the candidate a-line, if it's formatted properly.

句法

var protocol = RTCIceCandidate.protocol;
					

A DOMString which indicates what network protocol the candidate uses, UDP or TCP. These values are defined by the enumerated type RTCIceProtocol :

tcp
The candidate, if selected, would use TCP as the transport protocol for its data. The tcpType property provides additional information about the kind of TCP candidate represented by the object.
udp
The candidate will use the UDP transport protocol for its data. This is the preferred protocol for media interactions because of its better performance profile.

注意: 协议 is null — and 协议 is supported by the 用户代理 — passing the candidate to addIceCandidate() will fail, throwing an OperationError 异常。

用法注意事项

Here's an example candidate a-line from an ICE transaction:

a=candidate:4234997325 1 udp 2043278322 192.168.0.56 44323 typ host
					

The third field, "udp" , is the protocol type, indicating that the candidate would use the UDP transport protocol.

范例

This code snippet examines the value of 协议 to decide if it should look at the value of tcpType to see if it's a simultaneous-open ( S-O ) candidate.

if (candidate.protocol == "tcp") {
  if (candidate.tcpType == "so") {
    adjustForSimultaneousOpen(candidate);
}
					

规范

规范 状态 注释
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCIceCandidate.protocol' in that specification.
候选推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
协议 Chrome 74 Edge ≤18 Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari ? WebView Android 74 Chrome Android 74 Firefox Android 不支持 No Opera Android 不支持 No Safari iOS ? Samsung Internet Android 11.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

元数据

  • 最后修改: