Skip to content

Commit

Permalink
Merge pull request #130 from roamm/packet_send_callback
Browse files Browse the repository at this point in the history
Fixed packet send callback issues
  • Loading branch information
rauchg committed Dec 26, 2012
2 parents 9d9fe9e + 0dfa68c commit 3c968fc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ Socket.prototype.setupSendCallback = function () {
if ('function' == typeof seqFn) {
debug('executing send callback');
seqFn(self.transport);
} else if (Array.isArray(seqFn)) {
debug('executing batch send callback');
for (var i in seqFn) {
if ('function' == typeof seqFn) {
seqFn[i](self.transport);
}
}
}
}
});
Expand Down Expand Up @@ -288,9 +295,8 @@ Socket.prototype.sendPacket = function (type, data, callback) {
this.writeBuffer.push(packet);

//add send callback to object
if (callback) {
this.packetsFn.push(callback);
}
this.packetsFn.push(callback);

this.flush();
}
};
Expand All @@ -309,6 +315,9 @@ Socket.prototype.flush = function () {
this.server.emit('flush', this, this.writeBuffer);
var wbuf = this.writeBuffer;
this.writeBuffer = [];
if (!this.transport.supportsFraming) {
this.packetsFn = [this.packetsFn];
}
this.transport.send(wbuf);
this.emit('drain');
this.server.emit('drain', this);
Expand Down
8 changes: 8 additions & 0 deletions lib/transports/flashsocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ FlashSocket.prototype.__proto__ = WebSocket.prototype;

FlashSocket.prototype.name = 'flashsocket';

/**
* Advertise framing support.
*
* @api public
*/

FlashSocket.prototype.supportsFraming = true;

/**
* Listens for new configuration changes of the Manager
* this way we can enable and disable the flash server.
Expand Down
8 changes: 8 additions & 0 deletions lib/transports/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ WebSocket.prototype.name = 'websocket';

WebSocket.prototype.handlesUpgrades = true;

/**
* Advertise framing support.
*
* @api public
*/

WebSocket.prototype.supportsFraming = true;

/**
* Processes the incoming data.
*
Expand Down

0 comments on commit 3c968fc

Please sign in to comment.