mirror of https://github.com/calzoneman/sync.git
Finish most of the channel.js rewrite
This commit is contained in:
parent
89cca0d552
commit
1c79024984
1198
lib/channel-new.js
1198
lib/channel-new.js
File diff suppressed because it is too large
Load Diff
|
@ -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;
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue