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/Plugins/BasePlugin.js

83 lines
1.8 KiB
JavaScript
Raw Normal View History

/**
* BasePlugin class represents the base class for WetSock plugins.
*/
2024-04-02 15:57:41 +00:00
export default class BasePlugin {
#wetsock = undefined;
/**
* 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.
*/
2024-04-02 15:57:41 +00:00
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.
*/
2024-04-02 15:57:41 +00:00
onMessage(clientId, message) {}
/**
* Handle a client connection.
* @param {string} clientId - The ID of the connected client.
*/
2024-04-02 15:57:41 +00:00
onOpen(clientId) {}
/**
* Handle a client disconnection.
* @param {string} clientId - The ID of the disconnected client.
*/
2024-04-02 15:57:41 +00:00
onClose(clientId) {}
}