This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The RTCPeerConnection.ondatachannel property is an EventHandler which specifies a function which is called when the datachannel event occurs on an RTCPeerConnection. This event, of type RTCDataChannelEvent, is sent when an RTCDataChannel is added to the connection by the remote peer calling createDataChannel().

At the time this event is received, the RTCDataChannel it indicates may not yet actually be open. Be sure to wait for the "open" event to be fired on the new RTCDataChannel before using it.


RTCPeerConnection.ondatachannel = function;


Set this property to be a function you provide which receives as input a single parameter: an RTCDataChannelEvent which provides in its channel property the RTCDataChannel which has been created.


pc.ondatachannel = function(ev) {
  console.log('Data channel is created!');
  ev.channel.onopen = function() {
    console.log('Data channel is open and ready to be used.');


Specification Status Comment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCPeerConnection.ondatachannel' in that specification.
Candidate Recommendation Initial specification.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support56 Yes22 ?


37 — 43

FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support5656 Yes44


37 — 43


1. Promise based version.

See also

Document Tags and Contributors

Contributors to this page: fscholz, jlotto, jpmedley, Sheppy, so_matt_basta, teoli
Last updated by: fscholz,