Fix queue issues when moving videos

This commit is contained in:
calzoneman 2013-03-29 15:05:08 -05:00
parent 328b38f319
commit 6fbe2732c7
4 changed files with 31 additions and 33 deletions

View File

@ -664,9 +664,6 @@ Channel.prototype.unqueue = function(data) {
if(data.pos < this.currentPosition) { if(data.pos < this.currentPosition) {
this.currentPosition--; this.currentPosition--;
this.sendAll("updatePlaylistIdx", {
idx: this.currentPosition
});
} }
if(data.pos == this.currentPosition) { if(data.pos == this.currentPosition) {
this.currentPosition--; this.currentPosition--;
@ -678,6 +675,7 @@ Channel.prototype.unqueue = function(data) {
Channel.prototype.playNext = function() { Channel.prototype.playNext = function() {
if(this.queue.length == 0) if(this.queue.length == 0)
return; return;
var old = this.currentPosition;
if(this.currentPosition + 1 >= this.queue.length) { if(this.currentPosition + 1 >= this.queue.length) {
this.currentPosition = -1; this.currentPosition = -1;
} }
@ -687,6 +685,7 @@ Channel.prototype.playNext = function() {
this.sendAll("mediaUpdate", this.currentMedia.packupdate()); this.sendAll("mediaUpdate", this.currentMedia.packupdate());
this.sendAll("updatePlaylistIdx", { this.sendAll("updatePlaylistIdx", {
old: old,
idx: this.currentPosition idx: this.currentPosition
}); });
// Enable autolead for non-twitch // Enable autolead for non-twitch
@ -701,13 +700,15 @@ Channel.prototype.jumpTo = function(pos) {
return; return;
if(pos >= this.queue.length || pos < 0) if(pos >= this.queue.length || pos < 0)
return; return;
var old = this.currentPosition;
this.currentPosition = pos; this.currentPosition = pos;
this.currentMedia = this.queue[this.currentPosition]; this.currentMedia = this.queue[this.currentPosition];
this.currentMedia.currentTime = 0; this.currentMedia.currentTime = 0;
this.sendAll("mediaUpdate", this.currentMedia.packupdate()); this.sendAll("mediaUpdate", this.currentMedia.packupdate());
this.sendAll("updatePlaylistIdx", { this.sendAll("updatePlaylistIdx", {
idx: this.currentPosition idx: this.currentPosition,
old: old
}); });
// Enable autolead for non-twitch // Enable autolead for non-twitch
if(this.leader == null && this.currentMedia.type != "tw" && this.currentMedia.type != "li") { if(this.leader == null && this.currentMedia.type != "tw" && this.currentMedia.type != "li") {
@ -743,21 +744,22 @@ Channel.prototype.moveMedia = function(data) {
return; return;
var media = this.queue[data.src]; var media = this.queue[data.src];
this.queue.splice(data.dest + 1, 0, media);
this.queue.splice(data.src, 1); this.queue.splice(data.src, 1);
this.queue.splice(data.dest, 0, media);
this.sendAll("moveVideo", { this.sendAll("moveVideo", {
src: data.src, src: data.src,
dest: data.dest dest: data.dest
}); });
if(data.src < this.currentPosition && data.dest > this.currentPosition) { if(data.src < this.currentPosition && data.dest >= this.currentPosition) {
this.currentPosition--; this.currentPosition--;
} }
if(data.src > this.currentPosition && data.dest < this.currentPosition) { else if(data.src > this.currentPosition && data.dest < this.currentPosition) {
this.currentPosition++ this.currentPosition++
} }
if(data.src == this.currentPosition) else if(data.src == this.currentPosition) {
this.currentPosition = data.dest; this.currentPosition = data.dest;
}
} }
// Chat message from a user // Chat message from a user

View File

@ -170,9 +170,6 @@ User.prototype.initCallbacks = function() {
if(Rank.hasPermission(this, "queue") || if(Rank.hasPermission(this, "queue") ||
this.channel.leader == this || this.channel.leader == this ||
this.channel.opts.qopen_allow_playnext && !this.channel.qlocked) { this.channel.opts.qopen_allow_playnext && !this.channel.qlocked) {
if(this.channel.currentPosition + 1 >= this.channel.queue.length) {
this.channel.currentPosition = -1;
}
this.channel.playNext(); this.channel.playNext();
} }
}.bind(this)); }.bind(this));

View File

@ -133,9 +133,6 @@ function initCallbacks() {
}); });
socket.on("unqueue", function(data) { socket.on("unqueue", function(data) {
if(data.pos == POSITION && $("#queue").children().length > POSITION + 1) {
$($("#queue").children()[POSITION+1]).addClass("alert alert-info");
}
var li = $("#queue").children()[data.pos]; var li = $("#queue").children()[data.pos];
//$(li).hide("blind", function() { //$(li).hide("blind", function() {
$(li).remove(); $(li).remove();
@ -175,11 +172,14 @@ function initCallbacks() {
}); });
socket.on("updatePlaylistIdx", function(data) { socket.on("updatePlaylistIdx", function(data) {
var liold = $("#queue").children()[POSITION]; if(data.old != undefined) {
$(liold).removeClass("alert alert-info"); console.log("unhighlight", data.old);
var liold = $("#queue").children()[data.old];
$(liold).removeClass("alert alert-info");
}
var linew = $("#queue").children()[data.idx]; var linew = $("#queue").children()[data.idx];
$(linew).addClass("alert alert-info"); $(linew).addClass("alert alert-info");
POSITION= data.idx; POSITION = data.idx;
}); });
socket.on("mediaUpdate", function(data) { socket.on("mediaUpdate", function(data) {

View File

@ -191,11 +191,11 @@ function addQueueButtons(li) {
var idx = $("#queue").children().index(li); var idx = $("#queue").children().index(li);
var lidx = $("#queue").children().index(GRABBEDLI); var lidx = $("#queue").children().index(GRABBEDLI);
if(idx != lidx) if(idx != lidx)
moveVideo(lidx, idx); moveVideo(lidx, idx, true);
} }
}); });
$(li).mouseup(function() { $(document).mouseup(function() {
if(GRABBEDLI != null) { if(GRABBEDLI != null) {
var idx = $("#queue").children().index(GRABBEDLI); var idx = $("#queue").children().index(GRABBEDLI);
GRABBEDLI = null; GRABBEDLI = null;
@ -289,24 +289,23 @@ function moveVideo(src, dest, noanim) {
else { else {
ul.insertBefore(li, ul.getElementsByTagName("li")[dest]); ul.insertBefore(li, ul.getElementsByTagName("li")[dest]);
} }
return;
} }
$(li).hide("blind", function() { else {
ul.removeChild(li); $(li).hide("blind", function() {
if(dest == ul.children.length) { ul.removeChild(li);
ul.appendChild(li); if(dest == ul.children.length) {
} ul.appendChild(li);
else { }
ul.insertBefore(li, ul.getElementsByTagName("li")[dest]); else {
} ul.insertBefore(li, ul.getElementsByTagName("li")[dest]);
$(li).show("blind"); }
}); $(li).show("blind");
if(src < POSITION && dest > POSITION) });
}
if(src < POSITION && dest >= POSITION)
POSITION--; POSITION--;
if(src > POSITION && dest < POSITION) if(src > POSITION && dest < POSITION)
POSITION++; POSITION++;
if(src == POSITION)
POSITION = dest;
} }
// YouTube Synchronization // YouTube Synchronization