Skip to content
Merged
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
33 changes: 33 additions & 0 deletions lib/transports/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,44 @@ WS.prototype.doOpen = function(){
*/

WS.prototype.write = function(packets){
var self = this;
this.writable = false;
// encodePacket efficient as it uses WS framing
// no need for encodePayload
for (var i = 0, l = packets.length; i < l; i++) {
this.socket.send(parser.encodePacket(packets[i]));
}
function ondrain() {
self.writable = true;
self.emit('drain');
}
// check periodically if we're done sending
if ('bufferedAmount' in this.socket) {
this.bufferedAmountId = this.setInterval(function() {
if (self.socket.bufferedAmount == 0) {
clearInterval(self.bufferedAmountId);
ondrain();
}
}, 50);
} else {
// fake drain
// defer to next tick to allow Socket to clear writeBuffer
setTimeout(ondrain, 0);
}
};

/**
* Called upon close
*
* @api private
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n


WS.prototype.onClose = function(){
// stop checking to see if websocket is done sending buffer
clearInterval(this.bufferedAmountId);
Transport.prototype.onClose.call(this);
}

/**
* Closes socket.
*
Expand Down