Skip to content

Commit

Permalink
namespace: fix emit
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchg committed Dec 24, 2012
1 parent 5d4f90d commit dd0fd53
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,21 @@ Namespace.prototype.emit = function(ev){
if (~exports.events.indexOf(ev)) {
emit.apply(this, arguments);
} else {
for (var i = 0; i < this.sockets.length; i++) {
var socket = this.sockets[i];
this.rooms.forEach(function(room){
socket.to(room);
});
this.flags.forEach(function(flag){
socket = socket[flag];
});
socket.emit.apply(socket, arguments);
// set up packet object
var args = Array.prototype.slice.call(arguments);
var packet = { type: parser.EVENT, data: args };

if ('function' == typeof args[args.length - 1]) {
throw new Error('Callbacks are not supported when broadcasting');
}
if (this.flags.length) this.flags = [];
if (this.rooms.lenth) this.rooms = [];

this.adapter.broadcast(packet, {
rooms: this.rooms,
flags: this.flags
});

delete this.rooms;
delete this.flags;
}
return this;
};
Expand Down

0 comments on commit dd0fd53

Please sign in to comment.