diff --git a/package.json b/package.json index 7c1b5453..0c597651 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.14.5", + "version": "3.14.6", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/channel/channel.js b/src/channel/channel.js index f03bf47e..c20e2cb9 100644 --- a/src/channel/channel.js +++ b/src/channel/channel.js @@ -1,4 +1,3 @@ -var MakeEmitter = require("../emitter"); var Logger = require("../logger"); var ChannelModule = require("./module"); var Flags = require("../flags"); @@ -11,6 +10,7 @@ var db = require("../database"); import * as ChannelStore from '../channel-storage/channelstore'; import { ChannelStateSizeError } from '../errors'; import Promise from 'bluebird'; +import { EventEmitter } from 'events'; class ReferenceCounter { constructor(channel) { @@ -73,7 +73,6 @@ class ReferenceCounter { } function Channel(name) { - MakeEmitter(this); this.name = name; this.uniqueName = name.toLowerCase(); this.modules = {}; @@ -93,6 +92,8 @@ function Channel(name) { }); } +Channel.prototype = Object.create(EventEmitter.prototype); + Channel.prototype.is = function (flag) { return Boolean(this.flags & flag); }; @@ -114,7 +115,7 @@ Channel.prototype.waitFlag = function (flag, cb) { } else { var wait = function (f) { if (f === flag) { - self.unbind("setFlag", wait); + self.removeListener("setFlag", wait); cb(); } }; diff --git a/src/emitter.js b/src/emitter.js deleted file mode 100644 index ed487ba6..00000000 --- a/src/emitter.js +++ /dev/null @@ -1,72 +0,0 @@ -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) { - setImmediate(function () { - handler.fn.apply(self, args); - }); - - if (handler.remove) { - var i = self.__evHandlers[ev].indexOf(handler); - if (i >= 0) { - self.__evHandlers[ev].splice(i, 1); - } - } - }); - }; - - obj.unbind = function (ev, fn) { - var self = this; - if (ev in self.__evHandlers) { - if (!fn) { - self.__evHandlers[ev] = []; - } else { - var j = -1; - for (var i = 0; i < self.__evHandlers[ev].length; i++) { - if (self.__evHandlers[ev][i].fn === fn) { - j = i; - break; - } - } - - if (j >= 0) { - self.__evHandlers[ev].splice(j, 1); - } - } - } - }; -} - -module.exports = MakeEmitter; diff --git a/src/user.js b/src/user.js index 1e6612c0..6ae5dae6 100644 --- a/src/user.js +++ b/src/user.js @@ -1,17 +1,16 @@ var Logger = require("./logger"); var Server = require("./server"); var util = require("./utilities"); -var MakeEmitter = require("./emitter"); var db = require("./database"); var InfoGetter = require("./get-info"); var Config = require("./config"); var ACP = require("./acp"); var Account = require("./account"); var Flags = require("./flags"); +import { EventEmitter } from 'events'; function User(socket) { var self = this; - MakeEmitter(self); self.flags = 0; self.socket = socket; self.realip = socket._realip; @@ -103,6 +102,8 @@ function User(socket) { }); } +User.prototype = Object.create(EventEmitter.prototype); + User.prototype.die = function () { for (var key in this.socket._events) { delete this.socket._events[key]; @@ -143,7 +144,7 @@ User.prototype.waitFlag = function (flag, cb) { } else { var wait = function (f) { if (f === flag) { - self.unbind("setFlag", wait); + self.removeListener("setFlag", wait); cb(); } };