WebSocket class

The Zyno Bot Addons WebSocket class extends the NodeJS built-in EventEmitter class.

const websocket = new WebSocket(socket: WebSocket, handler: WebSocketHandler);

constructor

The constructor of the WebSocket class requires two arguments. The first argument must be an instance of the WS WebSocket class which provides the data for the WebSocket. The second argument must be an instance of the Zyno Bot Addons WebSocketHandler class which handles the WebSockets.

Properties

id

A randomly generated unique id to identify the WebSocket.

Functions

send

websocket.send(data: string | Buffer) : void;

Send a response to the client side of the WebSocket.

ArgumentDescription

data

A string or instance of the Buffer class which defines the data you'd like to send to the client side of the WebSocket.

close

websocket.close() : void;

Closes the connection between the server and the client side of the websocket.

Events

EventDescriptionArguments

message

Gets emitted when the client side of the WebSocket sends a message to the server side.

string

close

Gets emitted when the connection between the server and the client side of the websocket gets closed.

None

Last updated