mirror of https://github.com/calzoneman/sync.git
Implement shuffle/clear (Issue #48)
This commit is contained in:
parent
ce34a3efe0
commit
27c494e450
39
channel.js
39
channel.js
|
@ -785,6 +785,45 @@ Channel.prototype.tryJumpTo = function(user, data) {
|
|||
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) {
|
||||
if(this.leader != user) {
|
||||
return;
|
||||
|
|
12
user.js
12
user.js
|
@ -153,6 +153,18 @@ User.prototype.initCallbacks = function() {
|
|||
}
|
||||
}.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) {
|
||||
if(this.channel != null) {
|
||||
this.channel.trySetLock(this, data);
|
||||
|
|
|
@ -295,6 +295,14 @@ $("#chatline").keydown(function(ev) {
|
|||
$("#messagebuffer").mouseenter(function() { SCROLLCHAT = false; });
|
||||
$("#messagebuffer").mouseleave(function() { SCROLLCHAT = true; });
|
||||
|
||||
$("#clearplaylist").click(function() {
|
||||
socket.emit("clearqueue");
|
||||
});
|
||||
|
||||
$("#shuffleplaylist").click(function() {
|
||||
socket.emit("shufflequeue");
|
||||
});
|
||||
|
||||
$("#getplaylist").click(function() {
|
||||
var callback = function(data) {
|
||||
socket.listeners("playlist").splice(
|
||||
|
|
|
@ -86,7 +86,11 @@
|
|||
<ul id="queue" class="videolist">
|
||||
</ul>
|
||||
<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 class="span6" id="librarydiv">
|
||||
<div class="input-append">
|
||||
|
|
Loading…
Reference in New Issue