Skip to content

Get ws URI directly from server URL #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public interface ParseLiveQueryClient {

class Factory {

public static ParseLiveQueryClient getClient() {
return new ParseLiveQueryClientImpl();
}

public static ParseLiveQueryClient getClient(URI uri) {
return new ParseLiveQueryClientImpl(uri);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.json.JSONObject;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;

Expand All @@ -23,14 +25,37 @@
private final String applicationId;
private final String clientKey;
private final SparseArray<Subscription<? extends ParseObject>> subscriptions = new SparseArray<>();
private final URI uri;
private URI uri;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should keep it final, and only pass the result WSS URL when it's parsed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix it
Thanks

private final WebSocketClientFactory webSocketClientFactory;
private final WebSocketClient.WebSocketClientCallback webSocketClientCallback;

private WebSocketClient webSocketClient;
private int requestIdCount = 1;
private boolean userInitiatedDisconnect = false;

/* package */ ParseLiveQueryClientImpl() {
this(null);
URL serverUrl = ParseRESTCommand.server;
if (serverUrl == null) {
throw new RuntimeException("serverUrl is null. "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkInit is already called in the other constructor to do that check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

+ "You must call Parse.initialize(Context)"
+ " before using the Parse LiveQuery library.");
} else {
String url = serverUrl.toString();
if (serverUrl.getProtocol().equals("https")) {
url = url.replaceFirst("https", "wss");
} else {
url = url.replaceFirst("http", "ws");
}
try {
this.uri = new URI(url);
} catch (URISyntaxException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could extract that logic into a static util

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by 1040abb

}
}

/* package */ ParseLiveQueryClientImpl(URI uri) {
this(uri, new TubeSockWebSocketClient.TubeWebSocketClientFactory(), Task.BACKGROUND_EXECUTOR);
}
Expand Down