The optional property candidate RTCIceCandidateInit dictionary specifies the value of the RTCIceCandidate 对象的 candidate 特性。

A DOMString describing the properties of the candidate, taken directly from the SDP 属性 "candidate" . The candidate string specifies the network connectivity information for the candidate. If the candidate 为空字符串 ( "" ), the end of the candidate list has been reached; this candidate is known as the "end-of-candidates" marker.

The syntax of the candidate string is described in RFC 5245, section 15.1 . For an a-line (attribute line) that looks like this:

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

the corresponding candidate string's value will be "candidate:4234997325 1 udp 2043278322 192.168.0.56 44323 typ host" .

用户代理 always prefers candidates with the highest priority , all else being equal. In the example above, the priority is 2043278322 . The attributes are all separated by a single space character, and are in a specific order. The complete list of attributes for this example candidate is:

范例

When a new ICE candidate is received by your signaling code from the remote peer, you need to construct the RTCIceCandidate object that encapsulates it. This is done in the event handler for the icecandidate event. If your client-side signaling layer builds and transmits a JSON string including the candidate to the remote peer, the remote peer might handle receiving that JSON message like this:

function gotICECandidateMessage(msg) {
  var iceCandidate = new RTCIceCandidate({
        candidate: msg.candidate;
  });
  pc.addIceCandidate(iceCandidate).catch({
    /* handle error */
  });
}
					

It's helpful to note that for backward compatibility with older versions of the WebRTC specification, the RTCIceCandidate() constructor accepts the value of candidate as its only input, in place of the RTCIceCandidateInit dictionary. That usage would change the above sample to look like this:

function gotICECandidateMessage(msg) {
  var iceCandidate = new RTCIceCandidate(msg.candidate);
  pc.addIceCandidate(iceCandidate).catch({
    /* handle error */
  });
}
					

规范

规范 状态 注释
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCIceCandidateInit.candidate' 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
candidate Chrome Yes Edge ≤18 Firefox 22
22
Prior to Firefox 68, the candidate property was required; Firefox 68 and later make it optional per a mid-2017 specification update.
IE No Opera Yes Safari ? WebView Android Yes Chrome Android Yes Firefox Android Yes
Yes
Prior to Firefox 68, the candidate property was required; Firefox 68 and later make it optional per a mid-2017 specification update.
Opera Android Yes Safari iOS ? Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

见实现注意事项。

另请参阅

元数据

  • 最后修改: