Finish most of the channel.js rewrite

This commit is contained in:
calzoneman 2014-01-04 23:15:54 -06:00
parent 89cca0d552
commit 1c79024984
3 changed files with 1208 additions and 42 deletions

File diff suppressed because it is too large Load Diff

48
lib/emitter.js Normal file
View File

@ -0,0 +1,48 @@
function MakeEmitter(obj) {
obj.__evHandlers = {};
obj.on = function (ev, fn) {
if (!(ev in this.__evHandlers)) {
this.__evHandlers[ev] = [];
}
this.__evHandlers[ev].push({
fn: fn,
remove: false
});
};
obj.once = function (ev, fn) {
if (!(ev in this.__evHandlers)) {
this.__evHandlers[ev] = [];
}
this.__evHandlers[ev].push({
fn: fn,
remove: true
});
};
obj.emit = function (ev /*, arguments */) {
var self = this;
var handlers = self.__evHandlers[ev];
if (!(handlers instanceof Array)) {
handlers = [];
} else {
handlers = Array.prototype.slice.call(handlers);
}
var args = Array.prototype.slice.call(arguments);
args.shift();
handlers.forEach(function (handler) {
handler.fn.apply(self, args);
if (handler.remove) {
var i = self.__evHandlers[ev].indexOf(handler);
if (i >= 0) {
self.__evHandlers[ev].splice(i, 1);
}
}
});
};
}
module.exports = MakeEmitter;

View File

@ -236,7 +236,7 @@ Server.prototype.getChannel = function (name) {
Server.prototype.unloadChannel = function (chan) {
if (chan.registered)
chan.saveDump();
chan.saveState();
chan.playlist.die();
chan.logger.close();
@ -278,7 +278,7 @@ Server.prototype.shutdown = function () {
for (var i = 0; i < this.channels.length; i++) {
if (this.channels[i].registered) {
Logger.syslog.log("Saving /r/" + this.channels[i].name);
this.channels[i].saveDump();
this.channels[i].saveState();
}
}
Logger.syslog.log("Goodbye");