This is an experimental technologyCheck 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 to be received by the RTCPeerConnection
and when you receive it, use the RTCDataChannelEvent.channel
property to gain access to the data channel which has been opened.
Constructor
RTCDataChannelEvent()
- The
RTCDataChannelEvent()
constructor creates a newRTCDataChannelEvent
. channel
Read only- The read-only property
RTCDataChannelEvent
.channel
returns theRTCDataChannel
associated with the event.
Examples
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.
Specifications
Specification | Status | Comment |
WebRTC 1.0: Real-time Communication Between BrowsersThe definition of 'RTCDataChannelEvent' in that specification. | Candidate Recommendation | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
RTCDataChannelEvent
|
Chrome
Full support Yes |
Edge
Full support ≤79 |
Firefox
Full support 22 |
IE
No support No |
Opera
Full support Yes |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support 28 |
Firefox Android
Full support 22 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 1.5 |
RTCDataChannelEvent() constructor
|
Chrome
Full support 57 |
Edge
Full support ≤79 |
Firefox
Full support 22 |
IE
No support No |
Opera
Full support 44 |
Safari
? |
WebView Android
Full support 57 |
Chrome Android
Full support 57 |
Firefox Android
Full support 22 |
Opera Android
Full support 43 |
Safari iOS
? |
Samsung Internet Android
Full support 7.0 |
channel
|
Chrome
Full support Yes |
Edge
Full support ≤79 |
Firefox
Full support 22 |
IE
No support No |
Opera
Full support Yes |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support 28 |
Firefox Android
Full support 22 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 1.5 |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
See also
- WebRTC
RTCDataChannel
RTCDataChannel.ondatachannel
- A simple RTCDataChannel sample
RTCPeerConnection
(the target interface fordatachannel
events)
RTCDataChannelEvent by Mozilla Contributors is licensed under CC-BY-SA 2.5.