- Added a config system to the addons - Added options in the config for dynamic variables - Updated example and code to use new config and options
This commit is contained in:
7
server/addons/example/config.json
Normal file
7
server/addons/example/config.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "Addon 1",
|
||||
"enabled": false,
|
||||
"options": {
|
||||
"eventName": "connection"
|
||||
}
|
||||
}
|
||||
17
server/addons/example/index.js
Normal file
17
server/addons/example/index.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// addons/addon1/index.js
|
||||
|
||||
// Function called by the main application to initialize the addon
|
||||
export function initialize(nodeIo, config) {
|
||||
console.log(`Initializing ${config.name}`);
|
||||
|
||||
// Call other functions within the addon module
|
||||
registerSocketEvents(nodeIo, config);
|
||||
// Call additional initialization functions if needed
|
||||
}
|
||||
|
||||
// Function to register Socket.IO event handlers
|
||||
function registerSocketEvents(nodeIo, config) {
|
||||
nodeIo.on(config.options.eventName, (data) => {
|
||||
console.log(`Received event "${config.options.eventName}" from client:`, data);
|
||||
});
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// Function called by the main application to initialize the addon
|
||||
export function initialize(io) {
|
||||
console.log('Initializing addon1');
|
||||
|
||||
// Call other functions within the addon module
|
||||
registerSocketEvents(io);
|
||||
// Call additional initialization functions if needed
|
||||
}
|
||||
|
||||
// Function to register Socket.IO event handlers
|
||||
function registerSocketEvents(io) {
|
||||
io.on('connection', (socket) => {
|
||||
console.log('A client connected from addon1');
|
||||
|
||||
// Add more event handlers if needed
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user