diff --git a/include/websock.js b/include/websock.js index cc82e5a2..c5509047 100644 --- a/include/websock.js +++ b/include/websock.js @@ -175,7 +175,7 @@ function Websock() { } if (this._websocket.bufferedAmount < this.maxBufferedAmount) { - if (this._sQ.length > 0) { + if (this._sQ.length > 0 && this._websocket.readyState === WebSocket.OPEN) { this._websocket.send(this._encode_message()); this._sQ = []; } diff --git a/tests/test.websock.js b/tests/test.websock.js index 7d242d3e..0918d8c3 100644 --- a/tests/test.websock.js +++ b/tests/test.websock.js @@ -180,6 +180,7 @@ describe('Websock', function() { it('should actually send on the websocket if the websocket does not have too much buffered', function () { sock.maxBufferedAmount = 10; sock._websocket.bufferedAmount = 8; + sock._websocket.readyState = 1; sock._sQ = [1, 2, 3]; var encoded = sock._encode_message();