This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The RTCDataChannelEvent() constructor returns a new RTCDataChannelEvent object, which represents a datachannel event. These events sent to an RTCPeerConnection when its remote peer is asking to open an RTCDataChannel between the two peers.
You will rarely if ever construct an RTCDataChannelEvent by hand; instead, the WebRTC layer will generate and deliver them to you at the appropriate time. Just listen for the datachannel event and when you receive it, use the RTCDataChannelEvent.channel property to gain access to the data channel which has been opened.
RTCDataChannelEvent()
RTCDataChannelEvent() constructor creates a new RTCDataChannelEvent.Also inherits properties from: Event
channel Read only
RTCDataChannelEvent.channel returns the RTCDataChannel associated with the event.This interface has no methods, but inherits methods from: Event
In this example, the datachannel event handler is set up to save the data channel reference and set up handlers for the events which need to be monitored. The channel property provides the RTCDataChannel representing the connection to the other peer.
pc.ondatachannel = function(event) {
inboundDataChannel = event.channel;
inboundDataChannel.onmessage = handleIncomingMessage;
inboundDataChannel.onopen = handleChannelOpen;
inboundDataChannel.onclose = handleChannelClose;
}
See A simple RTCDataChannel sample for another, more complete, example of how to use data channels.
| Specification | Status | Comment |
|---|---|---|
| WebRTC 1.0: Real-time Communication Between Browsers The definition of 'RTCDataChannelEvent' in that specification. | Candidate Recommendation | Initial definition. |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | Yes | ? | 22 | No | Yes | ? |
RTCDataChannelEvent() constructor |
57 | ? | 22 | ? | 44 | ? |
channel |
Yes | ? | 22 | No | Yes | ? |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | Yes | 28 | ? | 22 | Yes | ? | Yes |
RTCDataChannelEvent() constructor |
57 | 57 | ? | 22 | 44 | ? | 7.0 |
channel |
Yes | 28 | ? | 22 | Yes | ? | Yes |
RTCDataChannelRTCDataChannel.ondatachannelRTCPeerConnection (the target interface for datachannel events)
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannelEvent