Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/esm/ws/base.js>WebSocketConnection

A JavaScript extension package for building strong and modern applications.
Latest
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 the close event will be dispatched.
  • close - Dispatched 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.

Constructors

new
WebSocketConnection(source)

Properties

deprecated
readonly
ready

A promise that resolves when the connection is ready to send and receive messages.

readonly
readyState

The current state of the WebSocket connection.

Methods

addEventListener(
event,
listener,
options?,
)
close(code, reason)

Closes the WebSocket connection.

removeEventListener(
event,
listener,
options?,
)
send(data)

Sends data to the WebSocket client.