You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`ServiceHubContext` provides methods to generate client endpoints and access tokens for SignalR clients to connect to Azure SignalR Service. Wrap `ServiceHubContext` into a [`IHostedService`](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-5.0) called `SignalRService` so that `ServiceHubContext` can be started and disposed when the web host started and stopped.
38
+
`ServiceHubContext` provides methods to generate client endpoints and access tokens for SignalR clients to connect to Azure SignalR Service. Wrap `ServiceHubContext` into a [`IHostedService`](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-5.0) called `SignalRService` so that `ServiceHubContext` can be started and disposed when the web host starts and stops.
39
39
40
-
In `SignalRService` class, create the `ServiceHubContext`.
40
+
In `SignalRService` class, create the `ServiceHubContext`. In the sample we have two hub, message hub and chat hub to demostrate how to set up multiple hubs. The chat hub is actually not used.
@@ -63,7 +63,6 @@ public Task StopAsync(CancellationToken cancellationToken) => HubContext?.Dispos
63
63
In the `NegotiateController` class, provide the negotiation endpoint `/negotiate?user=<User ID>`.
64
64
65
65
We use the `_hubContext` to generate a client endpoint and an access token and return to SignalR client following [Negotiation Protocol](https://github.com/aspnet/SignalR/blob/master/specs/TransportProtocols.md#post-endpoint-basenegotiate-request), which will redirect the SignalR client to the service.
66
-
67
66
```C#
68
67
[HttpPost("negotiate")]
69
68
publicasyncTask<ActionResult>Index(stringuser)
@@ -83,6 +82,16 @@ public async Task<ActionResult> Index(string user)
83
82
}
84
83
```
85
84
85
+
The sample above uses the default negotiation options. If you want to return detailed error messages to clients, you can set `EnableDetailedErrors` as follows:
> `EnableDetailedErrors` defaults to false because these exception messages can contain sensitive information.
86
95
## Full Sample
87
96
88
97
The full negotiation server sample can be found [here](.). The usage of this sample can be found [here](<https://github.com/aspnet/AzureSignalR-samples/tree/master/samples/Management#start-the-negotiation-server>).
Copy file name to clipboardExpand all lines: samples/Management/README.md
+14-6Lines changed: 14 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,10 @@ dotnet user-secrets set Azure:SignalR:ConnectionString "<Connection String>"
17
17
dotnet run
18
18
```
19
19
20
+
> Parameters of `dotnet run`
21
+
>
22
+
> --enableDetailedErrors: true to enable log detailed errors on client side, false to disable. The default value is false, as detailed errors might contain sensitive information. This is useful if you want client connection to get the exception on close.
23
+
20
24
### Start SignalR clients
21
25
22
26
```
@@ -44,13 +48,17 @@ dotnet run
44
48
Once the message publisher get started, use the command to send message
45
49
46
50
```
47
-
send user <User ID List (Separated by ',')> <Message>
48
-
send users <User List> <Message>
49
-
send group <Group Name> <Message>
50
-
send groups <Group List (Separated by ',')> <Message>
51
-
usergroup add <User ID> <Group Name>
52
-
usergroup remove <User ID> <Group Name>
51
+
send user <UserId> <Message>
52
+
send users <User1,User2,...> <Message>
53
+
send group <GroupName> <Message>
54
+
send groups <Group1,Group2,...> <Message>
55
+
usergroup add <User1,User2,...> <GroupName>
56
+
usergroup remove <UserId> <GroupName>
53
57
broadcast <Message>
58
+
close <ConnectionID> <Reason>?
59
+
checkexist connection <ConnectionID>
60
+
checkexist user <UserID>
61
+
checkexist group <GroupName>
54
62
```
55
63
For example, type `broadcast hello`, and press keyboard `enter` to publish messages.
0 commit comments