The bufferedAmount property is good for your application to control how much messages you can send (to avoid memory overhead), but it works only if you disable perMessageDeflate.
I propose to extend the property by calculating _sender.queue size as well.
Example:
get bufferedAmount () {
var amount = 0;
var senderQueueSize = 0;
if (this._socket) amount = this._socket.bufferSize || 0;
if (this._sender && this._sender.queue) {
for (i = 0; i < this._sender.queue.length; i += 1) {
senderQueueSize += this._sender.queue[i].data.length;
}
}
return amount + senderQueueSize;
}
The best solution is to avoid cycle at all by adding queueSize variable to _sender and add/subtract length when adding a new element to queue.
get bufferedAmount () {
var amount = 0;
var senderQueueSize = 0;
if (this._socket) amount = this._socket.bufferSize || 0;
return amount + this._sender.queueSize;
}
The bufferedAmount property is good for your application to control how much messages you can send (to avoid memory overhead), but it works only if you disable perMessageDeflate.
I propose to extend the property by calculating _sender.queue size as well.
Example:
The best solution is to avoid cycle at all by adding queueSize variable to _sender and add/subtract length when adding a new element to queue.