mirror of https://github.com/calzoneman/sync.git
Implement queue locking/unlocking
This commit is contained in:
parent
c5d9350351
commit
46bee2646d
10
channel.js
10
channel.js
|
@ -25,6 +25,7 @@ var Channel = function(name) {
|
|||
this.currentMedia = null;
|
||||
this.leader = null;
|
||||
this.recentChat = [];
|
||||
this.qlocked = true;
|
||||
|
||||
this.loadMysql();
|
||||
};
|
||||
|
@ -211,6 +212,7 @@ Channel.prototype.userJoin = function(user) {
|
|||
this.updateUsercount();
|
||||
// Set the new guy up
|
||||
this.sendPlaylist(user);
|
||||
user.socket.emit('queueLock', {locked: this.qlocked});
|
||||
this.sendUserlist(user);
|
||||
this.sendRecentChat(user);
|
||||
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
|
||||
Channel.prototype.update = function(data) {
|
||||
if(this.currentMedia == null) {
|
||||
|
|
1
rank.js
1
rank.js
|
@ -18,6 +18,7 @@ var permissions = {
|
|||
assignLeader: exports.Moderator,
|
||||
kick: exports.Moderator,
|
||||
promote: exports.Moderator,
|
||||
qlock: exports.Moderator,
|
||||
search: exports.Guest,
|
||||
chat: exports.Guest,
|
||||
};
|
||||
|
|
20
user.js
20
user.js
|
@ -93,21 +93,24 @@ User.prototype.initCallbacks = function() {
|
|||
}.bind(this));
|
||||
|
||||
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)
|
||||
this.channel.enqueue(data);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
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)
|
||||
this.channel.unqueue(data);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
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)
|
||||
this.channel.moveMedia(data);
|
||||
}
|
||||
|
@ -115,7 +118,8 @@ User.prototype.initCallbacks = function() {
|
|||
|
||||
this.socket.on('playNext', function() {
|
||||
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) {
|
||||
this.channel.currentPosition = -1;
|
||||
}
|
||||
|
@ -123,6 +127,14 @@ User.prototype.initCallbacks = function() {
|
|||
}
|
||||
}.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) {
|
||||
if(this.channel != null && this.channel.leader == this) {
|
||||
this.channel.update(data);
|
||||
|
|
|
@ -16,8 +16,10 @@ function initCallbacks() {
|
|||
});
|
||||
|
||||
socket.on('rank', function(data) {
|
||||
if(data.rank >= Rank.Moderator)
|
||||
if(data.rank >= Rank.Moderator) {
|
||||
$('#playlist_controls').css("display", "block");
|
||||
$('#qlockbtn').css("display", "block");
|
||||
}
|
||||
RANK = data.rank;
|
||||
});
|
||||
|
||||
|
@ -64,7 +66,7 @@ function initCallbacks() {
|
|||
}
|
||||
for(var i = 0; i < data.pl.length; i++) {
|
||||
var li = makeQueueEntry(data.pl[i]);
|
||||
if(RANK >= Rank.Moderator)
|
||||
if(RANK >= Rank.Moderator || OPENQUEUE)
|
||||
addQueueButtons(li);
|
||||
$(li).appendTo(ul);
|
||||
}
|
||||
|
@ -72,7 +74,7 @@ function initCallbacks() {
|
|||
|
||||
socket.on('queue', function(data) {
|
||||
var li = makeQueueEntry(data.media);
|
||||
if(RANK >= Rank.Moderator)
|
||||
if(RANK >= Rank.Moderator || OPENQUEUE)
|
||||
addQueueButtons(li);
|
||||
$(li).css('display', 'none');
|
||||
var idx = data.pos;
|
||||
|
@ -97,6 +99,31 @@ function initCallbacks() {
|
|||
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) {
|
||||
var liold = $('#queue').children()[POSITION];
|
||||
$(liold).removeClass("alert alert-info");
|
||||
|
@ -200,7 +227,7 @@ function initCallbacks() {
|
|||
var ul = $('#library')[0];
|
||||
for(var i = 0; i < data.results.length; i++) {
|
||||
var li = makeQueueEntry(data.results[i]);
|
||||
if(RANK >= Rank.Moderator)
|
||||
if(RANK >= Rank.Moderator || OPENQUEUE)
|
||||
addLibraryButtons(li, data.results[i].id);
|
||||
$(li).appendTo(ul);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ var PLAYER = false;
|
|||
var MEDIATYPE = "yt";
|
||||
var POSITION = -1;
|
||||
var RANK = 0;
|
||||
var OPENQUEUE = false;
|
||||
var uname = readCookie('sync_uname');
|
||||
var pw = readCookie('sync_pw');
|
||||
|
||||
|
@ -115,6 +116,12 @@ $('#play_next').click(function() {
|
|||
socket.emit('playNext');
|
||||
});
|
||||
|
||||
$('#qlockbtn').click(function() {
|
||||
socket.emit('queueLock', {
|
||||
locked: OPENQUEUE
|
||||
});
|
||||
});
|
||||
|
||||
function loginClick() {
|
||||
uname = $('#username').val();
|
||||
if($('#password').val() == "")
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
</div>
|
||||
<ul id="queue" class="videolist">
|
||||
</ul>
|
||||
<button class="btn btn-danger" id="qlockbtn" style="width: 100%; display:none;">Unlock Queue</button>
|
||||
</div>
|
||||
<div class="span6">
|
||||
<input type="text" id="library_query" style="margin:auto;">
|
||||
|
|
Loading…
Reference in New Issue