|
25 | 25 | private final String applicationId;
|
26 | 26 | private final String clientKey;
|
27 | 27 | private final SparseArray<Subscription<? extends ParseObject>> subscriptions = new SparseArray<>();
|
28 |
| - private URI uri; |
| 28 | + private final URI uri; |
29 | 29 | private final WebSocketClientFactory webSocketClientFactory;
|
30 | 30 | private final WebSocketClient.WebSocketClientCallback webSocketClientCallback;
|
31 | 31 |
|
|
34 | 34 | private boolean userInitiatedDisconnect = false;
|
35 | 35 |
|
36 | 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 |
| - } |
| 37 | + this(getDefaultUri()); |
57 | 38 | }
|
58 | 39 |
|
59 | 40 | /* package */ ParseLiveQueryClientImpl(URI uri) {
|
|
70 | 51 | this.webSocketClientCallback = getWebSocketClientCallback();
|
71 | 52 | }
|
72 | 53 |
|
| 54 | + private static URI getDefaultUri() { |
| 55 | + URL serverUrl = ParseRESTCommand.server; |
| 56 | + if (serverUrl != null) { |
| 57 | + String url = serverUrl.toString(); |
| 58 | + if (serverUrl.getProtocol().equals("https")) { |
| 59 | + url = url.replaceFirst("https", "wss"); |
| 60 | + } else { |
| 61 | + url = url.replaceFirst("http", "ws"); |
| 62 | + } |
| 63 | + try { |
| 64 | + return new URI(url); |
| 65 | + } catch (URISyntaxException e) { |
| 66 | + e.printStackTrace(); |
| 67 | + throw new RuntimeException(e.getMessage()); |
| 68 | + } |
| 69 | + } |
| 70 | + return null; |
| 71 | + } |
| 72 | + |
73 | 73 | @Override
|
74 | 74 | public <T extends ParseObject> SubscriptionHandling<T> subscribe(ParseQuery<T> query) {
|
75 | 75 | int requestId = requestIdGenerator();
|
|
0 commit comments