Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/main/java/com/pusher/client/PusherOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class PusherOptions {
private String host = "ws.pusherapp.com";
private int wsPort = WS_PORT;
private int wssPort = WSS_PORT;
private String path = "";
private boolean useTLS = true;
private long activityTimeout = DEFAULT_ACTIVITY_TIMEOUT;
private long pongTimeout = DEFAULT_PONG_TIMEOUT;
Expand Down Expand Up @@ -183,10 +184,26 @@ public PusherOptions setWssPort(final int wssPort) {
return this;
}

/**
* The path to which connections will be made.
* <p>
* Note that if you wish to connect to a standard Pusher cluster, the
* convenience method setCluster will set the host and ports correctly from
* a single argument.
*
* @param path The path
* @return this, for chaining
*/
public PusherOptions setPath(final String path) {
this.path = path;
return this;
}

public PusherOptions setCluster(final String cluster) {
host = "ws-" + cluster + "." + PUSHER_DOMAIN;
wsPort = WS_PORT;
wssPort = WSS_PORT;
path = "";
return this;
}

Expand Down Expand Up @@ -272,10 +289,11 @@ public long getPongTimeout() {
*/
public String buildUrl(final String apiKey) {
return String.format(
"%s://%s:%s/app/%s%s",
"%s://%s:%s%s/app/%s%s",
useTLS ? WSS_SCHEME : WS_SCHEME,
host,
useTLS ? wssPort : wsPort,
path,
apiKey,
URI_SUFFIX
);
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/pusher/client/PusherOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,17 @@ public void testSetProxy() {
public void testGetProxyReturnDefaultProxy() {
assertEquals(pusherOptions.getProxy(), Proxy.NO_PROXY);
}

@Test
public void testCustomHostPortAnPathURLIsCorrect() {
pusherOptions.setHost("subdomain.example.com").setWsPort(8080).setWssPort(8181).setPath("/custom/path");
assertEquals(
pusherOptions.buildUrl(API_KEY),
"wss://subdomain.example.com:8181/custom/path/app/" +
API_KEY +
"?client=java-client&protocol=5&version=" +
PusherOptions.LIB_VERSION
);
}

}