-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -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; | ||
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. " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. checkInit is already called in the other constructor to do that check. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could extract that logic into a static util There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it
Thanks