[]previous and next page

WebSocketConnection

One open connection, as the handlers see it.

One open connection, as the handlers see it.

Import#

ts
import type { WebSocketConnection } from "@shadow-js/dusk/server";

Signature#

ts
interface WebSocketConnection {
  /** A bag for this connection's state, filled in `open`. Not shared between connections. */
  readonly data: Record<string, unknown>;
  /** Aborted when the connection closes. */
  readonly signal: AbortSignal;
  /** `open` until the connection starts closing, then `closed`. */
  readonly readyState: "open" | "closed";
  /**
   * Sends a message: a string as text, bytes as binary. Returns false, and sends nothing, once the
   * connection is closed.
   */
  send(message: string | Uint8Array): boolean;
  /** Closes the connection with a code (default 1000) and a reason of at most 123 bytes. */
  close(code?: number, reason?: string): void;
}

Members#

Name Type Description
data readonly data: Record<string, unknown> A bag for this connection's state, filled in open. Not shared between connections.
signal readonly signal: AbortSignal Aborted when the connection closes.
readyState readonly readyState: "open" | "closed" open until the connection starts closing, then closed.
send send(message: string | Uint8Array): boolean Sends a message: a string as text, bytes as binary. Returns false, and sends nothing, once the connection is closed.
close close(code?: number, reason?: string): void Closes the connection with a code (default 1000) and a reason of at most 123 bytes.