Baseline Widely available
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.None.
Return valueNone (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â¦
Specifications Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3