I have a webapp where users can join a variable number of chatrooms. The firestore collection looks like this:
chatrooms: {
"g4HL09vHfkaO3": {
"name": "Chatroom 1",
"messages": ...
},
"lpScgY74gHJ87": {
"name": "Chatroom 2",
"messages": ...
}
}
When the user joins a chatroom, the webapp will attach a listener to the given document in order to get the messages and receive incoming ones, e.g.:
unsubscribe = firebase
.firestore()
.collection("chatrooms")
.doc("g4HL09vHfkaO3")
.onSnapshot( ... )
and when the user leave the chatroom, the app will detach the listener like this:
unsubscribe()
Now my goal is to display in the app the amount of users currently inside a given chatroom, so the question is:
- is it possible to get from firebase the global number of listeners attached to e.g. chatroom
g4HL09vHfkaO3
? - if not, what is the most straightforward way to achive what I want?