1
ModuleServerAPILibsWebSocketLib
Mees van der Wijk edited this page 2023-04-05 12:21:02 +02:00

ModuleServerAPI LibWebSocket

Class representing the ModuleServerAPI LibWebSocket.

Functions

on

Register a listener for messages from a LibWebSocketClient.

api.Libs.getWebSocket().on(header, callback);
Argument Type Description
header string To header of the messages the listener will receive.
callback ( client:LibWebSocketClient, ...args:any[] ):void Function that receives the incomming message and arguments.

onClientConnect

Assigns an event to be triggered when a new LibWebSocketClient connects.

api.Libs.getWebSocket().onClientConnect(callback);
Argument Type Description
callback ( client:LibWebSocketClient ):void Function will be called when a new LibWebSocketClient connects.

onClientDisconnect

Assigns an event to be triggered when a LibWebSocketClient disconnects.

api.Libs.getWebSocket().onClientDisconnect(callback);
Argument Type Description
callback ( socketId:string ):void Function will be called when a LibWebSocketClient disconnects.

getClients

Get the connected LibWebSocketClients.

api.Libs.getWebSocket().getClient(socketId);
Argument Type Description
socketId string The id of the socket client.

Return LibWebSocketClient Socket client

getClient

Get a specific LibWebSocketClient.

api.Libs.getWebSocket().getClient(socketId);
Argument Type Description
socketId string The id of the socket client.

Return LibWebSocketClient Socket client

broadcast

Broadcasts a message to all connected LibWebSocketClients.

api.Libs.getWebSocket().broadcast(header, ...args);
Argument Type Description
header string The header of the message.
args any[] Data of any type.

rawBroadcast

Broadcasts a raw message to all connected LibWebSocketClients.

api.Libs.getWebSocket().rawBroadcast(data);
Argument Type Description
data string Buffer DataView number ArrayBufferView Uint8Array ArrayBuffer SharedArrayBuffer ReadonlyArray ReadonlyArray { valueOf(): ArrayBuffer } { valueOf(): SharedArrayBuffer } { valueOf(): Uint8Array } { valueOf(): ReadonlyArray } { valueOf(): string } { [Symbol.toPrimitive](hint: string): string }; The data of the message.