WebRTC API
event
icecandidateerror
is sent to an
RTCPeerConnection
if an error occurs while performing ICE negotiations through a
STUN
or
TURN
server. The event object is of type
RTCPeerConnectionIceErrorEvent
, and contains information describing the error in some amount of detail.
| 冒泡 | No |
|---|---|
| 可取消 | No |
| 接口 |
RTCPeerConnectionIceErrorEvent
|
| 事件处理程序特性 |
RTCPeerConnection.onicecandidateerror
|
The error object's
errorCode
property is one of the numeric STUN error codes. There is one additional, WebRTC-specific, error which lies outside the valid STUN error code range: 701. Error 701 indicates that none of the ICE candidates were able to successfully make contact with the STUN or TURN server.
The 701 error is fired only once per server URL from the list of available STUN or TURN servers provided when creating the
RTCPeerConnection
. These errors occur only when the connection's
ICE gathering state
is
gathering
.
The following example establishes a handler for
icecandidateerror
s that occur on the
RTCPeerConnection
pc
. This handler looks specifically for 701 errors that indicate that candidates couldn't reach the STUN or TURN server.
When this happens, the server URL and the error message are passed to a function called
reportConnectFail()
to log or output the connection failure.
pc.addEventListener("icecandidateerror", (event) => {
if (event.errorCode === 701) {
reportConnectFail(event.url, event.errorText);
}
});
Note that if multiple STUN and/or TURN servers are provided when creating the connection, this error may happen more than once, if more than one of those servers fails. Each provided server is tried until a connection is established.
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'icecandidateerror' in that specification. |
候选推荐 | 初始定义。 |
No compatibility data found. Please contribute data for "api.RTCPeerConnection.icecandidateerror_event" (depth: 1) to the MDN 兼容性数据存储库 .
RTCPeerConnection
RTCSessionDescription
RTCIceCandidate
RTCPeerConnectionIceEvent
RTCPeerConnectionIceErrorEvent
RTCCertificate
RTCRtpSender
RTCRtpReceiver
RTCRtpTransceiver
RTCDtlsTransport
RTCIceTransport
RTCTrackEvent
RTCSctpTransport
RTCDataChannel
RTCDataChannelEvent
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCStatsReport
RTCStatsEvent
RTCErrorEvent