imp(wetsock) plugin handling and implementation
This commit is contained in:
@@ -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) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user