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
Thank you.
this library is very useful!!
however, I have one issue using this in ionic.
ERROR TypeError: Cannot read property 'remove' of null
at Gathering.leave (gathering.js:49)
at HomePage.webpackJsonp.92.HomePage.logout (home.ts:114)
at Object.eval [as handleEvent] (HomePage.html:9)
at handleEvent (core.js:13589)
at callWithDebugContext (core.js:15098)
at Object.debugHandleEvent [as handleEvent] (core.js:14685)
at dispatchEvent (core.js:10004)
at core.js:10629
at HTMLButtonElement. (platform-browser.js:2628)
at t.invokeTask (polyfills.js:3)
how can i fix them?