Skip to content

Commit

Permalink
Merge branch 'master' of github.com:LearnBoost/socket.io into logger
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Oct 11, 2011
2 parents 10ffbd5 + 175fe85 commit d9049f6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 15 deletions.
1 change: 1 addition & 0 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function Manager (server, options) {
, resource: '/socket.io'
, transports: defaultTransports
, authorization: false
, blacklist: ['disconnect']
, 'log level': 3
, 'log colors': tty.isatty(process.stdout.fd)
, 'close timeout': 25
Expand Down
35 changes: 20 additions & 15 deletions lib/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function SocketNamespace (mgr, name) {
SocketNamespace.prototype.__proto__ = EventEmitter.prototype;

/**
* Copies emit since we override it
* Copies emit since we override it.
*
* @api private
*/
Expand Down Expand Up @@ -103,7 +103,7 @@ SocketNamespace.prototype.__defineGetter__('volatile', function () {
});

/**
* Overrides the room to relay messages to (flag)
* Overrides the room to relay messages to (flag).
*
* @api public
*/
Expand All @@ -114,7 +114,7 @@ SocketNamespace.prototype.in = SocketNamespace.prototype.to = function (room) {
};

/**
* Adds a session id we should prevent relaying messages to (flag)
* Adds a session id we should prevent relaying messages to (flag).
*
* @api public
*/
Expand All @@ -139,7 +139,7 @@ SocketNamespace.prototype.setFlags = function () {
};

/**
* Sends out a packet
* Sends out a packet.
*
* @api private
*/
Expand Down Expand Up @@ -175,9 +175,9 @@ SocketNamespace.prototype.send = function (data) {
};

/**
* Emits to everyone (override)
* Emits to everyone (override).
*
* @api private
* @api public
*/

SocketNamespace.prototype.emit = function (name) {
Expand All @@ -196,7 +196,7 @@ SocketNamespace.prototype.emit = function (name) {
* Retrieves or creates a write-only socket for a client, unless specified.
*
* @param {Boolean} whether the socket will be readable when initialized
* @api private
* @api public
*/

SocketNamespace.prototype.socket = function (sid, readable) {
Expand All @@ -208,7 +208,7 @@ SocketNamespace.prototype.socket = function (sid, readable) {
};

/**
* Sets authorization for this namespace
* Sets authorization for this namespace.
*
* @api public
*/
Expand Down Expand Up @@ -264,6 +264,7 @@ SocketNamespace.prototype.authorize = function (data, fn) {
SocketNamespace.prototype.handlePacket = function (sessid, packet) {
var socket = this.socket(sessid)
, dataAck = packet.ack == 'data'
, manager = this.manager
, self = this;

function ack () {
Expand Down Expand Up @@ -296,8 +297,7 @@ SocketNamespace.prototype.handlePacket = function (sessid, packet) {
if (packet.endpoint == '') {
connect();
} else {
var manager = this.manager
, handshakeData = manager.handshaken[sessid];
var handshakeData = manager.handshaken[sessid];

this.authorize(handshakeData, function (err, authorized, newData) {
if (err) return error(err);
Expand All @@ -322,13 +322,18 @@ SocketNamespace.prototype.handlePacket = function (sessid, packet) {
break;

case 'event':
var params = [packet.name].concat(packet.args);
// check if the emitted event is not blacklisted
if (-~manager.get('blacklist').indexOf(packet.name)) {
this.log.debug('ignoring blacklisted event `' + packet.name + '`');
} else {
var params = [packet.name].concat(packet.args);

if (dataAck) {
params.push(ack);
}
if (dataAck) {
params.push(ack);
}

socket.$emit.apply(socket, params);
socket.$emit.apply(socket, params);
}
break;

case 'disconnect':
Expand Down
39 changes: 39 additions & 0 deletions test/namespace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,44 @@ module.exports = {
}
});
})
},

'ignoring blacklisted events': function (done) {
var cl = client(++ports)
, io = create(cl)
, calls = 0
, ws;

io.set('heartbeat interval', 1);
io.set('blacklist', ['foobar']);

io.sockets.on('connection', function (socket) {
socket.on('foobar', function () {
calls++;
});
});

cl.handshake(function (sid) {
ws = websocket(cl, sid);

ws.on('open', function (){
ws.packet({
type: 'event'
, name: 'foobar'
, endpoint: ''
});
});

ws.on('message', function (data) {
if (data.type === 'heartbeat') {
cl.end();
ws.finishClose();
io.server.close();

calls.should.equal(0);
done();
}
});
});
}
};

0 comments on commit d9049f6

Please sign in to comment.