Support click and drag to move; add play button; dump channels on exit
This commit is contained in:
parent
25421514d2
commit
546d50f917
48
channel.js
48
channel.js
|
@ -9,6 +9,7 @@ The above copyright notice and this permission notice shall be included in all c
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var fs = require("fs");
|
||||
var mysql = require("mysql-libmysqlclient");
|
||||
var Config = require("./config.js");
|
||||
var Rank = require("./rank.js");
|
||||
|
@ -44,6 +45,29 @@ var Channel = function(name) {
|
|||
|
||||
this.ipbans = {};
|
||||
this.logger = new Logger.Logger("chanlogs/" + this.name + ".log");
|
||||
fs.readFile("chandump/" + this.name, function(err, data) {
|
||||
if(err) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.logger.log("*** Loading channel dump from disk");
|
||||
data = JSON.parse(data);
|
||||
for(var i = 0; i < data.queue.length; i++) {
|
||||
var e = data.queue[i];
|
||||
this.queue.push(new Media(e.id, e.title, e.seconds, e.type));
|
||||
}
|
||||
this.sendAll("playlist", {
|
||||
pl: this.queue
|
||||
});
|
||||
this.currentPosition = data.currentPosition - 1;
|
||||
this.playNext();
|
||||
this.opts = data.opts;
|
||||
}
|
||||
catch(e) {
|
||||
Logger.errlog.log("Channel dump load failed: ");
|
||||
Logger.errlog.log(e);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
// Autolead stuff
|
||||
// Accumulator
|
||||
|
@ -667,6 +691,26 @@ Channel.prototype.playNext = function() {
|
|||
}
|
||||
}
|
||||
|
||||
Channel.prototype.jumpTo = function(pos) {
|
||||
if(this.queue.length == 0)
|
||||
return;
|
||||
if(pos >= this.queue.length || pos < 0)
|
||||
return;
|
||||
this.currentPosition = pos;
|
||||
this.currentMedia = this.queue[this.currentPosition];
|
||||
this.currentMedia.currentTime = 0;
|
||||
|
||||
this.sendAll("mediaUpdate", this.currentMedia.packupdate());
|
||||
this.sendAll("updatePlaylistIdx", {
|
||||
idx: this.currentPosition
|
||||
});
|
||||
// Enable autolead for non-twitch
|
||||
if(this.leader == null && this.currentMedia.type != "tw" && this.currentMedia.type != "li") {
|
||||
this.time = new Date().getTime();
|
||||
channelVideoUpdate(this, this.currentMedia.id);
|
||||
}
|
||||
}
|
||||
|
||||
Channel.prototype.setLock = function(locked) {
|
||||
this.qlocked = locked;
|
||||
this.sendAll("queueLock", {locked: locked});
|
||||
|
@ -701,12 +745,14 @@ Channel.prototype.moveMedia = function(data) {
|
|||
dest: data.dest
|
||||
});
|
||||
|
||||
if(data.src < this.currentPosition && data.dest >= this.currentPosition) {
|
||||
if(data.src < this.currentPosition && data.dest > this.currentPosition) {
|
||||
this.currentPosition--;
|
||||
}
|
||||
if(data.src > this.currentPosition && data.dest < this.currentPosition) {
|
||||
this.currentPosition++
|
||||
}
|
||||
if(data.src == this.currentPosition)
|
||||
this.currentPosition = data.dest;
|
||||
}
|
||||
|
||||
// Chat message from a user
|
||||
|
|
|
@ -22,6 +22,10 @@ exports.init = function() {
|
|||
var db = mysql.createConnectionSync();
|
||||
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
||||
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
||||
if(!db.connectedSync()) {
|
||||
Logger.errlog.log("database.init: DB connection failed");
|
||||
return false;
|
||||
}
|
||||
var query = "CREATE TABLE IF NOT EXISTS `channels` \
|
||||
(`id` INT NOT NULL, \
|
||||
`name` VARCHAR(255) NOT NULL, \
|
||||
|
|
1
rank.js
1
rank.js
|
@ -28,6 +28,7 @@ var permissions = {
|
|||
poll : exports.Moderator,
|
||||
shout : exports.Moderator,
|
||||
channelOpts : exports.Moderator,
|
||||
jump : exports.Moderator,
|
||||
search : exports.Guest,
|
||||
chat : exports.Guest,
|
||||
};
|
||||
|
|
25
server.js
25
server.js
|
@ -9,6 +9,7 @@ The above copyright notice and this permission notice shall be included in all c
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var fs = require("fs");
|
||||
var Logger = require("./logger.js");
|
||||
var Config = require("./config.js");
|
||||
var connect = require("connect");
|
||||
|
@ -25,3 +26,27 @@ exports.io.sockets.on("connection", function(socket) {
|
|||
var user = new User(socket, socket.handshake.address.address);
|
||||
Logger.syslog.log("Accepted connection from /" + user.ip);
|
||||
});
|
||||
|
||||
process.on("uncaughtException", function(err) {
|
||||
Logger.errlog.log("[SEVERE] Uncaught Exception: " + err);
|
||||
});
|
||||
|
||||
process.on("exit", shutdown);
|
||||
process.on("SIGINT", shutdown);
|
||||
|
||||
function shutdown() {
|
||||
Logger.syslog.log("Unloading channels...");
|
||||
for(var name in exports.channels) {
|
||||
var chan = exports.channels[name];
|
||||
var dump = {
|
||||
currentPosition: chan.currentPosition,
|
||||
queue: chan.queue,
|
||||
opts: chan.opts
|
||||
};
|
||||
var text = JSON.stringify(dump);
|
||||
fs.writeFileSync("chandump/" + name, text);
|
||||
chan.logger.flush();
|
||||
}
|
||||
Logger.syslog.log("Shutting Down");
|
||||
process.exit(0);
|
||||
}
|
||||
|
|
25
user.js
25
user.js
|
@ -42,8 +42,12 @@ User.prototype.initCallbacks = function() {
|
|||
}.bind(this));
|
||||
|
||||
this.socket.on("joinChannel", function(data) {
|
||||
if(data.name == undefined)
|
||||
return;
|
||||
if(!data.name.match(/^[a-zA-Z0-9]+$/))
|
||||
return;
|
||||
if(data.name.length > 100)
|
||||
return;
|
||||
// Channel already loaded
|
||||
if(data.name in Server.channels) {
|
||||
this.channel = Server.channels[data.name];
|
||||
|
@ -58,15 +62,25 @@ User.prototype.initCallbacks = function() {
|
|||
}.bind(this));
|
||||
|
||||
this.socket.on("login", function(data) {
|
||||
if(data.name == undefined || data.pw == undefined)
|
||||
return;
|
||||
if(data.pw.length > 100)
|
||||
data.pw = data.pw.substring(0, 100);
|
||||
if(this.name == "")
|
||||
this.login(data.name, data.pw);
|
||||
}.bind(this));
|
||||
|
||||
this.socket.on("register", function(data) {
|
||||
if(data.name == undefined || data.pw == undefined)
|
||||
return;
|
||||
if(data.pw.length > 100)
|
||||
data.pw = data.pw.substring(0, 100);
|
||||
this.register(data.name, data.pw);
|
||||
}.bind(this));
|
||||
|
||||
this.socket.on("assignLeader", function(data) {
|
||||
if(data.name == undefined)
|
||||
return;
|
||||
if(Rank.hasPermission(this, "assignLeader")) {
|
||||
if(this.channel != null)
|
||||
this.channel.changeLeader(data.name);
|
||||
|
@ -74,6 +88,8 @@ User.prototype.initCallbacks = function() {
|
|||
}.bind(this));
|
||||
|
||||
this.socket.on("promote", function(data) {
|
||||
if(data.name == undefined)
|
||||
return;
|
||||
if(Rank.hasPermission(this, "promote")) {
|
||||
if(this.channel != null) {
|
||||
this.channel.promoteUser(this, data.name);
|
||||
|
@ -137,6 +153,15 @@ User.prototype.initCallbacks = function() {
|
|||
}
|
||||
}.bind(this));
|
||||
|
||||
this.socket.on("jumpTo", function(data) {
|
||||
if(this.channel == null || data.pos == undefined)
|
||||
return;
|
||||
if(Rank.hasPermission(this, "jump") ||
|
||||
this.channel.leader == this) {
|
||||
this.channel.jumpTo(data.pos);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
this.socket.on("playNext", function() {
|
||||
if(this.channel == null)
|
||||
return;
|
||||
|
|
|
@ -68,7 +68,7 @@ function initCallbacks() {
|
|||
$("#opt_qopen_allow_playnext").prop("checked", opts.qopen_allow_playnext);
|
||||
$("#opt_pagetitle").attr("placeholder", opts.pagetitle);
|
||||
document.title = opts.pagetitle;
|
||||
$("opt_customcss").val(opts.customcss);
|
||||
$("#opt_customcss").attr("placeholder", opts.customcss);
|
||||
$("#customCss").remove();
|
||||
if(opts.customcss != "") {
|
||||
$("<link/>").attr("rel", "stylesheet")
|
||||
|
@ -82,6 +82,8 @@ function initCallbacks() {
|
|||
$("#queue_next").attr("disabled", false);
|
||||
if(opts.qopen_allow_playnext)
|
||||
$("#play_next").attr("disabled", false);
|
||||
else if(RANK < Rank.Moderator && !LEADER)
|
||||
$("#play_next").attr("disabled", true);
|
||||
rebuildPlaylist();
|
||||
});
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ var POSITION = -1;
|
|||
var RANK = 0;
|
||||
var OPENQUEUE = false;
|
||||
var CHANNELOPTS = {};
|
||||
var GRABBEDLI = null;
|
||||
var OLDINDEX = -1;
|
||||
var uname = readCookie("sync_uname");
|
||||
var pw = readCookie("sync_pw");
|
||||
|
||||
|
@ -218,13 +220,16 @@ $("#opt_submit").click(function() {
|
|||
var ptitle = $("#opt_pagetitle").val();
|
||||
if(ptitle == "")
|
||||
ptitle = $("#opt_pagetitle").attr("placeholder")
|
||||
var css = $("#opt_customcss").val();
|
||||
if(css == "")
|
||||
css = $("#opt_customcss").attr("placeholder");
|
||||
opts = {
|
||||
qopen_allow_qnext: $("#opt_qopen_allow_qnext").prop("checked"),
|
||||
qopen_allow_move: $("#opt_qopen_allow_move").prop("checked"),
|
||||
qopen_allow_delete: $("#opt_qopen_allow_delete").prop("checked"),
|
||||
qopen_allow_playnext: $("#opt_qopen_allow_playnext").prop("checked"),
|
||||
pagetitle: ptitle,
|
||||
customcss: $("#opt_customcss").val()
|
||||
customcss: css
|
||||
};
|
||||
socket.emit("channelOpts", opts);
|
||||
});
|
||||
|
|
|
@ -166,39 +166,57 @@ function makeQueueEntry(video) {
|
|||
function addQueueButtons(li) {
|
||||
var btnstrip = $("<div />").attr("class", "btn-group qe_buttons").prependTo(li);
|
||||
|
||||
var btnMove = $("<button />").addClass("btn qe_btn").appendTo(btnstrip);
|
||||
$("<i />").addClass("icon-resize-vertical").appendTo(btnMove);
|
||||
|
||||
var btnRemove = $("<button />").attr("class", "btn btn-danger qe_btn").appendTo(btnstrip);
|
||||
$("<i />").attr("class", "icon-remove").appendTo(btnRemove);
|
||||
|
||||
var btnUp = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
|
||||
$("<i />").attr("class", "icon-arrow-up").appendTo(btnUp);
|
||||
|
||||
var btnDown = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
|
||||
$("<i />").attr("class", "icon-arrow-down").appendTo(btnDown);
|
||||
var btnPlay = $("<button />").attr("class", "btn btn-success qe_btn").appendTo(btnstrip);
|
||||
$("<i />").attr("class", "icon-play").appendTo(btnPlay);
|
||||
|
||||
var btnNext = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
|
||||
//$("<i />").attr("class", "icon-play").appendTo(btnNext);
|
||||
btnNext.text("Next");
|
||||
|
||||
|
||||
// Callback time
|
||||
btnMove.mousedown(function() {
|
||||
GRABBEDLI = li;
|
||||
OLDINDEX = $("#queue").children().index(li);
|
||||
});
|
||||
|
||||
btnMove.mousemove(function() {
|
||||
if(GRABBEDLI != null) {
|
||||
var idx = $("#queue").children().index(li);
|
||||
var lidx = $("#queue").children().index(GRABBEDLI);
|
||||
if(idx != lidx)
|
||||
moveVideo(lidx, idx);
|
||||
}
|
||||
});
|
||||
|
||||
$(li).mouseup(function() {
|
||||
if(GRABBEDLI != null) {
|
||||
var idx = $("#queue").children().index(GRABBEDLI);
|
||||
GRABBEDLI = null;
|
||||
moveVideo(idx, OLDINDEX, true);
|
||||
socket.emit("moveMedia", {
|
||||
src: OLDINDEX,
|
||||
dest: idx
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(btnRemove).click(function() {
|
||||
btnstrip.remove();
|
||||
var idx = $("#queue").children().index(li);
|
||||
socket.emit("unqueue", { pos: idx });
|
||||
});
|
||||
|
||||
$(btnUp).click(function() {
|
||||
$(btnPlay).click(function() {
|
||||
var idx = $("#queue").children().index(li);
|
||||
socket.emit("moveMedia", {
|
||||
src: idx,
|
||||
dest: idx-1
|
||||
});
|
||||
});
|
||||
|
||||
$(btnDown).click(function() {
|
||||
var idx = $("#queue").children().index(li);
|
||||
socket.emit("moveMedia", {
|
||||
src: idx,
|
||||
dest: idx+1
|
||||
socket.emit("jumpTo", {
|
||||
pos: idx
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -214,12 +232,11 @@ function addQueueButtons(li) {
|
|||
if(RANK < Rank.Moderator && !LEADER) {
|
||||
if(!CHANNELOPTS.qopen_allow_delete)
|
||||
$(btnRemove).attr("disabled", true);
|
||||
if(!CHANNELOPTS.qopen_allow_move) {
|
||||
$(btnUp).attr("disabled", true);
|
||||
$(btnDown).attr("disabled", true);
|
||||
}
|
||||
if(!CHANNELOPTS.qopen_allow_move)
|
||||
$(btnMove).attr("disabled", true);
|
||||
if(!CHANNELOPTS.qopen_allow_qnext)
|
||||
$(btnNext).attr("disabled", true);
|
||||
$(btnPlay).attr("disabled", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,9 +278,19 @@ function addLibraryButtons(li, id) {
|
|||
}
|
||||
|
||||
// Rearranges the queue
|
||||
function moveVideo(src, dest) {
|
||||
function moveVideo(src, dest, noanim) {
|
||||
var li = $("#queue").children()[src];
|
||||
var ul = $("#queue")[0];
|
||||
if(noanim) {
|
||||
ul.removeChild(li);
|
||||
if(dest == ul.children.length) {
|
||||
ul.appendChild(li);
|
||||
}
|
||||
else {
|
||||
ul.insertBefore(li, ul.getElementsByTagName("li")[dest]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
$(li).hide("blind", function() {
|
||||
ul.removeChild(li);
|
||||
if(dest == ul.children.length) {
|
||||
|
@ -274,10 +301,12 @@ function moveVideo(src, dest) {
|
|||
}
|
||||
$(li).show("blind");
|
||||
});
|
||||
if(src < POSITION && dest >= POSITION)
|
||||
if(src < POSITION && dest > POSITION)
|
||||
POSITION--;
|
||||
if(src > POSITION && dest < POSITION)
|
||||
POSITION++;
|
||||
if(src == POSITION)
|
||||
POSITION = dest;
|
||||
}
|
||||
|
||||
// YouTube Synchronization
|
||||
|
|
Loading…
Reference in a new issue