2013-03-24 02:28:20 +00:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
Copyright (c) 2013 Calvin Montgomery
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of 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.
|
|
|
|
*/
|
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() {
|
|
|
|
$("<div/>").addClass("alert").addClass("alert-error")
|
|
|
|
.insertAfter($(".row")[0])[0]
|
2013-02-16 05:02:42 +00:00
|
|
|
.innerHTML = "<h3>Disconnected from server</h3>";
|
|
|
|
});
|
|
|
|
|
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 */
|
|
|
|
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-03-28 23:51:08 +00:00
|
|
|
$("#opt_customcss").attr("placeholder", opts.customcss);
|
2013-03-24 17:23:48 +00:00
|
|
|
$("#customCss").remove();
|
2013-03-23 22:15:19 +00:00
|
|
|
if(opts.customcss != "") {
|
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-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-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) {
|
|
|
|
$("#usercount").text(data.count + " connected users");
|
2013-03-07 01:38:16 +00:00
|
|
|
});
|
|
|
|
|
2013-03-24 17:23:48 +00:00
|
|
|
socket.on("chatMsg", function(data) {
|
2013-03-05 20:07:21 +00:00
|
|
|
var div = formatChatMessage(data);
|
2013-04-03 22:56:03 +00:00
|
|
|
div.appendTo($("#messagebuffer"));
|
2013-02-16 05:02:42 +00:00
|
|
|
// Cap chatbox at most recent 100 messages
|
2013-03-24 17:23:48 +00:00
|
|
|
if($("#messagebuffer").children().length > 100) {
|
|
|
|
$($("#messagebufer").children()[0]).remove();
|
2013-02-16 05:02:42 +00:00
|
|
|
}
|
2013-03-30 05:55:25 +00:00
|
|
|
if(SCROLLCHAT)
|
|
|
|
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
|
2013-02-16 05:02:42 +00:00
|
|
|
});
|
|
|
|
|
2013-04-03 22:56:03 +00:00
|
|
|
socket.on("userlist", function(data) {
|
|
|
|
for(var i = 0; i < data.length; i++) {
|
|
|
|
addUser(data[i].name, data[i].rank, data[i].leader);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("addUser", function(data) {
|
|
|
|
addUser(data.name, data.rank, data.leader);
|
|
|
|
});
|
|
|
|
|
|
|
|
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) {
|
|
|
|
fmtUserlistItem(users[i], data.rank, data.leader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
$(li).appendTo(ul);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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-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-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-03-25 18:54:18 +00:00
|
|
|
if(RANK >= Rank.Moderator || OPENQUEUE || LEADER)
|
2013-02-16 05:02:42 +00:00
|
|
|
addLibraryButtons(li, data.results[i].id);
|
|
|
|
$(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
|
|
|
}
|