如何检测停止在Firebase中监听的客户端? [英] How to detect a client that stops listening in firebase?

查看:38
本文介绍了如何检测停止在Firebase中监听的客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有3个客户端正在监听某个Firebase根上的更改.每个客户端将自己表示为用户(在根目录中的列表(或映射)中).我想删除失去连接或关闭其客户端应用程序(即停止监听)的用户.如何检测何时发生并处理更改?

Let's say I have 3 clients that are listening for changes on some firebase root. Each client represents themselves as a user in a List (or Map) on the root. I want to remove a user that loses their connection or closes their client app (i.e. stops listening). How can I detect when this happens and handle the change?

推荐答案

超级简单.查看onDisconnect().当用户断开连接甚至更新节点中的值时,它可以将数据写出到节点.例如,在断开连接时,将用户状态(可能存储在用户节点中)更改为status:disconnected.

Super easy. Check out onDisconnect(). It can write data out to a node when the user disconnects or even update the value in a node. For example, on disconnect change the user status (maybe stored in your users node) to status:disconnected.

这篇关于如何检测停止在Firebase中监听的客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆