From the course: Learning SignalR with ASP.NET Core

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Handle client connection events

Handle client connection events

From the course: Learning SignalR with ASP.NET Core

Start my 1-month free trial

Handle client connection events

- [Instructor] You can perform actions when a client connects or disconnects by listening to events. Handling an event when a connection is lost is especially important because SignalR clients won't automatically reconnect if they lose connection to the hub. I'll explain how to handle both connection and disconnection events. A nice feature for the support chat box would be to show a message if the client loses connection and automatically try to reconnect to the hub. Let's add some UI elements first. In the index page, right at the top of the chat dialog div, I'm gonna add another div with the ID chat connection info, and we'll just say connecting. Over in the CSS file, chat.css, I'm gonna paste some CSS code I've copied from the exercise files. This CSS will position the new connection info box above the rest of the elements if the chat dialog element has the class disconnected. Let's give it that class to start with. Class disconnected. Now, let's switch to the JavaScript and add…

Contents