English
Topic 14. Real time with ASP.NET Core SignalR: a typed hub, groups, presence and typing indicators
Goal: deliver every change to the browsers the moment it happens: a strongly typed SignalR hub with one group per chat, the SignalR implementation of the IChatNotifier of topic 10, authentication of WebSocket connections, online presence with a grace period, typing indicators, and tests with a real SignalR client.
Where we are
The last topic of the backend (Fig. 14.1). The business layer already announces its events; now they reach the clients.
Fig. 14.1. Events from the services to the browsers
- Starting point: topic 13 — the HTTP API is complete; 85 tests pass.
AddCorestill registers theNullChatNotifier. - At the end of the topic the backend is complete and identical to the reference: 93 tests pass, 33 of them over HTTP and SignalR.
Steps
- The hub contract and connections — SignalR in short · the events clients receive · connections and groups · who is online
- The chat hub — joining the groups on connect · typing · presence with a grace period
- From services to browsers — the SignalR notifier · tokens in the query string · registering SignalR · mapping the hub
- Testing real time — a recording hub client · connecting in tests · the hub tests
- Checkpoint — what must work, self-check questions and exercises
Materials
- Course slides, part 4, Real time and the TypeScript client (slides "Connections and chat groups", "A strongly typed hub", "One message, end to end", "Presence and reconnects")
Hubs/,ChatHubTests.cs,HubClient.csDocs/Realtime.md– hub events, presence and reconnects- The C# course topic SignalR