class WebSocketConnection
extends EventTarget
import { WebSocketConnection } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/ws/base.js";
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.
Methods
addEventListener()
event,
listener,
options?,
close(code, reason)
Closes the WebSocket connection.
removeEventListener()
event,
listener,
options?,
send(data)
Sends data to the WebSocket client.