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 toclosing
. - A background task is established to handle the remainder of the steps below, and
close()
returns to the caller. - The transport layer deals with any buffered messages; the protocol layer decides whether to send them or discard them.
- The underlying data transport is closed.
- The
RTCDataChannel.readyState
property is set toclosed
. - If the transport was closed with an error, the
RTCDataChannel
is sent anerror
event with itsname
set toNetworkError
. - A
close
event is sent to the channel.