Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
The close() method of the WebTransport interface closes an ongoing WebTransport session.
close(info)info OptionalAn object containing the following properties:
closeCodeA number representing the error code for the error.
reasonA string representing the reason for closing the WebTransport.
undefined.
WebTransportErrorThrown if close() is invoked while the WebTransport is in the process of connecting.
const url = "https://example.com:4999/wt";
// Initialize transport connection
const transport = new WebTransport(url);
// …
transport.close({
closeCode: 17,
reason: "CloseButtonPressed",
});