jamiewest / signalr_core

ASP.NET Core SignalR Dart Client
https://pub.dev/packages/signalr_core
MIT License
91 stars 58 forks source link

Passing data on connection #13

Closed jasson120 closed 3 years ago

jasson120 commented 4 years ago

Hi, you have TODO in code: static String _createConnectUrl(String url, String connectionToken) { if (connectionToken == null) { return url; } // TODO: Look at this... return url + '?' + 'id=$connectionToken'; //return url + (url.contains('?') ? '?' : '&') + 'id=$connectionToken'; }

And my question is do you plan change this TODO? because in this case is difficult pass data. When i set in url for example "https://test.com/Hub?userId=24" i get in server this one "https://test.com/Hub?userId=24?id=connectionToken"

jamiewest commented 4 years ago

I believe what you would want to use is the accessTokenFactory property on the HttpConnectionOptions class to pass connection related tokens to the server.

Example

final connection = HubConnectionBuilder()
   .withUrl('http://example.com', 
      HttpConnectionOptions(accessTokenFactory: () => 'MyAccessToken'))
   .build();
jasson120 commented 4 years ago

No, I would like to send the metadata in the URL to the hub for example userId. When I added parameter userId in URL("https://test.com/Hub?userId=24), then your function "_createConnectUrl" added some own parameter id=$connectionToken and resulting URL in HUB is "test.com/Hub?userId=24?id=connectionToken" and the correct result should be "test.com/Hub?userId=24&id=connectionToken".

The article what I mean: https://buildingsteps.wordpress.com/2018/10/14/signalr-metadata-for-asp-net-core-2-1/

I think you have a solution but you have it commented in function _createConnectUrl. //return url + (url.contains('?') ? '?' : '&') + 'id=$connectionToken'; }

adrianwang commented 3 years ago

https://github.com/soernt/signalr_client/blob/master/lib/http_connection.dart#L414