Skip to content

Commit

Permalink
[feature] Add support for all event emitter methods (#2601)
Browse files Browse the repository at this point in the history
  • Loading branch information
perrin4869 authored and darrachequesne committed Nov 5, 2016
1 parent 6f44f3a commit e9f980c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var engine = require('engine.io');
var client = require('socket.io-client');
var clientVersion = require('socket.io-client/package').version;
var Client = require('./client');
var Emitter = require('events').EventEmitter;
var Namespace = require('./namespace');
var Adapter = require('socket.io-adapter');
var debug = require('debug')('socket.io:server');
Expand Down Expand Up @@ -372,7 +373,11 @@ Server.prototype.close = function(){
* Expose main namespace (/).
*/

['on', 'to', 'in', 'use', 'emit', 'send', 'write', 'clients', 'compress'].forEach(function(fn){
var emitterMethods = Object.keys(Emitter.prototype).filter(function(key){
return typeof Emitter.prototype[key] === 'function';
});

emitterMethods.concat(['to', 'in', 'use', 'send', 'write', 'clients', 'compress']).forEach(function(fn){
Server.prototype[fn] = function(){
var nsp = this.sockets[fn];
return nsp.apply(this.sockets, arguments);
Expand Down

0 comments on commit e9f980c

Please sign in to comment.