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.
TheRTCDataChannelEvent() constructorcreates a newRTCDataChannelEvent object.
Note:You will rarely if ever construct anRTCDataChannelEvent by hand; theseevents are normally created and sent by the WebRTC layer itself.
In this article
Syntax
new RTCDataChannelEvent(type, options)Parameters
typeA string with the name of the event.It is case-sensitive and browsers always set it to
datachannel.optionsAn object that,in addition of the properties defined in
Event(), can have the following properties:channelA
RTCDataChannel, representing the data channel being associated with the event.
Return value
A newRTCDataChannelEvent object configured as specified.
Example
In this example, a newdatachannel event is created.dc is adata channel which already exists.
const event = new RTCDataChannelEvent("datachannel", { channel: dc });Specifications
| Specification |
|---|
| WebRTC: Real-Time Communication in Browsers> # dom-rtcdatachannelevent-constructor> |