firebasefirebase-realtime-databaseuser-presence

Firebase Realtime Database - using onDisconnect for Presence


I am trying to implement a presence feature in my Firestore app, for orientation I was using the suggested google solution that can be found in the link below (hybrid solution using Firebase Realtime Database and cloud functions):

https://firebase.google.com/docs/firestore/solutions/presence

I was hoping that the .onDisconnect would fire when I lose internet connection however that only happens after about 60seconds. Is that the normal behaviour of that method or did I do something wrong? I would love if that happened much quicker than that. Any firebase people who can explain what happens under the hood here? Couldn't find anything about triggering conditions for Firebase.Database.onDisconnect. Thank you so much.


Solution

  • This is the expected behavior. It takes that amount of time to discern if the connection is actually lost, or instead just temporarily blocked for whatever reason. Basically, 60 seconds is the "timeout" until a read or write on the socket between your client app and the server is expected to complete.