Skip to content

Commit

Permalink
[fix] Reset rooms object before broadcasting from namespace (socketio…
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne authored Aug 26, 2017
1 parent 6343b9f commit 0aa49ed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
33 changes: 19 additions & 14 deletions lib/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,28 @@ Namespace.prototype.remove = function(socket){
Namespace.prototype.emit = function(ev){
if (~exports.events.indexOf(ev)) {
emit.apply(this, arguments);
} else {
// set up packet object
var args = Array.prototype.slice.call(arguments);
var packet = { type: parser.EVENT, data: args };
return this;
}
// 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 ('function' == typeof args[args.length - 1]) {
throw new Error('Callbacks are not supported when broadcasting');
}

this.adapter.broadcast(packet, {
rooms: this.rooms,
flags: this.flags
});
var rooms = this.rooms.slice(0);
var flags = Object.assign({}, this.flags);

// reset flags
this.rooms = [];
this.flags = {};

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

this.rooms = [];
this.flags = {};
}
return this;
};

Expand Down
5 changes: 2 additions & 3 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var Emitter = require('events').EventEmitter;
var parser = require('socket.io-parser');
var url = require('url');
var debug = require('debug')('socket.io:socket');
var assign = require('object-assign');

/**
* Module exports.
Expand Down Expand Up @@ -115,7 +114,7 @@ Socket.prototype.buildHandshake = function(query){
function buildQuery(){
var requestQuery = url.parse(self.request.url, true).query;
//if socket-specific query exist, replace query strings in requestQuery
return assign({}, query, requestQuery);
return Object.assign({}, query, requestQuery);
}
return {
headers: this.request.headers,
Expand Down Expand Up @@ -160,7 +159,7 @@ Socket.prototype.emit = function(ev){
}

var rooms = this._rooms.slice(0);
var flags = assign({}, this.flags);
var flags = Object.assign({}, this.flags);

// reset flags
this._rooms = [];
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"dependencies": {
"debug": "~2.6.6",
"engine.io": "~3.1.0",
"object-assign": "~4.1.1",
"socket.io-adapter": "~1.1.0",
"socket.io-client": "~2.0.2",
"socket.io-parser": "~3.1.1"
Expand Down

0 comments on commit 0aa49ed

Please sign in to comment.