+ 10

How do I count online users in Firebase?

I have a mini chat app! Users can't able to see how many people are using the app! I tried a lot! So, I need to show the number of people! How do I come up with? This is my code: https://code.sololearn.com/WLaG3nAnA4bF/?ref=app

13th Feb 2019, 11:57 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
5 Answers
+ 5
It really depends on the structure. The standard way is using numChildren() in class DataSnapShot. Read more: https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot.html#numChildren Good luck on developing that nice app
13th Feb 2019, 12:53 PM
Seniru
Seniru - avatar
+ 5
Seniru Pasan bro would be better if you make the code! Plz!
13th Feb 2019, 3:36 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 5
Arb Rahim Badsa I tried this one msgRef.once("value").then((snap)=>{ snap.forEach((user)=>{ console.log((user)); //i cant find what is inside }) console.log(snap.numChildren()); }); You can get the names of all the user if can provide the user properties
13th Feb 2019, 4:24 PM
Seniru
Seniru - avatar
+ 5
Seniru Pasan problem solved bro!!! Thanks for your answer !!
13th Feb 2019, 4:25 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 2
Arb Rahim Badsa can u give the ref to the active users
13th Feb 2019, 4:17 PM
Seniru
Seniru - avatar