deno.com

interface CloseEvent

extends Event

The CloseEvent interface represents an event that occurs when a WebSocket connection is closed.

This event is sent to the client when the connection is closed, providing information about why the connection was closed through the code, reason, and wasClean properties.

Examples #

#
// Handling a close event
ws.addEventListener("close", (event: CloseEvent) => {
  console.log(`Connection closed with code ${event.code}`);
  console.log(`Reason: ${event.reason}`);
  console.log(`Clean close: ${event.wasClean}`);

  if (event.code === 1006) {
    console.log("Connection closed abnormally");
  }
});

Properties #

#code: number
readonly

Returns the WebSocket connection close code provided by the server.

#reason: string
readonly

Returns the WebSocket connection close reason provided by the server.

#wasClean: boolean
readonly

Returns true if the connection closed cleanly; false otherwise.

See #