imp(wetsock) plugin handling and implementation
This commit is contained in:
27
lib/WetSock/SocketClient.js
Normal file
27
lib/WetSock/SocketClient.js
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user