Skip to content

Commit

Permalink
Only send messages when the websocket is up
Browse files Browse the repository at this point in the history
  • Loading branch information
gustafg committed Oct 26, 2017
1 parent 2751e54 commit 8031f99
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ class Avanza extends EventEmitter {
}

_socketSend(data) {
this._socket.send(JSON.stringify([data]))
this._socketMessageCount += 1
if (this._socket && this._socket.readyState === this._socket.OPEN) {
this._socket.send(JSON.stringify([data]))
this._socketMessageCount += 1
}
}

_socketHandleMessage(data) {
Expand Down

0 comments on commit 8031f99

Please sign in to comment.