Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add nsp prefix to socket.id
  • Loading branch information
nkzawa authored and darrachequesne committed Jan 10, 2017
commit 9d518f1fd80e806f4293f02d87f2297f55928cc2
16 changes: 14 additions & 2 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,23 @@ Manager.prototype.emitAll = function () {
Manager.prototype.updateSocketIds = function () {
for (var nsp in this.nsps) {
if (has.call(this.nsps, nsp)) {
this.nsps[nsp].id = this.engine.id;
this.nsps[nsp].id = this.generateId(nsp);
}
}
};

/**
* generate `socket.id` for the given `nsp`
*
* @param {String} nsp
* @return {String}
* @api private
*/

Manager.prototype.generateId = function (nsp) {
return nsp + '#' + this.engine.id;
};

/**
* Mix in `Emitter`.
*/
Expand Down Expand Up @@ -358,7 +370,7 @@ Manager.prototype.socket = function (nsp, opts) {
var self = this;
socket.on('connecting', onConnecting);
socket.on('connect', function () {
socket.id = self.engine.id;
socket.id = self.generateId(nsp);
});

if (this.autoConnect) {
Expand Down
4 changes: 2 additions & 2 deletions test/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ var io = require('../');
describe('socket', function () {
this.timeout(70000);

it('should have an accessible socket id equal to the engine.io socket id', function (done) {
it('should have an accessible socket id equal to nsp + the engine.io socket id', function (done) {
var socket = io({ forceNew: true });
socket.on('connect', function () {
expect(socket.id).to.be.ok();
expect(socket.id).to.eql(socket.io.engine.id);
expect(socket.id).to.eql('/#' + socket.io.engine.id);
socket.disconnect();
done();
});
Expand Down