Skip to content
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

Add option to skip getting connection id #21

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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 @@ -30,7 +30,7 @@ class MainActivity : AppCompatActivity(), HubConnectionListener, HubEventListene
}

private val authHeader = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6Ijc5NzhjMjI3LWViMGItNGMwOS1iYWEyLTEwYmE0MjI4YWE4OSIsImNlcnRzZXJpYWxudW1iZXIiOiJtYWNfYWRkcmVzc19vZl9waG9uZSIsInNlY3VyaXR5U3RhbXAiOiJlMTAxOWNiYy1jMjM2LTQ0ZTEtYjdjYy0zNjMxYTYxYzMxYmIiLCJuYmYiOjE1MDYyODQ4NzMsImV4cCI6NDY2MTk1ODQ3MywiaWF0IjoxNTA2Mjg0ODczLCJpc3MiOiJCbGVuZCIsImF1ZCI6IkJsZW5kIn0.QUh241IB7g3axLcfmKR2899Kt1xrTInwT6BBszf6aP4"
private val connection: HubConnection = WebSocketHubConnectionP2("http://192.168.1.8:5002/signalr/hubs/auth", authHeader)
private val connection: HubConnection = WebSocketHubConnectionP2("http://192.168.1.8:5002/signalr/hubs/auth", authHeader, false)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ public class WebSocketHubConnectionP2 implements HubConnection {

private String connectionId = null;
private String authHeader;
private boolean skipConnectionId;

public WebSocketHubConnectionP2(String hubUrl, String authHeader) {
public WebSocketHubConnectionP2(String hubUrl, String authHeader, boolean skipGettingConnectionId) {
this.authHeader = authHeader;
parsedUri = Uri.parse(hubUrl);
skipConnectionId = skipGettingConnectionId;
}

@Override
Expand All @@ -50,7 +52,7 @@ public synchronized void connect() {
return;

Runnable runnable;
if (connectionId == null) {
if (connectionId == null && !skipConnectionId) {
runnable = new Runnable() {
public void run() {
getConnectionId();
Expand Down Expand Up @@ -113,7 +115,9 @@ private void getConnectionId() {

private void connectClient() {
Uri.Builder uriBuilder = parsedUri.buildUpon();
uriBuilder.appendQueryParameter("id", connectionId);
if (!skipConnectionId) {
uriBuilder.appendQueryParameter("id", connectionId);
}
uriBuilder.scheme(parsedUri.getScheme().replace("http", "ws"));
Uri uri = uriBuilder.build();
Map<String, String> headers = new HashMap<>();
Expand Down