2013-03-24 02:28:20 +00:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
Copyright (c) 2013 Calvin Montgomery
|
2013-04-11 16:30:20 +00:00
|
|
|
|
2013-03-24 02:28:20 +00:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
2013-04-11 16:30:20 +00:00
|
|
|
|
2013-03-24 02:28:20 +00:00
|
|
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
2013-04-11 16:30:20 +00:00
|
|
|
|
2013-03-24 02:28:20 +00:00
|
|
|
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.
|
|
|
|
*/
|
2013-02-16 17:19:59 +00:00
|
|
|
|
2013-02-16 05:02:42 +00:00
|
|
|
// Wrapped in a function so I can ensure that the socket
|
|
|
|
// is defined before these statements are run
|
|
|
|
function initCallbacks() {
|
2013-04-03 22:56:03 +00:00
|
|
|
/* REGION Globals */
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("disconnect", function() {
|
2013-04-06 20:47:27 +00:00
|
|
|
handleDisconnect();
|
2013-02-16 05:02:42 +00:00
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("announcement", function(data) {
|
2013-03-20 18:35:06 +00:00
|
|
|
showAnnouncement(data.title, data.text);
|
|
|
|
});
|
|
|
|
|
2013-04-03 22:56:03 +00:00
|
|
|
/* REGION Channel Meta */
|
2013-04-14 17:38:00 +00:00
|
|
|
socket.on("kick", function(data) {
|
|
|
|
KICKED = true;
|
|
|
|
$("<div/>")
|
|
|
|
.addClass("server-msg-disconnect")
|
|
|
|
.text("Kicked: " + data.reason)
|
|
|
|
.appendTo($("#messagebuffer"));
|
2013-04-23 19:17:42 +00:00
|
|
|
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("noflood", function(data) {
|
|
|
|
$("<div/>")
|
|
|
|
.addClass("server-msg-disconnect")
|
|
|
|
.text(data.action + ": " + data.msg)
|
|
|
|
.appendTo($("#messagebuffer"));
|
|
|
|
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
|
2013-04-14 17:38:00 +00:00
|
|
|
});
|
|
|
|
|
2013-04-03 22:56:03 +00:00
|
|
|
socket.on("channelNotRegistered", function() {
|
|
|
|
showChannelRegistration();
|
2013-04-01 21:02:09 +00:00
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("registerChannel", function(data) {
|
2013-03-17 17:14:34 +00:00
|
|
|
if(data.success) {
|
2013-03-24 17:23:48 +00:00
|
|
|
$("#chregnotice").remove();
|
2013-03-17 17:14:34 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
alert(data.error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-04-03 22:56:03 +00:00
|
|
|
socket.on("updateMotd", function(data) {
|
|
|
|
$("#motdtext").val(data.motd);
|
|
|
|
if(data.motd != "")
|
|
|
|
$("#motd").parent().css("display", "");
|
|
|
|
else
|
|
|
|
$("#motd").parent().css("display", "none");
|
|
|
|
$("#motd")[0].innerHTML = data.html;
|
2013-02-16 05:02:42 +00:00
|
|
|
});
|
|
|
|
|
2013-04-03 22:56:03 +00:00
|
|
|
socket.on("chatFilters", function(data) {
|
|
|
|
updateChatFilters(data.filters);
|
2013-02-16 05:02:42 +00:00
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("channelOpts", function(opts) {
|
|
|
|
$("#opt_qopen_allow_qnext").prop("checked", opts.qopen_allow_qnext);
|
|
|
|
$("#opt_qopen_allow_move").prop("checked", opts.qopen_allow_move);
|
|
|
|
$("#opt_qopen_allow_delete").prop("checked", opts.qopen_allow_delete);
|
|
|
|
$("#opt_qopen_allow_playnext").prop("checked", opts.qopen_allow_playnext);
|
|
|
|
$("#opt_pagetitle").attr("placeholder", opts.pagetitle);
|
2013-03-22 20:04:04 +00:00
|
|
|
document.title = opts.pagetitle;
|
2013-03-30 05:49:41 +00:00
|
|
|
PAGETITLE = opts.pagetitle;
|
2013-04-06 21:08:26 +00:00
|
|
|
$("#opt_customcss").val(opts.customcss);
|
2013-04-16 16:11:10 +00:00
|
|
|
$("#opt_customjs").val(opts.customjs);
|
2013-04-23 19:17:42 +00:00
|
|
|
$("#opt_chat_antiflood").prop("checked", opts.chat_antiflood);
|
2013-03-24 17:23:48 +00:00
|
|
|
$("#customCss").remove();
|
2013-04-06 21:08:26 +00:00
|
|
|
if(opts.customcss.trim() != "") {
|
2013-03-24 17:23:48 +00:00
|
|
|
$("<link/>").attr("rel", "stylesheet")
|
2013-03-23 22:15:19 +00:00
|
|
|
.attr("href", opts.customcss)
|
|
|
|
.attr("id", "customCss")
|
2013-03-24 17:23:48 +00:00
|
|
|
.insertAfter($("link[href='./assets/css/ytsync.css']"));
|
2013-03-23 22:15:19 +00:00
|
|
|
}
|
2013-04-02 19:07:22 +00:00
|
|
|
$("#opt_allow_voteskip").prop("checked", opts.allow_voteskip);
|
2013-04-21 01:17:38 +00:00
|
|
|
$("#opt_voteskip_ratio").val(opts.voteskip_ratio);
|
2013-04-16 16:11:10 +00:00
|
|
|
if(opts.customjs.trim() != "") {
|
|
|
|
$.getScript(opts.customjs);
|
|
|
|
}
|
2013-03-23 22:15:19 +00:00
|
|
|
|
2013-03-22 20:04:04 +00:00
|
|
|
CHANNELOPTS = opts;
|
|
|
|
if(opts.qopen_allow_qnext)
|
2013-03-24 17:23:48 +00:00
|
|
|
$("#queue_next").attr("disabled", false);
|
2013-04-03 22:56:03 +00:00
|
|
|
else if(RANK < Rank.Moderator && !LEADER)
|
|
|
|
$("#queue_next").attr("disabled", true);
|
2013-03-22 20:04:04 +00:00
|
|
|
if(opts.qopen_allow_playnext)
|
2013-03-24 17:23:48 +00:00
|
|
|
$("#play_next").attr("disabled", false);
|
2013-03-28 23:51:08 +00:00
|
|
|
else if(RANK < Rank.Moderator && !LEADER)
|
|
|
|
$("#play_next").attr("disabled", true);
|
2013-04-02 19:07:22 +00:00
|
|
|
|
|
|
|
if(opts.allow_voteskip)
|
|
|
|
$("#voteskip").attr("disabled", false);
|
|
|
|
else
|
|
|
|
$("#voteskip").attr("disabled", true);
|
2013-03-22 20:04:04 +00:00
|
|
|
rebuildPlaylist();
|
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("banlist", function(data) {
|
2013-03-24 03:45:10 +00:00
|
|
|
updateBanlist(data.entries);
|
|
|
|
});
|
|
|
|
|
2013-04-22 18:28:40 +00:00
|
|
|
socket.on("acl", updateACL);
|
|
|
|
|
2013-04-21 01:17:38 +00:00
|
|
|
socket.on("voteskip", function(data) {
|
|
|
|
if(data.count > 0) {
|
|
|
|
$("#voteskip").text("Voteskip ("+data.count+"/"+data.need+")");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#voteskip").text("Voteskip");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-04-03 22:56:03 +00:00
|
|
|
/* REGION Rank Stuff */
|
|
|
|
|
|
|
|
socket.on("rank", function(data) {
|
|
|
|
RANK = data.rank;
|
|
|
|
handleRankChange();
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("register", function(data) {
|
|
|
|
if(data.error) {
|
|
|
|
alert(data.error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("login", function(data) {
|
|
|
|
if(!data.success)
|
|
|
|
alert(data.error);
|
|
|
|
else {
|
|
|
|
$("#welcome")[0].innerHTML = "Welcome, " + uname;
|
|
|
|
$("#loginform").css("display", "none");
|
|
|
|
$("#logoutform").css("display", "");
|
|
|
|
$("#loggedin").css("display", "");
|
|
|
|
if(pw != "") {
|
|
|
|
createCookie("sync_uname", uname, 1);
|
|
|
|
createCookie("sync_pw", pw, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/* REGION Chat */
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("usercount", function(data) {
|
2013-04-22 17:38:42 +00:00
|
|
|
var text = data.count + " connected user";
|
|
|
|
if(data.count != 1) {
|
|
|
|
text += "s";
|
|
|
|
}
|
|
|
|
$("#usercount").text(text);
|
2013-03-07 01:38:16 +00:00
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("chatMsg", function(data) {
|
2013-04-16 01:28:01 +00:00
|
|
|
addChatMessage(data);
|
2013-02-16 05:02:42 +00:00
|
|
|
});
|
|
|
|
|
2013-04-03 22:56:03 +00:00
|
|
|
socket.on("userlist", function(data) {
|
2013-04-11 16:30:20 +00:00
|
|
|
$(".userlist_item").each(function() { $(this).remove(); });
|
2013-04-03 22:56:03 +00:00
|
|
|
for(var i = 0; i < data.length; i++) {
|
2013-04-19 19:50:08 +00:00
|
|
|
addUser(data[i]);
|
2013-04-03 22:56:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("addUser", function(data) {
|
2013-04-19 19:50:08 +00:00
|
|
|
addUser(data);
|
2013-04-03 22:56:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("updateUser", function(data) {
|
|
|
|
if(data.name == uname) {
|
|
|
|
LEADER = data.leader;
|
|
|
|
handleRankChange();
|
|
|
|
if(LEADER) {
|
|
|
|
// I'm a leader! Set up sync function
|
|
|
|
sendVideoUpdate = function() {
|
|
|
|
PLAYER.getTime(function(seconds) {
|
|
|
|
socket.emit("mediaUpdate", {
|
|
|
|
id: PLAYER.id,
|
|
|
|
currentTime: seconds,
|
|
|
|
paused: false,
|
|
|
|
type: PLAYER.type
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// I'm not a leader. Don't send syncs to the server
|
|
|
|
else {
|
|
|
|
sendVideoUpdate = function() { }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
var users = $("#userlist").children();
|
|
|
|
for(var i = 0; i < users.length; i++) {
|
|
|
|
var name = users[i].children[1].innerHTML;
|
|
|
|
// Reformat user
|
|
|
|
if(name == data.name) {
|
2013-04-19 19:50:08 +00:00
|
|
|
formatUserlistItem(users[i], data);
|
2013-04-03 22:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("userLeave", function(data) {
|
|
|
|
var users = $("#userlist").children();
|
|
|
|
for(var i = 0; i < users.length; i++) {
|
|
|
|
var name = users[i].children[1].innerHTML;
|
|
|
|
if(name == data.name) {
|
|
|
|
$("#userlist")[0].removeChild(users[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-04-04 19:56:43 +00:00
|
|
|
socket.on("drinkCount", function(data) {
|
2013-04-22 17:38:42 +00:00
|
|
|
if(data.count != 0) {
|
|
|
|
var text = data.count + " drink";
|
|
|
|
if(data.count != 1) {
|
|
|
|
text += "s";
|
|
|
|
}
|
|
|
|
$("#drinkcount").text(text);
|
2013-04-04 19:56:43 +00:00
|
|
|
$(".drinkbar").show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$(".drinkbar").hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-04-03 22:56:03 +00:00
|
|
|
/* REGION Playlist Stuff */
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("playlist", function(data) {
|
2013-04-03 22:56:03 +00:00
|
|
|
// Clear the playlist first
|
2013-03-24 17:23:48 +00:00
|
|
|
var ul = $("#queue")[0];
|
2013-02-16 05:02:42 +00:00
|
|
|
var n = ul.children.length;
|
|
|
|
for(var i = 0; i < n; i++) {
|
|
|
|
ul.removeChild(ul.children[0]);
|
|
|
|
}
|
|
|
|
for(var i = 0; i < data.pl.length; i++) {
|
|
|
|
var li = makeQueueEntry(data.pl[i]);
|
2013-03-25 18:54:18 +00:00
|
|
|
if(RANK >= Rank.Moderator || OPENQUEUE || LEADER)
|
2013-02-16 05:02:42 +00:00
|
|
|
addQueueButtons(li);
|
2013-04-24 18:10:08 +00:00
|
|
|
$(li).attr("title", data.pl[i].queueby
|
|
|
|
? ("Added by: " + data.pl[i].queueby)
|
|
|
|
: "Added by: Unknown");
|
2013-02-16 05:02:42 +00:00
|
|
|
$(li).appendTo(ul);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-04-24 19:28:20 +00:00
|
|
|
socket.on("updatePlaylistMeta", function(data) {
|
|
|
|
$("#plcount").text(data.count + " items");
|
|
|
|
$("#pllength").text(data.time);
|
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("queue", function(data) {
|
2013-02-16 05:02:42 +00:00
|
|
|
var li = makeQueueEntry(data.media);
|
2013-03-25 18:54:18 +00:00
|
|
|
if(RANK >= Rank.Moderator || OPENQUEUE || LEADER)
|
2013-02-16 05:02:42 +00:00
|
|
|
addQueueButtons(li);
|
2013-03-24 17:23:48 +00:00
|
|
|
$(li).css("display", "none");
|
2013-02-16 05:02:42 +00:00
|
|
|
var idx = data.pos;
|
2013-03-24 17:23:48 +00:00
|
|
|
var ul = $("#queue")[0];
|
2013-04-24 18:10:08 +00:00
|
|
|
$(li).attr("title", data.media.queueby
|
|
|
|
? ("Added by: " + data.media.queueby)
|
|
|
|
: "Added by: Unknown");
|
2013-02-16 05:02:42 +00:00
|
|
|
$(li).appendTo(ul);
|
|
|
|
if(idx < ul.children.length - 1)
|
|
|
|
moveVideo(ul.children.length - 1, idx);
|
2013-03-24 17:23:48 +00:00
|
|
|
$(li).show("blind");
|
2013-02-16 05:02:42 +00:00
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("unqueue", function(data) {
|
|
|
|
var li = $("#queue").children()[data.pos];
|
2013-04-03 22:56:03 +00:00
|
|
|
$(li).remove();
|
2013-02-16 05:02:42 +00:00
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("moveVideo", function(data) {
|
2013-02-16 05:02:42 +00:00
|
|
|
moveVideo(data.src, data.dest);
|
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("updatePlaylistIdx", function(data) {
|
2013-03-29 20:05:08 +00:00
|
|
|
if(data.old != undefined) {
|
|
|
|
var liold = $("#queue").children()[data.old];
|
|
|
|
$(liold).removeClass("alert alert-info");
|
|
|
|
}
|
2013-03-24 17:23:48 +00:00
|
|
|
var linew = $("#queue").children()[data.idx];
|
2013-02-16 05:02:42 +00:00
|
|
|
$(linew).addClass("alert alert-info");
|
2013-04-13 17:14:44 +00:00
|
|
|
$("#queue").scrollTop(0);
|
|
|
|
var scroll = $(linew).position().top - $("#queue").position().top;
|
|
|
|
$("#queue").scrollTop(scroll);
|
2013-03-29 20:05:08 +00:00
|
|
|
POSITION = data.idx;
|
2013-04-04 16:05:01 +00:00
|
|
|
if(CHANNELOPTS.allow_voteskip)
|
|
|
|
$("#voteskip").attr("disabled", false);
|
2013-02-16 05:02:42 +00:00
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("mediaUpdate", function(data) {
|
|
|
|
$("#currenttitle").text("Currently Playing: " + data.title);
|
2013-03-25 18:54:18 +00:00
|
|
|
if(data.type != "sc" && MEDIATYPE == "sc")
|
2013-04-03 22:56:03 +00:00
|
|
|
// [](/goddamnitmango)
|
2013-03-25 18:54:18 +00:00
|
|
|
fixSoundcloudShit();
|
2013-04-03 20:18:35 +00:00
|
|
|
if(data.type != MEDIATYPE) {
|
|
|
|
MEDIATYPE = data.type;
|
|
|
|
PLAYER = new Media(data);
|
|
|
|
}
|
2013-04-03 22:56:03 +00:00
|
|
|
else if(PLAYER.update) {
|
2013-04-03 20:18:35 +00:00
|
|
|
PLAYER.update(data);
|
|
|
|
}
|
2013-02-16 05:02:42 +00:00
|
|
|
});
|
|
|
|
|
2013-04-03 22:56:03 +00:00
|
|
|
socket.on("queueLock", function(data) {
|
|
|
|
OPENQUEUE = !data.locked;
|
|
|
|
if(OPENQUEUE) {
|
|
|
|
$("#playlist_controls").css("display", "");
|
|
|
|
if(RANK < Rank.Moderator) {
|
|
|
|
$("#qlockbtn").css("display", "none");
|
|
|
|
rebuildPlaylist();
|
|
|
|
if(!CHANNELOPTS.qopen_allow_qnext)
|
|
|
|
$("#queue_next").attr("disabled", true);
|
|
|
|
if(!CHANNELOPTS.qopen_allow_playnext)
|
|
|
|
$("#play_next").attr("disabled", true);
|
2013-02-16 05:02:42 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-03 22:56:03 +00:00
|
|
|
else if(RANK < Rank.Moderator && !LEADER) {
|
|
|
|
$("#playlist_controls").css("display", "none");
|
|
|
|
rebuildPlaylist();
|
2013-02-16 05:02:42 +00:00
|
|
|
}
|
2013-04-03 22:56:03 +00:00
|
|
|
if(OPENQUEUE) {
|
|
|
|
$("#qlockbtn").removeClass("btn-danger")
|
|
|
|
.addClass("btn-success")
|
|
|
|
.text("Lock Queue");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#qlockbtn").removeClass("btn-success")
|
|
|
|
.addClass("btn-danger")
|
|
|
|
.text("Unlock Queue");
|
2013-02-16 05:02:42 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("librarySearchResults", function(data) {
|
|
|
|
var n = $("#library").children().length;
|
2013-02-16 05:02:42 +00:00
|
|
|
for(var i = 0; i < n; i++) {
|
2013-03-24 17:23:48 +00:00
|
|
|
$("#library")[0].removeChild($("#library").children()[0]);
|
2013-02-16 05:02:42 +00:00
|
|
|
}
|
2013-03-24 17:23:48 +00:00
|
|
|
var ul = $("#library")[0];
|
2013-02-16 05:02:42 +00:00
|
|
|
for(var i = 0; i < data.results.length; i++) {
|
|
|
|
var li = makeQueueEntry(data.results[i]);
|
2013-04-04 20:55:43 +00:00
|
|
|
if(RANK >= Rank.Moderator || OPENQUEUE || LEADER) {
|
|
|
|
if(data.results[i].thumb)
|
|
|
|
addLibraryButtons(li, data.results[i].id, true);
|
|
|
|
else
|
|
|
|
addLibraryButtons(li, data.results[i].id);
|
|
|
|
}
|
2013-02-16 05:02:42 +00:00
|
|
|
$(li).appendTo(ul);
|
|
|
|
}
|
|
|
|
});
|
2013-03-16 21:49:58 +00:00
|
|
|
|
2013-04-03 22:56:03 +00:00
|
|
|
/* REGION Poll */
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("newPoll", function(data) {
|
2013-03-16 21:49:58 +00:00
|
|
|
addPoll(data);
|
2013-03-30 05:55:25 +00:00
|
|
|
if(SCROLLCHAT) {
|
|
|
|
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
|
|
|
|
}
|
2013-03-16 21:49:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("updatePoll", function(data) {
|
2013-03-16 21:49:58 +00:00
|
|
|
updatePoll(data);
|
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("closePoll", function() {
|
2013-03-16 21:49:58 +00:00
|
|
|
closePoll();
|
|
|
|
});
|
2013-02-16 05:02:42 +00:00
|
|
|
}
|