Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:mbarton/musictionary

  • Loading branch information...
commit 2aa9292e3b9cef1db4b885c7c7fcac523ea7ccf9 2 parents 1d9b6b0 + 173c65a
Kiril Piskunov ciudilo authored
9 server.py
View
@@ -55,12 +55,14 @@ def player(room, facebook_id):
if request.method == 'POST':
print "adding player {0} to room {1}".format(facebook_id, room)
app.p[room].trigger('presence', {"state": "add","facebook_id": facebook_id})
- app.users[room].append(facebook_id)
+ if facebook_id not in app.users[room]:
+ app.users[room].append(facebook_id)
elif request.method == 'DELETE':
print "removing player {0} to room {1}".format(facebook_id, room)
app.p[room].trigger('presence', {"state": "del","facebook_id": facebook_id})
app.users[room].remove(facebook_id)
else:
+ print json.dumps(app.users[room])
return json.dumps(app.users[room])
return "Done"
@@ -70,11 +72,12 @@ def room(room):
if room == "favicon.ico":
# LOL
return ""
-
+ host = False
if not room in app.rooms:
app.rooms[room] = copy.deepcopy(app.default_matrix)
+ host = True
app.users[str(room)] = []
- return render_template('room.html', matrix=json.dumps(app.rooms[room]), room=room)
+ return render_template('room.html', matrix=json.dumps(app.rooms[room]), room=room, host=host)
@app.route("/")
def index():
20 static/js/fb.js
View
@@ -2,6 +2,17 @@
MusictionaryFacebook = function(secret) {
+ confirmExit = function() {
+ if (app.currentUserId != null) {
+ var url = "player/" + MusictionaryRoom + "/" + app.currentUserId;
+ $.ajax(url, {type: "DELETE"});
+ }
+ }
+
+ window.onbeforeunload = confirmExit;
+
+
+
var self = {};
$(function(){
@@ -46,12 +57,12 @@ MusictionaryFacebook = function(secret) {
var user_info_el = $('#user_info');
- refresh_connected_users = function(ids_map) {
+ refresh_connected_users = function(ids) {
$('#connected_users').empty()
- $.each(ids_map, function(key, val) {
+ _.each(ids, function(val) {
get_user_info(val, function(user_info) {
$('#connected_users').append('<div class="user_info_item"><img src="' + user_info.pic_square + '" /><div><a href="https://www.facebook.com/'+user_info.username+'">'+user_info.name+'</a></div></div>');
- });
+ });
});
}
@@ -102,6 +113,9 @@ MusictionaryFacebook = function(secret) {
FB.Event.subscribe('auth.login', update_user_info);
FB.Event.subscribe('auth.logout', update_user_info);
+
+ app.net.channel.bind('presence', update_user_info);
+
/*FB.getLoginStatus(update_user_info);*/
};
10 static/js/ui.js
View
@@ -104,6 +104,9 @@ self.setEditing = function(index){
$(function(){
$(".trigger").live("click", function(){
+ if(MusictionaryHost == "False")
+ return
+
var instrument = $(this).parent().children(".label").html();
var index = $(this).parent().children(".trigger").index(this);
// Flip flop!
@@ -123,7 +126,14 @@ $("#stop").click(function(){
app.stop();
});
+$("#songD").click(function(){
+ $("#guesser").html("<h1>YOU ARE CORRECT ROCK ON!</h1>");
+})
+
$("body").keydown(function(ev){
+ if(MusictionaryHost == "False")
+ return
+
switch(ev.keyCode)
{
case UP_ARROW:
12 templates/room.html
View
@@ -12,6 +12,7 @@
MusictionaryMatrix = {{ matrix|safe }}
// TODO MRB: CAN U SPOT THE XSS ATTACK!
MusictionaryRoom = "{{ room|safe }}"
+ MusictionaryHost = "{{ host|safe }}"
</script>
<script type="text/javascript" src="{{ url_for('static', filename='js/secret.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/net.js') }}"></script>
@@ -50,12 +51,23 @@ <h3 id="room_name">Room {{ room }}</h3>
<button id="stop" class="btn"><img src="{{ url_for('static', filename='img/stop.png') }}" /></button>
</div>
</div>
+ {% if host %}
<div class="span6">
<h2>Recreate <strong>Thriller - Michael Jackson</strong>!</h2>
</div>
<div class="span2">
<button id="playclip" onclick="playClip()">Play Clip</button>
</div>
+ {% else %}
+ <div class="span7" id="guesser">
+ <h2>What is this tune?</h2>
+ <button id="songA">Beat It - Michael Jackson</button>
+ <button id="songB">Bangarang - Skrillex</button>
+ <button id="songC">Night Fever - The Bee Gees</button>
+ <button id="songD">Thriller - Michael Jackson</button>
+ <button id="songE">Telephone - Lady Gaga</button>
+ </div>
+ {% endif %}
</div>
</div>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.