mirror of https://github.com/calzoneman/sync.git
Fix queue issues when moving videos
This commit is contained in:
parent
328b38f319
commit
6fbe2732c7
18
channel.js
18
channel.js
|
@ -664,9 +664,6 @@ Channel.prototype.unqueue = function(data) {
|
|||
|
||||
if(data.pos < this.currentPosition) {
|
||||
this.currentPosition--;
|
||||
this.sendAll("updatePlaylistIdx", {
|
||||
idx: this.currentPosition
|
||||
});
|
||||
}
|
||||
if(data.pos == this.currentPosition) {
|
||||
this.currentPosition--;
|
||||
|
@ -678,6 +675,7 @@ Channel.prototype.unqueue = function(data) {
|
|||
Channel.prototype.playNext = function() {
|
||||
if(this.queue.length == 0)
|
||||
return;
|
||||
var old = this.currentPosition;
|
||||
if(this.currentPosition + 1 >= this.queue.length) {
|
||||
this.currentPosition = -1;
|
||||
}
|
||||
|
@ -687,6 +685,7 @@ Channel.prototype.playNext = function() {
|
|||
|
||||
this.sendAll("mediaUpdate", this.currentMedia.packupdate());
|
||||
this.sendAll("updatePlaylistIdx", {
|
||||
old: old,
|
||||
idx: this.currentPosition
|
||||
});
|
||||
// Enable autolead for non-twitch
|
||||
|
@ -701,13 +700,15 @@ Channel.prototype.jumpTo = function(pos) {
|
|||
return;
|
||||
if(pos >= this.queue.length || pos < 0)
|
||||
return;
|
||||
var old = this.currentPosition;
|
||||
this.currentPosition = pos;
|
||||
this.currentMedia = this.queue[this.currentPosition];
|
||||
this.currentMedia.currentTime = 0;
|
||||
|
||||
this.sendAll("mediaUpdate", this.currentMedia.packupdate());
|
||||
this.sendAll("updatePlaylistIdx", {
|
||||
idx: this.currentPosition
|
||||
idx: this.currentPosition,
|
||||
old: old
|
||||
});
|
||||
// Enable autolead for non-twitch
|
||||
if(this.leader == null && this.currentMedia.type != "tw" && this.currentMedia.type != "li") {
|
||||
|
@ -743,21 +744,22 @@ Channel.prototype.moveMedia = function(data) {
|
|||
return;
|
||||
|
||||
var media = this.queue[data.src];
|
||||
this.queue.splice(data.dest + 1, 0, media);
|
||||
this.queue.splice(data.src, 1);
|
||||
this.queue.splice(data.dest, 0, media);
|
||||
this.sendAll("moveVideo", {
|
||||
src: data.src,
|
||||
dest: data.dest
|
||||
});
|
||||
|
||||
if(data.src < this.currentPosition && data.dest > this.currentPosition) {
|
||||
if(data.src < this.currentPosition && data.dest >= 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++
|
||||
}
|
||||
if(data.src == this.currentPosition)
|
||||
else if(data.src == this.currentPosition) {
|
||||
this.currentPosition = data.dest;
|
||||
}
|
||||
}
|
||||
|
||||
// Chat message from a user
|
||||
|
|
3
user.js
3
user.js
|
@ -170,9 +170,6 @@ User.prototype.initCallbacks = function() {
|
|||
if(Rank.hasPermission(this, "queue") ||
|
||||
this.channel.leader == this ||
|
||||
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();
|
||||
}
|
||||
}.bind(this));
|
||||
|
|
|
@ -133,9 +133,6 @@ function initCallbacks() {
|
|||
});
|
||||
|
||||
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];
|
||||
//$(li).hide("blind", function() {
|
||||
$(li).remove();
|
||||
|
@ -175,11 +172,14 @@ function initCallbacks() {
|
|||
});
|
||||
|
||||
socket.on("updatePlaylistIdx", function(data) {
|
||||
var liold = $("#queue").children()[POSITION];
|
||||
$(liold).removeClass("alert alert-info");
|
||||
if(data.old != undefined) {
|
||||
console.log("unhighlight", data.old);
|
||||
var liold = $("#queue").children()[data.old];
|
||||
$(liold).removeClass("alert alert-info");
|
||||
}
|
||||
var linew = $("#queue").children()[data.idx];
|
||||
$(linew).addClass("alert alert-info");
|
||||
POSITION= data.idx;
|
||||
POSITION = data.idx;
|
||||
});
|
||||
|
||||
socket.on("mediaUpdate", function(data) {
|
||||
|
|
|
@ -191,11 +191,11 @@ function addQueueButtons(li) {
|
|||
var idx = $("#queue").children().index(li);
|
||||
var lidx = $("#queue").children().index(GRABBEDLI);
|
||||
if(idx != lidx)
|
||||
moveVideo(lidx, idx);
|
||||
moveVideo(lidx, idx, true);
|
||||
}
|
||||
});
|
||||
|
||||
$(li).mouseup(function() {
|
||||
$(document).mouseup(function() {
|
||||
if(GRABBEDLI != null) {
|
||||
var idx = $("#queue").children().index(GRABBEDLI);
|
||||
GRABBEDLI = null;
|
||||
|
@ -289,24 +289,23 @@ function moveVideo(src, dest, noanim) {
|
|||
else {
|
||||
ul.insertBefore(li, ul.getElementsByTagName("li")[dest]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
$(li).hide("blind", function() {
|
||||
ul.removeChild(li);
|
||||
if(dest == ul.children.length) {
|
||||
ul.appendChild(li);
|
||||
}
|
||||
else {
|
||||
ul.insertBefore(li, ul.getElementsByTagName("li")[dest]);
|
||||
}
|
||||
$(li).show("blind");
|
||||
});
|
||||
if(src < POSITION && dest > POSITION)
|
||||
else {
|
||||
$(li).hide("blind", function() {
|
||||
ul.removeChild(li);
|
||||
if(dest == ul.children.length) {
|
||||
ul.appendChild(li);
|
||||
}
|
||||
else {
|
||||
ul.insertBefore(li, ul.getElementsByTagName("li")[dest]);
|
||||
}
|
||||
$(li).show("blind");
|
||||
});
|
||||
}
|
||||
if(src < POSITION && dest >= POSITION)
|
||||
POSITION--;
|
||||
if(src > POSITION && dest < POSITION)
|
||||
POSITION++;
|
||||
if(src == POSITION)
|
||||
POSITION = dest;
|
||||
}
|
||||
|
||||
// YouTube Synchronization
|
||||
|
|
Loading…
Reference in New Issue