Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/policy #454

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
37 changes: 37 additions & 0 deletions test/transports.websocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down