Firebase goOnline() does NOT reconnect

1,347 views
Skip to first unread message

Pierre Delannoy

unread,
Mar 6, 2016, 6:13:45 PM3/6/16
to Firebase Google Group
Hi all,

I am using Firebase with Ionic for my app development.

I have set up a presence system, to show when the user is online or not.

My concern is, if the user leaves the app in background he gets disconnected from firebase after a while. (so far, so good)
I have a checkOnline() function on resuming the app, to check if the connection is still up with firebase, to make sure his actions are actually sent to the database. (nothing worse than a user believing his actions worked when they never got sent and firebase makes it look like it worked becauseo of offline capabilities)

This function looks like that:

$rootScope.checkOnline = function() {
  var isOnline = new Firebase('https://myapp.firebaseio.com/.info/connected');
  isOnline.on('value', function(snapshot) {
console.log(snapshot.val());
if (snapshot.val()) {
return;
}
else {
    Firebase.goOnline();
}
  });
}

But this Firebase.goOnline() does not work!
If I have left the app in background for more than a few minutes, it seems like it doesn't reconnect anything..

Any help, please?

Kato Richardson

unread,
Mar 7, 2016, 3:34:53 PM3/7/16
to Firebase Google Group
Hi Pierre,

One thing that can help you get some insights into the process is to turn on debug logging and check out the console output:

JS:  Firebase.enableLogging(true);
iOS:  [Firebase setLoggingEnabled:YES];
Android:  Firebase.getDefaultConfig().setLogLevel(Logger.Level.DEBUG);

Note that, in your specific case, there's nothing Firebase (or you) can do at the point that the app is backgrounded. That's entirely the purview of the OS and it can (and does!) close socket connections on backgrounded apps. Using a push notifications of some sort may be the only automated way to wake the app up again.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/ddbd2074-5753-4810-a668-0c97e4e98b57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pierre Delannoy

unread,
Mar 9, 2016, 9:09:50 AM3/9/16
to Firebase Google Group
Hi Kato,

Thanks for taking the time to answer.

I know there is nothing we can do about the app being in the background.
What I was hoping for is that, once I'm back in my app and I do a call toward firebase, it would open the socket again if it was closed forcefully (because of timeout) before.

Anyway, it seems that the only way to not get surprised by "forever dead socket" is to manually close/open them using firebase.goOffline() on pausing the app, and firebase.goOnline() on resuming.
Although it creates a slight lag on resume, it's the best solution so far.

Kato Richardson

unread,
Mar 9, 2016, 10:43:02 AM3/9/16
to Firebase Google Group
When the app is restored to the foreground, the connections should be reopened automatically.

Try the debug logging and see if that offers any clues.

Reply all
Reply to author
Forward
0 new messages