Skip to content
Merged
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
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 @@ -31,6 +33,10 @@
private int requestIdCount = 1;
private boolean userInitiatedDisconnect = false;

/* package */ ParseLiveQueryClientImpl() {
this(getDefaultUri());
}

/* package */ ParseLiveQueryClientImpl(URI uri) {
this(uri, new TubeSockWebSocketClient.TubeWebSocketClientFactory(), Task.BACKGROUND_EXECUTOR);
}
Expand All @@ -45,6 +51,23 @@
this.webSocketClientCallback = getWebSocketClientCallback();
}

private static URI getDefaultUri() {
URL serverUrl = ParseRESTCommand.server;
if (serverUrl == null) return null;
String url = serverUrl.toString();
if (serverUrl.getProtocol().equals("https")) {
url = url.replaceFirst("https", "wss");
} else {
url = url.replaceFirst("http", "ws");
}
try {
return new URI(url);
} catch (URISyntaxException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}

@Override
public <T extends ParseObject> SubscriptionHandling<T> subscribe(ParseQuery<T> query) {
int requestId = requestIdGenerator();
Expand Down