0

If I have a Firebase Realtime Database server app hosted in the cloud (on, say, Heroku) with a typical listener:

FirebaseOptions options = new FirebaseOptions.Builder()
    ...
FirebaseApp.initializeApp(options);
...
ref.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        ...
    }
});

and this server app goes to sleep occasionally, will it wake up for listener events? What is the mechanism that Firebase uses to talk to my server app for a listener event, is it a normal http request?

aez
  • 2,406
  • 2
  • 26
  • 46

1 Answers1

1
  • Firebase clients (such as the one that you run on your app server) typically use (web) sockets to communicate with the back-end.

  • On Heroku most likely you'll be running a web socket emulation layer on top of the native sockets.

  • In browsers where no web sockets are available, the Firebase clients fall back on long-polling.

  • The Firebase clients send periodic keep-alives to prevent the socket from timing out.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • What would be the case in an Android app. I have a db listener set in Android app. How should I wake the device whenever child is added. Putting the listener in a service doesnt wakeup the device so I might have to use a WakefulBroadcast. On the other hand, does firebase has the capacity to wake the device by any means – Hanu Aug 30 '17 at 05:31
  • 1
    The Firebase Database relies on the socket connection. If the device closes the socket, there is no way for the database client to wake up. But you can use Firebase Cloud Messaging in such a case to send a message that wakes up the device, giving the database client the chance to restore its connection and get the data. This is informally known as push-to-sync or tickle-to-sync. See my answer here: https://stackoverflow.com/a/44828984/209103 – Frank van Puffelen Aug 30 '17 at 13:44