Implement queue locking/unlocking

This commit is contained in:
calzoneman 2013-03-16 15:39:58 -05:00
parent c5d9350351
commit 46bee2646d
6 changed files with 66 additions and 8 deletions

View file

@ -25,6 +25,7 @@ var Channel = function(name) {
this.currentMedia = null; this.currentMedia = null;
this.leader = null; this.leader = null;
this.recentChat = []; this.recentChat = [];
this.qlocked = true;
this.loadMysql(); this.loadMysql();
}; };
@ -211,6 +212,7 @@ Channel.prototype.userJoin = function(user) {
this.updateUsercount(); this.updateUsercount();
// Set the new guy up // Set the new guy up
this.sendPlaylist(user); this.sendPlaylist(user);
user.socket.emit('queueLock', {locked: this.qlocked});
this.sendUserlist(user); this.sendUserlist(user);
this.sendRecentChat(user); this.sendRecentChat(user);
if(user.playerReady) if(user.playerReady)
@ -356,6 +358,14 @@ Channel.prototype.playNext = function() {
} }
} }
Channel.prototype.setLock = function(locked) {
this.qlocked = locked;
this.sendAll('queueLock', {locked: locked});
for(var i = 0; i < this.users.length; i++) {
this.sendPlaylist(this.users[i]);
}
}
// Synchronize to a sync packet from the leader // Synchronize to a sync packet from the leader
Channel.prototype.update = function(data) { Channel.prototype.update = function(data) {
if(this.currentMedia == null) { if(this.currentMedia == null) {

View file

@ -18,6 +18,7 @@ var permissions = {
assignLeader: exports.Moderator, assignLeader: exports.Moderator,
kick: exports.Moderator, kick: exports.Moderator,
promote: exports.Moderator, promote: exports.Moderator,
qlock: exports.Moderator,
search: exports.Guest, search: exports.Guest,
chat: exports.Guest, chat: exports.Guest,
}; };

20
user.js
View file

@ -93,21 +93,24 @@ User.prototype.initCallbacks = function() {
}.bind(this)); }.bind(this));
this.socket.on('queue', function(data) { this.socket.on('queue', function(data) {
if(Rank.hasPermission(this, "queue")) { if(Rank.hasPermission(this, "queue") ||
(this.channel != null && !this.channel.qlocked)) {
if(this.channel != null) if(this.channel != null)
this.channel.enqueue(data); this.channel.enqueue(data);
} }
}.bind(this)); }.bind(this));
this.socket.on('unqueue', function(data) { this.socket.on('unqueue', function(data) {
if(Rank.hasPermission(this, "queue")) { if(Rank.hasPermission(this, "queue") ||
(this.channel != null && !this.channel.qlocked)) {
if(this.channel != null) if(this.channel != null)
this.channel.unqueue(data); this.channel.unqueue(data);
} }
}.bind(this)); }.bind(this));
this.socket.on('moveMedia', function(data) { this.socket.on('moveMedia', function(data) {
if(Rank.hasPermission(this, "queue")) { if(Rank.hasPermission(this, "queue") ||
(this.channel != null && !this.channel.qlocked)) {
if(this.channel != null) if(this.channel != null)
this.channel.moveMedia(data); this.channel.moveMedia(data);
} }
@ -115,7 +118,8 @@ User.prototype.initCallbacks = function() {
this.socket.on('playNext', function() { this.socket.on('playNext', function() {
if(Rank.hasPermission(this, "queue") || if(Rank.hasPermission(this, "queue") ||
(this.channel != null && this.channel.leader == this)) { (this.channel != null && (
this.channel.leader == this || !this.channel.qlocked))) {
if(this.channel.currentPosition + 1 >= this.channel.queue.length) { if(this.channel.currentPosition + 1 >= this.channel.queue.length) {
this.channel.currentPosition = -1; this.channel.currentPosition = -1;
} }
@ -123,6 +127,14 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on('queueLock', function(data) {
if(Rank.hasPermission(this, "qlock")) {
if(this.channel != null) {
this.channel.setLock(data.locked);
}
}
}.bind(this));
this.socket.on('mediaUpdate', function(data) { this.socket.on('mediaUpdate', function(data) {
if(this.channel != null && this.channel.leader == this) { if(this.channel != null && this.channel.leader == this) {
this.channel.update(data); this.channel.update(data);

View file

@ -16,8 +16,10 @@ function initCallbacks() {
}); });
socket.on('rank', function(data) { socket.on('rank', function(data) {
if(data.rank >= Rank.Moderator) if(data.rank >= Rank.Moderator) {
$('#playlist_controls').css("display", "block"); $('#playlist_controls').css("display", "block");
$('#qlockbtn').css("display", "block");
}
RANK = data.rank; RANK = data.rank;
}); });
@ -64,7 +66,7 @@ function initCallbacks() {
} }
for(var i = 0; i < data.pl.length; i++) { for(var i = 0; i < data.pl.length; i++) {
var li = makeQueueEntry(data.pl[i]); var li = makeQueueEntry(data.pl[i]);
if(RANK >= Rank.Moderator) if(RANK >= Rank.Moderator || OPENQUEUE)
addQueueButtons(li); addQueueButtons(li);
$(li).appendTo(ul); $(li).appendTo(ul);
} }
@ -72,7 +74,7 @@ function initCallbacks() {
socket.on('queue', function(data) { socket.on('queue', function(data) {
var li = makeQueueEntry(data.media); var li = makeQueueEntry(data.media);
if(RANK >= Rank.Moderator) if(RANK >= Rank.Moderator || OPENQUEUE)
addQueueButtons(li); addQueueButtons(li);
$(li).css('display', 'none'); $(li).css('display', 'none');
var idx = data.pos; var idx = data.pos;
@ -97,6 +99,31 @@ function initCallbacks() {
moveVideo(data.src, data.dest); moveVideo(data.src, data.dest);
}); });
socket.on('queueLock', function(data) {
OPENQUEUE = !data.locked;
if(OPENQUEUE) {
$('#playlist_controls').css('display', '');
if(RANK < Rank.Moderator) {
$('#qlockbtn').css('display', 'none');
}
}
else if(RANK < Rank.Moderator) {
$('#playlist_controls').css('display', 'none');
}
if(RANK >= Rank.Moderator) {
if(OPENQUEUE) {
$('#qlockbtn').removeClass('btn-danger')
.addClass('btn-success')
.text('Lock Queue');
}
else {
$('#qlockbtn').removeClass('btn-success')
.addClass('btn-danger')
.text('Unlock Queue');
}
}
});
socket.on('updatePlaylistIdx', function(data) { socket.on('updatePlaylistIdx', function(data) {
var liold = $('#queue').children()[POSITION]; var liold = $('#queue').children()[POSITION];
$(liold).removeClass("alert alert-info"); $(liold).removeClass("alert alert-info");
@ -200,7 +227,7 @@ function initCallbacks() {
var ul = $('#library')[0]; var ul = $('#library')[0];
for(var i = 0; i < data.results.length; i++) { for(var i = 0; i < data.results.length; i++) {
var li = makeQueueEntry(data.results[i]); var li = makeQueueEntry(data.results[i]);
if(RANK >= Rank.Moderator) if(RANK >= Rank.Moderator || OPENQUEUE)
addLibraryButtons(li, data.results[i].id); addLibraryButtons(li, data.results[i].id);
$(li).appendTo(ul); $(li).appendTo(ul);
} }

View file

@ -12,6 +12,7 @@ var PLAYER = false;
var MEDIATYPE = "yt"; var MEDIATYPE = "yt";
var POSITION = -1; var POSITION = -1;
var RANK = 0; var RANK = 0;
var OPENQUEUE = false;
var uname = readCookie('sync_uname'); var uname = readCookie('sync_uname');
var pw = readCookie('sync_pw'); var pw = readCookie('sync_pw');
@ -115,6 +116,12 @@ $('#play_next').click(function() {
socket.emit('playNext'); socket.emit('playNext');
}); });
$('#qlockbtn').click(function() {
socket.emit('queueLock', {
locked: OPENQUEUE
});
});
function loginClick() { function loginClick() {
uname = $('#username').val(); uname = $('#username').val();
if($('#password').val() == "") if($('#password').val() == "")

View file

@ -79,6 +79,7 @@
</div> </div>
<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>
</div> </div>
<div class="span6"> <div class="span6">
<input type="text" id="library_query" style="margin:auto;"> <input type="text" id="library_query" style="margin:auto;">