RTCPeerConnection
property
onicecandidate
property is an
EventHandler
which specifies a function to be called when the
icecandidate
event occurs on an
RTCPeerConnection
instance. This happens whenever the local
ICE
agent needs to deliver a message to the other peer through the signaling server.
This lets the ICE agent perform negotiation with the remote peer without the browser itself needing to know any specifics about the technology being used for signaling; simply implement this method to use whatever messaging technology you choose to send the ICE candidate to the remote peer.
rtcPeerConnection.onicecandidate = eventHandler;
This should be set to a function which you provide that accepts as input an
RTCPeerConnectionIceEvent
object representing the
icecandidate
event. The function should deliver the ICE candidate, whose
SDP
can be found in the event's
candidate
property, to the remote peer through the signaling server.
If the event's
candidate
特性为
null
, ICE gathering has finished. This message should not be sent to the remote peer. When this happens, the connection's
iceGatheringState
has also changed to
complete
. You don't need to watch for this explicitly; instead, if you need to sense the end of signaling, you should watch for a
icegatheringstatechange
event indicating that the ICE negotiation has transitioned to the
complete
状态。
The example below, which is based on the code from the article
Signaling and video calling
, sets up a handler for
icecandidate
events to send the candidates to the remote peer.
pc.onicecandidate = function(event) {
if (event.candidate) {
// Send the candidate to the remote peer
} else {
// All ICE candidates have been sent
}
}
Notice that the end of negotiation is detected here when the event's
candidate
特性为
null
.
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCPeerConnection.onicecandidate' in that specification. |
候选推荐 | 最初的规范。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
onicecandidate
|
Chrome 24 | Edge 15 | Firefox 22 | IE No |
Opera
43
|
Safari 11 | WebView Android Yes | Chrome Android Yes | Firefox Android 44 |
Opera Android
43
|
Safari iOS Yes | Samsung Internet Android 6.0 |
完整支持
不支持
见实现注意事项。
icecandidate
event and its type,
RTCPeerConnectionIceEvent
.
RTCPeerConnection
canTrickleIceCandidates
connectionState
currentLocalDescription
currentRemoteDescription
getDefaultIceServers()
iceConnectionState
iceGatheringState
localDescription
onaddstream
onconnectionstatechange
ondatachannel
onicecandidate
oniceconnectionstatechange
onicegatheringstatechange
onidentityresult
onidpassertionerror
onidpvalidationerror
onnegotiationneeded
onpeeridentity
onremovestream
onsignalingstatechange
ontrack
peerIdentity
pendingLocalDescription
pendingRemoteDescription
remoteDescription
sctp
signalingState
addIceCandidate()
addStream()
addTrack()
close()
createAnswer()
createDataChannel()
createOffer()
generateCertificate()
getConfiguration()
getIdentityAssertion()
getReceivers()
getSenders()
getStats()
getStreamById()
getTransceivers()
removeStream()
removeTrack()
restartIce()
setConfiguration()
setIdentityProvider()
setLocalDescription()
setRemoteDescription()
MediaDevices.getUserMedia()
Navigator.mediaDevices
RTCCertificate
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCDataChannel
RTCDataChannelEvent
RTCDtlsTransport
RTCErrorEvent
RTCIceCandidate
RTCIceTransport
RTCPeerConnectionIceErrorEvent
RTCPeerConnectionIceEvent
RTCRtpReceiver
RTCRtpSender
RTCRtpTransceiver
RTCSctpTransport
RTCSessionDescription
RTCStatsEvent
RTCStatsReport
RTCTrackEvent