RTCDataChannelEvent: RTCDataChannelEvent() constructor

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() constructor creates a new RTCDataChannelEvent object.

Note: You will rarely if ever construct an RTCDataChannelEvent by hand; these events are normally created and sent by the WebRTC layer itself.

Syntax

js
new RTCDataChannelEvent(type, options)

Parameters

type

A string with the name of the event. It is case-sensitive and browsers always set it to datachannel.

options

An object that, in addition of the properties defined in Event(), can have the following properties:

channel

A RTCDataChannel, representing the data channel being associated with the event.

Return value

A new RTCDataChannelEvent object configured as specified.

Example

In this example, a new datachannel event is created. dc is a data channel which already exists.

js
const event = new RTCDataChannelEvent("datachannel", { channel: dc });

Specifications

Specification
WebRTC: Real-Time Communication in Browsers
# dom-rtcdatachannelevent-constructor

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() constructor

Legend

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

Full support
Full support

See also