mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Idle players now changing song when they need to, to keep up with the channel
This commit is contained in:
@@ -187,7 +187,7 @@ function skip(list, guid, coll, offline, socket) {
|
|||||||
else
|
else
|
||||||
to_skip = (Math.ceil(frontpage_viewers[0].viewers/2) - docs[0].skips.length-1);
|
to_skip = (Math.ceil(frontpage_viewers[0].viewers/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', {from: name, msg: " voted to skip"});
|
socket.to(coll).emit('chat', {from: name, msg: " voted to skip"});
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
socket.emit("toast", "alreadyskip");
|
socket.emit("toast", "alreadyskip");
|
||||||
@@ -212,7 +212,7 @@ function skip(list, guid, coll, offline, socket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function change_song(coll, error, id, callback) {
|
function change_song(coll, error, id, callback, socket) {
|
||||||
db.collection(coll + "_settings").find(function(err, docs){
|
db.collection(coll + "_settings").find(function(err, docs){
|
||||||
var startTime = docs[0].startTime;
|
var startTime = docs[0].startTime;
|
||||||
if(docs !== null && docs.length !== 0)
|
if(docs !== null && docs.length !== 0)
|
||||||
@@ -244,7 +244,7 @@ function change_song(coll, error, id, callback) {
|
|||||||
db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
|
db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
|
||||||
var next_song;
|
var next_song;
|
||||||
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
||||||
List.change_song_post(coll, next_song, callback);
|
List.change_song_post(coll, next_song, callback, socket);
|
||||||
if(!callback) {
|
if(!callback) {
|
||||||
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
|
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ function change_song(coll, error, id, callback) {
|
|||||||
},{multi:true}, function(err, docs){
|
},{multi:true}, function(err, docs){
|
||||||
var next_song;
|
var next_song;
|
||||||
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
||||||
if(docs.n >= 1) List.change_song_post(coll, next_song, callback);
|
if(docs.n >= 1) List.change_song_post(coll, next_song, callback, socket);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -273,7 +273,7 @@ function change_song(coll, error, id, callback) {
|
|||||||
db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
|
db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
|
||||||
var next_song;
|
var next_song;
|
||||||
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
||||||
List.change_song_post(coll, next_song, callback);
|
List.change_song_post(coll, next_song, callback, socket);
|
||||||
if(!callback) {
|
if(!callback) {
|
||||||
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
|
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
|
||||||
}
|
}
|
||||||
@@ -291,7 +291,7 @@ function change_song(coll, error, id, callback) {
|
|||||||
},{multi:true}, function(err, docs){
|
},{multi:true}, function(err, docs){
|
||||||
var next_song;
|
var next_song;
|
||||||
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
||||||
List.change_song_post(coll, next_song, callback);
|
List.change_song_post(coll, next_song, callback, socket);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,7 +303,7 @@ function change_song(coll, error, id, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function change_song_post(coll, next_song, callback)
|
function change_song_post(coll, next_song, callback, socket)
|
||||||
{
|
{
|
||||||
db.collection(coll).aggregate([{
|
db.collection(coll).aggregate([{
|
||||||
$match:{
|
$match:{
|
||||||
@@ -349,6 +349,8 @@ function change_song_post(coll, next_song, callback)
|
|||||||
io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay});
|
io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay});
|
||||||
List.send_play(coll);
|
List.send_play(coll);
|
||||||
} else {
|
} else {
|
||||||
|
socket.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay});
|
||||||
|
List.send_play(coll, socket, true);
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
Frontpage.update_frontpage(coll, docs[0].id, docs[0].title);
|
Frontpage.update_frontpage(coll, docs[0].id, docs[0].title);
|
||||||
@@ -418,7 +420,7 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
|
|||||||
if(Functions.get_time()-conf[0].startTime > np_docs[0].duration){
|
if(Functions.get_time()-conf[0].startTime > np_docs[0].duration){
|
||||||
List.change_song(coll, false, np_docs[0].id, function() {
|
List.change_song(coll, false, np_docs[0].id, function() {
|
||||||
List.send_list(coll, socket, send, list_send, configs, shuffled);
|
List.send_list(coll, socket, send, list_send, configs, shuffled);
|
||||||
});
|
}, socket);
|
||||||
} else {
|
} else {
|
||||||
if(list_send) {
|
if(list_send) {
|
||||||
io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
|
io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
|
||||||
@@ -538,7 +540,7 @@ function end(obj, coll, guid, offline, socket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function send_play(coll, socket)
|
function send_play(coll, socket, broadcast)
|
||||||
{
|
{
|
||||||
db.collection(coll).find({now_playing:true}, function(err, np){
|
db.collection(coll).find({now_playing:true}, function(err, np){
|
||||||
db.collection(coll + "_settings").find(function(err, conf){
|
db.collection(coll + "_settings").find(function(err, conf){
|
||||||
@@ -560,12 +562,21 @@ function send_play(coll, socket)
|
|||||||
List.getNextSong(coll)
|
List.getNextSong(coll)
|
||||||
sendColor(coll, false, np[0].id);
|
sendColor(coll, false, np[0].id);
|
||||||
} else {
|
} else {
|
||||||
socket.emit("np", toSend);
|
|
||||||
sendColor(coll, socket, np[0].id);
|
sendColor(coll, socket, np[0].id);
|
||||||
|
if(broadcast) {
|
||||||
|
socket.to(coll).emit("np", toSend);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
socket.emit("np", toSend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(e){
|
} catch(e){
|
||||||
|
console.log(e);
|
||||||
if(socket) {
|
if(socket) {
|
||||||
|
if(broadcast) {
|
||||||
|
socket.to(coll).emit("np", {});
|
||||||
|
return;
|
||||||
|
}
|
||||||
socket.emit("np", {});
|
socket.emit("np", {});
|
||||||
} else {
|
} else {
|
||||||
io.to(coll).emit("np", {});
|
io.to(coll).emit("np", {});
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ var Player = {
|
|||||||
if(prev_state == 2 && !chromecastAvailable) {
|
if(prev_state == 2 && !chromecastAvailable) {
|
||||||
Player.stopVideo();
|
Player.stopVideo();
|
||||||
was_stopped = true;
|
was_stopped = true;
|
||||||
|
Player.cueVideoById(video_id, duration);
|
||||||
if(!durationBegun) {
|
if(!durationBegun) {
|
||||||
Player.durationSetter();
|
Player.durationSetter();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user