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 CONNECT_TIMEOUT_IN_MS to specify the websocket connection timeout in milliseconds and use it when creating `WebSocketClient`. The default value is `0`, which means _no timeout_.
  • Loading branch information
Stefan Rehlig committed Oct 17, 2021
1 parent f2410da commit 6a7cd1d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ 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 CONNECT_TIMEOUT_IN_MS_PARAMETER = "CONNECT_TIMEOUT_IN_MS";

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

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

int connectTimeout =
this.configuration.getParameter(JSONConfiguration.CONNECT_TIMEOUT_IN_MS_PARAMETER, 0);

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

0 comments on commit 6a7cd1d

Please sign in to comment.