imp(wetsock) plugin handling and implementation

This commit is contained in:
gh0sTedBuddy
2024-04-07 20:07:50 +01:00
parent 2c72652e15
commit 2a2a8c800f
4 changed files with 269 additions and 23 deletions

View File

@@ -1,17 +1,82 @@
/**
* BasePlugin class represents the base class for WetSock plugins.
*/
export default class BasePlugin {
#wetsock = undefined;
constructor() {
}
/**
* Create a new instance of BasePlugin.
*/
constructor() {}
/**
* Get the WetSock server instance.
* @returns {Object} The WetSock server instance.
* @private
*/
_getServer() {
return this.#wetsock;
}
/**
* Get a list of available actions.
* @returns {Array} The keys of available actions.
*/
actions() {
return [];
}
/**
* Initialize the plugin with the WetSock server instance.
* @param {Object} wetsock - The WetSock server instance.
*/
initialize(wetsock) {
this.#wetsock = wetsock;
}
/**
* Register an event listener.
* @param {string} event - The event name.
* @param {function} listener - The event listener function.
*/
on(event, listener) {
this.#wetsock.on(event, listener);
}
/**
* Remove an event listener.
* @param {string} event - The event name.
* @param {function} listener - The event listener function to remove.
*/
off(event, listener) {
this.#wetsock.off(event, listener);
}
/**
* Emit an event.
* @param {string} event - The event name.
* @param {...*} args - The arguments to pass to the event listeners.
*/
emit(event, ...args) {
this.#wetsock.emit(event, ...args);
}
/**
* Handle an incoming message from a client.
* @param {string} clientId - The ID of the client.
* @param {*} message - The message received from the client.
*/
onMessage(clientId, message) {}
/**
* Handle a client connection.
* @param {string} clientId - The ID of the connected client.
*/
onOpen(clientId) {}
/**
* Handle a client disconnection.
* @param {string} clientId - The ID of the disconnected client.
*/
onClose(clientId) {}
}