Keep list (and count) of online users in a Firebase web app - by isolated rooms or globally.
Let's create a new gathering
firebase.initializeApp({...});
var gathering = new Gathering(firebase.database(), 'A Room Name');
Now you'll have the following functions and properties to work with -
gathering.join(uid, displayName)
- Add me to gathering. Optionally can provide aunique id
anddisplayName
.gathering.leave()
- Leave (that means remove myself from) the gatheringgathering.over()
- Remove gathering from databasegathering.onUpdated(callback)
- That function will be called (with user count and hash of users as param) every time the user list changedgathering.roomName
- The gathering namegathering.myName
- Current users's name in gathering, if joinedgathering.room
- Firebase Database reference to the gathering room. Can be listened for removal or anything.
To see the usages in more details, please check the firebase-online-user-count-example.md file
I don't know if I will get an answer to this but let me ask hoping that I do
Thank you for this awesome library, I am faced with an issue of the online users duplicating after a page refresh.
When a user logs in, the count is accurate and online users too are accurate but when one of the users logs out or closes his/her browser, the users that are still logged in can see the count reduce by 1 but the logged out user name still appears.
Let assume, I have the following list as online users;
User1
User2
User3
After User1 closes the tab, this is what I would have;
User1
User2
User3
User2
User3
Any help would be appreciated, I tried modifying the code to something like this;
let unique_users = array_unique(users);
for(var i in unique_users)
but I am still getting the same results.
but I still get the same result.