mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-05 04:07:23 +02:00
Major changes around events, event log, etc.
* User event log is now functional & attached to various events * Add additional missing system events * Completely re-write last_callers to have new functionality, etc. * Events.addListenerMultipleEvents() * New 'moduleInitialize' export for module init vs Event specific registerEvents * Add docs on last_callers mod
This commit is contained in:
parent
c1ae3d88ba
commit
52585c78f0
16 changed files with 392 additions and 171 deletions
|
@ -1,20 +1,14 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
const paths = require('path');
|
||||
const events = require('events');
|
||||
const Log = require('./logger.js').log;
|
||||
const SystemEvents = require('./system_events.js');
|
||||
|
||||
// deps
|
||||
const _ = require('lodash');
|
||||
const async = require('async');
|
||||
const glob = require('glob');
|
||||
|
||||
module.exports = new class Events extends events.EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
this.setMaxListeners(32); // :TODO: play with this...
|
||||
this.setMaxListeners(64); // :TODO: play with this...
|
||||
}
|
||||
|
||||
getSystemEvents() {
|
||||
|
@ -41,39 +35,21 @@ module.exports = new class Events extends events.EventEmitter {
|
|||
return super.once(event, listener);
|
||||
}
|
||||
|
||||
addListenerMultipleEvents(events, listener) {
|
||||
Log.trace( { events }, 'Registring event listeners');
|
||||
events.forEach(eventName => {
|
||||
this.on(eventName, event => {
|
||||
listener(eventName, event);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
removeListener(event, listener) {
|
||||
Log.trace( { event : event }, 'Removing listener');
|
||||
return super.removeListener(event, listener);
|
||||
}
|
||||
|
||||
startup(cb) {
|
||||
async.each(require('./module_util.js').getModulePaths(), (modulePath, nextPath) => {
|
||||
glob('*{.js,/*.js}', { cwd : modulePath }, (err, files) => {
|
||||
if(err) {
|
||||
return nextPath(err);
|
||||
}
|
||||
|
||||
async.each(files, (moduleName, nextModule) => {
|
||||
const fullModulePath = paths.join(modulePath, moduleName);
|
||||
|
||||
try {
|
||||
const mod = require(fullModulePath);
|
||||
|
||||
if(_.isFunction(mod.registerEvents)) {
|
||||
// :TODO: ... or just systemInit() / systemShutdown() & mods could call Events.on() / Events.removeListener() ?
|
||||
mod.registerEvents(this);
|
||||
}
|
||||
} catch(e) {
|
||||
Log.warn( { error : e }, 'Exception during module "registerEvents"');
|
||||
}
|
||||
|
||||
return nextModule(null);
|
||||
}, err => {
|
||||
return nextPath(err);
|
||||
});
|
||||
});
|
||||
}, err => {
|
||||
return cb(err);
|
||||
});
|
||||
return cb(null);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue