This repository has been archived on 2025-03-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
wetsock/lib/WetSock/SocketClient.js
2024-04-07 20:07:50 +01:00

28 lines
691 B
JavaScript

/**
* Represents a connected WebSocket client
*/
export default class SocketClient {
#id;
#ws;
/**
* Create a new websocket server client instance.
* @param {string} id - The unique identifier of the client.
* @param {ServerWebSocket} - The Socket object for sending messages.
*/
constructor(id, ws) {
this.#id = id;
this.#ws = ws;
}
/**
* Sends a message to the client
* @param {*} message - The data to be sent to the client. Will be converted to string if not a string.
*/
send(message) {
if(typeof(message) != 'string') message = JSON.stringify(message);
this.#ws.send(message);
}
}