简体   繁体   English

Whatsapp 喜欢在线/离线状态与 firebase 反应本机

[英]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).嗨,我正在开发一个应用程序,该应用程序在用户使用该应用程序时显示在线用户状态,并在用户退出应用程序(使用 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.我试过 firebase,但它只在用户退出应用程序时显示离线。

I assume you're using Firebase Realtime Database onDisconnect handlers to build a presence system .我假设您正在使用 Firebase Realtime Database onDisconnect处理程序构建状态系统


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.当用户退出应用程序时,Firebase SDK 通常有足够的时间调用数据库服务器并让它知道它正在关闭,因此服务器会立即为该客户端执行onDisconnect处理程序。


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.当连接突然断开时,SDK 没有机会调用服务器,此时服务器只有在其套接字超时时才注意到客户端已经消失,这可能需要几分钟。

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.然后,您可以在客户端中使用它来检测用户/应用程序最后一次主动连接的时间,并基于此显示状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM