Last active
December 20, 2015 07:59
-
-
Save awbauer/6097023 to your computer and use it in GitHub Desktop.
NEXIS "Who's here" script. Shows photos of foursquare users currently at a venue & new check-ins in realtime. Powered by foursquare & SocketIO.
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
/*** | |
* NEXIS 'Who's here' script | |
* Author: Andrew Bauer | |
* Dependencies: jQuery, socketIO | |
* Requires socketIO server @ http://tospace.starshipnexis.com:8000 | |
***/ | |
var socket = io.connect('http://tospace.starshipnexis.com:8000'), | |
whoshere = [], | |
refreshInt, | |
count=0, | |
venueid="4d3729aedb5ba35d6e5c41c7", // Starship NEXIS - http://foursquare.com/v/starshipnexis/4d3729aedb5ba35d6e5c41c7 | |
photosqueue = $({}); | |
socket.on('checkin', function (data) { | |
if($.inArray(data.user.id, whoshere) < 0) { | |
$("#nobodyhere").hide(); | |
whoshere.push(data.user.id); | |
$("#whoshere").append("<img src='"+data.user.photo+"' id='"+data.user.id+"-photo' />"); | |
$("#"+data.user.id+"-photo").fadeIn(); | |
} | |
}); | |
function load_all_here(){ | |
$.getJSON('/foursquare/whoshere/'+venueid, function(r){ | |
//remove anyone already on page | |
for(var y in whoshere) $("#"+whoshere[y]+"-photo").fadeOut(); | |
whoshere = []; | |
$("#whoshere").html(''); | |
if(!r.length) { | |
$("#nobodyhere").show(); | |
return; | |
} else { | |
$("#nobodyhere").hide(); | |
} | |
for(var x in r){ | |
$("#whoshere").append("<img src='"+r[x].user_photo+"' id='"+r[x].foursquare_userid+"-photo' />"); | |
whoshere.push(r[x].foursquare_userid); | |
$("#whoshere img").each(function() { | |
var ele = this; | |
photosqueue.queue(function(next) {$(ele).fadeIn(next);}); | |
}); | |
} | |
}); | |
} | |
$(function(){ | |
load_all_here(); | |
refreshInt = setInterval(load_all_here, 600000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment