The read-only property
candidate
在
RTCIceCandidate
interface returns a
DOMString
describing the candidate in detail.
Most of the other properties of
RTCIceCandidate
are actually extracted from this string.
This property can be configured by specifying the value of the
candidate
property when constructing the new candidate object using
RTCIceCandidate()
.
var candidate = 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:
foundation
= 4234997325
component
=
"rtp"
(the number 1 is encoded to this string; 2 becomes
"rtcp"
)
协议
=
"udp"
priority
= 2043278322
ip
=
"192.168.0.56"
port
= 44323
type
=
"host"
In this example, we see a function which receives as input an SDP string containing an ICE candidate received from the remote peer during the signaling process.
function handleNewIceCandidate(candidateSDP) {
var candidateObj = new RTCIceCandidate(candidateSDP);
myPeerConnection.addIceCandidate(candidateObj).catch({
/* handle the error thrown by addIceCandidate() */
});
}
handleNewIceCandidate()
function shown here passes the received candidate's SDP text into
RTCIceCandidate()
to receive an
RTCIceCanddiate
object in return, which represents the candidate.
The new candidate is then passed into
RTCPeerConnection.addIceCandidate()
to add the candidate to the list of candidates for WebRTC to consider using for the connection being established.
This example could be simplified somewhat; you may more often see the code look something like this, taking advantage of more advanced ECMAScript 2016 features:
let handleNewIceCandidate = candidateSDP => myPeerConnection.addIceCandidate(new RTCIceCandidate(candidateSDP));
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCIceCandidate.candidate' in that specification. |
候选推荐 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
完整支持
不支持
RTCIceCandidate
MediaDevices.getUserMedia()
Navigator.mediaDevices
RTCCertificate
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCDataChannel
RTCDataChannelEvent
RTCDtlsTransport
RTCErrorEvent
RTCIceTransport
RTCPeerConnection
RTCPeerConnectionIceErrorEvent
RTCPeerConnectionIceEvent
RTCRtpReceiver
RTCRtpSender
RTCRtpTransceiver
RTCSctpTransport
RTCSessionDescription
RTCStatsEvent
RTCStatsReport
RTCTrackEvent