JavaScripture
Contribute via GitHub Feedback

RTCDataChannel : EventTarget

Allows sending arbitrary data over a WebRTC connection. Created using RTCPeerConnection.createDataChannel().

Although WebRTC is a peer to peer protocol, the peers need some information about each other before they can communicate. Typically this is done with a Signaling Server, but any mechanism to transfer data can be used. The following demonstrates setting up the peer connection using the clipboard (via copy/paste) to transfer the connection data.

Offerer

This example demonstrates the peer that creates the offer.

Example:

Run

Results:

 

Answerer

This example demonstrates the peer that receives the offer and creates the answer.

Example:

Run

Results:

 

Instance Properties

binaryType : String

bufferedAmount : Number  

bufferedAmountLowThreshold : Number

id : Number  

label : String  

maxPacketLifeTime : Number  

maxRetransmits : Number  

negotiated : Boolean  

ordered : Boolean  

protocol : String  

readyState : String  

One of 'connecting', 'open', 'closing', or 'closed'.

Instance Methods

close() : undefined

send 4 variants
send(data : String) : undefined

send(data : Blob) : undefined

send(data : ArrayBuffer) : undefined

send(data : ArrayBufferView) : undefined

Instance Events

onbufferedamountlow / 'bufferedamountlow'  
listener(event : Event) : undefined

onclose / 'close'  
listener(event : Event) : undefined

onclosing / 'closing'  
listener(event : Event) : undefined

onerror / 'error'  
listener(event : RTCErrorEvent) : undefined

onmessage / 'message'  
listener(event : MessageEvent) : undefined

onopen / 'open'  
listener(event : Event) : undefined