RTCDataChannel.onopen

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The RTCDataChannel.onopen property is an EventHandler which specifies a function to be called when the open event is fired; this is a simple Event which is sent when the data channel's underlying data transport—the link over which the RTCDataChannel's messages flow—is established or re-established.

Syntax

JavaScript
RTCDataChannel.onopen = function;

Value

A function which the browser will call to handle the open event. The function receives as its only input parameter the event itself, of type Event.

Example

This example adds a new data channel to an existing RTCPeerConnection, myPeerConnection. It then establishes an open event handler which updates some user interface elements to prepare them for being used to send messages over the data channel.

JavaScript
let dc = myPeerConnection.createDataChannel("Message Channel");

dc.onopen = function(event) {
  let messageBox = document.getElementById("messageBox");
  let sendButton = document.getElementById("sendButton");

  messageBox.disabled = false;
  messageBox.focus();
  sendButton.disabled = false;
}

Specifications

Specification Status Comment
WebRTC 1.0: Real-time Communication Between Browser
The definition of 'RTCDataChannel.onopen' in that specification.
Working Draft Initial specification.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) 22 (22) [1] No support (Yes) ?
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support No support 28 [2] 22.0 (22) [1] No support No support No support (Yes)

[1] The interface is called DataChannel and not RTCDataChannel in Firefox. However, a binding has been in place since Firefox 24 so that either name will work.

[2] WebRTC, including RTCDataChannel, was introduced in Chrome 28 for Android behind a flag, and enabled by default starting in Chrome 29 for Android.

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/rtcdatachannel/onopen

Event Handler Experimental onopen Property Reference RTCDataChannel WebRTC