net/websockets
Documentation
- source: net/websockets.ts
Overview
Classes
Websockets
createWebsocket()
Creates a new WebSocket client connection to a specified URI, managed by a handler script.
tsstatic createWebsocket(uri: string, handler: string): WebsocketClient;
Parameter Type Description 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.
tsstatic 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.
tsstatic getClient(id: string): WebsocketClient;
Parameter Type Description 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.
tsstatic getClientByHandler(handler: string): WebsocketClient;
Parameter Type Description 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.
tsstatic getMessage(): any;Returns
- Type:
any- Description: The message content.
getError()
Retrieves error details from the current context, typically used inside an 'onerror' handler.
tsstatic 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").
tsstatic getMethod(): string;Returns
- Type:
string- Description: The name of the event method.
isOnOpen()
Checks if the current event context is 'onopen'.
tsstatic isOnOpen(): boolean;Returns
- Type:
boolean- Description: True if the method is 'onopen'.
isOnMessage()
Checks if the current event context is 'onmessage'.
tsstatic isOnMessage(): boolean;Returns
- Type:
boolean- Description: True if the method is 'onmessage'.
isOnError()
Checks if the current event context is 'onerror'.
tsstatic isOnError(): boolean;Returns
- Type:
boolean- Description: True if the method is 'onerror'.
isOnClose()
Checks if the current event context is 'onclose'.
tsstatic isOnClose(): boolean;Returns
- Type:
boolean- Description: True if the method is 'onclose'.
