Hi Evans,
This may not be clear from the presence docs guide, but the way you would do this is that you'd actually store everyone's presence status in Firebase itself. You could create a /presence/ node which has child keys which are people's uids. When a user arrives, you add them to the /presence/ node, indicating that they are currently online. So the node will look something like this:
{
"presence": {
"simplelogin:25151": true,
"facebook:958163": true,
...
}
}
When a user loses connection, you want to remove them from the /presence/ node. You can do this via a combination of .info/connected and onDisconnect(). The entire thing would look like this:
ref.child(".info/connected").on("value", function(snapshot) {
if (snapshot.val() === true) {
// We're connected (or reconnected)! Do anything here that should happen only if online (or on reconnect).
// Get a reference to the logged-in user's presence ref
var userPresenceRef = ref.child("presence").child(uid);
// Add the user to the presence ref
userPresenceRef.set(true);
// When the user is disconnected, remove them from the presence ref
userPresenceRef.onDisconnect().remove();
}
});
Now, any other user can just listen for the uid of the person they are talking to and if that user is removed from the /presence/ node, they know that user went offline.
Hope that helps,
Jacob