diff --git a/lib/manager.js b/lib/manager.js index b5f32dbb10..6530b7d30d 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -71,7 +71,7 @@ function Manager (server, options) { , 'heartbeat interval': 20 , 'polling duration': 20 , 'flash policy server': true - , 'flash policy port': 843 + , 'flash policy port': 10843 , 'destroy upgrade': true , 'browser client': true , 'browser client minification': false diff --git a/lib/socket.js b/lib/socket.js index 22a8abf41a..fe34e33447 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -50,13 +50,33 @@ Socket.prototype.__proto__ = EventEmitter.prototype; /** * Accessor shortcut for the handshake data * - * @api private + * @api public */ Socket.prototype.__defineGetter__('handshake', function () { return this.manager.handshaken[this.id]; }); +/** + * Accessor shortcut to see which rooms the socket has joined + * + * @api public + */ + +Socket.prototype.__defineGetter__('rooms', function () { + return Object.keys(this.manager.roomClients[this.id]) + .map(function (room) { + if (room && room[0] === '/') { + return room.slice(1); + } + + return; + }) + .filter(function (room) { + return !!room; + }); +}); + /** * Accessor shortcut for the logger. * diff --git a/test/transports.websocket.test.js b/test/transports.websocket.test.js index 4b9ff6150f..e3b9b15019 100644 --- a/test/transports.websocket.test.js +++ b/test/transports.websocket.test.js @@ -952,6 +952,43 @@ module.exports = { }); }, + 'test room lookup': function (done) { + var port = ++ports + , cl = client(port) + , io = create(cl) + , joins = 0 + , disconnects = 0; + + io.set('close timeout', 0); + + io.sockets.on('connection', function (socket) { + socket.join('foo'); + socket.join('bar'); + + console.log(socket.rooms); + socket.rooms.indexOf('foo').should.be.above(-1); + socket.rooms.indexOf('bar').should.be.above(-1); + socket.rooms.indexOf('baz').should.eql(-1); + + socket.on('disconnect', function () { + io.server.close(); + cl.end(); + done(); + }) + }); + + cl.handshake(function (sid) { + var ws = websocket(cl, sid); + ws.on('message', function (msg) { + if (!ws.connected) { + msg.type.should.eql('connect'); + ws.connected = true; + ws.finishClose(); + } + }); + }); + }, + 'test message with broadcast flag': function (done) { var port = ++ports , cl1 = client(port)