import { WebSocketConnection } from "https://deno.land/x/ayonli_jsext@v0.9.72/workerd/ws.ts";
This class represents a WebSocket connection on the server side. Normally we don't create instances of this class directly, but rather use the WebSocketServer to handle WebSocket connections, which will create the instance for us.
Events:
open
- Dispatched when the connection is ready.message
- Dispatched when a message is received.error
- Dispatched when an error occurs, such as network failure. After this event is dispatched, the connection will be closed and theclose
event will be dispatched.close
- Dispatched when the connection is closed. If the connection is closed due to some error, theerror
event will be dispatched before this event, and the close event will have thewasClean
set tofalse
, and thereason
property contains the error message, if any.
Constructors
Properties
A promise that resolves when the connection is ready to send and receive messages.
Methods
Adds an event listener that will be called when the connection is ready.
Adds an event listener that will be called when a message is received.
Adds an event listener that will be called when the connection is
interrupted. After this event is dispatched, the connection will be
closed and the close
event will be dispatched.
Adds an event listener that will be called when the connection is closed.
If the connection is closed due to some error, the error
event will be
dispatched before this event, and the close event will have the wasClean
set to false
, and the reason
property contains the error message, if
any.
Closes the WebSocket connection.
Sends data to the WebSocket client.