Skip to content

net/websockets

Documentation

Overview

Classes

Websockets

createWebsocket()

Creates a new WebSocket client connection to a specified URI, managed by a handler script.

ts
static createWebsocket(uri: string, handler: string): WebsocketClient;
ParameterTypeDescription
uristringThe target WebSocket URI (e.g., 'ws://example.com/socket').
handlerstringThe identifier or path of the script handling the WebSocket events.

Returns

  • Type: WebsocketClient
  • Description: A wrapper object for the new WebSocket session.

getClients()

Retrieves a list of all active WebSocket clients.

ts
static getClients(): void;

Returns

  • Type: void
  • Description: An array of objects detailing the URI and handler of each client.

getClient()

Retrieves a specific WebSocket client wrapper by its session ID.

ts
static getClient(id: string): WebsocketClient;
ParameterTypeDescription
idstringThe session ID of the client.

Returns

  • Type: WebsocketClient
  • Description: The client wrapper or undefined if not found.

getClientByHandler()

Retrieves a specific WebSocket client wrapper by its handler identifier.

ts
static getClientByHandler(handler: string): WebsocketClient;
ParameterTypeDescription
handlerstringThe handler identifier associated with the client.

Returns

  • Type: WebsocketClient
  • Description: The client wrapper or undefined if not found.

getMessage()

Retrieves the message payload from the current context, typically used inside an 'onmessage' handler.

ts
static getMessage(): any;

Returns

  • Type: any
  • Description: The message content.

getError()

Retrieves error details from the current context, typically used inside an 'onerror' handler.

ts
static getError(): any;

Returns

  • Type: any
  • Description: The error object or string.

getMethod()

Retrieves the event method name that triggered the current script execution (e.g., "onopen", "onmessage").

ts
static getMethod(): string;

Returns

  • Type: string
  • Description: The name of the event method.

isOnOpen()

Checks if the current event context is 'onopen'.

ts
static isOnOpen(): boolean;

Returns

  • Type: boolean
  • Description: True if the method is 'onopen'.

isOnMessage()

Checks if the current event context is 'onmessage'.

ts
static isOnMessage(): boolean;

Returns

  • Type: boolean
  • Description: True if the method is 'onmessage'.

isOnError()

Checks if the current event context is 'onerror'.

ts
static isOnError(): boolean;

Returns

  • Type: boolean
  • Description: True if the method is 'onerror'.

isOnClose()

Checks if the current event context is 'onclose'.

ts
static isOnClose(): boolean;

Returns

  • Type: boolean
  • Description: True if the method is 'onclose'.