Implement shuffle/clear (Issue #48)

This commit is contained in:
calzoneman 2013-04-22 15:37:42 -05:00
parent ce34a3efe0
commit 27c494e450
4 changed files with 64 additions and 1 deletions

View File

@ -785,6 +785,45 @@ Channel.prototype.tryJumpTo = function(user, data) {
this.jumpTo(data.pos); this.jumpTo(data.pos);
} }
Channel.prototype.clearqueue = function() {
this.queue = [];
for(var i = 0; i < this.users.length; i++) {
this.sendPlaylist(this.users[i]);
}
}
Channel.prototype.tryClearqueue = function(user) {
if(!Rank.hasPermission(user, "queue")) {
return;
}
this.clearqueue();
}
Channel.prototype.shufflequeue = function() {
var n = [];
var current = false;
while(this.queue.length > 0) {
var i = parseInt(Math.random() * this.queue.length);
n.push(this.queue[i]);
if(!current && i == this.position) {
this.position = n.length - 1;
current = true;
}
this.queue.splice(i, 1);
}
this.queue = n;
for(var i = 0; i < this.users.length; i++) {
this.sendPlaylist(this.users[i]);
}
}
Channel.prototype.tryShufflequeue = function(user) {
if(!Rank.hasPermission(user, "queue")) {
return;
}
this.shufflequeue();
}
Channel.prototype.tryUpdate = function(user, data) { Channel.prototype.tryUpdate = function(user, data) {
if(this.leader != user) { if(this.leader != user) {
return; return;

12
user.js
View File

@ -153,6 +153,18 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on("clearqueue", function() {
if(this.channel != null) {
this.channel.tryClearqueue(this);
}
}.bind(this));
this.socket.on("shufflequeue", function() {
if(this.channel != null) {
this.channel.tryShufflequeue(this);
}
}.bind(this));
this.socket.on("queueLock", function(data) { this.socket.on("queueLock", function(data) {
if(this.channel != null) { if(this.channel != null) {
this.channel.trySetLock(this, data); this.channel.trySetLock(this, data);

View File

@ -295,6 +295,14 @@ $("#chatline").keydown(function(ev) {
$("#messagebuffer").mouseenter(function() { SCROLLCHAT = false; }); $("#messagebuffer").mouseenter(function() { SCROLLCHAT = false; });
$("#messagebuffer").mouseleave(function() { SCROLLCHAT = true; }); $("#messagebuffer").mouseleave(function() { SCROLLCHAT = true; });
$("#clearplaylist").click(function() {
socket.emit("clearqueue");
});
$("#shuffleplaylist").click(function() {
socket.emit("shufflequeue");
});
$("#getplaylist").click(function() { $("#getplaylist").click(function() {
var callback = function(data) { var callback = function(data) {
socket.listeners("playlist").splice( socket.listeners("playlist").splice(

View File

@ -86,7 +86,11 @@
<ul id="queue" class="videolist"> <ul id="queue" class="videolist">
</ul> </ul>
<button class="btn btn-danger" id="qlockbtn" style="width: 100%; display:none;">Unlock Queue</button> <button class="btn btn-danger" id="qlockbtn" style="width: 100%; display:none;">Unlock Queue</button>
<button class="btn" id="getplaylist" style="width: 100%;">Get Playlist URLs</button> <div class="btn-group" style="width: 100%;">
<button class="btn" id="getplaylist" style="width: 34%">Get Playlist URLs</button>
<button class="btn" id="clearplaylist" style="width: 33%">Clear Playlist</button>
<button class="btn" id="shuffleplaylist" style="width: 33%">Shuffle Playlist</button>
</div>
</div> </div>
<div class="span6" id="librarydiv"> <div class="span6" id="librarydiv">
<div class="input-append"> <div class="input-append">