English
Topic 20. The real-time client: the SignalR connection, typed events, catch-up after reconnects, presence and typing
Goal: bring the client to life: one SignalR connection per signed-in tab, the hub's events as a TypeScript discriminated union, stores that apply them, catching up with ?after= after a reconnect, presence dots and "last seen", typing indicators and a banner while the connection is down.
Where we are
The hub of topic 14 has been sending events since then; now the client listens (Fig. 20.1). No new screens appear — the existing ones start to update by themselves.
Fig. 20.1. Events from the hub to the stores
- Starting point: topic 19 — conversations work over HTTP; other users' messages appear only after reopening a chat; 38 tests pass.
- At the end of the topic messages, edits, deletions, read receipts, membership changes, presence and typing arrive live in every open tab, and a reconnect fills the gap. 49 tests pass.
Steps
- The SignalR connection — the client library · the connection's life cycle · events as a discriminated union · reconnecting · a fake for tests
- Stores that apply events — the chat list and the conversation react to events · unread counts · catching up after a reconnect · tests
- Presence and typing — who is online · "last seen" · typing indicators with throttling and expiry · the connection banner
- Checkpoint — what must work, self-check questions and exercises
Materials
- Course slides, part 4, Real time and the TypeScript client (slides "One message, end to end", "Presence and reconnects", "The Angular client", "Events as a discriminated union", "A signal store")
core/realtime/,chats.store.ts,messages.store.tsDocs/Realtime.md– the events, the client methods, presence and reconnects