这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
RTCPeerConnection.oniceconnectionstatechange
property is an event handler which specifies a function to be called when the
iceconnectionstatechange
event is fired on an
RTCPeerConnection
instance. This happens when the state of the connection's ICE agent, as represented by the
iceConnectionState
property, changes.
RTCPeerConnection.oniceconnectionstatechange = eventHandler;
This event handler can be set to function which is passed a single input parameter: an
事件
object describing the
iceconnectionstatechange
event which occurred. Your code can look at the value of
RTCPeerConnection.iceConnectionState
to determine what the new state is.
The example below watches the state of the ICE agent for a failure or unexpected closure and takes appropriate action, such as presenting an error message or attempting to restart the ICE agent.
pc.oniceconnectionstatechange = function(event) {
if (pc.iceConnectionState === "failed" ||
pc.iceConnectionState === "disconnected" ||
pc.iceConnectionState === "closed") {
// Handle the failure
}
};
Of course, "disconnected" and "closed" don't necessarily indicate errors; these can be the result of normal ICE negotiation, so be sure to handle these properly (if at all).
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCPeerConnection.oniceconnectionstatechange' in that specification. |
候选推荐 | 最初的规范。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
oniceconnectionstatechange
|
Chrome 28 | Edge 15 | Firefox 22 | IE No |
Opera
43
|
Safari 11 | WebView Android Yes | Chrome Android 28 | Firefox Android 44 |
Opera Android
43
|
Safari iOS Yes | Samsung Internet Android 6.0 |
完整支持
不支持
见实现注意事项。
iceconnectionstatechange
event and its type,
事件
.
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