Skip to content

Commit

Permalink
Await for a successful connection to the websocket before listening t…
Browse files Browse the repository at this point in the history
…o messages
  • Loading branch information
miguelcmedeiros committed Apr 18, 2024
1 parent fb11446 commit 6ce168b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/src/socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ class PhoenixSocket {
_ws = _webSocketChannelFactory != null
? _webSocketChannelFactory!(_mountPoint)
: WebSocketChannel.connect(_mountPoint);

// Wait for the WebSocket to be ready before continuing. In case of a
// failure to connect, the future will complete with an error and will be
// caught.
await _ws!.ready;

_ws!.stream
.where(_shouldPipeMessage)
.listen(_onSocketData, cancelOnError: true)
Expand Down

0 comments on commit 6ce168b

Please sign in to comment.