RTCDataChannelEvent

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

The RTCDataChannelEvent interface represents an event related to a specific RTCDataChannel.

Event RTCDataChannelEvent

Constructor

RTCDataChannelEvent()

Creates a new RTCDataChannelEvent.

Instance properties

Also inherits properties from Event.

channel Read only

Returns the RTCDataChannel 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.

js
pc.ondatachannel = (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
WebRTC: Real-Time Communication in Browsers
# rtcdatachannelevent

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
RTCDataChannelEvent
RTCDataChannelEvent() constructor
channel

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also