Skip to content

Commit

Permalink
Merge pull request #108 from lavrov/websocket-send-connected
Browse files Browse the repository at this point in the history
WebSocket: only send when connected
  • Loading branch information
yurique authored Jan 10, 2022
2 parents 46c4bb5 + dec2343 commit 7f3baa7
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ class WebSocket[Receive, Send](
}

private def trySend(): Unit = {
if (js.isUndefined(maybeWS)) {
val connectedWS = maybeWS.filter(_.readyState == 1 /* OPEN */ )
if (js.isUndefined(connectedWS)) {
if (!bufferWhenDisconnected) {
sendBuffer.clear()
} else if (sendBuffer.size > bufferSize) {
sendBuffer.drop(sendBuffer.size - bufferSize)
}
}
maybeWS.foreach { ws =>
connectedWS.foreach { ws =>
sendBuffer.foreach { message =>
sender(ws, message)
}
Expand Down

0 comments on commit 7f3baa7

Please sign in to comment.