A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/datachannel_event below:

RTCPeerConnection: datachannel event - Web APIs

RTCPeerConnection: datachannel event

Baseline Widely available

A datachannel event is sent to an RTCPeerConnection instance when an RTCDataChannel has been added to the connection, as a result of the remote peer calling RTCPeerConnection.createDataChannel().

Note: This event is not dispatched when the local end of the connection creates the channel.

This event is not cancelable and does not bubble.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

addEventListener("datachannel", (event) => { })

ondatachannel = (event) => { }
Event type Event properties

Also inherits properties from Event.

channel Read only

Returns the RTCDataChannel associated with the event.

Examples

This example sets up a function that handles datachannel events by gathering the information needed to communicate with the newly added RTCDataChannel and by adding event handlers for the events that occur on that channel.

pc.addEventListener(
  "datachannel",
  (ev) => {
    receiveChannel = ev.channel;
    receiveChannel.onmessage = myHandleMessage;
    receiveChannel.onopen = myHandleOpen;
    receiveChannel.onclose = myHandleClose;
  },
  false,
);

receiveChannel is set to the value of the event's channel property, which specifies the RTCDataChannel object representing the data channel linking the remote peer to the local one.

This same code can also instead use the RTCPeerConnection interface's ondatachannel event handler property, like this:

pc.ondatachannel = (ev) => {
  receiveChannel = ev.channel;
  receiveChannel.onmessage = myHandleMessage;
  receiveChannel.onopen = myHandleOpen;
  receiveChannel.onclose = myHandleClose;
};
Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.3