Skip to content

Commit

Permalink
Enable ws connection timeout
Browse files Browse the repository at this point in the history
Add a new configuration parameter CONNECTION_TIMEOUT_IN_MS to specify the websocket connection timout in milliseconds and use it when creating `WebSocketClient`. The default value is `0`, which means _no timeout_.
  • Loading branch information
Stefan Rehlig committed Oct 15, 2021
1 parent f2410da commit cf0f1dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class JSONConfiguration {
public static final String PING_INTERVAL_PARAMETER = "PING_INTERVAL";
public static final String USERNAME_PARAMETER = "USERNAME";
public static final String PASSWORD_PARAMETER = "PASSWORD";

public static final String CONNECTION_TIMEOUT_IN_MS = "CONNECTION_TIMEOUT_IN_MS";

private final HashMap<String, Object> parameters = new HashMap<>();

private JSONConfiguration() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ public void connect(String uri, RadioEvents events) {
httpHeaders.put("Authorization", "Basic " + new String(base64Credentials));
}

long connectionTimeout = this.configuration.getParameter(JSONConfiguration.CONNECTION_TIMEOUT_IN_MS, 0);

client =
new WebSocketClient(resource, draft, httpHeaders) {
new WebSocketClient(resource, draft, httpHeaders, connectionTimeout) {
@Override
public void onOpen(ServerHandshake serverHandshake) {
logger.debug("On connection open (HTTP status: {})", serverHandshake.getHttpStatus());
Expand Down

0 comments on commit cf0f1dc

Please sign in to comment.