Made socketeventheaders better, none of that chan,np, just np now

This commit is contained in:
Kasper Rynning-Tønnesen
2015-06-13 02:19:25 +02:00
parent 63e0d9104e
commit 0b1d075e5b
6 changed files with 23 additions and 416 deletions

View File

@@ -6,6 +6,7 @@ if(isset($_GET['chan'])){
} }
?> ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#">
<head> <head>
<?php include("header.php"); ?> <?php include("header.php"); ?>

View File

@@ -68,8 +68,8 @@ io.on('connection', function(socket){
{ {
if(name.length < 9 && name.indexOf(" ") == -1) if(name.length < 9 && name.indexOf(" ") == -1)
{ {
io.to(coll).emit('chat,'+coll, [name, " changed name to " + data]); io.to(coll).emit('chat', [name, " changed name to " + data]);
io.to(coll).emit('chat.all', [name ," changed name to " + data, coll]); io.sockets.emit('chat.all', [name ," changed name to " + data, coll]);
name = data; name = data;
} }
}); });
@@ -77,14 +77,14 @@ io.on('connection', function(socket){
socket.on('chat', function (data) { socket.on('chat', function (data) {
check_inlist(coll, guid, socket, name); check_inlist(coll, guid, socket, name);
if(data != "" && data !== undefined && data !== null && data.length < 151 && data.replace(/\s/g, '').length) if(data != "" && data !== undefined && data !== null && data.length < 151 && data.replace(/\s/g, '').length)
io.to(coll).emit('chat,'+coll, [name, ": " + data]); io.to(coll).emit('chat', [name, ": " + data]);
}); });
socket.on("all,chat", function(data) socket.on("all,chat", function(data)
{ {
check_inlist(coll, guid, socket, name); check_inlist(coll, guid, socket, name);
if(data != "" && data !== undefined && data !== null && data.length < 151 && data.replace(/\s/g, '').length) if(data != "" && data !== undefined && data !== null && data.length < 151 && data.replace(/\s/g, '').length)
io.to(coll).emit('chat.all', [name, ": " + data, coll]); io.sockets.emit('chat.all', [name, ": " + data, coll]);
}); });
socket.on('frontpage_lists', function() socket.on('frontpage_lists', function()
@@ -161,7 +161,7 @@ io.on('connection', function(socket){
check_inlist(coll, guid, socket, name); check_inlist(coll, guid, socket, name);
//io.sockets.emit(coll+",viewers", lists[coll].length); //io.sockets.emit(coll+",viewers", lists[coll].length);
io.to(coll).emit(coll+",viewers", lists[coll].length); io.to(coll).emit("viewers", lists[coll].length);
db.getCollectionNames(function(err, docs){ db.getCollectionNames(function(err, docs){
@@ -398,7 +398,7 @@ io.on('connection', function(socket){
change_song(coll); change_song(coll);
socket.emit("toast", "skip"); socket.emit("toast", "skip");
//io.sockets.emit('chat,'+coll, [name, " skipped"]); //io.sockets.emit('chat,'+coll, [name, " skipped"]);
io.to(coll).emit('chat,'+coll, [name, " skipped"]); io.to(coll).emit('chat', [name, " skipped"]);
}/*else if(get_time() - docs[0]["startTime"] < 10 && lists[coll].length == 2 && !error) }/*else if(get_time() - docs[0]["startTime"] < 10 && lists[coll].length == 2 && !error)
{ {
socket.emit("toast", "notyetskip"); socket.emit("toast", "notyetskip");
@@ -409,7 +409,7 @@ io.on('connection', function(socket){
else else
to_skip = (Math.ceil(lists[coll].length/2) - docs[0]["skips"].length-1); to_skip = (Math.ceil(lists[coll].length/2) - docs[0]["skips"].length-1);
socket.emit("toast", to_skip + " more are needed to skip!"); socket.emit("toast", to_skip + " more are needed to skip!");
socket.broadcast.to(coll).emit('chat,'+coll, [name, " voted to skip"]); socket.broadcast.to(coll).emit('chat', [name, " voted to skip"]);
}); });
}else{ }else{
socket.emit("toast", "alreadyskip"); socket.emit("toast", "alreadyskip");
@@ -458,7 +458,7 @@ io.on('connection', function(socket){
db.collection(coll).find({views:{$exists:true}}, function(err, docs) db.collection(coll).find({views:{$exists:true}}, function(err, docs)
{ {
//io.sockets.emit(coll+",conf", docs); //io.sockets.emit(coll+",conf", docs);
io.to(coll).emit(coll+",conf", docs); io.to(coll).emit("conf", docs);
socket.emit("toast", "savedsettings"); socket.emit("toast", "savedsettings");
}); });
}); });
@@ -517,8 +517,8 @@ io.on('connection', function(socket){
lists[coll].splice(index, 1); lists[coll].splice(index, 1);
//io.sockets.emit(coll+",viewers", lists[coll].length); //io.sockets.emit(coll+",viewers", lists[coll].length);
//io.sockets.emit('chat,'+coll, [name, " left"]); //io.sockets.emit('chat,'+coll, [name, " left"]);
io.to(coll).emit(coll+",viewers", lists[coll].length); io.to(coll).emit("viewers", lists[coll].length);
io.to(coll).emit('chat,'+coll, [name, " left"]); io.to(coll).emit('chat', [name, " left"]);
} }
@@ -536,8 +536,8 @@ io.on('connection', function(socket){
lists[coll].splice(index, 1); lists[coll].splice(index, 1);
//io.sockets.emit(coll+",viewers", lists[coll].length); //io.sockets.emit(coll+",viewers", lists[coll].length);
//io.sockets.emit('chat,'+coll, [name, " left"]); //io.sockets.emit('chat,'+coll, [name, " left"]);
io.to(coll).emit(coll+",viewers", lists[coll].length); io.to(coll).emit("viewers", lists[coll].length);
io.to(coll).emit('chat,'+coll, [name, " left"]); io.to(coll).emit('chat', [name, " left"]);
} }
} }
@@ -572,14 +572,14 @@ function check_inlist(coll, guid, socket, name)
lists[coll] = []; lists[coll] = [];
lists[coll].push(guid); lists[coll].push(guid);
//io.sockets.emit(coll+",viewers", lists[coll].length); //io.sockets.emit(coll+",viewers", lists[coll].length);
io.to(coll).emit(coll+",viewers", lists[coll].length); io.to(coll).emit("viewers", lists[coll].length);
socket.broadcast.to(coll).emit('chat,'+coll, [name, " joined"]); socket.broadcast.to(coll).emit('chat', [name, " joined"]);
}else if(!contains(lists[coll], guid)) }else if(!contains(lists[coll], guid))
{ {
lists[coll].push(guid); lists[coll].push(guid);
//io.sockets.emit(coll+",viewers", lists[coll].length); //io.sockets.emit(coll+",viewers", lists[coll].length);
io.to(coll).emit(coll+",viewers", lists[coll].length); io.to(coll).emit("viewers", lists[coll].length);
socket.broadcast.to(coll).emit('chat,'+coll, [name, " joined"]); socket.broadcast.to(coll).emit('chat', [name, " joined"]);
} }
} }
@@ -688,9 +688,9 @@ function send_play(coll, socket)
{ {
toSend = [np,conf,get_time()]; toSend = [np,conf,get_time()];
if(socket === undefined) if(socket === undefined)
io.to(coll).emit(coll+",np", toSend); io.to(coll).emit("np", toSend);
else else
socket.emit(coll+",np", toSend); socket.emit("np", toSend);
} }
}); });
}); });

View File

@@ -65,7 +65,7 @@ socket.on("pw", function(msg)
Materialize.toast("Correct password. You now have access to the sacred realm of The Admin.", 4000); Materialize.toast("Correct password. You now have access to the sacred realm of The Admin.", 4000);
}); });
socket.on(chan.toLowerCase()+",conf", function(msg) socket.on("conf", function(msg)
{ {
set_conf(msg[0]); set_conf(msg[0]);
}); });

View File

@@ -67,7 +67,7 @@ $(window).focus(function(){
function setup_chat_listener(channel) function setup_chat_listener(channel)
{ {
document.getElementsByClassName("chat-tab")[0].innerHTML = channel; document.getElementsByClassName("chat-tab")[0].innerHTML = channel;
socket.on("chat,"+channel.toLowerCase(), function(data) socket.on("chat", function(data)
{ {
if($("#chat-bar").position()["left"] != 0) if($("#chat-bar").position()["left"] != 0)
{ {

View File

@@ -25,7 +25,7 @@ var playing = false;
//play new song //play new song
function setup_youtube_listener(channel) function setup_youtube_listener(channel)
{ {
socket.on(channel.toLowerCase()+",np", function(obj) socket.on("np", function(obj)
{ {
console.log(obj); console.log(obj);
if(obj[0].length == 0){ if(obj[0].length == 0){
@@ -67,7 +67,7 @@ function setup_youtube_listener(channel)
} }
}); });
socket.on(channel.toLowerCase()+",viewers", function(view) socket.on("viewers", function(view)
{ {
viewers = view; viewers = view;
if(song_title !== undefined) if(song_title !== undefined)

File diff suppressed because one or more lines are too long