Gathering.js - How to use ================= Keep list (and count) of online users in a Firebase web app - by isolated rooms or globally. Live Demo ------------ [Firebase Shared Checklist](https://fir-app-4125e.firebaseapp.com/) is a demo application that shows the number of users joined a checklist using gathering.js. Here is a [1 minute screencast](https://www.youtube.com/watch?v=buqgHLBe48A) of using this application. You may have a look at the [source code](https://github.com/ajaxray/shared-checklist) to see example usages. Initialization -------------- ```javascript firebase.initializeApp({...}); // default/global gathering var onlineUsers = new Gathering(firebase.database()); // Create an isolated space var chatroom = new Gathering(firebase.database(), 'Special Name'); ``` Joining, Leaving and Ending (removing) a gathering --------------- ```javascript var gathering = new Gathering(firebase.database(), 'Gathering Name'); // Join Anonymously gathering.join(); // Or Join with a unique id // This will ensure distinct presense of a user, even if opened on multiple browser tab or device gathering.join(firebase.auth().currentUser.uid); // Also can set a display name (along with or without unique id) gathering.join(null, 'Superman'); gathering.join(firebase.auth().currentUser.uid, 'Superman'); // When I am finished with the gathering, I may leave // When browser is closed/refreshed, current user will automatically leave gathering.leave(); // When all user's have left, or the meetup is over, we can remove the gathering gathering.over(); ``` Let's do something with the user count and user name list ----------------- ```javascript var gathering = new Gathering(firebase.database(), 'Gathering Name'); // Attach a callback function to track updates // That function will be called (with the user count and array of users) every time user list updated gathering.onUpdated(function(count, users) { console.log(gathering.roomName + ' have '+ count +' members.'); console.log('Here is the updated users list -'); for(var i in users) { console.log(users[i] + '(id: '+ i + ')'); } }); ```