The RTCDataChannel interface represents a network channel which can be used for bidirectional peer-to-peer transfers of arbitrary data. Every data channel is associated with an RTCPeerConnection, and each peer connection can have up to a theoretical maximum of 65,534 data channels (the actual limit may vary from browser to browser).
To create a data channel and ask a remote peer to join you, call the RTCPeerConnection's createDataChannel() method. The peer being invited to exchange data receives a datachannel event (which has type RTCDataChannelEvent) to let it know the data channel has been added to the connection.
Properties
Also inherits properties from: EventTarget
binaryType- The property
binaryTypeon theRTCDataChannelinterface is aDOMStringwhich specifies the type of JavaScript object which should be used to represent binary data received on theRTCDataChannel. Values allowed by theWebSocket.binaryTypeproperty are also permitted here:"blob"ifBlobobjects are being used or"arraybuffer"ifArrayBufferobjects are being used. The default is"blob". bufferedAmountRead only- The read-only
RTCDataChannelpropertybufferedAmountreturns the number of bytes of data currently queued to be sent over the data channel. bufferedAmountLowThreshold- The
RTCDataChannelpropertybufferedAmountLowThresholdis used to specify the number of bytes of buffered outgoing data that is considered "low." The default value is 0. idRead only- The read-only
RTCDataChannelpropertyidreturns an ID number (between 0 and 65,534) which uniquely identifies theRTCDataChannel. labelRead only- The read-only
RTCDataChannelpropertylabelreturns aDOMStringcontaining a name describing the data channel. These labels are not required to be unique. maxPacketLifeTimeRead only- The read-only
RTCDataChannelpropertymaxPacketLifeTimereturns the amount of time, in milliseconds, the browser is allowed to take to attempt to transmit a message, as set when the data channel was created, ornull. maxRetransmitsRead only- The read-only
RTCDataChannelpropertymaxRetransmitsreturns the maximum number of times the browser should try to retransmit a message before giving up, as set when the data channel was created, ornull, which indicates that there is no maximum. negotiatedRead only- The read-only
RTCDataChannelpropertynegotiatedindicates whether theRTCDataChannel's connection was negotiated by the Web app (true) or by the WebRTC layer (false). orderedRead only- The read-only
RTCDataChannelpropertyorderedindicates whether or not the data channel guarantees in-order delivery of messages; the default istrue, which indicates that the data channel is indeed ordered. protocolRead only- The read-only
RTCDataChannelpropertyprotocolreturns aDOMStringcontaining the name of the subprotocol in use. If no protocol was specified when the data channel was created, then this property's value is "" (the empty string). readyStateRead only- The read-only
RTCDataChannelpropertyreadyStatereturns an enum of typeRTCDataChannelStatewhich indicates the state of the data channel's underlying data connection. Read onlyreliable- The read-only
RTCDataChannelpropertyreliableindicates whether or not the data channel is reliable. Read onlystream- The deprecated (and never part of the official specification) read-only
RTCDataChannelpropertystreamreturns an ID number (between 0 and 65,535) which uniquely identifies theRTCDataChannel. onbufferedamountlow- The
RTCDataChannel.onbufferedamountlowproperty is anEventHandlerwhich specifies a function the browser calls when thebufferedamountlowevent is sent to theRTCDataChannel. This event, which is represented by a simpleEventobject, is sent when the amount of data buffered to be sent falls to or below the threshold specified by the channel'sbufferedAmountLowThreshold. onclose- The
RTCDataChannel.oncloseproperty is anEventHandlerwhich specifies a function to be called by the browser when thecloseevent is received by theRTCDataChannel. This is a simpleEventwhich indicates that the data channel has closed down. onclosing- The
RTCDataChannel.onclosingproperty is anEventHandlerwhich specifies a function to be called by the browser when theclosingevent is received by theRTCDataChannel. This is a simpleEventwhich indicates that the data channel is being closed, that is,RTCDataChanneltransitions to "closing" state. For example, afterRTCDataChannel.close()was called but the underlying data transport might not have been closed yet. onerror- The
RTCDataChannel.onerrorproperty is anEventHandlerwhich specifies a function to be called when theerrorevent is received. When an error occurs on the data channel, the function receives as input anErrorEventobject describing the error which occurred. onmessage- The
RTCDataChannel.onmessageproperty stores anEventHandlerwhich specifies a function to be called when themessageevent is fired on the channel. This event is represented by theMessageEventinterface. This event is sent to the channel when a message is received from the other peer. onopen- The
RTCDataChannel.onopenproperty is anEventHandlerwhich specifies a function to be called when theopenevent is fired; this is a simpleEventwhich is sent when the data channel's underlying data transport—the link over which theRTCDataChannel's messages flow—is established or re-established. close()- The
RTCDataChannel.close()method closes theRTCDataChannel. Either peer is permitted to call this method to initiate closure of the channel. send()- The
send()method of theRTCDataChannelinterface sends data across the data channel to the remote peer.
Event handlers
Also inherits event handlers from: EventTarget
Methods
Also inherits methods from: EventTarget
Events
bufferedamountlow- Sent to the channel's
onbufferedamountlowevent handler when the number of bytes of data in the outgoing data buffer falls below the value specified bybufferedAmountLowThreshold. close- Sent to the
oncloseevent handler when the underlying data transport closes. error- Sent to the
onerrorevent handler when an error occurs on the data channel. message- Sent to the
onmessageevent handler when a message has been received from the remote peer. The message contents can be found in the event'sdataproperty. open- Sent to the
onopenevent handler when the data channel is first opened, or when an existing data channel's underlying connection re-opens.
Data format
The underlying data format is defined by the IEEE draft specification draft-ietf-mmusic-sctp-sdp. The current format specifies its protocol as either "UDP/DTLS/SCTP" (UDP carrying DTLS carrying SCTP) or "TCP/DTLS/SCTP" (TCP carrying DTLS carrying SCTP). Older browsers may only specify "DTLS/SCTP".
Example
var pc = new RTCPeerConnection();
var dc = pc.createDataChannel("my channel");
dc.onmessage = function (event) {
console.log("received: " + event.data);
};
dc.onopen = function () {
console.log("datachannel open");
};
dc.onclose = function () {
console.log("datachannel close");
};
Specifications
| Specification | Status | Comment |
|---|---|---|
| WebRTC 1.0: Real-time Communication Between Browsers The definition of 'RTCDataChannel' in that specification. |
Candidate Recommendation | Initial specification. |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
RTCDataChannel | Chrome Full support Yes | Edge Full support ≤79 | Firefox
Full support
24
| IE No support No | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 4.4 | Chrome Android Full support 29 | Firefox Android
Full support
24
| Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 2.0 |
binaryType | Chrome Full support Yes | Edge Full support ≤79 | Firefox Full support 18 | IE No support No | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 4.4 | Chrome Android Full support 29 | Firefox Android Full support 18 | Opera Android Full support Yes | Safari iOS No support No | Samsung Internet Android Full support 2.0 |
bufferedAmount | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support 18 | IE No support No | Opera Full support 43 | Safari Full support Yes | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support 18 | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
bufferedamountlow event | Chrome
Full support
57
| Edge
Full support
≤79
| Firefox Full support Yes | IE No support No | Opera
Full support
44
| Safari Full support Yes | WebView Android
Full support
57
| Chrome Android
Full support
57
| Firefox Android Full support Yes | Opera Android
Full support
43
| Safari iOS No support No | Samsung Internet Android
Full support
7.0
|
bufferedAmountLowThreshold | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari Full support Yes | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android No support No | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
close | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support Yes | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
close event | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari ? | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support Yes | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
error event | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari ? | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support Yes | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
id | Chrome Full support 56 | Edge Full support ≤79 | Firefox No support No | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android No support No | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
label | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support Yes | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
maxPacketLifeTime | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support 62 | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support 62 | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
maxRetransmits | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support 62 | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support 62 | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
message event | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari Full support Yes | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support Yes | Opera Android Full support 43 | Safari iOS Full support Yes | Samsung Internet Android Full support 6.0 |
negotiated | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support 68 | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support 68 | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
onbufferedamountlow | Chrome
Full support
57
| Edge
Full support
≤79
| Firefox Full support Yes | IE No support No | Opera
Full support
44
| Safari Full support Yes | WebView Android
Full support
57
| Chrome Android
Full support
57
| Firefox Android Full support Yes | Opera Android
Full support
43
| Safari iOS No support No | Samsung Internet Android
Full support
7.0
|
onclose | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support Yes | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
onclosing | Chrome Full support 81 | Edge Full support 81 | Firefox No support No | IE No support No | Opera Full support 68 | Safari No support No | WebView Android Full support 81 | Chrome Android Full support 81 | Firefox Android No support No | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
onerror | Chrome Full support 56 | Edge Full support ≤79 | Firefox No support No | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android No support No | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
onmessage | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari Full support Yes | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support Yes | Opera Android Full support 43 | Safari iOS Full support Yes | Samsung Internet Android Full support 6.0 |
onopen | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari Full support Yes | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support Yes | Opera Android Full support 43 | Safari iOS Full support Yes | Samsung Internet Android Full support 6.0 |
open event | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari Full support Yes | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support Yes | Opera Android Full support 43 | Safari iOS Full support Yes | Samsung Internet Android Full support 6.0 |
ordered | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support Yes | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
priority | Chrome No support No | Edge No support No | Firefox ? | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android No support No | Firefox Android ? | Opera Android ? | Safari iOS No support No | Samsung Internet Android No support No |
protocol | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support Yes | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
readyState | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support Yes | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
reliable | Chrome Full support 56 | Edge Full support ≤79 | Firefox No support No | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android No support No | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
| Support for sctp-sdp-21 format | Chrome Full support 58 | Edge Full support ≤79 | Firefox Full support 63 | IE No support No | Opera ? | Safari No support No | WebView Android Full support 58 | Chrome Android Full support 58 | Firefox Android Full support 63 | Opera Android ? | Safari iOS No support No | Samsung Internet Android Full support 7.0 |
send | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support Yes | IE No support No | Opera Full support 43 | Safari Full support Yes | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support Yes | Opera Android Full support 43 | Safari iOS Full support Yes | Samsung Internet Android Full support 6.0 |
stream | Chrome Full support 56 | Edge Full support ≤79 | Firefox No support No | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android No support No | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- Non-standard. Expect poor cross-browser support.
- Non-standard. Expect poor cross-browser support.
- Deprecated. Not for use in new websites.
- Deprecated. Not for use in new websites.
- See implementation notes.
- See implementation notes.
- Uses a non-standard name.
- Uses a non-standard name.
