Trigger callback even when joining an already joined room

This commit is contained in:
Damien Arrachequesne
2015-11-27 22:08:18 +01:00
parent 35a0fe0377
commit 1dfacc6647
2 changed files with 19 additions and 1 deletions

View File

@@ -222,7 +222,10 @@ Socket.prototype.packet = function(packet, opts){
Socket.prototype.join = function(room, fn){
debug('joining room %s', room);
var self = this;
if (this.rooms.hasOwnProperty(room)) return this;
if (this.rooms.hasOwnProperty(room)) {
fn && fn(null);
return this;
}
this.adapter.add(this.id, room, function(err){
if (err) return fn && fn(err);
debug('joined room %s', room);

View File

@@ -1685,6 +1685,21 @@ describe('socket.io', function(){
});
});
});
it('should always trigger the callback (if provided) when joining a room', function(done){
var srv = http();
var sio = io(srv);
srv.listen(function(){
var socket = client(srv);
sio.on('connection', function(s){
s.join('a', function(){
s.join('a', done);
});
});
});
});
});
describe('messaging many', function(){