Book Image

SignalR: Real-time Application Development - Second Edition

By : Einar Ingerbrigsten
Book Image

SignalR: Real-time Application Development - Second Edition

By: Einar Ingerbrigsten

Overview of this book

Table of Contents (19 chapters)
SignalR – Real-time Application Development Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
11
Hosting a Server Using Self-hosted OWIN
Index

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