Skip to content

Instantly share code, notes, and snippets.

@mikelehen
Created January 10, 2014 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikelehen/8362328 to your computer and use it in GitHub Desktop.
Save mikelehen/8362328 to your computer and use it in GitHub Desktop.
Per-session presence bits.
var presenceRef = new Firebase('https://mike.firebaseio.com/users/michael/presence');
presenceRef.root().child('.info/connected').on('value', function(s) {
if (s.val() === true) {
// we're connected. Set up presence with a per-session presence bit.
var ref = presenceRef.push();
ref.onDisconnect().remove();
ref.set(true);
}
});
presenceRef.on('value', function(s) {
// If there are any active sessions, michael is online.
if (s.hasChildren()) {
console.log('michael is online.');
} else {
console.log('michael is offline.');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment