Created
January 10, 2014 20:51
-
-
Save mikelehen/8362328 to your computer and use it in GitHub Desktop.
Per-session presence bits.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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