diff --git a/php/header.php b/php/header.php index dcbb94b7..6a275c86 100755 --- a/php/header.php +++ b/php/header.php @@ -16,4 +16,4 @@ - \ No newline at end of file + diff --git a/server/server.js b/server/server.js index 091eddd1..583e1a98 100755 --- a/server/server.js +++ b/server/server.js @@ -37,6 +37,7 @@ io.on('connection', function(socket){ var in_list = false; socket.on('chat', function (data) { + check_inlist(coll, guid, socket); if(data != "" && data !== undefined && data !== null && data.length < 151 && data.replace(/\s/g, '').length) io.sockets.emit('chat,'+coll, rndName(guid) + ": " + data); }); @@ -95,16 +96,7 @@ io.on('connection', function(socket){ console.log(guid + " joined list " + coll); - if(lists[coll] == undefined) - { - lists[coll] = []; - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - }else if(!contains(lists[coll], guid)) - { - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - } + check_inlist(coll, guid, socket); io.sockets.emit(coll+",viewers", lists[coll].length); @@ -134,16 +126,7 @@ io.on('connection', function(socket){ { if(id !== undefined && id !== null && id != "") { - if(lists[coll] == undefined) - { - lists[coll] = []; - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - }else if(!contains(lists[coll], guid)) - { - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - } + check_inlist(coll, guid, socket); db.collection(coll).find({now_playing:true}, function(err, np){ //console.log(docs); @@ -208,16 +191,7 @@ io.on('connection', function(socket){ { if(arr !== undefined && arr !== null && arr != "") { - if(lists[coll] == undefined) - { - lists[coll] = []; - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - }else if(!contains(lists[coll], guid)) - { - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - } + check_inlist(coll, guid, socket); var id = arr[0]; var title = arr[1]; @@ -258,16 +232,7 @@ io.on('connection', function(socket){ { if(msg !== undefined && msg !== null) { - if(lists[coll] == undefined) - { - lists[coll] = []; - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - }else if(!contains(lists[coll], guid)) - { - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - } + check_inlist(coll, guid, socket); if(msg[2] == "del") del(msg, socket); @@ -297,16 +262,8 @@ io.on('connection', function(socket){ pw = inp[0]; coll = inp[1]; //guid = inp[2]; - if(lists[coll] == undefined) - { - lists[coll] = []; - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - }else if(!contains(lists[coll], guid)) - { - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - } + check_inlist(coll, guid, socket); + //console.log(coll); db.collection(coll).find({views:{$exists:true}}, function(err, docs){ //console.log(docs); @@ -330,16 +287,7 @@ io.on('connection', function(socket){ { if(list !== undefined && list !== null && list != "") { - if(lists[coll] == undefined) - { - lists[coll] = []; - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - }else if(!contains(lists[coll], guid)) - { - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - } + check_inlist(coll, guid, socket); adminpass = ""; @@ -375,10 +323,10 @@ io.on('connection', function(socket){ }else if(get_time() - docs[0]["startTime"] < 10 && lists[coll].length == 2 && !error) { socket.emit("toast", "notyetskip"); - }else if(!contains(docs[0]["skips"], guid) && get_time() - docs[0]["startTime"] >= 30){ + }else if(!contains(docs[0]["skips"], guid)){ db.collection(coll).update({views:{$exists:true}}, {$push:{skips:guid}}, function(err, d){ socket.emit("toast", (Math.ceil(lists[coll].length/2) - docs[0]["skips"].length-1) + " more are needed to skip!"); - io.sockets.emit('chat,'+coll, rndName(guid) + " tried to skip!"); + socket.broadcast.emit('chat,'+coll, rndName(guid) + " voted to skip"); }); }else{ socket.emit("toast", "alreadyskip"); @@ -394,16 +342,7 @@ io.on('connection', function(socket){ { if(params !== undefined && params !== null && params != "") { - if(lists[coll] == undefined) - { - lists[coll] = []; - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - }else if(!contains(lists[coll], guid)) - { - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - } + check_inlist(coll, guid, socket); var voting = params[0]; var addsongs = params[1]; @@ -453,16 +392,7 @@ io.on('connection', function(socket){ { if(pass !== undefined && pass !== null && pass != "") { - if(lists[coll] == undefined) - { - lists[coll] = []; - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - }else if(!contains(lists[coll], guid)) - { - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - } + check_inlist(coll, guid, socket); var hash = hash_pass(pass); db.collection(coll).find({views:{$exists:true}}, function(err, docs){ @@ -498,29 +428,21 @@ io.on('connection', function(socket){ { if(in_list) { - try - { + if(contains(lists[coll], guid)) + { console.log(guid + " left list " + coll); var index = lists[coll].indexOf(guid); lists[coll].splice(index, 1); io.sockets.emit(coll+",viewers", lists[coll].length); - }catch(err){} + io.sockets.emit('chat,'+coll, rndName(guid) + " left"); + } + } }); socket.on('pos', function() { - if(lists[coll] == undefined) - { - lists[coll] = []; - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - }else if(!contains(lists[coll], guid)) - { - lists[coll].push(guid); - io.sockets.emit(coll+",viewers", lists[coll].length); - } - + check_inlist(coll, guid, socket); send_play(coll, socket); }); }); @@ -536,7 +458,23 @@ function del(params, socket) sort_list(coll, undefined, false, true); }) } - }) + }); +} + +function check_inlist(coll, guid, socket) +{ + if(lists[coll] == undefined) + { + lists[coll] = []; + lists[coll].push(guid); + io.sockets.emit(coll+",viewers", lists[coll].length); + socket.broadcast.emit('chat,'+coll, rndName(guid) + " joined"); + }else if(!contains(lists[coll], guid)) + { + lists[coll].push(guid); + io.sockets.emit(coll+",viewers", lists[coll].length); + socket.broadcast.emit('chat,'+coll, rndName(guid) + " joined"); + } } function hash_pass(adminpass) @@ -681,4 +619,4 @@ function rndName(seed) { word += arr[(seed[i%seed.length].charCodeAt()+i) % arr.length-1]; } return word.substring(0,8) -} \ No newline at end of file +} diff --git a/static/css/style.css b/static/css/style.css index 726de918..ab5efe2d 100755 --- a/static/css/style.css +++ b/static/css/style.css @@ -208,6 +208,11 @@ hide mdi-action-visibility mdi-action-visibility-off float: left; } +#chat-btn i { + -webkit-transition:opacity 1s; + transition:opacity 1s; +} + ul #chat-log{ padding: 0px 0px 0px 11px !important; } diff --git a/static/js/chat.js b/static/js/chat.js index 7f4eed9e..fcc75d66 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -1,3 +1,5 @@ +var blink_interval; +var blink_interval_exists = false; function chat(data) { @@ -11,14 +13,24 @@ function chat(data) document.getElementById("chat-btn").addEventListener("click", function(){ console.log("clicked"); $("#text-chat-input").focus(); - $("#chat-btn").css("color", "white"); + //$("#chat-btn").css("color", "white"); + $("#chat-btn i").css("opacity", 1); + clearInterval(blink_interval); + blink_interval_exists = false; + $("#favicon").attr("href", "static/images/favicon.png"); }); socket.on("chat,"+chan.toLowerCase(), function(data) { if($("#chat-bar").position()["left"] != 0) { - $("#chat-btn").css("color", "grey"); + //$("#chat-btn").css("color", "grey"); + if(!blink_interval_exists) + { + $("#favicon").attr("href", "static/images/highlogo.png"); + blink_interval_exists = true; + blink_interval = setInterval(chat_blink, 2000); + } } var color = intToARGB(hashCode(data.substring(0,8))).substring(0,6); $("#chat").append("