From 546107f53bd56d40fb284330f6a7d2287523fe43 Mon Sep 17 00:00:00 2001 From: Brady Gaster <41929050+bradygaster@users.noreply.github.com> Date: Thu, 31 Jan 2019 11:45:51 -0800 Subject: [PATCH] Added user code to sample (#10632) * finished #6925 * augmented per @BrennanConroy * fixed css link * added method to hub * added code from sample to file * fixed user sample * removed the email version of this sample * removed last mention of the customization * Minor edits --- aspnetcore/signalr/configuration.md | 4 ++-- aspnetcore/signalr/groups.md | 16 +--------------- aspnetcore/signalr/groups/sample/Hubs/ChatHub.cs | 5 +++++ .../groups/sample/Pages/Shared/_Layout.cshtml | 2 +- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/aspnetcore/signalr/configuration.md b/aspnetcore/signalr/configuration.md index 7f5a9dda73..71692c21d2 100644 --- a/aspnetcore/signalr/configuration.md +++ b/aspnetcore/signalr/configuration.md @@ -5,7 +5,7 @@ description: Learn how to configure ASP.NET Core SignalR apps. monikerRange: '>= aspnetcore-2.1' ms.author: bradyg ms.custom: mvc -ms.date: 09/06/2018 +ms.date: 01/29/2019 uid: signalr/configuration --- # ASP.NET Core SignalR configuration @@ -57,7 +57,7 @@ The following table describes options for configuring SignalR hubs: | Option | Default Value | Description | | ------ | ------------- | ----------- | -| `ClientTimeoutInterval` | 30 seconds | The server will consider the client disconnected if it hasn't received a message (including keep-alive) in this interval. It is possible for it to take longer than this timeout interval for the client to actually be marked disconnected, due to how this is implemented. The recommended value is double the `KeepAliveInterval` value.| +| `ClientTimeoutInterval` | 30 seconds | The server will consider the client disconnected if it hasn't received a message (including keep-alive) in this interval. It could take longer than this timeout interval for the client to actually be marked disconnected, due to how this is implemented. The recommended value is double the `KeepAliveInterval` value.| | `HandshakeTimeout` | 15 seconds | If the client doesn't send an initial handshake message within this time interval, the connection is closed. This is an advanced setting that should only be modified if handshake timeout errors are occurring due to severe network latency. For more detail on the handshake process, see the [SignalR Hub Protocol Specification](https://github.com/aspnet/SignalR/blob/master/specs/HubProtocol.md). | | `KeepAliveInterval` | 15 seconds | If the server hasn't sent a message within this interval, a ping message is sent automatically to keep the connection open. When changing `KeepAliveInterval`, change the `ServerTimeout`/`serverTimeoutInMilliseconds` setting on the client. The recommended `ServerTimeout`/`serverTimeoutInMilliseconds` value is double the `KeepAliveInterval` value. | | `SupportedProtocols` | All installed protocols | Protocols supported by this hub. By default, all protocols registered on the server are allowed, but protocols can be removed from this list to disable specific protocols for individual hubs. | diff --git a/aspnetcore/signalr/groups.md b/aspnetcore/signalr/groups.md index fffc6721ca..80318055d4 100644 --- a/aspnetcore/signalr/groups.md +++ b/aspnetcore/signalr/groups.md @@ -26,21 +26,7 @@ Send a message to a specific user by passing the user identifier to the `User` f > [!NOTE] > The user identifier is case-sensitive. -```csharp -public Task SendPrivateMessage(string user, string message) -{ - return Clients.User(user).SendAsync("ReceiveMessage", message); -} -``` - -The user identifier can be customized by creating an `IUserIdProvider`, and registering it in `ConfigureServices`. - -[!code-csharp[UserIdProvider](groups/sample/customuseridprovider.cs?range=4-10)] - -[!code-csharp[Configure service](groups/sample/startup.cs?range=21-22,39-42)] - -> [!NOTE] -> AddSignalR must be called before registering your custom SignalR services. +[!code-csharp[Configure service](groups/sample/hubs/chathub.cs?range=29-32)] ## Groups in SignalR diff --git a/aspnetcore/signalr/groups/sample/Hubs/ChatHub.cs b/aspnetcore/signalr/groups/sample/Hubs/ChatHub.cs index a53db48345..9061e73c9b 100644 --- a/aspnetcore/signalr/groups/sample/Hubs/ChatHub.cs +++ b/aspnetcore/signalr/groups/sample/Hubs/ChatHub.cs @@ -25,5 +25,10 @@ namespace SignalRChat.Hubs await Clients.Group(groupName).SendAsync("Send", $"{Context.ConnectionId} has left the group {groupName}."); } + + public Task SendPrivateMessage(string user, string message) + { + return Clients.User(user).SendAsync("ReceiveMessage", message); + } } } diff --git a/aspnetcore/signalr/groups/sample/Pages/Shared/_Layout.cshtml b/aspnetcore/signalr/groups/sample/Pages/Shared/_Layout.cshtml index 49480d5ea5..2cd7f5c8b9 100644 --- a/aspnetcore/signalr/groups/sample/Pages/Shared/_Layout.cshtml +++ b/aspnetcore/signalr/groups/sample/Pages/Shared/_Layout.cshtml @@ -13,7 +13,7 @@ - +