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(); }, 5000); });