From 46bee2646dbf10cc1198a61be650f082f5e9d769 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sat, 16 Mar 2013 15:39:58 -0500 Subject: [PATCH] Implement queue locking/unlocking --- channel.js | 10 ++++++++++ rank.js | 1 + user.js | 20 ++++++++++++++++---- www/assets/js/callbacks.js | 35 +++++++++++++++++++++++++++++++---- www/assets/js/client.js | 7 +++++++ www/index.html | 1 + 6 files changed, 66 insertions(+), 8 deletions(-) diff --git a/channel.js b/channel.js index 88f031ae..94ba72b5 100644 --- a/channel.js +++ b/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) { diff --git a/rank.js b/rank.js index 5358b015..82583df2 100644 --- a/rank.js +++ b/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, }; diff --git a/user.js b/user.js index 37c2d254..8b83c3ab 100644 --- a/user.js +++ b/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); diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 0b5593b1..0826d6b4 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -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); } diff --git a/www/assets/js/client.js b/www/assets/js/client.js index 085d1206..de1f093c 100644 --- a/www/assets/js/client.js +++ b/www/assets/js/client.js @@ -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() == "") diff --git a/www/index.html b/www/index.html index 900f741f..10bf6857 100644 --- a/www/index.html +++ b/www/index.html @@ -79,6 +79,7 @@ +