clocksmith
clocksmith

Reputation: 6266

How to detect a client that stops listening in 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?

Upvotes: 2

Views: 380

Answers (1)

Jay
Jay

Reputation: 35657

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.

Upvotes: 4

Related Questions