Skip to content

Commit 1040abb

Browse files
committed
extract method
1 parent db767c0 commit 1040abb

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

ParseLiveQuery/src/main/java/com/parse/ParseLiveQueryClientImpl.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
private final String applicationId;
2626
private final String clientKey;
2727
private final SparseArray<Subscription<? extends ParseObject>> subscriptions = new SparseArray<>();
28-
private URI uri;
28+
private final URI uri;
2929
private final WebSocketClientFactory webSocketClientFactory;
3030
private final WebSocketClient.WebSocketClientCallback webSocketClientCallback;
3131

@@ -34,26 +34,7 @@
3434
private boolean userInitiatedDisconnect = false;
3535

3636
/* 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());
5738
}
5839

5940
/* package */ ParseLiveQueryClientImpl(URI uri) {
@@ -70,6 +51,25 @@
7051
this.webSocketClientCallback = getWebSocketClientCallback();
7152
}
7253

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+
7373
@Override
7474
public <T extends ParseObject> SubscriptionHandling<T> subscribe(ParseQuery<T> query) {
7575
int requestId = requestIdGenerator();

0 commit comments

Comments
 (0)