diff --git a/channel.js b/channel.js index 9b71b5cd..375610b4 100644 --- a/channel.js +++ b/channel.js @@ -1262,15 +1262,9 @@ Channel.prototype.trySetTemp = function(user, data) { Channel.prototype.dequeue = function(uid, removeonly) { - if(!this.playlist.remove(uid)) + if(!this.playlist.remove(uid, true)) return; - this.sendAll("delete", { - uid: uid - }); this.broadcastPlaylistMeta(); - - if(removeonly) - return; } Channel.prototype.tryDequeue = function(user, data) { @@ -1392,16 +1386,15 @@ Channel.prototype.tryUpdate = function(user, data) { return; } - if(data == null || - data.id == undefined || data.currentTime == undefined) { + if(typeof data.id !== "string" || typeof data.currentTime !== "number") return; - } if(this.playlist.current === null) { return; } - if(isLive(this.playlist.current.media.type) && this.playlist.current.media.type != "jw") { + if(isLive(this.playlist.current.media.type) + && this.playlist.current.media.type != "jw") { return; } diff --git a/playlist.js b/playlist.js index 2beeae03..301e2d5b 100644 --- a/playlist.js +++ b/playlist.js @@ -28,16 +28,24 @@ function Playlist(chan) { this.leading = true; this.callbacks = { "changeMedia": [], - "mediaUpdate": [] + "mediaUpdate": [], + "remove": [], }; if(chan) { + var pl = this; this.on("mediaUpdate", function(m) { chan.sendAll("mediaUpdate", m.timeupdate()); }); this.on("changeMedia", function(m) { + chan.sendAll("setCurrent", pl.current.uid); chan.sendAll("changeMedia", m.fullupdate()); }); + this.on("remove", function(item) { + chan.sendAll("delete", { + uid: item.uid + }); + }); } } @@ -141,6 +149,8 @@ Playlist.prototype.remove = function(uid, next) { if(item.next) item.next.prev = item.prev; + this.on("remove")(item); + if(this.current == item && next) this._next(); @@ -218,6 +228,7 @@ Playlist.prototype.clear = function() { Playlist.prototype.lead = function(lead) { this.leading = lead; + var pl = this; if(!this.leading && this._leadInterval) { clearInterval(this._leadInterval); this._leadInterval = false; @@ -234,6 +245,8 @@ Playlist.prototype.startPlayback = function() { this.current.media.currentTime = -2; var pl = this; setTimeout(function() { + if(!pl.current) + return; pl.current.media.paused = false; pl.on("mediaUpdate")(pl.current.media); }, 2000); diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 14d53014..7a34cb19 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -718,21 +718,22 @@ Callbacks = { playlistMove(data.from, data.after); }, - changeMedia: function(data) { - PL_CURRENT = data.uid; + setCurrent: function(uid) { + PL_CURRENT = uid; var qli = $("#queue li"); - $("#queue li").removeClass("queue_active"); - var li = $(".pluid-" + data.uid); + qli.removeClass("queue_active"); + var li = $(".pluid-" + uid); if(li.length == 0) { - console.log("couldn't find uid" + data.uid); + return false; } - // TODO send separate frame for highlight - //li.addClass("queue_active"); + li.addClass("queue_active"); $("#queue").scrollTop(0); - //var scroll = li.position().top - $("#queue").position().top; - //$("#queue").scrollTop(scroll); + var scroll = li.position().top - $("#queue").position().top; + $("#queue").scrollTop(scroll); + }, + changeMedia: function(data) { if(CHANNEL.opts.allow_voteskip) $("#voteskip").attr("disabled", false);