|
7 | 7 | import org.json.JSONObject;
|
8 | 8 |
|
9 | 9 | import java.net.URI;
|
| 10 | +import java.net.URISyntaxException; |
| 11 | +import java.net.URL; |
10 | 12 | import java.util.concurrent.Callable;
|
11 | 13 | import java.util.concurrent.Executor;
|
12 | 14 |
|
|
23 | 25 | private final String applicationId;
|
24 | 26 | private final String clientKey;
|
25 | 27 | private final SparseArray<Subscription<? extends ParseObject>> subscriptions = new SparseArray<>();
|
26 |
| - private final URI uri; |
| 28 | + private URI uri; |
27 | 29 | private final WebSocketClientFactory webSocketClientFactory;
|
28 | 30 | private final WebSocketClient.WebSocketClientCallback webSocketClientCallback;
|
29 | 31 |
|
30 | 32 | private WebSocketClient webSocketClient;
|
31 | 33 | private int requestIdCount = 1;
|
32 | 34 | private boolean userInitiatedDisconnect = false;
|
33 | 35 |
|
| 36 | + /* package */ ParseLiveQueryClientImpl() { |
| 37 | + this(null); |
| 38 | + URL serverUrl = ParseRESTCommand.server; |
| 39 | + if (serverUrl == null) { |
| 40 | + throw new RuntimeException("serverUrl is null. " |
| 41 | + + "You must call Parse.initialize(Context)" |
| 42 | + + " before using the Parse LiveQuery library."); |
| 43 | + } else { |
| 44 | + String url = serverUrl.toString(); |
| 45 | + if (serverUrl.getProtocol().equals("https")) { |
| 46 | + url = url.replaceFirst("https", "wss"); |
| 47 | + } else { |
| 48 | + url = url.replaceFirst("http", "ws"); |
| 49 | + } |
| 50 | + try { |
| 51 | + this.uri = new URI(url); |
| 52 | + } catch (URISyntaxException e) { |
| 53 | + e.printStackTrace(); |
| 54 | + throw new RuntimeException(e.getMessage()); |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + |
34 | 59 | /* package */ ParseLiveQueryClientImpl(URI uri) {
|
35 | 60 | this(uri, new TubeSockWebSocketClient.TubeWebSocketClientFactory(), Task.BACKGROUND_EXECUTOR);
|
36 | 61 | }
|
|
0 commit comments