fahad sheikh
fahad sheikh

Reputation: 19

Whatsapp like online/offline status in react native with firebase

HI Iam working on an application which shows a user status online when he is using the app and shows offline when user quits the application(using firebase). but it is not showing status offline when a user data connection is lost during the conversation.

I tried firebase, but it is only showing offline when user quits the application.

Upvotes: 0

Views: 263

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598847

I assume you're using Firebase Realtime Database onDisconnect handlers to build a presence system.


When the user quits the application, the Firebase SDK usually has enough time to call to the database server and let it know it is shutting down, so the server immediately executes the onDisconnect handlers for that client.


When the connection suddenly drops, the SDK has no opportunity to call the server, and in that case the server only notices that the client is gone when its socket times out, which may take a few minutes.

If you need to know whether the client is active sooner than that, consider having the client periodically write a so-called heartbeat value (typically the current server timestamp) to the database. You can then use that in your clients to detect when the user/app was last actively connected, and show a status based on that.

Upvotes: 1

Related Questions