RTCIceCandidate

RTCIceCandidate interface—part of the WebRTC API —represents a candidate Internet Connectivity Establishment ( ICE ) configuration which may be used to establish an RTCPeerConnection .

An ICE candidate describes the protocols and routing needed for WebRTC to be able to communicate with a remote device. When starting a WebRTC peer connection, typically a number of candidates are proposed by each end of the connection, until they mutually agree upon one which describes the connection they decide will be best. WebRTC then uses that candidate's details to initiate the connection.

For details on how the ICE process works, see Lifetime of a WebRTC session . The article WebRTC connectivity provides additional useful details.

构造函数

RTCIceCandidate()
创建 RTCIceCandidate object to represent a single ICE candidate, optionally configured based on an object based on the RTCIceCandidateInit dictionary.
注意: For backward compatibility, the constructor also accepts as input a string containing the value of the candidate property instead of a RTCIceCandidateInit object, since the candidate includes all of the information that RTCIceCandidateInit does and more.

特性

candidate 只读
A DOMString representing the transport address for the candidate that can be used for connectivity checks. The format of this address is a candidate-attribute 作为定义在 RFC 5245 . This string is empty ( "" ) if the RTCIceCandidate is an "end of candidates" indicator.
component 只读
A DOMString which indicates whether the candidate is an RTP or an RTCP candidate; its value is either "rtp" or "rtcp" , and is derived from the "component-id" field in the candidate a-line string. The permitted values are listed in the RTCIceComponent enumerated type.
foundation 只读
返回 DOMString containing a unique identifier that is the same for any candidates of the same type, share the same base (the address from which the ICE agent sent the candidate), and come from the same STUN server. This is used to help optimize ICE performance while prioritizing and correlating candidates that appear on multiple RTCIceTransport 对象。
ip 只读
A DOMString containing the IP address of the candidate.
port 只读
An integer value indicating the candidate's port number.
priority 只读
A long integer value indicating the candidate's priority.
protocol 只读
A string indicating whether the candidate's protocol is "tcp" or "udp" . The string is one of those in the enumerated type RTCIceProtocol .
relatedAddress 只读
If the candidate is derived from another candidate, relatedAddress DOMString containing that host candidate's IP address. For host candidates, this value is null .
relatedPort 只读
For a candidate that is derived from another, such as a relay or reflexive candidate, the relatedPort is a number indicating the port number of the candidate from which this candidate is derived. For host candidates, the relatedPort 特性为 null .
sdpMid 只读
A DOMString specifying the candidate's media stream identification tag which uniquely identifies the media stream within the component with which the candidate is associated, or null if no such association exists.
sdpMLineIndex 只读
If not null , sdpMLineIndex indicates the zero-based index number of the media description (as defined in RFC 4566 ) in the SDP with which the candidate is associated.
tcpType 只读
protocol is "tcp" , tcpType represents the type of TCP candidate. Otherwise, tcpType is null .
type 只读
A DOMString indicating the type of candidate as one of the strings from the RTCIceCandidateType enumerated type.
usernameFragment 只读
A DOMString containing a randomly-generated username fragment ("ice-ufrag") which ICE uses for message integrity along with a randomly-generated password ("ice-pwd"). You can use this string to verify generations of ICE generation; each generation of the same ICE process will use the same usernameFragment , even across ICE restarts.

方法

toJSON()
Given the RTCIceCandidate 's current configuration, toJSON() 返回 DOMString 包含 JSON representation of that configuration in the form of a RTCIceCandidateInit 对象。

范例

For examples, see the article Signaling and video calling , which demonstrates the entire process.

规范

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

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
RTCIceCandidate Chrome Yes Edge ≤18 Firefox 22 IE 不支持 No Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
RTCIceCandidate() 构造函数 Chrome Yes Edge ≤18 Firefox 22
注意事项
22
注意事项
Before Firefox 68, the constructor's options parameter was required.
IE 不支持 No Opera Yes Safari ? WebView Android Yes Chrome Android Yes Firefox Android Yes
注意事项
Yes
注意事项
Before Firefox 68, the constructor's options parameter was required.
Opera Android Yes Safari iOS ? Samsung Internet Android Yes
address Chrome 74 Edge 79
79
≤18 — 79
Alternate Name
Alternate Name Uses the non-standard name: ip
Firefox ? IE 不支持 No Opera ? Safari ? WebView Android 74 Chrome Android 74 Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android 11.0
candidate Chrome 23 Edge 15 Firefox 22 IE 不支持 No Opera 15 Safari Yes WebView Android Yes Chrome Android 25 Firefox Android Yes Opera Android 14 Safari iOS Yes Samsung Internet Android 1.5
component Chrome 74 Edge ≤79 Firefox 不支持 No IE 不支持 No Opera ? Safari ? WebView Android 74 Chrome Android 74 Firefox Android 不支持 No Opera Android ? Safari iOS ? Samsung Internet Android 11.0
foundation Chrome 74 Edge ≤18 Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari ? WebView Android 74 Chrome Android 74 Firefox Android ? Opera Android 不支持 No Safari iOS ? Samsung Internet Android 11.0
port 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
priority 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
protocol 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
relatedAddress 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
relatedPort 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
sdpMid Chrome 23 Edge 15 Firefox 22 IE 不支持 No Opera 15 Safari Yes WebView Android Yes Chrome Android 25 Firefox Android Yes Opera Android 14 Safari iOS Yes Samsung Internet Android 1.5
sdpMLineIndex Chrome 23 Edge 15 Firefox 22 IE 不支持 No Opera 15 Safari Yes WebView Android Yes Chrome Android 25 Firefox Android Yes Opera Android 14 Safari iOS Yes Samsung Internet Android 1.5
tcpType 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
toJSON Chrome 45 Edge 15 Firefox 27 IE 不支持 No Opera 32 Safari Yes WebView Android 45 Chrome Android 45 Firefox Android 27 Opera Android 32 Safari iOS Yes Samsung Internet Android 5.0
type 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
usernameFragment Chrome 74 Edge ≤79 Firefox 67 IE 不支持 No Opera ? Safari ? WebView Android 74 Chrome Android 74 Firefox Android 67 Opera Android ? Safari iOS ? Samsung Internet Android 11.0

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知
见实现注意事项。
使用非标名称。
使用非标名称。