Skip to content

Commit

Permalink
Use EventEmitter public API instead of the private _events array
Browse files Browse the repository at this point in the history
  • Loading branch information
christiaan committed May 28, 2010
1 parent 7f5228a commit dc593e9
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/socket.io/listener.js
Expand Up @@ -27,17 +27,15 @@ Listener = this.Listener = Class({
this.clients = [];
this.clientsIndex = {};

var listener = (this.server._events['request'] instanceof Array)
? this.server._events['request'][0]
: this.server._events['request'];
if (listener){
this.server._events['request'] = function(req, res){
if (self.check(req, res)) return;
listener(req, res);
};
} else {
throw new Error('Couldn\'t find the `request` event in the HTTP server.');
}
var listeners = this.server.listeners('request');
this.server.removeAllListeners('request');

this.server.addListener('request', function(req, res){
if (self.check(req, res)) return;
for (var i = 0; i < listeners.length; i++) {
listeners[i].call(this, req, res);
}
});

this.server.addListener('upgrade', function(req, socket, head){
if (!self.check(req, socket, true)){
Expand Down

0 comments on commit dc593e9

Please sign in to comment.