Skip to content

Commit

Permalink
set exception on connect future if socket receives failure or close w…
Browse files Browse the repository at this point in the history
…hile connecting
  • Loading branch information
Luke Gehorsam committed Mar 19, 2021
1 parent ba95f1a commit cacb383
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http://keepachangelog.com/) and this project uses [semantic versioning](http://semver.org/).

## [Unreleased]

## [2.1.3] - 2021-3-16
### Fixed
- Dispatch error callback when socket connect fails.

## [2.1.2] - 2021-3-16
### Fixed
- Properly enable protobuf-javalite for Android builds.

## [2.1.1] - 2021-02-17
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/heroiclabs/nakama/WebSocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,11 @@ public void onClosed(final WebSocket webSocket, final int code, final String rea
// Graceful socket disconnect is complete, clean up.
synchronized (lock) {
socket = null;
// TODO callback any leftover deferred items with a disconnect error message?
collationIds.clear();

if (!connectFuture.isCancelled() && !connectFuture.isDone()) {
connectFuture.setException(new Throwable("Socket closed."));
}
}
listener.onDisconnect(null);
}
Expand All @@ -291,8 +294,11 @@ public void onFailure(final WebSocket webSocket, final Throwable t, final Respon
// Socket has failed and is no longer connected, clean up.
synchronized (lock) {
socket = null;
// TODO callback any leftover deferred items with a disconnect error message?
collationIds.clear();

if (!connectFuture.isCancelled() && !connectFuture.isDone()) {
connectFuture.setException(t);
}
}

listener.onDisconnect(t);
Expand Down

0 comments on commit cacb383

Please sign in to comment.