add 'drain' emit to WS

This commit is contained in:
albertyfwu
2013-03-16 16:53:26 -04:00
parent fb3dff6ab6
commit 05a0647e52

View File

@@ -82,9 +82,17 @@ WS.prototype.doOpen = function(){
*/
WS.prototype.write = function(packets){
for (var i = 0, l = packets.length; i < l; i++) {
this.socket.send(parser.encodePacket(packets[i]));
}
// encodePayload instead of encodePacket
this.writable = false;
this.socket.send(parser.encodePayload(packets));
// check periodically if we're done sending
var bufferedAmountId = this.setInterval(function() {
if (socket.bufferedAmount == 0) {
clearInterval(bufferedAmountId);
this.writable = true;
this.emit('drain');
}
}, 50);
};
/**