O'Reilly logo

SignalR - Real-time Application Development - Second Edition by Einar Ingebrigtsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Life cycle events

With hubs, there is a full set of events you can subscribe to, to deal with the life cycle.

The events you have are as follows:

connectionSlow
reconnecting
reconnected
disconnected

All of these events can be useful, not only for your application but also for notifying the user as to what is going on. This is especially true for slow connections and disconnected:

$.connection.hub.connectionSlow(function() {
    // Notify user about slow connection
});
$.connection.hub.disconnected(function() {
    // Notify user about being disconnected
});

For disconnected connections, you might want to retry connecting after a certain amount of time out; for instance, after 5 seconds:

$.connection.hub.disconnected(function() { setTimeout(function() { $.connection.hub.start(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required