Sending conf as own message instead of with the list

This commit is contained in:
Kasper Rynning-Tønnesen
2015-07-03 15:15:16 +02:00
parent 7bbf09e697
commit 8b2f463b6d
3 changed files with 18 additions and 24 deletions

View File

@@ -167,13 +167,13 @@ io.on('connection', function(socket){
if(contains(docs, coll)) if(contains(docs, coll))
{ {
send_list(coll, socket, true, false); send_list(coll, socket, true, false, true);
}else }else
{ {
db.createCollection(coll, function(err, docs){ db.createCollection(coll, function(err, docs){
db.collection(coll).insert({"addsongs":false, "adminpass":"", "allvideos":false, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":get_time(), "views": [], "vote": false}, function(err, docs) db.collection(coll).insert({"addsongs":false, "adminpass":"", "allvideos":false, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":get_time(), "views": [], "vote": false}, function(err, docs)
{ {
send_list(coll, socket, true, false); send_list(coll, socket, true, false, true);
}); });
}); });
@@ -464,7 +464,7 @@ io.on('connection', function(socket){
{ {
db.collection(coll).find({now_playing:false}).forEach(function(err, docs){ db.collection(coll).find({now_playing:false}).forEach(function(err, docs){
if(!docs){ if(!docs){
send_list(coll, undefined, false, true); send_list(coll, undefined, false, true, false);
socket.emit("toast", "shuffled"); socket.emit("toast", "shuffled");
return; return;
}else{ }else{
@@ -479,7 +479,7 @@ io.on('connection', function(socket){
var complete = function(tot, curr){ var complete = function(tot, curr){
if(tot == curr) if(tot == curr)
{ {
send_list(coll, undefined, false, true); send_list(coll, undefined, false, true, false);
} }
}; };
}else }else
@@ -654,9 +654,9 @@ function change_song_post(coll)
}); });
} }
function send_list(coll, socket, send, list_send) function send_list(coll, socket, send, list_send, configs)
{ {
db.collection(coll).find(function(err, docs) db.collection(coll).find({views:{$exists:false}}, function(err, docs)
{ {
if(list_send) if(list_send)
io.to(coll).emit("channel", ["list", docs]); io.to(coll).emit("channel", ["list", docs]);
@@ -667,6 +667,14 @@ function send_list(coll, socket, send, list_send)
else if(send) else if(send)
send_play(coll, socket); send_play(coll, socket);
}); });
if(configs)
{
db.collection(coll).find({views:{$exists:true}}, function(err, conf){
io.to(coll).emit("conf", conf);
});
}
} }
function send_play(coll, socket) function send_play(coll, socket)

File diff suppressed because one or more lines are too long

View File

@@ -12,14 +12,10 @@ var List = {
if(msg[0] == "list") if(msg[0] == "list")
{ {
full_playlist = msg[1]; full_playlist = msg[1];
var index_of_conf = List.getIndexOfConf(full_playlist);
conf = full_playlist[index_of_conf];
full_playlist.splice(index_of_conf, 1);
full_playlist.sort(Helper.predicate({ full_playlist.sort(Helper.predicate({
name: 'votes', name: 'votes',
reverse: true reverse: true
}, 'added')); }, 'added'));
Admin.set_conf(conf);
List.populate_list(full_playlist); List.populate_list(full_playlist);
}else if(msg[0] == "added") }else if(msg[0] == "added")
{ {
@@ -217,15 +213,5 @@ var List = {
} }
}); });
return indexes[0]; return indexes[0];
},
getIndexOfConf: function(flist)
{
indexes = $.map(flist, function(obj, index) {
if("views" in obj) {
return index;
}
});
return indexes[0];
} }
} }