A
datachannel
event is sent to an
RTCPeerConnection
instance when an
RTCDataChannel
has been added to the connection, as a result of the remote peer calling
RTCPeerConnection.createDataChannel()
.
注意: This event is not dispatched when the local end of the connection creates the channel.
| 冒泡 | No |
|---|---|
| 可取消 | No |
| 接口 |
RTCDataChannelEvent
|
| 事件处理程序特性 |
ondatachannel
|
This example sets up a function that handles
datachannel
events by gathering the information needed to communicate with the newly added
RTCDataChannel
and by adding event handlers for the events that occur on that channel.
pc.addEventListener("datachannel", ev => {
receiveChannel = ev.channel;
receiveChannel.onmessage = myHandleMessage;
receiveChannel.onopen = myHandleOpen;
receiveChannel.onclose = myHandleClose;
}, false);
receiveChannel
is set to the value of the event's
channel
property, which specifies the
RTCDataChannel
object representing the data channel linking the remote peer to the local one.
This same code can also instead use the
RTCPeerConnection
接口的
ondatachannel
event handler property, like this:
pc.ondatachannel = ev => {
receiveChannel = ev.channel;
receiveChannel.onmessage = myHandleMessage;
receiveChannel.onopen = myHandleOpen;
receiveChannel.onclose = myHandleClose;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'datachannel' in that specification. |
候选推荐 | Basic definition. |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
datachannel
event
|
Chrome 25 | Edge ≤18 | Firefox 22 | IE No | Opera 43 | Safari 11 | WebView Android Yes | Chrome Android 25 | Firefox Android 44 | Opera Android 43 | Safari iOS ? | Samsung Internet Android 6.0 |
完整支持
不支持
兼容性未知
RTCDataChannelEvent
RTCPeerConnection.ondatachannel
RTCPeerConnection.createDataChannel()
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