This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
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 an error event with its name set to NetworkError.close event is sent to the channel.close()
None.
None (undefined).
const pc = new RTCPeerConnection();
const dc = pc.createDataChannel("my channel");
dc.onmessage = (event) => {
console.log(`received: ${event.data}`);
dc.close(); // We decided to close after the first received message
};
dc.onopen = () => {
console.log("datachannel open");
};
dc.onclose = () => {
console.log("datachannel close");
};
// Now negotiate the connection and so forth…
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
close |
24 | 79 | 22 | 15 | 11 | 25 | 24 | 14 | 11 | 1.5 | 4.4 | 11 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/close