Skip to content

Instantly share code, notes, and snippets.

@adamyeats-zz
Last active December 25, 2015 04:59
Show Gist options
  • Save adamyeats-zz/6921501 to your computer and use it in GitHub Desktop.
Save adamyeats-zz/6921501 to your computer and use it in GitHub Desktop.
Presence channel queueing
var pusher = new Pusher(PUSHER_KEY, { authEndpoint: 'pusher_auth.php' });
// use three channels, one for users waiting in the queue (waiting)
// another for users connected to the TV (control)
// another for sending messages to a specific user (user)
var user = pusher.subscribe('user-id'),
waiting = pusher.subscribe('presence-screen'),
control = pusher.subscribe('control');
waiting.bind('pusher:subscription_succeeded', function (members) {
queue(members.count);
});
control.bind('pusher:member_removed', function (member) {
queue(waiting.members.count);
});
function queue (count) {
if (count < 1) {
var isNextInQueue = null; // you'll need to find out where in the queue you are by calling to you app server
if (isNextInQueue === true) {
waiting.unsubscribe();
// render control UI
}
else {
return;
}
}
else {
// keep waiting
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment