Change quotes to be consistent

Fixes Issue#11
This commit is contained in:
calzoneman 2013-03-24 12:23:48 -05:00
parent a5ca7d227e
commit 5f5049db12
12 changed files with 527 additions and 527 deletions

10
auth.js
View File

@ -9,8 +9,8 @@ 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. 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 mysql = require('mysql-libmysqlclient'); var mysql = require("mysql-libmysqlclient");
var Config = require('./config.js'); var Config = require("./config.js");
// Check if a name is taken // Check if a name is taken
exports.isRegistered = function(name) { exports.isRegistered = function(name) {
@ -21,7 +21,7 @@ exports.isRegistered = function(name) {
console.log("MySQL Connection Failed"); console.log("MySQL Connection Failed");
return true; return true;
} }
var query = 'SELECT * FROM registrations WHERE uname="{}"' var query = "SELECT * FROM registrations WHERE uname='{}'"
.replace(/\{\}/, name); .replace(/\{\}/, name);
var results = db.querySync(query); var results = db.querySync(query);
var rows = results.fetchAllSync(); var rows = results.fetchAllSync();
@ -51,7 +51,7 @@ exports.register = function(name, sha256) {
console.log("MySQL Connection Failed"); console.log("MySQL Connection Failed");
return false; return false;
} }
var query = 'INSERT INTO registrations VALUES (NULL, "{1}", "{2}", 0)' var query = "INSERT INTO registrations VALUES (NULL, '{1}', '{2}', 0)"
.replace(/\{1\}/, name) .replace(/\{1\}/, name)
.replace(/\{2\}/, sha256); .replace(/\{2\}/, sha256);
var results = db.querySync(query); var results = db.querySync(query);
@ -68,7 +68,7 @@ exports.login = function(name, sha256) {
console.log("MySQL Connection Failed"); console.log("MySQL Connection Failed");
return false; return false;
} }
var query = 'SELECT * FROM registrations WHERE uname="{1}" AND pw="{2}"' var query = "SELECT * FROM registrations WHERE uname='{1}' AND pw='{2}'"
.replace(/\{1\}/, name) .replace(/\{1\}/, name)
.replace(/\{2\}/, sha256); .replace(/\{2\}/, sha256);
var results = db.querySync(query); var results = db.querySync(query);

View File

@ -9,14 +9,14 @@ 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. 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 mysql = require('mysql-libmysqlclient'); var mysql = require("mysql-libmysqlclient");
var Config = require('./config.js'); var Config = require("./config.js");
var Rank = require('./rank.js'); var Rank = require("./rank.js");
// I should use the <noun><verb>er naming scheme more often // I should use the <noun><verb>er naming scheme more often
var InfoGetter = require('./get-info.js'); var InfoGetter = require("./get-info.js");
var Media = require('./media.js').Media; var Media = require("./media.js").Media;
var ChatCommand = require('./chatcommand.js'); var ChatCommand = require("./chatcommand.js");
var Server = require('./server.js'); var Server = require("./server.js");
var io = Server.io; var io = Server.io;
var Channel = function(name) { var Channel = function(name) {
@ -63,7 +63,7 @@ Channel.prototype.loadMysql = function() {
return false; return false;
} }
// Check if channel exists // Check if channel exists
var query = 'SELECT * FROM channels WHERE name="{}"' var query = "SELECT * FROM channels WHERE name='{}'"
.replace(/\{\}/, this.name); .replace(/\{\}/, this.name);
var results = db.querySync(query); var results = db.querySync(query);
if(!results) { if(!results) {
@ -78,7 +78,7 @@ Channel.prototype.loadMysql = function() {
this.registered = true; this.registered = true;
// Load library // Load library
var query = 'SELECT * FROM chan_{}_library' var query = "SELECT * FROM chan_{}_library"
.replace(/\{\}/, this.name); .replace(/\{\}/, this.name);
var results = db.querySync(query); var results = db.querySync(query);
if(!results) { if(!results) {
@ -91,7 +91,7 @@ Channel.prototype.loadMysql = function() {
} }
// Load bans // Load bans
var query = 'SELECT * FROM chan_{}_bans' var query = "SELECT * FROM chan_{}_bans"
.replace(/\{\}/, this.name); .replace(/\{\}/, this.name);
var results = db.querySync(query); var results = db.querySync(query);
if(!results) { if(!results) {
@ -153,7 +153,7 @@ Channel.prototype.createTables = function() {
results = db.querySync(query) || results; results = db.querySync(query) || results;
// Insert into global channel table // Insert into global channel table
var query = 'INSERT INTO channels (`id`, `name`) VALUES (NULL, "{}")' var query = "INSERT INTO channels (`id`, `name`) VALUES (NULL, '{}')"
.replace(/\{\}/, this.name); .replace(/\{\}/, this.name);
results = db.querySync(query) || results; results = db.querySync(query) || results;
db.closeSync(); db.closeSync();
@ -162,20 +162,20 @@ Channel.prototype.createTables = function() {
Channel.prototype.tryRegister = function(user) { Channel.prototype.tryRegister = function(user) {
if(this.registered) { if(this.registered) {
user.socket.emit('registerChannel', { user.socket.emit("registerChannel", {
success: false, success: false,
error: "This channel is already registered" error: "This channel is already registered"
}); });
} }
else if(!user.loggedIn) { else if(!user.loggedIn) {
user.socket.emit('registerChannel', { user.socket.emit("registerChannel", {
success: false, success: false,
error: "You must log in to register a channel" error: "You must log in to register a channel"
}); });
} }
else if(!Rank.hasPermission(user, "registerChannel")) { else if(!Rank.hasPermission(user, "registerChannel")) {
user.socket.emit('registerChannel', { user.socket.emit("registerChannel", {
success: false, success: false,
error: "You don't have permission to register this channel" error: "You don't have permission to register this channel"
}); });
@ -184,12 +184,12 @@ Channel.prototype.tryRegister = function(user) {
if(this.createTables()) { if(this.createTables()) {
this.registered = true; this.registered = true;
this.saveRank(user); this.saveRank(user);
user.socket.emit('registerChannel', { user.socket.emit("registerChannel", {
success: true, success: true,
}); });
} }
else { else {
user.socket.emit('registerChannel', { user.socket.emit("registerChannel", {
success: false, success: false,
error: "Unable to register channel, see an admin" error: "Unable to register channel, see an admin"
}); });
@ -197,7 +197,7 @@ Channel.prototype.tryRegister = function(user) {
} }
} }
// Retrieves a user's rank from the database // Retrieves a user"s rank from the database
Channel.prototype.getRank = function(name) { Channel.prototype.getRank = function(name) {
if(!this.registered) if(!this.registered)
return Rank.Guest; return Rank.Guest;
@ -208,7 +208,7 @@ Channel.prototype.getRank = function(name) {
console.log("MySQL Connection Failed"); console.log("MySQL Connection Failed");
return Rank.Guest; return Rank.Guest;
} }
var query = 'SELECT * FROM chan_{1}_ranks WHERE name="{2}"' var query = "SELECT * FROM chan_{1}_ranks WHERE name='{2}'"
.replace(/\{1\}/, this.name) .replace(/\{1\}/, this.name)
.replace(/\{2\}/, name); .replace(/\{2\}/, name);
var results = db.querySync(query); var results = db.querySync(query);
@ -223,7 +223,7 @@ Channel.prototype.getRank = function(name) {
return rows[0].rank; return rows[0].rank;
} }
// Saves a user's rank to the database // Saves a user"s rank to the database
Channel.prototype.saveRank = function(user) { Channel.prototype.saveRank = function(user) {
if(!this.registered) if(!this.registered)
return false; return false;
@ -234,14 +234,14 @@ Channel.prototype.saveRank = function(user) {
console.log("MySQL Connection Failed"); console.log("MySQL Connection Failed");
return false; return false;
} }
var query = 'UPDATE chan_{1}_ranks SET rank="{2}" WHERE name="{3}"' var query = "UPDATE chan_{1}_ranks SET rank='{2}' WHERE name='{3}'"
.replace(/\{1\}/, this.name) .replace(/\{1\}/, this.name)
.replace(/\{2\}/, user.rank) .replace(/\{2\}/, user.rank)
.replace(/\{3\}/, user.name); .replace(/\{3\}/, user.name);
var results = db.querySync(query); var results = db.querySync(query);
// Gonna have to insert a new one, bugger // Gonna have to insert a new one, bugger
if(!results.fetchAllSync) { if(!results.fetchAllSync) {
var query = 'INSERT INTO chan_{1}_ranks (`name`, `rank`) VALUES ("{2}", "{3}")' var query = "INSERT INTO chan_{1}_ranks (`name`, `rank`) VALUES ('{2}', '{3}')"
.replace(/\{1\}/, this.name) .replace(/\{1\}/, this.name)
.replace(/\{2\}/, user.name) .replace(/\{2\}/, user.name)
.replace(/\{3\}/, user.rank); .replace(/\{3\}/, user.rank);
@ -264,7 +264,7 @@ Channel.prototype.addToLibrary = function(media) {
console.log("MySQL Connection Failed"); console.log("MySQL Connection Failed");
return false; return false;
} }
var query = 'INSERT INTO chan_{1}_library VALUES ("{2}", "{3}", {4}, "{5}", "{6}")' var query = "INSERT INTO chan_{1}_library VALUES ('{2}', '{3}', {4}, '{5}', '{6}')"
.replace(/\{1\}/, this.name) .replace(/\{1\}/, this.name)
.replace(/\{2\}/, media.id) .replace(/\{2\}/, media.id)
.replace(/\{3\}/, media.title) .replace(/\{3\}/, media.title)
@ -290,7 +290,7 @@ Channel.prototype.banIP = function(banner, bannee) {
console.log("MySQL Connection Failed"); console.log("MySQL Connection Failed");
return false; return false;
} }
var query = 'INSERT INTO chan_{1}_bans (`ip`, `name`, `banner`) VALUES ("{2}", "{3}", "{4}")' var query = "INSERT INTO chan_{1}_bans (`ip`, `name`, `banner`) VALUES ('{2}', '{3}', '{4}')"
.replace(/\{1\}/, this.name) .replace(/\{1\}/, this.name)
.replace(/\{2\}/, bannee.ip) .replace(/\{2\}/, bannee.ip)
.replace(/\{3\}/, bannee.name) .replace(/\{3\}/, bannee.name)
@ -317,7 +317,7 @@ Channel.prototype.unbanIP = function(ip) {
return false; return false;
} }
var query = 'DELETE FROM chan_{1}_bans WHERE `ip` = "{2}"' var query = "DELETE FROM chan_{1}_bans WHERE `ip` = '{2}'"
.replace(/\{1\}/, this.name) .replace(/\{1\}/, this.name)
.replace(/\{2\}/, ip); .replace(/\{2\}/, ip);
@ -363,18 +363,18 @@ Channel.prototype.userJoin = function(user) {
if(this.users[i].name == user.name) { if(this.users[i].name == user.name) {
user.name = ""; user.name = "";
user.loggedIn = false; user.loggedIn = false;
user.socket.emit('login', { user.socket.emit("login", {
success: false, success: false,
error: "The username " + user.name + " is already in use on this channel" error: "The username " + user.name + " is already in use on this channel"
}); });
} }
} }
} }
// If the channel is empty and isn't registered, the first person // If the channel is empty and isn"t registered, the first person
// gets ownership of the channel (temporarily) // gets ownership of the channel (temporarily)
if(this.users.length == 0 && !this.registered) { if(this.users.length == 0 && !this.registered) {
user.rank = (user.rank < Rank.Owner) ? Rank.Owner + 7 : user.rank; user.rank = (user.rank < Rank.Owner) ? Rank.Owner + 7 : user.rank;
user.socket.emit('channelNotRegistered'); user.socket.emit("channelNotRegistered");
} }
this.users.push(user); this.users.push(user);
if(user.name != "") { if(user.name != "") {
@ -383,13 +383,13 @@ 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}); user.socket.emit("queueLock", {locked: this.qlocked});
this.sendUserlist(user); this.sendUserlist(user);
this.sendRecentChat(user); this.sendRecentChat(user);
if(this.poll) { if(this.poll) {
user.socket.emit('newPoll', this.poll.packUpdate()); user.socket.emit("newPoll", this.poll.packUpdate());
} }
user.socket.emit('channelOpts', this.opts); user.socket.emit("channelOpts", this.opts);
var ents = []; var ents = [];
for(var ip in this.ipbans) { for(var ip in this.ipbans) {
if(this.ipbans[ip] != null) { if(this.ipbans[ip] != null) {
@ -400,7 +400,7 @@ Channel.prototype.userJoin = function(user) {
}); });
} }
} }
user.socket.emit('banlist', {entries: ents}); user.socket.emit("banlist", {entries: ents});
if(user.playerReady) if(user.playerReady)
this.sendMediaUpdate(user); this.sendMediaUpdate(user);
console.log("/" + user.ip + " joined channel " + this.name); console.log("/" + user.ip + " joined channel " + this.name);
@ -424,7 +424,7 @@ Channel.prototype.userLeave = function(user) {
this.users.splice(idx, 1); this.users.splice(idx, 1);
this.updateUsercount(); this.updateUsercount();
if(user.name != "") { if(user.name != "") {
this.sendAll('userLeave', { this.sendAll("userLeave", {
name: user.name name: user.name
}); });
} }
@ -436,7 +436,7 @@ Channel.prototype.enqueue = function(data) {
// Try to look up cached metadata first // Try to look up cached metadata first
if(data.id in this.library) { if(data.id in this.library) {
this.queue.splice(idx, 0, this.library[data.id]); this.queue.splice(idx, 0, this.library[data.id]);
this.sendAll('queue', { this.sendAll("queue", {
media: this.library[data.id].pack(), media: this.library[data.id].pack(),
pos: idx pos: idx
}); });
@ -451,11 +451,11 @@ Channel.prototype.enqueue = function(data) {
try { try {
// Whoever decided on this variable name should be fired // Whoever decided on this variable name should be fired
var seconds = data.entry.media$group.yt$duration.seconds; var seconds = data.entry.media$group.yt$duration.seconds;
// This one's slightly better // This one"s slightly better
var title = data.entry.title.$t; var title = data.entry.title.$t;
var vid = new Media(id, title, seconds, "yt"); var vid = new Media(id, title, seconds, "yt");
chan.queue.splice(idx, 0, vid); chan.queue.splice(idx, 0, vid);
chan.sendAll('queue', { chan.sendAll("queue", {
media: vid.pack(), media: vid.pack(),
pos: idx pos: idx
}); });
@ -471,7 +471,7 @@ Channel.prototype.enqueue = function(data) {
else if(data.type == "tw") { else if(data.type == "tw") {
var media = new Media(data.id, "Twitch ~ " + data.id, 0, "tw"); var media = new Media(data.id, "Twitch ~ " + data.id, 0, "tw");
this.queue.splice(idx, 0, media); this.queue.splice(idx, 0, media);
this.sendAll('queue', { this.sendAll("queue", {
media: media.pack(), media: media.pack(),
pos: idx pos: idx
}); });
@ -479,7 +479,7 @@ Channel.prototype.enqueue = function(data) {
else if(data.type == "li") { else if(data.type == "li") {
var media = new Media(data.id, "Livestream ~ " + data.id, 0, "li"); var media = new Media(data.id, "Livestream ~ " + data.id, 0, "li");
this.queue.splice(idx, 0, media); this.queue.splice(idx, 0, media);
this.sendAll('queue', { this.sendAll("queue", {
media: media.pack(), media: media.pack(),
pos: idx pos: idx
}); });
@ -495,7 +495,7 @@ Channel.prototype.enqueue = function(data) {
var title = data.title; var title = data.title;
var vid = new Media(id, title, seconds, "sc"); var vid = new Media(id, title, seconds, "sc");
chan.queue.splice(idx, 0, vid); chan.queue.splice(idx, 0, vid);
chan.sendAll('queue', { chan.sendAll("queue", {
media: vid.pack(), media: vid.pack(),
pos: idx pos: idx
}); });
@ -515,7 +515,7 @@ Channel.prototype.enqueue = function(data) {
var title = data.title; var title = data.title;
var vid = new Media(id, title, seconds, "vi"); var vid = new Media(id, title, seconds, "vi");
chan.queue.splice(idx, 0, vid); chan.queue.splice(idx, 0, vid);
chan.sendAll('queue', { chan.sendAll("queue", {
media: vid.pack(), media: vid.pack(),
pos: idx pos: idx
}); });
@ -535,7 +535,7 @@ Channel.prototype.enqueue = function(data) {
var title = data.title; var title = data.title;
var vid = new Media(id, title, seconds, "dm"); var vid = new Media(id, title, seconds, "dm");
chan.queue.splice(idx, 0, vid); chan.queue.splice(idx, 0, vid);
chan.sendAll('queue', { chan.sendAll("queue", {
media: vid.pack(), media: vid.pack(),
pos: idx pos: idx
}); });
@ -552,13 +552,13 @@ Channel.prototype.unqueue = function(data) {
return; return;
this.queue.splice(data.pos, 1); this.queue.splice(data.pos, 1);
this.sendAll('unqueue', { this.sendAll("unqueue", {
pos: data.pos pos: data.pos
}); });
if(data.pos < this.currentPosition) { if(data.pos < this.currentPosition) {
this.currentPosition--; this.currentPosition--;
this.sendAll('updatePlaylistIdx', { this.sendAll("updatePlaylistIdx", {
idx: this.currentPosition idx: this.currentPosition
}); });
} }
@ -579,8 +579,8 @@ Channel.prototype.playNext = function() {
this.currentMedia = this.queue[this.currentPosition]; this.currentMedia = this.queue[this.currentPosition];
this.currentMedia.currentTime = 0; this.currentMedia.currentTime = 0;
this.sendAll('mediaUpdate', this.currentMedia.packupdate()); this.sendAll("mediaUpdate", this.currentMedia.packupdate());
this.sendAll('updatePlaylistIdx', { this.sendAll("updatePlaylistIdx", {
idx: this.currentPosition idx: this.currentPosition
}); });
// Enable autolead for non-twitch // Enable autolead for non-twitch
@ -592,7 +592,7 @@ Channel.prototype.playNext = function() {
Channel.prototype.setLock = function(locked) { Channel.prototype.setLock = function(locked) {
this.qlocked = locked; this.qlocked = locked;
this.sendAll('queueLock', {locked: locked}); this.sendAll("queueLock", {locked: locked});
for(var i = 0; i < this.users.length; i++) { for(var i = 0; i < this.users.length; i++) {
this.sendPlaylist(this.users[i]); this.sendPlaylist(this.users[i]);
} }
@ -606,7 +606,7 @@ Channel.prototype.update = function(data) {
} }
else else
this.currentMedia.currentTime = data.seconds; this.currentMedia.currentTime = data.seconds;
this.sendAll('mediaUpdate', this.currentMedia.packupdate()); this.sendAll("mediaUpdate", this.currentMedia.packupdate());
} }
// Move something around in the queue // Move something around in the queue
@ -619,7 +619,7 @@ Channel.prototype.moveMedia = function(data) {
var media = this.queue[data.src]; var media = this.queue[data.src];
this.queue.splice(data.src, 1); this.queue.splice(data.src, 1);
this.queue.splice(data.dest, 0, media); this.queue.splice(data.dest, 0, media);
this.sendAll('moveVideo', { this.sendAll("moveVideo", {
src: data.src, src: data.src,
dest: data.dest dest: data.dest
}); });
@ -645,11 +645,11 @@ Channel.prototype.chatMessage = function(user, msg) {
} }
Channel.prototype.sendMessage = function(username, msg, msgclass) { Channel.prototype.sendMessage = function(username, msg, msgclass) {
// I don't want HTML from strangers // I don"t want HTML from strangers
msg = msg.replace(/</g, "&lt;").replace(/>/g, "&gt;"); msg = msg.replace(/</g, "&lt;").replace(/>/g, "&gt;");
// Match URLs // Match URLs
msg = msg.replace(/(((https?)|(ftp))(:\/\/[0-9a-zA-Z\.]+(:[0-9]+)?[^\s$]+))/, "<a href=\"$1\" target=\"_blank\">$1</a>"); msg = msg.replace(/(((https?)|(ftp))(:\/\/[0-9a-zA-Z\.]+(:[0-9]+)?[^\s$]+))/, "<a href=\"$1\" target=\"_blank\">$1</a>");
this.sendAll('chatMsg', { this.sendAll("chatMsg", {
username: username, username: username,
msg: msg, msg: msg,
msgclass: msgclass msgclass: msgclass
@ -676,8 +676,8 @@ Channel.prototype.promoteUser = function(actor, name) {
if(receiver) { if(receiver) {
// You can only promote someone if you are 2 ranks or higher above // You can only promote someone if you are 2 ranks or higher above
// them. This way you can't promote them to your rank and end // them. This way you can"t promote them to your rank and end
// up in a situation where you can't demote them // up in a situation where you can"t demote them
if(actor.rank > receiver.rank + 1) { if(actor.rank > receiver.rank + 1) {
receiver.rank++; receiver.rank++;
if(receiver.loggedIn) { if(receiver.loggedIn) {
@ -688,7 +688,7 @@ Channel.prototype.promoteUser = function(actor, name) {
} }
} }
// You're fired // You"re fired
Channel.prototype.demoteUser = function(actor, name) { Channel.prototype.demoteUser = function(actor, name) {
var receiver; var receiver;
for(var i = 0; i < this.users.length; i++) { for(var i = 0; i < this.users.length; i++) {
@ -699,8 +699,8 @@ Channel.prototype.demoteUser = function(actor, name) {
} }
if(receiver) { if(receiver) {
// Wouldn't it be funny if you could demote people who rank higher // Wouldn"t it be funny if you could demote people who rank higher
// than you? No, it wouldn't. // than you? No, it wouldn"t.
if(actor.rank > receiver.rank) { if(actor.rank > receiver.rank) {
receiver.rank--; receiver.rank--;
if(receiver.loggedIn) { if(receiver.loggedIn) {
@ -711,7 +711,7 @@ Channel.prototype.demoteUser = function(actor, name) {
} }
} }
// Manual leader. This shouldn't be necessary since the server autoleads, // Manual leader. This shouldn"t be necessary since the server autoleads,
// but you never know // but you never know
Channel.prototype.changeLeader = function(name) { Channel.prototype.changeLeader = function(name) {
if(this.leader != null) { if(this.leader != null) {
@ -736,11 +736,11 @@ Channel.prototype.changeLeader = function(name) {
} }
// Send the userlist to a client // Send the userlist to a client
// Do you know you're all my very best friends? // Do you know you"re all my very best friends?
Channel.prototype.sendUserlist = function(user) { Channel.prototype.sendUserlist = function(user) {
var users = []; var users = [];
for(var i = 0; i < this.users.length; i++) { for(var i = 0; i < this.users.length; i++) {
// Skip people who haven't logged in // Skip people who haven"t logged in
if(this.users[i].name != "") { if(this.users[i].name != "") {
users.push({ users.push({
name: this.users[i].name, name: this.users[i].name,
@ -749,21 +749,21 @@ Channel.prototype.sendUserlist = function(user) {
}); });
} }
} }
user.socket.emit('userlist', users) user.socket.emit("userlist", users)
} }
Channel.prototype.updateUsercount = function() { Channel.prototype.updateUsercount = function() {
this.sendAll('usercount', { this.sendAll("usercount", {
count: this.users.length count: this.users.length
}); });
} }
// Send the play queue // Send the play queue
Channel.prototype.sendPlaylist = function(user) { Channel.prototype.sendPlaylist = function(user) {
user.socket.emit('playlist', { user.socket.emit("playlist", {
pl: this.queue pl: this.queue
}); });
user.socket.emit('updatePlaylistIdx', { user.socket.emit("updatePlaylistIdx", {
idx: this.currentPosition idx: this.currentPosition
}); });
} }
@ -771,32 +771,32 @@ Channel.prototype.sendPlaylist = function(user) {
// Send the last 15 messages for context // Send the last 15 messages for context
Channel.prototype.sendRecentChat = function(user) { Channel.prototype.sendRecentChat = function(user) {
for(var i = 0; i < this.recentChat.length; i++) { for(var i = 0; i < this.recentChat.length; i++) {
user.socket.emit('chatMsg', this.recentChat[i]); user.socket.emit("chatMsg", this.recentChat[i]);
} }
} }
// Send a sync packet // Send a sync packet
Channel.prototype.sendMediaUpdate = function(user) { Channel.prototype.sendMediaUpdate = function(user) {
if(this.currentMedia != null) { if(this.currentMedia != null) {
user.socket.emit('mediaUpdate', this.currentMedia.packupdate()); user.socket.emit("mediaUpdate", this.currentMedia.packupdate());
} }
else { else {
console.log('currentMedia is null'); console.log("currentMedia is null");
} }
} }
// Sent when someone logs in, to add them to the user list // Sent when someone logs in, to add them to the user list
Channel.prototype.broadcastNewUser = function(user) { Channel.prototype.broadcastNewUser = function(user) {
this.sendAll('addUser', { this.sendAll("addUser", {
name: user.name, name: user.name,
rank: user.rank, rank: user.rank,
leader: this.leader == user leader: this.leader == user
}); });
} }
// Someone's rank changed, or their leadership status changed // Someone"s rank changed, or their leadership status changed
Channel.prototype.broadcastRankUpdate = function(user) { Channel.prototype.broadcastRankUpdate = function(user) {
this.sendAll('updateUser', { this.sendAll("updateUser", {
name: user.name, name: user.name,
rank: user.rank, rank: user.rank,
leader: this.leader == user leader: this.leader == user
@ -804,19 +804,19 @@ Channel.prototype.broadcastRankUpdate = function(user) {
} }
Channel.prototype.broadcastPoll = function() { Channel.prototype.broadcastPoll = function() {
this.sendAll('newPoll', this.poll.packUpdate()); this.sendAll("newPoll", this.poll.packUpdate());
} }
Channel.prototype.broadcastPollUpdate = function() { Channel.prototype.broadcastPollUpdate = function() {
this.sendAll('updatePoll', this.poll.packUpdate()); this.sendAll("updatePoll", this.poll.packUpdate());
} }
Channel.prototype.broadcastPollClose = function() { Channel.prototype.broadcastPollClose = function() {
this.sendAll('closePoll'); this.sendAll("closePoll");
} }
Channel.prototype.broadcastOpts = function() { Channel.prototype.broadcastOpts = function() {
this.sendAll('channelOpts', this.opts); this.sendAll("channelOpts", this.opts);
} }
Channel.prototype.broadcastIpbans = function() { Channel.prototype.broadcastIpbans = function() {
@ -830,7 +830,7 @@ Channel.prototype.broadcastIpbans = function() {
}); });
} }
} }
this.sendAll('banlist', {entries: ents}); this.sendAll("banlist", {entries: ents});
} }
// Send to ALL the clients! // Send to ALL the clients!
@ -840,7 +840,7 @@ Channel.prototype.sendAll = function(message, data) {
// Autolead yay // Autolead yay
function channelVideoUpdate(chan, id) { function channelVideoUpdate(chan, id) {
// Someone changed the video or there's a manual leader, so your // Someone changed the video or there"s a manual leader, so your
// argument is invalid // argument is invalid
if(chan.currentMedia == null || id != chan.currentMedia.id || chan.leader != null) if(chan.currentMedia == null || id != chan.currentMedia.id || chan.leader != null)
return; return;
@ -853,7 +853,7 @@ function channelVideoUpdate(chan, id) {
} }
// Every ~5 seconds send a sync packet to everyone // Every ~5 seconds send a sync packet to everyone
else if(chan.i % 5 == 0) else if(chan.i % 5 == 0)
chan.sendAll('mediaUpdate', chan.currentMedia.packupdate()); chan.sendAll("mediaUpdate", chan.currentMedia.packupdate());
chan.i++; chan.i++;
// Do it all over again in about a second // Do it all over again in about a second
setTimeout(function() { channelVideoUpdate(chan, id); }, 1000); setTimeout(function() { channelVideoUpdate(chan, id); }, 1000);

View File

@ -9,8 +9,8 @@ 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. 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 Rank = require('./rank.js'); var Rank = require("./rank.js");
var Poll = require('./poll.js').Poll; var Poll = require("./poll.js").Poll;
function handle(chan, user, msg) { function handle(chan, user, msg) {
if(msg.indexOf("/me ") == 0) if(msg.indexOf("/me ") == 0)
@ -23,13 +23,13 @@ function handle(chan, user, msg) {
} }
} }
else if(msg.indexOf("/kick ") == 0) { else if(msg.indexOf("/kick ") == 0) {
handleKick(chan, user, msg.substring(6).split(' ')); handleKick(chan, user, msg.substring(6).split(" "));
} }
else if(msg.indexOf("/ban ") == 0) { else if(msg.indexOf("/ban ") == 0) {
handleBan(chan, user, msg.substring(5).split(' ')); handleBan(chan, user, msg.substring(5).split(" "));
} }
else if(msg.indexOf("/unban ") == 0) { else if(msg.indexOf("/unban ") == 0) {
handleUnban(chan, user, msg.substring(7).split(' ')); handleUnban(chan, user, msg.substring(7).split(" "));
} }
else if(msg.indexOf("/poll ") == 0) { else if(msg.indexOf("/poll ") == 0) {
handlePoll(chan, user, msg.substring(6)); handlePoll(chan, user, msg.substring(6));
@ -74,7 +74,7 @@ function handleUnban(chan, user, args) {
function handlePoll(chan, user, msg) { function handlePoll(chan, user, msg) {
if(Rank.hasPermission(user, "poll")) { if(Rank.hasPermission(user, "poll")) {
var args = msg.split(','); var args = msg.split(",");
var title = args[0]; var title = args[0];
args.splice(0, 1); args.splice(0, 1);
var poll = new Poll(user.name, title, args); var poll = new Poll(user.name, title, args);

View File

@ -9,8 +9,8 @@ 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. 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.
*/ */
exports.MYSQL_SERVER = ''; exports.MYSQL_SERVER = "";
exports.MYSQL_DB = ''; exports.MYSQL_DB = "";
exports.MYSQL_USER = ''; exports.MYSQL_USER = "";
exports.MYSQL_PASSWORD = ''; exports.MYSQL_PASSWORD = "";
exports.IO_PORT = 1337; exports.IO_PORT = 1337;

View File

@ -9,8 +9,8 @@ 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. 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 mysql = require('mysql-libmysqlclient'); var mysql = require("mysql-libmysqlclient");
var Config = require('./config.js'); var Config = require("./config.js");
var initialized = false; var initialized = false;

View File

@ -9,19 +9,19 @@ 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. 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 http = require('http'); var http = require("http");
var https = require('https'); var https = require("https");
// Helper function for making an HTTP request and getting the result // Helper function for making an HTTP request and getting the result
// as JSON // as JSON
function getJSON(options, callback) { function getJSON(options, callback) {
var req = http.request(options, function(res){ var req = http.request(options, function(res){
var buffer = ''; var buffer = "";
res.setEncoding('utf8'); res.setEncoding("utf8");
res.on('data', function (chunk) { res.on("data", function (chunk) {
buffer += chunk; buffer += chunk;
}); });
res.on('end', function() { res.on("end", function() {
try { try {
var data = JSON.parse(buffer); var data = JSON.parse(buffer);
} }
@ -39,12 +39,12 @@ function getJSON(options, callback) {
// Dailymotion uses HTTPS for anonymous requests... [](/picard) // Dailymotion uses HTTPS for anonymous requests... [](/picard)
function getJSONHTTPS(options, callback) { function getJSONHTTPS(options, callback) {
var req = https.request(options, function(res){ var req = https.request(options, function(res){
var buffer = ''; var buffer = "";
res.setEncoding('utf8'); res.setEncoding("utf8");
res.on('data', function (chunk) { res.on("data", function (chunk) {
buffer += chunk; buffer += chunk;
}); });
res.on('end', function() { res.on("end", function() {
try { try {
var data = JSON.parse(buffer); var data = JSON.parse(buffer);
} }
@ -72,13 +72,13 @@ exports.getYTInfo = function(id, callback) {
} }
// Look up Soundcloud metadata // Look up Soundcloud metadata
// Whoever designed this should rethink it. I'll submit a feedback // Whoever designed this should rethink it. I"ll submit a feedback
// form on their website. // form on their website.
exports.getSCInfo = function(url, callback) { exports.getSCInfo = function(url, callback) {
const SC_CLIENT = '2e0c82ab5a020f3a7509318146128abd'; const SC_CLIENT = "2e0c82ab5a020f3a7509318146128abd";
// SoundCloud is dumb // SoundCloud is dumb
// I have to request the API URL for the given input URL // I have to request the API URL for the given input URL
// Because the sound ID isn't in the URL // Because the sound ID isn"t in the URL
getJSON({ getJSON({
host: "api.soundcloud.com", host: "api.soundcloud.com",
port: 80, port: 80,

View File

@ -9,17 +9,17 @@ 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. 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 Config = require('./config.js'); var Config = require("./config.js");
var connect = require('connect'); var connect = require("connect");
var app = connect.createServer(connect.static(__dirname+'/www')).listen(Config.IO_PORT); var app = connect.createServer(connect.static(__dirname+"/www")).listen(Config.IO_PORT);
exports.io = require('socket.io').listen(app); exports.io = require("socket.io").listen(app);
var User = require('./user.js').User; var User = require("./user.js").User;
var Database = require('./database.js'); var Database = require("./database.js");
Database.init(); Database.init();
exports.channels = {}; exports.channels = {};
exports.io.sockets.on('connection', function(socket) { exports.io.sockets.on("connection", function(socket) {
var user = new User(socket, socket.handshake.address.address); var user = new User(socket, socket.handshake.address.address);
console.log('New connection from /' + user.ip); console.log("New connection from /" + user.ip);
}); });

98
user.js
View File

@ -9,11 +9,11 @@ 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. 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 Rank = require('./rank.js'); var Rank = require("./rank.js");
var Auth = require('./auth.js'); var Auth = require("./auth.js");
var Channel = require('./channel.js').Channel; var Channel = require("./channel.js").Channel;
var Server = require('./server.js'); var Server = require("./server.js");
var Database = require('./database.js'); var Database = require("./database.js");
// Represents a client connected via socket.io // Represents a client connected via socket.io
var User = function(socket, ip) { var User = function(socket, ip) {
@ -27,7 +27,7 @@ var User = function(socket, ip) {
this.initCallbacks(); this.initCallbacks();
if(Server.announcement != null) { if(Server.announcement != null) {
this.socket.emit('announcement', Server.announcement); this.socket.emit("announcement", Server.announcement);
} }
}; };
@ -35,12 +35,12 @@ var User = function(socket, ip) {
// Set up socket callbacks // Set up socket callbacks
User.prototype.initCallbacks = function() { User.prototype.initCallbacks = function() {
// What a shame // What a shame
this.socket.on('disconnect', function() { this.socket.on("disconnect", function() {
if(this.channel != null) if(this.channel != null)
this.channel.userLeave(this); this.channel.userLeave(this);
}.bind(this)); }.bind(this));
this.socket.on('joinChannel', function(data) { this.socket.on("joinChannel", function(data) {
if(!data.name.match(/^[a-zA-Z0-9]+$/)) if(!data.name.match(/^[a-zA-Z0-9]+$/))
return; return;
// Channel already loaded // Channel already loaded
@ -56,23 +56,23 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on('login', function(data) { this.socket.on("login", function(data) {
if(this.name == "") if(this.name == "")
this.login(data.name, data.sha256); this.login(data.name, data.sha256);
}.bind(this)); }.bind(this));
this.socket.on('register', function(data) { this.socket.on("register", function(data) {
this.register(data.name, data.sha256); this.register(data.name, data.sha256);
}.bind(this)); }.bind(this));
this.socket.on('assignLeader', function(data) { this.socket.on("assignLeader", function(data) {
if(Rank.hasPermission(this, "assignLeader")) { if(Rank.hasPermission(this, "assignLeader")) {
if(this.channel != null) if(this.channel != null)
this.channel.changeLeader(data.name); this.channel.changeLeader(data.name);
} }
}.bind(this)); }.bind(this));
this.socket.on('promote', function(data) { this.socket.on("promote", function(data) {
if(Rank.hasPermission(this, "promote")) { if(Rank.hasPermission(this, "promote")) {
if(this.channel != null) { if(this.channel != null) {
this.channel.promoteUser(this, data.name); this.channel.promoteUser(this, data.name);
@ -80,7 +80,7 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on('demote', function(data) { this.socket.on("demote", function(data) {
if(Rank.hasPermission(this, "promote")) { if(Rank.hasPermission(this, "promote")) {
if(this.channel != null) { if(this.channel != null) {
this.channel.demoteUser(this, data.name); this.channel.demoteUser(this, data.name);
@ -88,20 +88,20 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on('chatMsg', function(data) { this.socket.on("chatMsg", function(data) {
if(this.name != "" && this.channel != null) { if(this.name != "" && this.channel != null) {
this.channel.chatMessage(this, data.msg); this.channel.chatMessage(this, data.msg);
} }
}.bind(this)); }.bind(this));
this.socket.on('playerReady', function() { this.socket.on("playerReady", function() {
if(this.channel != null) { if(this.channel != null) {
this.channel.sendMediaUpdate(this); this.channel.sendMediaUpdate(this);
} }
this.playerReady = true; this.playerReady = true;
}.bind(this)); }.bind(this));
this.socket.on('queue', function(data) { this.socket.on("queue", function(data) {
if(this.channel == null) if(this.channel == null)
return; return;
if(Rank.hasPermission(this, "queue") || if(Rank.hasPermission(this, "queue") ||
@ -116,7 +116,7 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on('unqueue', function(data) { this.socket.on("unqueue", function(data) {
if(this.channel == null) if(this.channel == null)
return; return;
if(Rank.hasPermission(this, "queue") || if(Rank.hasPermission(this, "queue") ||
@ -126,7 +126,7 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on('moveMedia', function(data) { this.socket.on("moveMedia", function(data) {
if(this.channel == null) if(this.channel == null)
return; return;
if(Rank.hasPermission(this, "queue") || if(Rank.hasPermission(this, "queue") ||
@ -136,7 +136,7 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on('playNext', function() { this.socket.on("playNext", function() {
if(this.channel == null) if(this.channel == null)
return; return;
if(Rank.hasPermission(this, "queue") || if(Rank.hasPermission(this, "queue") ||
@ -149,7 +149,7 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on('queueLock', function(data) { this.socket.on("queueLock", function(data) {
if(Rank.hasPermission(this, "qlock")) { if(Rank.hasPermission(this, "qlock")) {
if(this.channel != null) { if(this.channel != null) {
this.channel.setLock(data.locked); this.channel.setLock(data.locked);
@ -157,21 +157,21 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.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);
} }
}.bind(this)); }.bind(this));
this.socket.on('searchLibrary', function(data) { this.socket.on("searchLibrary", function(data) {
if(this.channel != null && Rank.hasPermission(this, "search")) { if(this.channel != null && Rank.hasPermission(this, "search")) {
this.socket.emit('librarySearchResults', { this.socket.emit("librarySearchResults", {
results: this.channel.searchLibrary(data.query) results: this.channel.searchLibrary(data.query)
}); });
} }
}.bind(this)); }.bind(this));
this.socket.on('closePoll', function() { this.socket.on("closePoll", function() {
if(Rank.hasPermission(this, "poll")) { if(Rank.hasPermission(this, "poll")) {
if(this.channel != null && this.channel.poll) { if(this.channel != null && this.channel.poll) {
this.channel.poll = null; this.channel.poll = null;
@ -180,16 +180,16 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on('vote', function(data) { this.socket.on("vote", function(data) {
if(this.channel != null && this.channel.poll) { if(this.channel != null && this.channel.poll) {
this.channel.poll.vote(this.ip, data.option); this.channel.poll.vote(this.ip, data.option);
this.channel.broadcastPollUpdate(); this.channel.broadcastPollUpdate();
} }
}.bind(this)); }.bind(this));
this.socket.on('registerChannel', function(data) { this.socket.on("registerChannel", function(data) {
if(this.channel == null) { if(this.channel == null) {
this.socket.emit('channelRegistration', { this.socket.emit("channelRegistration", {
success: false, success: false,
error: "You're not in any channel!" error: "You're not in any channel!"
}); });
@ -199,25 +199,25 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on('adm', function(data) { this.socket.on("adm", function(data) {
if(Rank.hasPermission(this, "acp")) { if(Rank.hasPermission(this, "acp")) {
this.handleAdm(data); this.handleAdm(data);
} }
}.bind(this)); }.bind(this));
this.socket.on('announce', function(data) { this.socket.on("announce", function(data) {
if(Rank.hasPermission(this, "announce")) { if(Rank.hasPermission(this, "announce")) {
if(data.clear) { if(data.clear) {
Server.announcement = null; Server.announcement = null;
} }
else { else {
Server.io.sockets.emit('announcement', data); Server.io.sockets.emit("announcement", data);
Server.announcement = data; Server.announcement = data;
} }
} }
}.bind(this)); }.bind(this));
this.socket.on('channelOpts', function(data) { this.socket.on("channelOpts", function(data) {
if(Rank.hasPermission(this, "channelOpts") && this.channel != null) { if(Rank.hasPermission(this, "channelOpts") && this.channel != null) {
this.channel.opts = data; this.channel.opts = data;
this.channel.broadcastOpts(); this.channel.broadcastOpts();
@ -239,7 +239,7 @@ User.prototype.handleAdm = function(data) {
nowplaying: nowplaying nowplaying: nowplaying
}); });
} }
this.socket.emit('adm', { this.socket.emit("adm", {
cmd: "listchannels", cmd: "listchannels",
chans: chans chans: chans
}); });
@ -255,7 +255,7 @@ User.prototype.handleAdm = function(data) {
rank: dbusers[i].global_rank rank: dbusers[i].global_rank
}; };
} }
this.socket.emit('adm', { this.socket.emit("adm", {
cmd: "listusers", cmd: "listusers",
users: users users: users
}); });
@ -263,7 +263,7 @@ User.prototype.handleAdm = function(data) {
else if(data.cmd == "listchannelranks") { else if(data.cmd == "listchannelranks") {
if(data.chan == undefined) if(data.chan == undefined)
return; return;
this.socket.emit('adm', { this.socket.emit("adm", {
cmd: "listchannelranks", cmd: "listchannelranks",
ranks: Database.listChannelRanks(data.chan) ranks: Database.listChannelRanks(data.chan)
}); });
@ -276,7 +276,7 @@ User.prototype.login = function(name, sha256) {
if(this.channel != null && name != "") { if(this.channel != null && name != "") {
for(var i = 0; i < this.channel.users.length; i++) { for(var i = 0; i < this.channel.users.length; i++) {
if(this.channel.users[i].name == name) { if(this.channel.users[i].name == name) {
this.socket.emit('login', { this.socket.emit("login", {
success: false, success: false,
error: "The username " + name + " is already in use on this channel" error: "The username " + name + " is already in use on this channel"
}); });
@ -286,9 +286,9 @@ User.prototype.login = function(name, sha256) {
} }
// No password => try guest login // No password => try guest login
if(sha256 == "") { if(sha256 == "") {
// Sorry bud, can't take that name // Sorry bud, can"t take that name
if(Auth.isRegistered(name)) { if(Auth.isRegistered(name)) {
this.socket.emit('login', { this.socket.emit("login", {
success: false, success: false,
error: "That username is already taken" error: "That username is already taken"
}); });
@ -296,7 +296,7 @@ User.prototype.login = function(name, sha256) {
} }
// YOUR ARGUMENT IS INVALID // YOUR ARGUMENT IS INVALID
else if(!Auth.validateName(name)) { else if(!Auth.validateName(name)) {
this.socket.emit('login', { this.socket.emit("login", {
success: false, success: false,
error: "Invalid username. Usernames must be 1-20 characters long and consist only of alphanumeric characters and underscores" error: "Invalid username. Usernames must be 1-20 characters long and consist only of alphanumeric characters and underscores"
}); });
@ -306,10 +306,10 @@ User.prototype.login = function(name, sha256) {
console.log(this.ip + " signed in as " + name); console.log(this.ip + " signed in as " + name);
this.name = name; this.name = name;
this.loggedIn = false; this.loggedIn = false;
this.socket.emit('login', { this.socket.emit("login", {
success: true success: true
}); });
this.socket.emit('rank', { this.socket.emit("rank", {
rank: this.rank rank: this.rank
}); });
if(this.channel != null) { if(this.channel != null) {
@ -323,17 +323,17 @@ User.prototype.login = function(name, sha256) {
var row; var row;
if((row = Auth.login(name, sha256))) { if((row = Auth.login(name, sha256))) {
this.loggedIn = true; this.loggedIn = true;
this.socket.emit('login', { this.socket.emit("login", {
success: true success: true
}); });
console.log(this.ip + " logged in as " + name); console.log(this.ip + " logged in as " + name);
// Sweet, let's look up our rank // Sweet, let"s look up our rank
var chanrank = (this.channel != null) ? this.channel.getRank(name) var chanrank = (this.channel != null) ? this.channel.getRank(name)
: Rank.Guest; : Rank.Guest;
var rank = (chanrank > row.global_rank) ? chanrank var rank = (chanrank > row.global_rank) ? chanrank
: row.global_rank; : row.global_rank;
this.rank = (this.rank > rank) ? this.rank : rank; this.rank = (this.rank > rank) ? this.rank : rank;
this.socket.emit('rank', { this.socket.emit("rank", {
rank: this.rank rank: this.rank
}); });
this.name = name; this.name = name;
@ -345,7 +345,7 @@ User.prototype.login = function(name, sha256) {
} }
// Wrong password // Wrong password
else { else {
this.socket.emit('login', { this.socket.emit("login", {
success: false, success: false,
error: "Invalid username/password pair" error: "Invalid username/password pair"
}); });
@ -358,34 +358,34 @@ User.prototype.login = function(name, sha256) {
User.prototype.register = function(name, sha256) { User.prototype.register = function(name, sha256) {
if(sha256 == "") { if(sha256 == "") {
// Sorry bud, password required // Sorry bud, password required
this.socket.emit('register', { this.socket.emit("register", {
success: false, success: false,
error: "You must provide a password" error: "You must provide a password"
}); });
return false; return false;
} }
else if(Auth.isRegistered(name)) { else if(Auth.isRegistered(name)) {
this.socket.emit('register', { this.socket.emit("register", {
success: false, success: false,
error: "That username is already taken" error: "That username is already taken"
}); });
return false; return false;
} }
else if(!Auth.validateName(name)) { else if(!Auth.validateName(name)) {
this.socket.emit('register', { this.socket.emit("register", {
success: false, success: false,
error: "Invalid username. Usernames must be 1-20 characters long and consist only of alphanumeric characters and underscores" error: "Invalid username. Usernames must be 1-20 characters long and consist only of alphanumeric characters and underscores"
}); });
} }
else if(Auth.register(name, sha256)) { else if(Auth.register(name, sha256)) {
console.log(this.ip + " registered " + name); console.log(this.ip + " registered " + name);
this.socket.emit('register', { this.socket.emit("register", {
success: true success: true
}); });
this.login(name, sha256); this.login(name, sha256);
} }
else { else {
this.socket.emit('register', { this.socket.emit("register", {
success: false, success: false,
error: "[](/ppshrug) Registration Failed." error: "[](/ppshrug) Registration Failed."
}); });

View File

@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
*/ */
var RANK = 0; var RANK = 0;
var uname = readCookie('sync_uname'); var uname = readCookie("sync_uname");
var pw = readCookie('sync_pw'); var pw = readCookie("sync_pw");
var manageChannel = false; var manageChannel = false;
var Rank = { var Rank = {
@ -27,44 +27,44 @@ initCallbacks();
function initCallbacks() { function initCallbacks() {
socket.on('adm', function(data) { socket.on("adm", function(data) {
console.log(data); console.log(data);
if(data.cmd == "listchannels") if(data.cmd == "listchannels")
handleChannelList(data); handleChannelList(data);
}); });
socket.on('login', function(data) { socket.on("login", function(data) {
if(data.success && $('#password').val()) { if(data.success && $("#password").val()) {
createCookie('sync_uname', uname, 1); createCookie("sync_uname", uname, 1);
createCookie('sync_pw', pw, 1); createCookie("sync_pw", pw, 1);
} }
if(data.success) { if(data.success) {
$('#loggedin').css('display', ''); $("#loggedin").css("display", "");
$('#logoutform').css('display', ''); $("#logoutform").css("display", "");
$('#loginform').css('display', 'none'); $("#loginform").css("display", "none");
} }
socket.emit('adm', { socket.emit("adm", {
cmd: "listchannels" cmd: "listchannels"
}); });
}); });
} }
function handleChannelList(data) { function handleChannelList(data) {
if($('#chanlist').children.length > 1) if($("#chanlist").children.length > 1)
$($('#chanlist').children()[1]).remove(); $($("#chanlist").children()[1]).remove();
for(var i = 0; i < data.chans.length; i++) { for(var i = 0; i < data.chans.length; i++) {
var row = $('<tr/>').appendTo($('#chanlist')); var row = $("<tr/>").appendTo($("#chanlist"));
var name = $('<td/>').appendTo(row).text(data.chans[i].name); var name = $("<td/>").appendTo(row).text(data.chans[i].name);
var usercount = $('<td/>').appendTo(row).text(data.chans[i].usercount); var usercount = $("<td/>").appendTo(row).text(data.chans[i].usercount);
var nowplaying = $('<td/>').appendTo(row).text(data.chans[i].nowplaying); var nowplaying = $("<td/>").appendTo(row).text(data.chans[i].nowplaying);
} }
} }
var params = {}; var params = {};
if(window.location.search) { if(window.location.search) {
var parameters = window.location.search.substring(1).split('&'); var parameters = window.location.search.substring(1).split("&");
for(var i = 0; i < parameters.length; i++) { for(var i = 0; i < parameters.length; i++) {
var s = parameters[i].split('='); var s = parameters[i].split("=");
if(s.length != 2) if(s.length != 2)
continue; continue;
params[s[0]] = s[1]; params[s[0]] = s[1];
@ -72,37 +72,37 @@ if(window.location.search) {
} }
if(uname != null && pw != null && pw != "false") { if(uname != null && pw != null && pw != "false") {
socket.emit('login', { socket.emit("login", {
name: uname, name: uname,
sha256: pw sha256: pw
}); });
} }
function loginClick() { function loginClick() {
uname = $('#username').val(); uname = $("#username").val();
if($('#password').val() == "") if($("#password").val() == "")
pw = ""; pw = "";
else else
pw = SHA256($('#password').val()); pw = SHA256($("#password").val());
socket.emit('login', { socket.emit("login", {
name: uname, name: uname,
sha256: pw sha256: pw
}); });
}; };
$('#login').click(loginClick); $("#login").click(loginClick);
$('#username').keydown(function(ev) { $("#username").keydown(function(ev) {
if(ev.key == 13) if(ev.key == 13)
loginClick(); loginClick();
}); });
$('#password').keydown(function(ev) { $("#password").keydown(function(ev) {
if(ev.key == 13) if(ev.key == 13)
loginClick(); loginClick();
}); });
$('#logout').click(function() { $("#logout").click(function() {
eraseCookie('sync_uname'); eraseCookie("sync_uname");
eraseCookie('sync_pw'); eraseCookie("sync_pw");
document.location.reload(true); document.location.reload(true);
}); });
@ -119,10 +119,10 @@ function createCookie(name,value,days) {
function readCookie(name) { function readCookie(name) {
var nameEQ = name + "="; var nameEQ = name + "=";
var ca = document.cookie.split(';'); var ca = document.cookie.split(";");
for(var i=0;i < ca.length;i++) { for(var i=0;i < ca.length;i++) {
var c = ca[i]; var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length); while (c.charAt(0)==" ") c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
} }
return null; return null;

View File

@ -12,120 +12,120 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
// Wrapped in a function so I can ensure that the socket // Wrapped in a function so I can ensure that the socket
// is defined before these statements are run // is defined before these statements are run
function initCallbacks() { function initCallbacks() {
socket.on('disconnect', function() { socket.on("disconnect", function() {
$('<div/>').addClass('alert').addClass('alert-error') $("<div/>").addClass("alert").addClass("alert-error")
.insertAfter($('.row')[0])[0] .insertAfter($(".row")[0])[0]
.innerHTML = "<h3>Disconnected from server</h3>"; .innerHTML = "<h3>Disconnected from server</h3>";
}); });
socket.on('channelNotRegistered', function() { socket.on("channelNotRegistered", function() {
showChannelRegistration(); showChannelRegistration();
}); });
socket.on('announcement', function(data) { socket.on("announcement", function(data) {
showAnnouncement(data.title, data.text); showAnnouncement(data.title, data.text);
}); });
socket.on('registerChannel', function(data) { socket.on("registerChannel", function(data) {
if(data.success) { if(data.success) {
$('#chregnotice').remove(); $("#chregnotice").remove();
} }
else { else {
alert(data.error); alert(data.error);
} }
}); });
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");
$('#playlist_controls button').each(function() { $("#playlist_controls button").each(function() {
$(this).attr('disabled', false); $(this).attr("disabled", false);
}); });
$('#qlockbtn').css("display", "block"); $("#qlockbtn").css("display", "block");
var poll = $('#pollcontainer .active'); var poll = $("#pollcontainer .active");
if(poll.length > 0) { if(poll.length > 0) {
$('<button/>').addClass('btn btn-danger pull-right').text('Close Poll') $("<button/>").addClass("btn btn-danger pull-right").text("Close Poll")
.insertAfter(poll.find('.close')) .insertAfter(poll.find(".close"))
.click(function() { .click(function() {
socket.emit('closePoll') socket.emit("closePoll")
}); });
} }
var users = $('#userlist').children(); var users = $("#userlist").children();
for(var i = 0; i < users.length; i++) { for(var i = 0; i < users.length; i++) {
addUserDropdown(users[i], users[i].children[1].innerHTML); addUserDropdown(users[i], users[i].children[1].innerHTML);
} }
$('#modnav').show(); $("#modnav").show();
$('#chancontrols').show(); $("#chancontrols").show();
} }
RANK = data.rank; RANK = data.rank;
}); });
socket.on('login', function(data) { socket.on("login", function(data) {
if(!data.success) if(!data.success)
alert(data.error); alert(data.error);
else { else {
$('#welcome')[0].innerHTML = "Welcome, " + uname; $("#welcome")[0].innerHTML = "Welcome, " + uname;
$('#loginform').css("display", "none"); $("#loginform").css("display", "none");
$('#logoutform').css("display", ""); $("#logoutform").css("display", "");
$('#loggedin').css("display", ""); $("#loggedin").css("display", "");
if(pw != "") { if(pw != "") {
createCookie('sync_uname', uname, 1); createCookie("sync_uname", uname, 1);
createCookie('sync_pw', pw, 1); createCookie("sync_pw", pw, 1);
} }
} }
}); });
socket.on('register', function(data) { socket.on("register", function(data) {
if(data.error) { if(data.error) {
alert(data.error); alert(data.error);
} }
}); });
socket.on('channelOpts', function(opts) { socket.on("channelOpts", function(opts) {
$('#opt_qopen_allow_qnext').prop('checked', opts.qopen_allow_qnext); $("#opt_qopen_allow_qnext").prop("checked", opts.qopen_allow_qnext);
$('#opt_qopen_allow_move').prop('checked', opts.qopen_allow_move); $("#opt_qopen_allow_move").prop("checked", opts.qopen_allow_move);
$('#opt_qopen_allow_delete').prop('checked', opts.qopen_allow_delete); $("#opt_qopen_allow_delete").prop("checked", opts.qopen_allow_delete);
$('#opt_qopen_allow_playnext').prop('checked', opts.qopen_allow_playnext); $("#opt_qopen_allow_playnext").prop("checked", opts.qopen_allow_playnext);
$('#opt_pagetitle').attr('placeholder', opts.pagetitle); $("#opt_pagetitle").attr("placeholder", opts.pagetitle);
document.title = opts.pagetitle; document.title = opts.pagetitle;
$('opt_customcss').val(opts.customcss); $("opt_customcss").val(opts.customcss);
$('#customCss').remove(); $("#customCss").remove();
if(opts.customcss != "") { if(opts.customcss != "") {
$('<link/>').attr("rel", "stylesheet") $("<link/>").attr("rel", "stylesheet")
.attr("href", opts.customcss) .attr("href", opts.customcss)
.attr("id", "customCss") .attr("id", "customCss")
.insertAfter($('link[href="./assets/css/ytsync.css"]')); .insertAfter($("link[href='./assets/css/ytsync.css']"));
} }
CHANNELOPTS = opts; CHANNELOPTS = opts;
if(opts.qopen_allow_qnext) if(opts.qopen_allow_qnext)
$('#queue_next').attr('disabled', false); $("#queue_next").attr("disabled", false);
if(opts.qopen_allow_playnext) if(opts.qopen_allow_playnext)
$('#play_next').attr('disabled', false); $("#play_next").attr("disabled", false);
rebuildPlaylist(); rebuildPlaylist();
}); });
socket.on('banlist', function(data) { socket.on("banlist", function(data) {
updateBanlist(data.entries); updateBanlist(data.entries);
}); });
socket.on('usercount', function(data) { socket.on("usercount", function(data) {
$('#usercount').text(data.count + " connected users"); $("#usercount").text(data.count + " connected users");
}); });
socket.on('chatMsg', function(data) { socket.on("chatMsg", function(data) {
var div = formatChatMessage(data); var div = formatChatMessage(data);
$('#messagebuffer')[0].appendChild(div); $("#messagebuffer")[0].appendChild(div);
// Cap chatbox at most recent 100 messages // Cap chatbox at most recent 100 messages
if($('#messagebuffer').children().length > 100) { if($("#messagebuffer").children().length > 100) {
$($('#messagebufer').children()[0]).remove(); $($("#messagebufer").children()[0]).remove();
} }
$('#messagebuffer').scrollTop($('#messagebuffer').prop("scrollHeight")); $("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
}); });
socket.on('playlist', function(data) { socket.on("playlist", function(data) {
var ul = $('#queue')[0]; var ul = $("#queue")[0];
var n = ul.children.length; var n = ul.children.length;
for(var i = 0; i < n; i++) { for(var i = 0; i < n; i++) {
ul.removeChild(ul.children[0]); ul.removeChild(ul.children[0]);
@ -138,71 +138,71 @@ 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 || OPENQUEUE) 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;
var ul = $('#queue')[0]; var ul = $("#queue")[0];
$(li).appendTo(ul); $(li).appendTo(ul);
if(idx < ul.children.length - 1) if(idx < ul.children.length - 1)
moveVideo(ul.children.length - 1, idx); moveVideo(ul.children.length - 1, idx);
$(li).show('blind'); $(li).show("blind");
}); });
socket.on('unqueue', function(data) { socket.on("unqueue", function(data) {
if(data.pos == POSITION && $('#queue').children().length > POSITION + 1) { if(data.pos == POSITION && $("#queue").children().length > POSITION + 1) {
$($('#queue').children()[POSITION+1]).addClass("alert alert-info"); $($("#queue").children()[POSITION+1]).addClass("alert alert-info");
} }
var li = $('#queue').children()[data.pos]; var li = $("#queue").children()[data.pos];
//$(li).hide('blind', function() { //$(li).hide("blind", function() {
$(li).remove(); $(li).remove();
//}); //});
}); });
socket.on('moveVideo', function(data) { socket.on("moveVideo", function(data) {
moveVideo(data.src, data.dest); moveVideo(data.src, data.dest);
}); });
socket.on('queueLock', function(data) { socket.on("queueLock", function(data) {
OPENQUEUE = !data.locked; OPENQUEUE = !data.locked;
if(OPENQUEUE) { if(OPENQUEUE) {
$('#playlist_controls').css('display', ''); $("#playlist_controls").css("display", "");
if(RANK < Rank.Moderator) { if(RANK < Rank.Moderator) {
$('#qlockbtn').css('display', 'none'); $("#qlockbtn").css("display", "none");
rebuildPlaylist(); rebuildPlaylist();
if(!CHANNELOPTS.qopen_allow_qnext) if(!CHANNELOPTS.qopen_allow_qnext)
$('#queue_next').attr('disabled', true); $("#queue_next").attr("disabled", true);
if(!CHANNELOPTS.qopen_allow_playnext) if(!CHANNELOPTS.qopen_allow_playnext)
$('#play_next').attr('disabled', true); $("#play_next").attr("disabled", true);
} }
} }
else if(RANK < Rank.Moderator) { else if(RANK < Rank.Moderator) {
$('#playlist_controls').css('display', 'none'); $("#playlist_controls").css("display", "none");
} }
if(OPENQUEUE) { if(OPENQUEUE) {
$('#qlockbtn').removeClass('btn-danger') $("#qlockbtn").removeClass("btn-danger")
.addClass('btn-success') .addClass("btn-success")
.text('Lock Queue'); .text("Lock Queue");
} }
else { else {
$('#qlockbtn').removeClass('btn-success') $("#qlockbtn").removeClass("btn-success")
.addClass('btn-danger') .addClass("btn-danger")
.text('Unlock Queue'); .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");
var linew = $('#queue').children()[data.idx]; var linew = $("#queue").children()[data.idx];
$(linew).addClass("alert alert-info"); $(linew).addClass("alert alert-info");
POSITION= data.idx; POSITION= data.idx;
}); });
socket.on('mediaUpdate', function(data) { socket.on("mediaUpdate", function(data) {
$('#currenttitle').text("Currently Playing: " + data.title); $("#currenttitle").text("Currently Playing: " + data.title);
if(data.type == "yt") if(data.type == "yt")
updateYT(data); updateYT(data);
else if(data.type == "tw") else if(data.type == "tw")
@ -217,24 +217,24 @@ function initCallbacks() {
updateDM(data); updateDM(data);
}); });
socket.on('userlist', function(data) { socket.on("userlist", function(data) {
for(var i = 0; i < data.length; i++) { for(var i = 0; i < data.length; i++) {
addUser(data[i].name, data[i].rank, data[i].leader); addUser(data[i].name, data[i].rank, data[i].leader);
} }
}); });
socket.on('addUser', function(data) { socket.on("addUser", function(data) {
addUser(data.name, data.rank, data.leader); addUser(data.name, data.rank, data.leader);
}); });
socket.on('updateUser', function(data) { socket.on("updateUser", function(data) {
if(data.name == uname) { if(data.name == uname) {
LEADER = data.leader; LEADER = data.leader;
if(LEADER) { if(LEADER) {
// I'm a leader! Set up sync function // I"m a leader! Set up sync function
sendVideoUpdate = function() { sendVideoUpdate = function() {
if(MEDIATYPE == "yt") { if(MEDIATYPE == "yt") {
socket.emit('mediaUpdate', { socket.emit("mediaUpdate", {
id: parseYTURL(PLAYER.getVideoUrl()), id: parseYTURL(PLAYER.getVideoUrl()),
seconds: PLAYER.getCurrentTime(), seconds: PLAYER.getCurrentTime(),
paused: PLAYER.getPlayerState() == YT.PlayerState.PAUSED, paused: PLAYER.getPlayerState() == YT.PlayerState.PAUSED,
@ -243,7 +243,7 @@ function initCallbacks() {
} }
else if(MEDIATYPE == "sc") { else if(MEDIATYPE == "sc") {
PLAYER.getPosition(function(pos) { PLAYER.getPosition(function(pos) {
socket.emit('mediaUpdate', { socket.emit("mediaUpdate", {
id: PLAYER.mediaId, id: PLAYER.mediaId,
seconds: pos / 1000, seconds: pos / 1000,
paused: false, paused: false,
@ -252,8 +252,8 @@ function initCallbacks() {
}); });
} }
else if(MEDIATYPE == "vi") { else if(MEDIATYPE == "vi") {
PLAYER.api('getCurrentTime', function(data) { PLAYER.api("getCurrentTime", function(data) {
socket.emit('mediaUpdate', { socket.emit("mediaUpdate", {
id: PLAYER.videoid, id: PLAYER.videoid,
seconds: data, seconds: data,
paused: false, paused: false,
@ -262,7 +262,7 @@ function initCallbacks() {
}); });
} }
else if(MEDIATYPE == "dm") { else if(MEDIATYPE == "dm") {
socket.emit('mediaUpdate', { socket.emit("mediaUpdate", {
id: PLAYER.mediaId, id: PLAYER.mediaId,
seconds: PLAYER.currentTime, seconds: PLAYER.currentTime,
paused: PLAYER.paused, paused: PLAYER.paused,
@ -271,16 +271,16 @@ function initCallbacks() {
} }
}; };
} }
// I'm not a leader. Don't send syncs to the server // I"m not a leader. Don"t send syncs to the server
else { else {
sendVideoUpdate = function() { } sendVideoUpdate = function() { }
} }
RANK = data.rank; RANK = data.rank;
if(data.rank >= Rank.Moderator) if(data.rank >= Rank.Moderator)
$('#playlist_controls').css("display", "block"); $("#playlist_controls").css("display", "block");
} }
var users = $('#userlist').children(); var users = $("#userlist").children();
for(var i = 0; i < users.length; i++) { for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerHTML; var name = users[i].children[1].innerHTML;
// Reformat user // Reformat user
@ -290,22 +290,22 @@ function initCallbacks() {
} }
}); });
socket.on('userLeave', function(data) { socket.on("userLeave", function(data) {
var users = $('#userlist').children(); var users = $("#userlist").children();
for(var i = 0; i < users.length; i++) { for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerHTML; var name = users[i].children[1].innerHTML;
if(name == data.name) { if(name == data.name) {
$('#userlist')[0].removeChild(users[i]); $("#userlist")[0].removeChild(users[i]);
} }
} }
}); });
socket.on('librarySearchResults', function(data) { socket.on("librarySearchResults", function(data) {
var n = $('#library').children().length; var n = $("#library").children().length;
for(var i = 0; i < n; i++) { for(var i = 0; i < n; i++) {
$('#library')[0].removeChild($('#library').children()[0]); $("#library")[0].removeChild($("#library").children()[0]);
} }
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 || OPENQUEUE) if(RANK >= Rank.Moderator || OPENQUEUE)
@ -314,15 +314,15 @@ function initCallbacks() {
} }
}); });
socket.on('newPoll', function(data) { socket.on("newPoll", function(data) {
addPoll(data); addPoll(data);
}); });
socket.on('updatePoll', function(data) { socket.on("updatePoll", function(data) {
updatePoll(data); updatePoll(data);
}); });
socket.on('closePoll', function() { socket.on("closePoll", function() {
closePoll(); closePoll();
}); });
} }

View File

@ -17,8 +17,8 @@ var POSITION = -1;
var RANK = 0; var RANK = 0;
var OPENQUEUE = false; var OPENQUEUE = false;
var CHANNELOPTS = {}; var CHANNELOPTS = {};
var uname = readCookie('sync_uname'); var uname = readCookie("sync_uname");
var pw = readCookie('sync_pw'); var pw = readCookie("sync_pw");
var Rank = { var Rank = {
Guest: 0, Guest: 0,
@ -33,31 +33,31 @@ initCallbacks();
var params = {}; var params = {};
if(window.location.search) { if(window.location.search) {
var parameters = window.location.search.substring(1).split('&'); var parameters = window.location.search.substring(1).split("&");
for(var i = 0; i < parameters.length; i++) { for(var i = 0; i < parameters.length; i++) {
var s = parameters[i].split('='); var s = parameters[i].split("=");
if(s.length != 2) if(s.length != 2)
continue; continue;
params[s[0]] = s[1]; params[s[0]] = s[1];
} }
} }
if(params['novideo'] != undefined) { if(params["novideo"] != undefined) {
$('.span7').remove(); $(".span7").remove();
} }
if(params['channel'] == undefined) { if(params["channel"] == undefined) {
var main = $($('.container')[1]); var main = $($(".container")[1]);
var container = $('<div/>').addClass('container').insertBefore(main); var container = $("<div/>").addClass("container").insertBefore(main);
var row = $('<div/>').addClass('row').appendTo(container); var row = $("<div/>").addClass("row").appendTo(container);
var div = $('<div/>').addClass('span6').appendTo(row); var div = $("<div/>").addClass("span6").appendTo(row);
main.css("display", "none"); main.css("display", "none");
var label = $('<label/>').text('Enter Channel:').appendTo(div); var label = $("<label/>").text("Enter Channel:").appendTo(div);
var entry = $('<input/>').attr('type', 'text').appendTo(div); var entry = $("<input/>").attr("type", "text").appendTo(div);
entry.keydown(function(ev) { entry.keydown(function(ev) {
if(ev.keyCode == 13) { if(ev.keyCode == 13) {
document.location = document.location + "?channel=" + entry.val(); document.location = document.location + "?channel=" + entry.val();
socket.emit('joinChannel', { socket.emit("joinChannel", {
name: entry.val() name: entry.val()
}); });
container.remove(); container.remove();
@ -65,38 +65,38 @@ if(params['channel'] == undefined) {
} }
}); });
} }
else if(!params['channel'].match(/^[a-zA-Z0-9]+$/)) { else if(!params["channel"].match(/^[a-zA-Z0-9]+$/)) {
$('<div/>').addClass('alert alert-error') $("<div/>").addClass("alert alert-error")
.insertAfter($('.row')[0])[0] .insertAfter($(".row")[0])[0]
.innerHTML = "<h3>Invalid Channel Name</h3><p>Channel names must conain only numbers and letters</p>"; .innerHTML = "<h3>Invalid Channel Name</h3><p>Channel names must conain only numbers and letters</p>";
} }
else { else {
socket.emit('joinChannel', { socket.emit("joinChannel", {
name: params['channel'] name: params["channel"]
}); });
} }
// Load the youtube iframe API // Load the youtube iframe API
var tag = document.createElement('script'); var tag = document.createElement("script");
tag.src = "http://www.youtube.com/iframe_api"; tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0]; var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// Load the Dailymotion iframe API // Load the Dailymotion iframe API
/* /*
var tag = document.createElement('script'); var tag = document.createElement("script");
tag.src = "http://api.dmcdn.net/all.js"; tag.src = "http://api.dmcdn.net/all.js";
var firstScriptTag = document.getElementsByTagName('script')[0]; var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
*/ */
if(uname != null && pw != null && pw != "false") { if(uname != null && pw != null && pw != "false") {
socket.emit('login', { socket.emit("login", {
name: uname, name: uname,
sha256: pw sha256: pw
}); });
@ -107,95 +107,95 @@ setInterval(function() {
sendVideoUpdate(); sendVideoUpdate();
}, 5000); }, 5000);
$('#queue_end').click(function() { $("#queue_end").click(function() {
var parsed = parseVideoURL($('#mediaurl').val()); var parsed = parseVideoURL($("#mediaurl").val());
var id = parsed[0]; var id = parsed[0];
var type = parsed[1]; var type = parsed[1];
if(id) { if(id) {
$('#mediaurl').val(""); $("#mediaurl").val("");
} }
socket.emit('queue', { socket.emit("queue", {
id: id, id: id,
pos: "end", pos: "end",
type: type type: type
}); });
}); });
$('#queue_next').click(function() { $("#queue_next").click(function() {
var parsed = parseVideoURL($('#mediaurl').val()); var parsed = parseVideoURL($("#mediaurl").val());
var id = parsed[0]; var id = parsed[0];
var type = parsed[1]; var type = parsed[1];
if(id) { if(id) {
$('#mediaurl').val(""); $("#mediaurl").val("");
} }
socket.emit('queue', { socket.emit("queue", {
id: id, id: id,
pos: "next", pos: "next",
type: type type: type
}); });
}); });
$('#play_next').click(function() { $("#play_next").click(function() {
socket.emit('playNext'); socket.emit("playNext");
}); });
$('#qlockbtn').click(function() { $("#qlockbtn").click(function() {
socket.emit('queueLock', { socket.emit("queueLock", {
locked: OPENQUEUE locked: OPENQUEUE
}); });
}); });
function loginClick() { function loginClick() {
uname = $('#username').val(); uname = $("#username").val();
if($('#password').val() == "") if($("#password").val() == "")
pw = ""; pw = "";
else else
pw = SHA256($('#password').val()); pw = SHA256($("#password").val());
socket.emit('login', { socket.emit("login", {
name: uname, name: uname,
sha256: pw sha256: pw
}); });
}; };
$('#login').click(loginClick); $("#login").click(loginClick);
$('#username').keydown(function(ev) { $("#username").keydown(function(ev) {
if(ev.key == 13) if(ev.key == 13)
loginClick(); loginClick();
}); });
$('#password').keydown(function(ev) { $("#password").keydown(function(ev) {
if(ev.key == 13) if(ev.key == 13)
loginClick(); loginClick();
}); });
$('#logout').click(function() { $("#logout").click(function() {
eraseCookie('sync_uname'); eraseCookie("sync_uname");
eraseCookie('sync_pw'); eraseCookie("sync_pw");
document.location.reload(true); document.location.reload(true);
}); });
$('#register').click(function() { $("#register").click(function() {
uname = $('#username').val(); uname = $("#username").val();
if($('#password').val() == "") if($("#password").val() == "")
pw = ""; pw = "";
else else
pw = SHA256($('#password').val()); pw = SHA256($("#password").val());
socket.emit('register', { socket.emit("register", {
name: uname, name: uname,
sha256: pw sha256: pw
}); });
}); });
$('#chatline').keydown(function(ev) { $("#chatline").keydown(function(ev) {
if(ev.keyCode == 13 && $('#chatline').val() != '') { if(ev.keyCode == 13 && $("#chatline").val() != "") {
socket.emit('chatMsg', { socket.emit("chatMsg", {
msg: $('#chatline').val() msg: $("#chatline").val()
}); });
$('#chatline').val(''); $("#chatline").val("");
} }
else if(ev.keyCode == 9) { // Tab completion else if(ev.keyCode == 9) { // Tab completion
var words = $('#chatline').val().split(' '); var words = $("#chatline").val().split(" ");
var current = words[words.length - 1].toLowerCase(); var current = words[words.length - 1].toLowerCase();
var users = $('#userlist').children(); var users = $("#userlist").children();
var match = null; var match = null;
for(var i = 0; i < users.length; i++) { for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerHTML.toLowerCase(); var name = users[i].children[1].innerHTML.toLowerCase();
@ -213,79 +213,79 @@ $('#chatline').keydown(function(ev) {
words[0] += ": "; words[0] += ": ";
else else
words[words.length - 1] += " "; words[words.length - 1] += " ";
$('#chatline').val(words.join(' ')); $("#chatline").val(words.join(" "));
} }
ev.preventDefault(); ev.preventDefault();
return false; return false;
} }
}); });
$('#opt_submit').click(function() { $("#opt_submit").click(function() {
var ptitle = $('#opt_pagetitle').val(); var ptitle = $("#opt_pagetitle").val();
if(ptitle == '') if(ptitle == "")
ptitle = $('#opt_pagetitle').attr('placeholder') ptitle = $("#opt_pagetitle").attr("placeholder")
opts = { opts = {
qopen_allow_qnext: $('#opt_qopen_allow_qnext').prop('checked'), qopen_allow_qnext: $("#opt_qopen_allow_qnext").prop("checked"),
qopen_allow_move: $('#opt_qopen_allow_move').prop('checked'), qopen_allow_move: $("#opt_qopen_allow_move").prop("checked"),
qopen_allow_delete: $('#opt_qopen_allow_delete').prop('checked'), qopen_allow_delete: $("#opt_qopen_allow_delete").prop("checked"),
qopen_allow_playnext: $('#opt_qopen_allow_playnext').prop('checked'), qopen_allow_playnext: $("#opt_qopen_allow_playnext").prop("checked"),
pagetitle: ptitle, pagetitle: ptitle,
customcss: $('#opt_customcss').val() customcss: $("#opt_customcss").val()
}; };
socket.emit('channelOpts', opts); socket.emit("channelOpts", opts);
}); });
$('#show_chancontrols').click(function() { $("#show_chancontrols").click(function() {
$('#show_chancontrols').parent().addClass("active"); $("#show_chancontrols").parent().addClass("active");
$('#show_banlist').parent().removeClass("active"); $("#show_banlist").parent().removeClass("active");
$('#banlist').hide(); $("#banlist").hide();
$('#chancontrols').show(); $("#chancontrols").show();
}); });
$('#show_banlist').click(function() { $("#show_banlist").click(function() {
$('#show_chancontrols').parent().removeClass("active"); $("#show_chancontrols").parent().removeClass("active");
$('#show_banlist').parent().addClass("active"); $("#show_banlist").parent().addClass("active");
$('#banlist').show(); $("#banlist").show();
$('#chancontrols').hide(); $("#chancontrols").hide();
}); });
function searchLibrary() { function searchLibrary() {
socket.emit('searchLibrary', { socket.emit("searchLibrary", {
query: $('#library_query').val() query: $("#library_query").val()
}); });
} }
$('#library_search').click(searchLibrary); $("#library_search").click(searchLibrary);
$('#library_query').keydown(function(ev) { $("#library_query").keydown(function(ev) {
if(ev.key == 13) if(ev.key == 13)
searchLibrary(); searchLibrary();
}); });
function onYouTubeIframeAPIReady() { function onYouTubeIframeAPIReady() {
PLAYER = new YT.Player('ytapiplayer', { PLAYER = new YT.Player("ytapiplayer", {
height: '390', height: "390",
width: '640', width: "640",
videoId: '', videoId: "",
playerVars: { playerVars: {
'autoplay': 0, "autoplay": 0,
'controls': 1, "controls": 1,
}, },
events: { events: {
'onReady': onPlayerReady, "onReady": onPlayerReady,
'onStateChange': onPlayerStateChange "onStateChange": onPlayerStateChange
} }
}); });
} }
function onPlayerReady() { function onPlayerReady() {
socket.emit('playerReady'); socket.emit("playerReady");
} }
function onPlayerStateChange(state) { function onPlayerStateChange(state) {
if(LEADER && state.data == YT.PlayerState.ENDED) { if(LEADER && state.data == YT.PlayerState.ENDED) {
socket.emit('playNext'); socket.emit("playNext");
} }
else if(LEADER && state.data == YT.PlayerState.PAUSED) { else if(LEADER && state.data == YT.PlayerState.PAUSED) {
socket.emit('mediaUpdate', { socket.emit("mediaUpdate", {
id: parseYTURL(PLAYER.getVideoUrl()), id: parseYTURL(PLAYER.getVideoUrl()),
seconds: PLAYER.getCurrentTime(), seconds: PLAYER.getCurrentTime(),
type: "yt", type: "yt",
@ -293,7 +293,7 @@ function onPlayerStateChange(state) {
}); });
} }
if(LEADER && state.data == YT.PlayerState.PLAYING) { if(LEADER && state.data == YT.PlayerState.PLAYING) {
socket.emit('mediaUpdate', { socket.emit("mediaUpdate", {
id: parseYTURL(PLAYER.getVideoUrl()), id: parseYTURL(PLAYER.getVideoUrl()),
seconds: PLAYER.getCurrentTime(), seconds: PLAYER.getCurrentTime(),
type: "yt", type: "yt",
@ -314,10 +314,10 @@ function createCookie(name,value,days) {
function readCookie(name) { function readCookie(name) {
var nameEQ = name + "="; var nameEQ = name + "=";
var ca = document.cookie.split(';'); var ca = document.cookie.split(";");
for(var i=0;i < ca.length;i++) { for(var i=0;i < ca.length;i++) {
var c = ca[i]; var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length); while (c.charAt(0)==" ") c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
} }
return null; return null;

View File

@ -11,17 +11,17 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
// Adds a user to the chatbox userlist // Adds a user to the chatbox userlist
function addUser(name, rank, leader) { function addUser(name, rank, leader) {
var div = document.createElement('div'); var div = document.createElement("div");
$(div).attr("class", "userlist_item"); $(div).attr("class", "userlist_item");
var span = document.createElement('span'); var span = document.createElement("span");
var flair = document.createElement('span'); var flair = document.createElement("span");
span.innerHTML = name; span.innerHTML = name;
div.appendChild(flair); div.appendChild(flair);
div.appendChild(span); div.appendChild(span);
fmtUserlistItem(div, rank, leader); fmtUserlistItem(div, rank, leader);
if(RANK >= Rank.Moderator) if(RANK >= Rank.Moderator)
addUserDropdown(div, name); addUserDropdown(div, name);
var users = $('#userlist').children(); var users = $("#userlist").children();
for(var i = 0; i < users.length; i++) { for(var i = 0; i < users.length; i++) {
var othername = users[i].children[1].innerHTML; var othername = users[i].children[1].innerHTML;
if(othername.toLowerCase() > name.toLowerCase()) { if(othername.toLowerCase() > name.toLowerCase()) {
@ -29,10 +29,10 @@ function addUser(name, rank, leader) {
return; return;
} }
} }
$('#userlist')[0].appendChild(div); $("#userlist")[0].appendChild(div);
} }
// Format a userlist entry based on a person's rank // Format a userlist entry based on a person"s rank
function fmtUserlistItem(div, rank, leader) { function fmtUserlistItem(div, rank, leader) {
var span = div.children[1]; var span = div.children[1];
if(rank >= Rank.Siteadmin) if(rank >= Rank.Siteadmin)
@ -54,63 +54,63 @@ function fmtUserlistItem(div, rank, leader) {
// Adds a dropdown with user actions (promote/demote/leader) // Adds a dropdown with user actions (promote/demote/leader)
function addUserDropdown(entry, name) { function addUserDropdown(entry, name) {
var div = $('<div />').addClass("dropdown").appendTo(entry); var div = $("<div />").addClass("dropdown").appendTo(entry);
var ul = $('<ul />').addClass("dropdown-menu").appendTo(div); var ul = $("<ul />").addClass("dropdown-menu").appendTo(div);
ul.attr("role", "menu"); ul.attr("role", "menu");
ul.attr("aria-labelledby", "dropdownMenu"); ul.attr("aria-labelledby", "dropdownMenu");
var makeLeader = $('<li />').appendTo(ul); var makeLeader = $("<li />").appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(makeLeader); var a = $("<a />").attr("tabindex", "-1").attr("href", "#").appendTo(makeLeader);
a.text("Make Leader"); a.text("Make Leader");
a.click(function() { a.click(function() {
socket.emit('assignLeader', { socket.emit("assignLeader", {
name: name name: name
}); });
}); });
var takeLeader = $('<li />').appendTo(ul); var takeLeader = $("<li />").appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(takeLeader); var a = $("<a />").attr("tabindex", "-1").attr("href", "#").appendTo(takeLeader);
a.text("Take Leader"); a.text("Take Leader");
a.click(function() { a.click(function() {
socket.emit('assignLeader', { socket.emit("assignLeader", {
name: "" name: ""
}); });
}); });
var kick = $('<li />').appendTo(ul); var kick = $("<li />").appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(kick); var a = $("<a />").attr("tabindex", "-1").attr("href", "#").appendTo(kick);
a.text("Kick"); a.text("Kick");
a.click(function() { a.click(function() {
socket.emit('chatMsg', { socket.emit("chatMsg", {
msg: "/kick " + name msg: "/kick " + name
}); });
}); });
var ban = $('<li />').appendTo(ul); var ban = $("<li />").appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(ban); var a = $("<a />").attr("tabindex", "-1").attr("href", "#").appendTo(ban);
a.text("IP Ban"); a.text("IP Ban");
a.click(function() { a.click(function() {
socket.emit('chatMsg', { socket.emit("chatMsg", {
msg: "/ban " + name msg: "/ban " + name
}); });
}); });
$('<li />').addClass("divider").appendTo(ul); $("<li />").addClass("divider").appendTo(ul);
var promote = $('<li />').appendTo(ul); var promote = $("<li />").appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(promote); var a = $("<a />").attr("tabindex", "-1").attr("href", "#").appendTo(promote);
a.text("Promote"); a.text("Promote");
a.click(function() { a.click(function() {
socket.emit('promote', { socket.emit("promote", {
name: name name: name
}); });
}); });
var demote = $('<li />').appendTo(ul); var demote = $("<li />").appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(demote); var a = $("<a />").attr("tabindex", "-1").attr("href", "#").appendTo(demote);
a.text("Demote"); a.text("Demote");
a.click(function() { a.click(function() {
socket.emit('demote', { socket.emit("demote", {
name: name name: name
}); });
}); });
@ -127,18 +127,18 @@ function addUserDropdown(entry, name) {
} }
function formatChatMessage(data) { function formatChatMessage(data) {
var div = document.createElement('div'); var div = document.createElement("div");
if(data.msg.indexOf(uname) != -1) if(data.msg.indexOf(uname) != -1)
$(div).addClass('nick-highlight'); $(div).addClass("nick-highlight");
if(data.msgclass == "action") { if(data.msgclass == "action") {
var message = document.createElement('span'); var message = document.createElement("span");
$(message).addClass('action'); $(message).addClass("action");
message.innerHTML = data.username + " " + data.msg; message.innerHTML = data.username + " " + data.msg;
div.appendChild(message); div.appendChild(message);
} }
else { else {
var name = document.createElement('span'); var name = document.createElement("span");
var message = document.createElement('span'); var message = document.createElement("span");
name.innerHTML = "<strong>&lt;" + data.username + "&gt;</strong> "; name.innerHTML = "<strong>&lt;" + data.username + "&gt;</strong> ";
if(data.msgclass == "shout") if(data.msgclass == "shout")
$(name).addClass("shout"); $(name).addClass("shout");
@ -152,60 +152,60 @@ function formatChatMessage(data) {
// Creates and formats a queue entry // Creates and formats a queue entry
function makeQueueEntry(video) { function makeQueueEntry(video) {
var li = $('<li />'); var li = $("<li />");
li.attr("class", "well"); li.attr("class", "well");
var title = $('<span />').attr("class", "qe_title").appendTo(li); var title = $("<span />").attr("class", "qe_title").appendTo(li);
title.text(video.title); title.text(video.title);
var time = $('<span />').attr("class", "qe_time").appendTo(li); var time = $("<span />").attr("class", "qe_time").appendTo(li);
time.text(video.duration); time.text(video.duration);
var clear = $('<div />').attr("class", "qe_clear").appendTo(li); var clear = $("<div />").attr("class", "qe_clear").appendTo(li);
return li; return li;
} }
// Add buttons to a queue list entry // Add buttons to a queue list entry
function addQueueButtons(li) { function addQueueButtons(li) {
var btnstrip = $('<div />').attr("class", "btn-group qe_buttons").prependTo(li); var btnstrip = $("<div />").attr("class", "btn-group qe_buttons").prependTo(li);
var btnRemove = $('<button />').attr("class", "btn btn-danger qe_btn").appendTo(btnstrip); var btnRemove = $("<button />").attr("class", "btn btn-danger qe_btn").appendTo(btnstrip);
$('<i />').attr("class", "icon-remove").appendTo(btnRemove); $("<i />").attr("class", "icon-remove").appendTo(btnRemove);
var btnUp = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip); var btnUp = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
$('<i />').attr("class", "icon-arrow-up").appendTo(btnUp); $("<i />").attr("class", "icon-arrow-up").appendTo(btnUp);
var btnDown = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip); var btnDown = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
$('<i />').attr("class", "icon-arrow-down").appendTo(btnDown); $("<i />").attr("class", "icon-arrow-down").appendTo(btnDown);
var btnNext = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip); var btnNext = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
//$('<i />').attr("class", "icon-play").appendTo(btnNext); //$("<i />").attr("class", "icon-play").appendTo(btnNext);
btnNext.text('Next'); btnNext.text("Next");
// Callback time // Callback time
$(btnRemove).click(function() { $(btnRemove).click(function() {
btnstrip.remove(); btnstrip.remove();
var idx = $('#queue').children().index(li); var idx = $("#queue").children().index(li);
socket.emit('unqueue', { pos: idx }); socket.emit("unqueue", { pos: idx });
}); });
$(btnUp).click(function() { $(btnUp).click(function() {
var idx = $('#queue').children().index(li); var idx = $("#queue").children().index(li);
socket.emit('moveMedia', { socket.emit("moveMedia", {
src: idx, src: idx,
dest: idx-1 dest: idx-1
}); });
}); });
$(btnDown).click(function() { $(btnDown).click(function() {
var idx = $('#queue').children().index(li); var idx = $("#queue").children().index(li);
socket.emit('moveMedia', { socket.emit("moveMedia", {
src: idx, src: idx,
dest: idx+1 dest: idx+1
}); });
}); });
$(btnNext).click(function() { $(btnNext).click(function() {
var idx = $('#queue').children().index(li); var idx = $("#queue").children().index(li);
var dest = idx < POSITION ? POSITION : POSITION + 1; var dest = idx < POSITION ? POSITION : POSITION + 1;
socket.emit('moveMedia', { socket.emit("moveMedia", {
src: idx, src: idx,
dest: dest dest: dest
}); });
@ -213,19 +213,19 @@ function addQueueButtons(li) {
if(RANK < Rank.Moderator && !LEADER) { if(RANK < Rank.Moderator && !LEADER) {
if(!CHANNELOPTS.qopen_allow_delete) if(!CHANNELOPTS.qopen_allow_delete)
$(btnRemove).attr('disabled', true); $(btnRemove).attr("disabled", true);
if(!CHANNELOPTS.qopen_allow_move) { if(!CHANNELOPTS.qopen_allow_move) {
$(btnUp).attr('disabled', true); $(btnUp).attr("disabled", true);
$(btnDown).attr('disabled', true); $(btnDown).attr("disabled", true);
} }
if(!CHANNELOPTS.qopen_allow_qnext) if(!CHANNELOPTS.qopen_allow_qnext)
$(btnNext).attr('disabled', true); $(btnNext).attr("disabled", true);
} }
} }
function rebuildPlaylist() { function rebuildPlaylist() {
$('#queue li').each(function() { $("#queue li").each(function() {
$(this).find('.btn-group').remove(); $(this).find(".btn-group").remove();
if(RANK >= Rank.Moderator || LEADER || OPENQUEUE) if(RANK >= Rank.Moderator || LEADER || OPENQUEUE)
addQueueButtons(this); addQueueButtons(this);
}); });
@ -233,27 +233,27 @@ function rebuildPlaylist() {
// Add buttons to a list entry for the library search results // Add buttons to a list entry for the library search results
function addLibraryButtons(li, id) { function addLibraryButtons(li, id) {
var btnstrip = $('<div />').attr("class", "btn-group qe_buttons").prependTo(li); var btnstrip = $("<div />").attr("class", "btn-group qe_buttons").prependTo(li);
var btnNext = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip); var btnNext = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
//$('<i />').attr("class", "icon-play").appendTo(btnNext); //$("<i />").attr("class", "icon-play").appendTo(btnNext);
btnNext.text('Next'); btnNext.text("Next");
var btnEnd = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip); var btnEnd = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
//$('<i />').attr("class", "icon-fast-forward").appendTo(btnEnd); //$("<i />").attr("class", "icon-fast-forward").appendTo(btnEnd);
btnEnd.text('End'); btnEnd.text("End");
// Callback time // Callback time
$(btnNext).click(function() { $(btnNext).click(function() {
socket.emit('queue', { socket.emit("queue", {
id: id, id: id,
pos: "next" pos: "next"
}); });
}); });
$(btnEnd).click(function() { $(btnEnd).click(function() {
socket.emit('queue', { socket.emit("queue", {
id: id, id: id,
pos: "end" pos: "end"
}); });
@ -262,17 +262,17 @@ function addLibraryButtons(li, id) {
// Rearranges the queue // Rearranges the queue
function moveVideo(src, dest) { function moveVideo(src, dest) {
var li = $('#queue').children()[src]; var li = $("#queue").children()[src];
var ul = $('#queue')[0]; var ul = $("#queue")[0];
$(li).hide('blind', function() { $(li).hide("blind", function() {
ul.removeChild(li); ul.removeChild(li);
if(dest == ul.children.length) { if(dest == ul.children.length) {
ul.appendChild(li); ul.appendChild(li);
} }
else { else {
ul.insertBefore(li, ul.getElementsByTagName('li')[dest]); ul.insertBefore(li, ul.getElementsByTagName("li")[dest]);
} }
$(li).show('blind'); $(li).show("blind");
}); });
if(src < POSITION && dest >= POSITION) if(src < POSITION && dest >= POSITION)
POSITION--; POSITION--;
@ -286,24 +286,24 @@ function updateYT(data) {
removeCurrentPlayer(); removeCurrentPlayer();
MEDIATYPE = "yt"; MEDIATYPE = "yt";
// Note to Soundcloud/Vimeo API designers: // Note to Soundcloud/Vimeo API designers:
// YouTube's API is actually nice to use // YouTube"s API is actually nice to use
PLAYER = new YT.Player('ytapiplayer', { PLAYER = new YT.Player("ytapiplayer", {
height: '390', height: "390",
width: '640', width: "640",
videoId: '', videoId: "",
playerVars: { playerVars: {
'autoplay': 0, "autoplay": 0,
'controls': 1, "controls": 1,
}, },
events: { events: {
'onReady': onPlayerReady, "onReady": onPlayerReady,
'onStateChange': onPlayerStateChange "onStateChange": onPlayerStateChange
} }
}); });
} }
// Load new video // Load new video
if(PLAYER.getVideoUrl && data.id != parseYTURL(PLAYER.getVideoUrl())) { if(PLAYER.getVideoUrl && data.id != parseYTURL(PLAYER.getVideoUrl())) {
PLAYER.loadVideoById(data.id, data.currentTime, $('#quality').val()); PLAYER.loadVideoById(data.id, data.currentTime, $("#quality").val());
if(data.paused) if(data.paused)
PLAYER.pauseVideo(); PLAYER.pauseVideo();
} }
@ -327,7 +327,7 @@ function updateSC(data) {
iframe.css("width", "100%").attr("height", "166") iframe.css("width", "100%").attr("height", "166")
.attr("frameborder", "no"); .attr("frameborder", "no");
PLAYER = SC.Widget('ytapiplayer'); PLAYER = SC.Widget("ytapiplayer");
MEDIATYPE = "sc"; MEDIATYPE = "sc";
} }
// Server is on a different soundcloud track than client // Server is on a different soundcloud track than client
@ -338,7 +338,7 @@ function updateSC(data) {
// Keep track of current ID // Keep track of current ID
PLAYER.mediaId = data.id; PLAYER.mediaId = data.id;
} }
// Soundcloud's API is async // Soundcloud"s API is async
// Query the playback position and compare that with the sync packet // Query the playback position and compare that with the sync packet
PLAYER.getPosition(function(pos) { PLAYER.getPosition(function(pos) {
if(Math.abs(pos / 1000 - data.currentTime) > SYNC_THRESHOLD) { if(Math.abs(pos / 1000 - data.currentTime) > SYNC_THRESHOLD) {
@ -380,15 +380,15 @@ function updateVI(data) {
if(MEDIATYPE != "vi") { if(MEDIATYPE != "vi") {
initVI(data); initVI(data);
} }
// Either vimeo's API doesn't support loading a new video // Either vimeo"s API doesn"t support loading a new video
// or their terrible documentation doesn't document it // or their terrible documentation doesn"t document it
else if(data.id != PLAYER.videoid) { else if(data.id != PLAYER.videoid) {
initVI(data); initVI(data);
} }
PLAYER.api('getCurrentTime', function(time) { PLAYER.api("getCurrentTime", function(time) {
if(Math.abs(time - data.currentTime) > SYNC_THRESHOLD) { if(Math.abs(time - data.currentTime) > SYNC_THRESHOLD) {
PLAYER.api('seekTo', data.currentTime); PLAYER.api("seekTo", data.currentTime);
} }
}); });
} }
@ -398,16 +398,16 @@ function initVI(data) {
var currentEmbed = $("#ytapiplayer"); var currentEmbed = $("#ytapiplayer");
var div = currentEmbed.parent(); var div = currentEmbed.parent();
currentEmbed.remove(); currentEmbed.remove();
// Ugly but it's the only way I managed to get the API calls to work // Ugly but it"s the only way I managed to get the API calls to work
div[0].innerHTML += '<iframe id="ytapiplayer" src="http://player.vimeo.com/video/' + data.id + '?api=1&player_id=ytapiplayer" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; div[0].innerHTML += "<iframe id=\"ytapiplayer\" src=\"http://player.vimeo.com/video/" + data.id + "?api=1&player_id=ytapiplayer\" width=\"640\" height=\"390\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>";
// $f() is defined by froogaloop, Vimeo's API wrapper // $f() is defined by froogaloop, Vimeo"s API wrapper
PLAYER = $f($('iframe')[0]); PLAYER = $f($("iframe")[0]);
// So we can retrieve the ID synchronously instead of waiting for // So we can retrieve the ID synchronously instead of waiting for
// getVideoId with a callback // getVideoId with a callback
PLAYER.videoid = data.id; PLAYER.videoid = data.id;
PLAYER.addEvent('ready', function() { PLAYER.addEvent("ready", function() {
// Autoplay // Autoplay
PLAYER.api('play'); PLAYER.api("play");
}); });
MEDIATYPE = "vi"; MEDIATYPE = "vi";
} }
@ -425,14 +425,14 @@ function loadTwitch(channel) {
id: "live_embed_player_flash", id: "live_embed_player_flash",
flashvars:"hostname=www.twitch.tv&channel="+channel+"&auto_play=true&start_volume=100" flashvars:"hostname=www.twitch.tv&channel="+channel+"&auto_play=true&start_volume=100"
}; };
swfobject.embedSWF( url, "ytapiplayer", '640', '390', "8", null, null, params, {} ); swfobject.embedSWF( url, "ytapiplayer", "640", "390", "8", null, null, params, {} );
} }
function loadLivestream(channel) { function loadLivestream(channel) {
MEDIATYPE = "li"; MEDIATYPE = "li";
removeCurrentPlayer(); removeCurrentPlayer();
flashvars = { channel: channel }; flashvars = { channel: channel };
params = { AllowScriptAccess: 'always' }; params = { AllowScriptAccess: "always" };
swfobject.embedSWF("http://cdn.livestream.com/chromelessPlayer/v20/playerapi.swf", "ytapiplayer", "640", "390", "9.0.0", "expressInstall.swf", flashvars, params); swfobject.embedSWF("http://cdn.livestream.com/chromelessPlayer/v20/playerapi.swf", "ytapiplayer", "640", "390", "9.0.0", "expressInstall.swf", flashvars, params);
} }
@ -519,13 +519,13 @@ function parseDailymotion(url) {
} }
function closePoll() { function closePoll() {
if($('#pollcontainer .active').length != 0) { if($("#pollcontainer .active").length != 0) {
var poll = $('#pollcontainer .active'); var poll = $("#pollcontainer .active");
poll.removeClass("active").addClass("muted"); poll.removeClass("active").addClass("muted");
poll.find('.option button').each(function() { poll.find(".option button").each(function() {
$(this).attr('disabled', 'disabled'); $(this).attr("disabled", "disabled");
}); });
poll.find('.btn-danger').each(function() { poll.find(".btn-danger").each(function() {
$(this).remove() $(this).remove()
}); });
} }
@ -533,34 +533,34 @@ function closePoll() {
function addPoll(data) { function addPoll(data) {
closePoll(); closePoll();
var pollMsg = $('<div/>').addClass('poll-notify') var pollMsg = $("<div/>").addClass("poll-notify")
.text(data.initiator + ' opened a poll: "' + data.title + '"') .text(data.initiator + " opened a poll: \"" + data.title + "\"")
.appendTo($('#messagebuffer')); .appendTo($("#messagebuffer"));
var poll = $('<div/>').addClass('well active').prependTo($('#pollcontainer')); var poll = $("<div/>").addClass("well active").prependTo($("#pollcontainer"));
$('<button/>').addClass('close pull-right').text('×') $("<button/>").addClass("close pull-right").text("×")
.appendTo(poll) .appendTo(poll)
.click(function() { poll.remove(); }); .click(function() { poll.remove(); });
if(RANK >= Rank.Moderator) { if(RANK >= Rank.Moderator) {
$('<button/>').addClass('btn btn-danger pull-right').text('Close Poll') $("<button/>").addClass("btn btn-danger pull-right").text("Close Poll")
.appendTo(poll) .appendTo(poll)
.click(function() { .click(function() {
socket.emit('closePoll') socket.emit("closePoll")
}); });
} }
$('<h3/>').text(data.title).appendTo(poll); $("<h3/>").text(data.title).appendTo(poll);
for(var i = 0; i < data.options.length; i++) { for(var i = 0; i < data.options.length; i++) {
var callback = (function(i) { return function() { var callback = (function(i) { return function() {
console.log(i); console.log(i);
socket.emit('vote', { socket.emit("vote", {
option: i option: i
}); });
poll.find('.option button').each(function() { poll.find(".option button").each(function() {
$(this).attr('disabled', 'disabled'); $(this).attr("disabled", "disabled");
}); });
} })(i); } })(i);
$('<button/>').addClass('btn').text(data.counts[i]) $("<button/>").addClass("btn").text(data.counts[i])
.prependTo($('<div/>').addClass('option').text(data.options[i]) .prependTo($("<div/>").addClass("option").text(data.options[i])
.appendTo(poll)) .appendTo(poll))
.click(callback); .click(callback);
@ -568,54 +568,54 @@ function addPoll(data) {
} }
function updatePoll(data) { function updatePoll(data) {
var poll = $('#pollcontainer .active'); var poll = $("#pollcontainer .active");
var i = 0; var i = 0;
poll.find('.option button').each(function() { poll.find(".option button").each(function() {
$(this).text(data.counts[i]); $(this).text(data.counts[i]);
i++; i++;
}); });
} }
function showChannelRegistration() { function showChannelRegistration() {
var div = $('<div/>').addClass('alert alert-info').attr('id', 'chregnotice') var div = $("<div/>").addClass("alert alert-info").attr("id", "chregnotice")
.insertAfter($('.row')[0]); .insertAfter($(".row")[0]);
$('<button/>').addClass('close pull-right').text('×') $("<button/>").addClass("close pull-right").text("×")
.appendTo(div) .appendTo(div)
.click(function() { div.remove(); }); .click(function() { div.remove(); });
$('<h3/>').text("This channel isn't registered").appendTo(div); $("<h3/>").text("This channel isn"t registered").appendTo(div);
$('<button/>').addClass('btn btn-primary').text('Register it') $("<button/>").addClass("btn btn-primary").text("Register it")
.appendTo(div) .appendTo(div)
.click(function() { .click(function() {
socket.emit('registerChannel'); socket.emit("registerChannel");
}); });
} }
function showAnnouncement(title, text) { function showAnnouncement(title, text) {
var div = $('<div/>').addClass('alert') var div = $("<div/>").addClass("alert")
.insertAfter($('.row')[0]); .insertAfter($(".row")[0]);
$('<button/>').addClass('close pull-right').text('×') $("<button/>").addClass("close pull-right").text("×")
.appendTo(div) .appendTo(div)
.click(function() { div.remove(); }); .click(function() { div.remove(); });
$('<h3/>').text(title).appendTo(div); $("<h3/>").text(title).appendTo(div);
$('<p/>').html(text).appendTo(div); $("<p/>").html(text).appendTo(div);
} }
function updateBanlist(entries) { function updateBanlist(entries) {
var tbl = $('#banlist table'); var tbl = $("#banlist table");
if(tbl.children().length > 1) { if(tbl.children().length > 1) {
$(tbl.children()[1]).remove(); $(tbl.children()[1]).remove();
} }
for(var i = 0; i < entries.length; i++) { for(var i = 0; i < entries.length; i++) {
var tr = $('<tr/>').appendTo(tbl); var tr = $("<tr/>").appendTo(tbl);
var remove = $('<button/>').addClass("btn btn-mini btn-danger") var remove = $("<button/>").addClass("btn btn-mini btn-danger")
.appendTo($('<td/>').appendTo(tr)); .appendTo($("<td/>").appendTo(tr));
$('<i/>').addClass("icon-remove-circle").appendTo(remove); $("<i/>").addClass("icon-remove-circle").appendTo(remove);
var ip = $('<td/>').text(entries[i].ip).appendTo(tr); var ip = $("<td/>").text(entries[i].ip).appendTo(tr);
var name = $('<td/>').text(entries[i].name).appendTo(tr); var name = $("<td/>").text(entries[i].name).appendTo(tr);
var banner = $('<td/>').text(entries[i].banner).appendTo(tr); var banner = $("<td/>").text(entries[i].banner).appendTo(tr);
var callback = (function(ip) { return function() { var callback = (function(ip) { return function() {
socket.emit('chatMsg', { socket.emit("chatMsg", {
msg: "/unban " + ip msg: "/unban " + ip
}); });
} })(entries[i].ip); } })(entries[i].ip);