Gathering.js - How to use ================= Keep list (and count) of online users in a Firebase web app - by isolated rooms or globally. 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 unique 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 ser will automatically leave gathering.leave(); // When all user's have left, we can remove the room gathering.end(); ``` Let's do something with the user count and user name list ----------------- ```javascript var gathering = new Gathering(firebase.database(), 'Gathering Name'); // Attach another callback function with user list (array) // That function will be called (with the array of users) every time user list changed. 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 + ')'); } }); ```