Last active
December 25, 2015 04:59
-
-
Save adamyeats-zz/6921501 to your computer and use it in GitHub Desktop.
Presence channel queueing
This file contains hidden or 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 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