Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Using WebRTC data channels

Draft
This page is not complete.

Once you've established a WebRTC peer connection using the RTCPeerConnection interface, you're able to send and receive media data between the two peers on the connection. But there's a lot more you can do with WebRTC. In this guide, we'll examine how to add a data channel to a peer connection, which can then be used to exchange arbitrary data; that is, any kind of data we wish, in any format we choose.

Creating a data channel

The underlying data transport used by the RTCDataChannel can be created in one of two ways:

  • Let WebRTC create the transport and announce it to the remote peer for you (by causing it to receive a datachannel event). This is the easy way, and works for a wide variety of use cases, but may not be flexible enough for your needs.
  • Write your own code to negotiate the data transport and write your own code to signal to the other peer that it needs to connect to the new channel.

Let's look at each of these cases, starting with the first, which is the most common.

Automatic negotiation

more details soon.

<<<discuss negotiation and connections, especially RTCDataChannel.negotiated and what happens when true vs false>>>

...

Buffering

WebRTC data channels support buffering of outbound data. This is handled automatically. While there's no way to control the size of the buffer, you can learn how much data is currently buffered, and you can choose to be notified by an event when the buffer starts to run low on queued data. This makes it easy to write efficient routines that make sure there's always data ready to send without over-using memory or swamping the channel completely.

<<<write more about using bufferedAmount, bufferedAmountLowThreshold, onbufferedamountlow, and bufferedamountlow here>>>

...

Document Tags and Contributors

 Contributors to this page: Sheppy
 Last updated by: Sheppy,