Skip to content

Commit b68b4c2

Browse files
committed
Update UpgradeHubService.cs
1 parent f20cad3 commit b68b4c2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/c#/GeneralUpdate.ClientCore/Hubs/UpgradeHubService.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ namespace GeneralUpdate.ClientCore.Hubs;
88
/// Upgrade the push notification service.
99
/// </summary>
1010
/// <param name="url">Subscription address, for example: http://127.0.0.1/UpgradeHub</param>
11-
public class UpgradeHubService(string url) : IUpgradeHubService
11+
/// <param name="token">ID4 authentication token string.</param>
12+
/// <param name="args">Parameters to be sent to the server upon connection (recommended as a JSON string).</param>
13+
public class UpgradeHubService(string url, string? token = null, string? args = null) : IUpgradeHubService
1214
{
1315
private const string Onlineflag = "Online";
1416
private const string ReceiveMessageflag = "ReceiveMessage";
1517

1618
private readonly HubConnection? _connection = new HubConnectionBuilder()
17-
.WithUrl(url)
19+
.WithUrl(url, config =>
20+
{
21+
if (!string.IsNullOrWhiteSpace(token))
22+
config.AccessTokenProvider = () => Task.FromResult(token);
23+
24+
if (!string.IsNullOrWhiteSpace(args))
25+
config.Headers.Add("client", args);
26+
})
1827
.WithAutomaticReconnect(new RandomRetryPolicy())
1928
.Build();
2029

0 commit comments

Comments
 (0)