Detect if Firebase connection is lost/regained

firebase

Solution

This is a commonly requested feature, and we just released an API update to let you do this!

var firebaseRef = new Firebase('http://INSTANCE.firebaseio.com');
firebaseRef.child('.info/connected').on('value', function(connectedSnap) {
  if (connectedSnap.val() === true) {
    /* we're connected! */
  } else {
    /* we're disconnected! */
  }
});

Full docs are available at https://firebase.google.com/docs/database/web/offline-capabilities.

Problem

Is there a strategy that would work within the current Firebase offering to detect if the server connection is lost and/or regained? I'm considering some offline contingencies for mobile devices and I would like a reliable means to determine when the Firebase data layer is available.

Original source