files/en-us/web/api/rtcdatachannel/closing_event/index.md
{{APIRef("WebRTC")}}
The closing event is sent to an {{domxref("RTCDataChannel")}} just before the channel begins the process of shutting down its underlying data transport.
This event is not cancelable and does not bubble.
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
addEventListener("closing", (event) => { })
onclosing = (event) => { }
A generic {{domxref("Event")}}.
While the closing event is sent to the channel just before beginning to close the channel's data transport, the {{domxref("RTCDataChannel.close_event", "close")}} event is sent once the closing process is complete.
This example updates a connection status interface when the closing event arrives.
First, an example using {{domxref("EventTarget.addEventListener", "addEventListener()")}}:
dataChannel.addEventListener("closing", (ev) => {
myConnectionStatus.icon = closingIcon;
myConnectionStatus.text = "Connection closing";
});
You can also set the onclosing event handler property directly:
pc.onclosing = (ev) => {
myConnectionStatus.icon = closingIcon;
myConnectionStatus.text = "Connection closing";
};
{{Specifications}}
{{Compat}}