Skip to content

Commit

Permalink
Inital stab at blacklisting client side events
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Oct 11, 2011
1 parent 59e4c3b commit b8f6dc7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function Manager (server, options) {
, resource: '/socket.io'
, transports: defaultTransports
, authorization: false
, blacklist: ['connect', 'disconnect']
, 'log level': 3
, 'close timeout': 25
, 'heartbeat timeout': 15
Expand Down
19 changes: 12 additions & 7 deletions lib/namespace.js
Original file line number Diff line number Diff line change
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 manager = 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)) {
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);
} else {
this.log.info('ignoring blacklisted event ' + packet.name);
}
break;

case 'disconnect':
Expand Down

0 comments on commit b8f6dc7

Please sign in to comment.