The RTCDataChannel.close()
method closes the RTCDataChannel
. Either peer is permitted to call this method to initiate closure of the channel.
Closure of the data channel is not instantaneous. Most of the process of closing the connection is handled asynchronously; you can detect when the channel has finished closing by watching for a close
event on the data channel.
The sequence of events which occurs in response to this method being called:
RTCDataChannel.readyState
is set to "closing"
.close()
returns to the caller.RTCDataChannel.readyState
property is set to "closed"
.RTCDataChannel
is sent a NetworkError
event.close
event is sent to the channel.In Firefox, the RTCDataChannel
interface was implemented under the name DataChannel
until Firefox 24, so this method was called DataChannel.close()
.
RTCDataChannel.close();
None.
undefined
.
var pc = new RTCPeerConnection(); var dc = pc.createDataChannel("my channel"); dc.onmessage = function (event) { console.log("received: " + event.data); dc.close(); // We decided to close after the first received message }; dc.onopen = function () { console.log("datachannel open"); }; dc.onclose = function ( console.log("datachannel close"); }; // Now negotiate the connection and so forth...
Specification | Status | Comment |
---|---|---|
WebRTC 1.0: Real-time Communication Between Browsers The definition of 'RTCDataChannel.close()' in that specification. | Working Draft | Initial specification. |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 23 | 22 (22) [1] | No support | (Yes) | ? |
Feature | Android Webview | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | ? | 29 | 22 (22) [1] | No support | ? | ? |
[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.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/close