1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732 |
- Playlists = new Mongo.Collection("playlists");
- Rooms = new Mongo.Collection("rooms");
- Queues = new Mongo.Collection("queues");
- Reports = new Mongo.Collection("reports");
- if (Meteor.isClient) {
- Meteor.startup(function() {
- reCAPTCHA.config({
- publickey: '6LcVxg0TAAAAAE18vBiH00UAyaJggsmLm890SjZl'
- });
- });
- Meteor.subscribe("queues");
- Meteor.subscribe("playlists");
- var minterval;
- var hpSound = undefined;
- var songsArr = [];
- var ytArr = [];
- var _sound = undefined;
- var parts = location.href.split('/');
- var id = parts.pop();
- var type = id.toLowerCase();
- var resizeSeekerbarInterval;
- function getSpotifyInfo(title, cb, artist) {
- var q = "";
- q = title;
- if (artist !== undefined) {
- q += " artist:" + artist;
- }
- $.ajax({
- type: "GET",
- url: 'https://api.spotify.com/v1/search?q=' + encodeURIComponent(q) + '&type=track',
- applicationType: "application/json",
- contentType: "json",
- success: function (data) {
- cb(data);
- }
- });
- }
- Template.profile.helpers({
- "username": function() {
- return Session.get("username");
- },
- "first_joined": function() {
- return moment(Session.get("first_joined")).format("DD/MM/YYYY HH:mm:ss");
- },
- "rank": function() {
- return Session.get("rank");
- },
- loaded: function() {
- return Session.get("loaded");
- }
- });
- Template.profile.onCreated(function() {
- var parts = location.href.split('/');
- var username = parts.pop();
- Session.set("loaded", false);
- Meteor.subscribe("userProfiles", function() {
- if (Meteor.users.find({"profile.usernameL": username.toLowerCase()}).count() === 0) {
- window.location = "/";
- } else {
- var data = Meteor.users.findOne({"profile.usernameL": username.toLowerCase()});
- Session.set("username", data.profile.username);
- Session.set("first_joined", data.createdAt);
- Session.set("rank", data.profile.rank);
- Session.set("loaded", true);
- }
- });
- });
- curPath=function(){var c=window.location.pathname;var b=c.slice(0,-1);var a=c.slice(-1);if(b==""){return"/"}else{if(a=="/"){return b}else{return c}}};
- Handlebars.registerHelper('active', function(path) {
- return curPath() == path ? 'active' : '';
- });
- Template.header.helpers({
- currentUser: function() {
- return Meteor.user();
- },
- isAdmin: function() {
- if (Meteor.user() && Meteor.user().profile) {
- return Meteor.user().profile.rank === "admin";
- } else {
- return false;
- }
- }
- });
- Template.header.events({
- "click .logout": function(e){
- e.preventDefault();
- Meteor.logout();
- if (hpSound !== undefined) {
- hpSound.stop();
- }
- }
- });
- Template.register.events({
- "submit form": function(e){
- e.preventDefault();
- var username = e.target.registerUsername.value;
- var email = e.target.registerEmail.value;
- var password = e.target.registerPassword.value;
- var captchaData = grecaptcha.getResponse();
- Meteor.call("createUserMethod", {username: username, email: email, password: password}, captchaData, function(err, res) {
- grecaptcha.reset();
- if (err) {
- console.log(err);
- var errAlert = $('<div class="alert alert-danger" role="alert"><strong>Oh Snap!</strong> ' + err.reason + '</div>');
- $("#login").after(errAlert);
- errAlert.fadeOut(20000, function() {
- errAlert.remove();
- });
- } else {
- Meteor.loginWithPassword(username, password);
- Accounts.onLogin(function(){
- window.location.href = "/";
- })
- }
- });
- },
- "click #github-login": function(){
- Meteor.loginWithGithub()
- Accounts.onLogin(function(){
- window.location.href = "/"
- });
- }
- });
- Template.login.events({
- "submit form": function(e){
- e.preventDefault();
- var username = e.target.loginUsername.value;
- var password = e.target.loginPassword.value;
- Meteor.loginWithPassword(username, password);
- Accounts.onLogin(function(){
- window.location.href = "/";
- })
- Accounts.onLoginFailure(function(){
- $("#login-form input").css("background-color","indianred");
- $("#login-form input").on("click",function(){
- $("#login-form input").css({
- "-webkit-appearance": "none",
- " -moz-appearance": "none",
- " appearance": "none",
- "outline": "0",
- "border": "1px solid rgba(255, 255, 255, 0.4)",
- "background-color": "rgba(255, 255, 255, 0.2)",
- "width": "304px",
- "border-radius": "3px",
- "padding": "10px 15px",
- "margin": "0 auto 10px auto",
- "display": "block",
- "text-align": "center",
- "font-size": "18px",
- "color": "white",
- "-webkit-transition-duration": "0.25s",
- " transition-duration": "0.25s",
- "font-weight": "300"
- });
- $("#login-form input:focus").css({
- "width": "354px",
- "color": "white"
- })
- $("#login-form input").on("blur", function(){
- $(this).css("width", "304px");
- })
- })
- });
- },
- "click #github-login": function(){
- Meteor.loginWithGithub()
- Accounts.onLogin(function(){
- window.location.href = "/"
- });
- }
- });
- Template.dashboard.helpers({
- rooms: function() {
- return Rooms.find({});
- },
- currentSong: function() {
- var type = this.type;
- var room = Rooms.findOne({type: type});
- if (room !== undefined) {
- return room.currentSong;
- } else {
- return {};
- }
- }
- });
- Template.dashboard.onCreated(function() {
- if (_sound !== undefined) _sound.stop();
- if (minterval !== undefined) {
- Meteor.clearInterval(minterval);
- }
- if (resizeSeekerbarInterval !== undefined) {
- Meteor.clearInterval(resizeSeekerbarInterval);
- resizeSeekerbarInterval = undefined;
- }
- Session.set("type", undefined);
- });
- Template.room.events({
- "click #like": function(e) {
- Meteor.call("likeSong", Session.get("currentSong").mid);
- },
- "click #dislike": function(e) {
- Meteor.call("dislikeSong", Session.get("currentSong").mid);
- },
- "click #report-prev": function(e) {
- if (Session.get("previousSong") !== undefined) {
- Session.set("reportPrevious", true);
- $("#report-prev").prop("disabled", true);
- $("#report-curr").prop("disabled", false);
- }
- },
- "click #report-curr": function(e) {
- Session.set("reportPrevious", false);
- $("#report-prev").prop("disabled", false);
- $("#report-curr").prop("disabled", true);
- },
- "click #report-modal": function() {
- Session.set("currentSongR", Session.get("currentSong"));
- Session.set("previousSongR", Session.get("previousSong"));
- },
- "click #add-song-button": function(e){
- e.preventDefault();
- parts = location.href.split('/');
- id = parts.pop();
- var genre = id.toLowerCase();
- var type = $("#type").val();
- id = $("#id").val();
- var title = $("#title").val();
- var artist = $("#artist").val();
- var img = $("#img").val();
- var songData = {type: type, id: id, title: title, artist: artist, img: img};
- Meteor.call("addSongToQueue", genre, songData, function(err, res) {
- console.log(err, res);
- });
- $("#close-modal-a").click();
- },
- "click #toggle-video": function(e){
- e.preventDefault();
- if (Session.get("mediaHidden")) {
- $("#media-container").removeClass("hidden");
- $("#toggle-video").text("Hide video");
- Session.set("mediaHidden", false);
- } else {
- $("#media-container").addClass("hidden");
- $("#toggle-video").text("Show video");
- Session.set("mediaHidden", true);
- }
- },
- "click #return": function(e){
- $("#add-info").hide();
- $("#search-info").show();
- },
- "click #search-song": function(){
- $("#song-results").empty();
- var search_type = $("#search_type").val();
- if (search_type === "YouTube") {
- $.ajax({
- type: "GET",
- url: "https://www.googleapis.com/youtube/v3/search?part=snippet&q=" + $("#song-input").val() + "&key=AIzaSyAgBdacEWrHCHVPPM4k-AFM7uXg-Q__YXY",
- applicationType: "application/json",
- contentType: "json",
- success: function(data){
- for(var i in data.items){
- $("#song-results").append("<p>" + data.items[i].snippet.title + "</p>");
- ytArr.push({title: data.items[i].snippet.title, id: data.items[i].id.videoId});
- }
- $("#song-results p").click(function(){
- $("#search-info").hide();
- $("#add-info").show();
- var title = $(this).text();
- for(var i in ytArr){
- if(ytArr[i].title === title){
- var songObj = {
- id: ytArr[i].id,
- title: ytArr[i].title,
- type: "youtube"
- };
- $("#title").val(songObj.title);
- $("#artist").val("");
- $("#id").val(songObj.id);
- $("#type").val("YouTube");
- getSpotifyInfo(songObj.title.replace(/\[.*\]/g, ""), function(data) {
- if (data.tracks.items.length > 0) {
- $("#title").val(data.tracks.items[0].name);
- var artists = [];
- $("#img").val(data.tracks.items[0].album.images[1].url);
- data.tracks.items[0].artists.forEach(function(artist) {
- artists.push(artist.name);
- });
- $("#artist").val(artists.join(", "));
- }
- });
- }
- }
- })
- }
- })
- } else if (search_type === "SoundCloud") {
- SC.get('/tracks', { q: $("#song-input").val()}, function(tracks) {
- for(var i in tracks){
- $("#song-results").append("<p>" + tracks[i].title + "</p>")
- songsArr.push({title: tracks[i].title, id: tracks[i].id, duration: tracks[i].duration / 1000});
- }
- $("#song-results p").click(function(){
- $("#search-info").hide();
- $("#add-info").show();
- var title = $(this).text();
- for(var i in songsArr){
- if(songsArr[i].title === title){
- var id = songsArr[i].id;
- var duration = songsArr[i].duration;
- var songObj = {
- title: songsArr[i].title,
- id: id,
- duration: duration,
- type: "soundcloud"
- }
- $("#title").val(songObj.title);
- // Set ID field
- $("#id").val(songObj.id);
- $("#type").val("SoundCloud");
- getSpotifyInfo(songObj.title.replace(/\[.*\]/g, ""), function(data) {
- if (data.tracks.items.length > 0) {
- $("#title").val(data.tracks.items[0].name);
- var artists = [];
- data.tracks.items[0].artists.forEach(function(artist) {
- artists.push(artist.name);
- });
- $("#artist").val(artists.join(", "));
- }
- // Set title field again if possible
- // Set artist if possible
- });
- }
- }
- })
- });
- }
- },
- "click #add-songs": function(){
- $("#add-songs-modal").show();
- },
- "click #close-modal-a": function(){
- $("#search-info").show();
- $("#add-info").hide();
- },
- "click #volume-icon": function(){
- var volume = 0;
- var slider = $("#volume-slider").slider();
- $("#volume-icon").removeClass("fa-volume-down").addClass("fa-volume-off")
- if (yt_player !== undefined) {
- yt_player.setVolume(volume);
- localStorage.setItem("volume", volume);
- $("#volume-slider").slider("setValue", volume);
- } else if (_sound !== undefined) {
- _sound.setVolume(volume);
- localStorage.setItem("volume", volume);
- $("#volume-slider").slider("setValue", volume);
- }
- },
- "click #play": function() {
- Meteor.call("resumeRoom", type);
- },
- "click #pause": function() {
- Meteor.call("pauseRoom", type);
- },
- "click #skip": function() {
- Meteor.call("skipSong", type);
- },
- "click #shuffle": function() {
- Meteor.call("shufflePlaylist", type);
- },
- "change input": function(e) {
- if (e.target && e.target.id) {
- var partsOfId = e.target.id.split("-");
- partsOfId[1] = partsOfId[1].charAt(0).toUpperCase() + partsOfId[1].slice(1);
- var camelCase = partsOfId.join("");
- Session.set(camelCase, e.target.checked);
- }
- },
- "click #report-song-button": function() {
- var report = {};
- report.reportSongB = $("#report-song").is(":checked");
- report.reportTitleB = $("#report-title").is(":checked");
- report.reportAuthorB = $("#report-author").is(":checked");
- report.reportDurationB = $("#report-duration").is(":checked");
- report.reportAudioB = $("#report-audio").is(":checked");
- report.reportAlbumartB = $("#report-albumart").is(":checked");
- report.reportOtherB = $("#report-other").is(":checked");
-
- if (report.reportSongB) {
- report.reportSong = {};
- report.reportSong.notPlayingB = $("#report-song-not-playing").is(":checked");
- report.reportSong.doesNotExistB = $("#report-song-does-not-exist").is(":checked");
- report.reportSong.otherB = $("#report-song-other").is(":checked");
- if (report.reportSong.otherB) {
- report.reportSong.other = $("#report-song-other-ta").val();
- }
- }
- if (report.reportTitleB) {
- report.reportTitle = {};
- report.reportTitle.incorrectB = $("#report-title-incorrect").is(":checked");
- report.reportTitle.inappropriateB = $("#report-title-inappropriate").is(":checked");
- report.reportTitle.otherB = $("#report-title-other").is(":checked");
- if (report.reportTitle.otherB) {
- report.reportTitle.other = $("#report-title-other-ta").val();
- }
- }
- if (report.reportAuthorB) {
- report.reportAuthor = {};
- report.reportAuthor.incorrectB = $("#report-author-incorrect").is(":checked");
- report.reportAuthor.inappropriateB = $("#report-author-inappropriate").is(":checked");
- report.reportAuthor.otherB = $("#report-author-other").is(":checked");
- if (report.reportAuthor.otherB) {
- report.reportAuthor.other = $("#report-author-other-ta").val();
- }
- }
- if (report.reportDurationB) {
- report.reportDuration = {};
- report.reportDuration.longB = $("#report-duration-incorrect").is(":checked");
- report.reportDuration.shortB = $("#report-duration-inappropriate").is(":checked");
- report.reportDuration.otherB = $("#report-duration-other").is(":checked");
- if (report.reportDuration.otherB) {
- report.reportDuration.other = $("#report-duration-other-ta").val();
- }
- }
- if (report.reportAudioB) {
- report.reportAudio = {};
- report.reportAudio.inappropriate = $("#report-audio-inappropriate").is(":checked");
- report.reportAudio.notPlayingB = $("#report-audio-incorrect").is(":checked");
- report.reportAudio.otherB = $("#report-audio-other").is(":checked");
- if (report.reportAudio.otherB) {
- report.reportAudio.other = $("#report-audio-other-ta").val();
- }
- }
- if (report.reportAlbumartB) {
- report.reportAlbumart = {};
- report.reportAlbumart.incorrectB = $("#report-albumart-incorrect").is(":checked");
- report.reportAlbumart.inappropriateB = $("#report-albumart-inappropriate").is(":checked");
- report.reportAlbumart.notShowingB = $("#report-albumart-inappropriate").is(":checked");
- report.reportAlbumart.otherB = $("#report-albumart-other").is(":checked");
- if (report.reportAlbumart.otherB) {
- report.reportAlbumart.other = $("#report-albumart-other-ta").val();
- }
- }
- if (report.reportOtherB) {
- report.other = $("#report-other-ta").val();
- }
- Meteor.call("submitReport", report, Session.get("id"), function() {
- $("#close-modal-r").click();
- });
- }
- });
- Template.room.onRendered(function() {
- $(document).ready(function() {
- function makeSlider(){
- var slider = $("#volume-slider").slider();
- var volume = localStorage.getItem("volume") || 20;
- $("#volume-slider").slider("setValue", volume);
- if (slider.length === 0) {
- Meteor.setTimeout(function() {
- makeSlider();
- }, 500);
- } else {
- slider.on("slide", function(val) {
- if (val.value === 0) {
- $("#volume-icon").removeClass("fa-volume-down").addClass("fa-volume-off")
- } else {
- $("#volume-icon").removeClass("fa-volume-off").addClass("fa-volume-down")
- }
- if (yt_player !== undefined) {
- yt_player.setVolume(val.value);
- localStorage.setItem("volume", val.value);
- } else if (_sound !== undefined) {
- //_sound
- var volume = val.value / 100;
- _sound.setVolume(volume);
- localStorage.setItem("volume", val.value);
- }
- });
- }
- }
- makeSlider();
- });
- });
- Template.room.helpers({
- likes: function() {
- var playlist = Playlists.findOne({type: Session.get("type")});
- var likes = 0;
- playlist.songs.forEach(function(song) {
- if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
- likes = song.likes;
- return;
- }
- });
- return likes;
- },
- dislikes: function() {
- var playlist = Playlists.findOne({type: Session.get("type")});
- var dislikes = 0;
- playlist.songs.forEach(function(song) {
- if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
- dislikes = song.dislikes;
- return;
- }
- });
- return dislikes;
- },
- liked: function() {
- if (Meteor.userId()) {
- var currentSong = Session.get("currentSong");
- if (currentSong && Meteor.user().profile.liked.indexOf(currentSong.mid) !== -1) {
- return "active";
- } else {
- return "";
- }
- } else {
- "";
- }
- },
- disliked: function() {
- if (Meteor.userId()) {
- var currentSong = Session.get("currentSong");
- if (currentSong && Meteor.user().profile.disliked.indexOf(currentSong.mid) !== -1) {
- return "active";
- } else {
- return "";
- }
- } else {
- "";
- }
- },
- type: function() {
- var parts = location.href.split('/');
- var id = parts.pop().toLowerCase();
- return Rooms.findOne({type: id}).display;
- },
- title: function(){
- return Session.get("title");
- },
- artist: function(){
- return Session.get("artist");
- },
- loaded: function() {
- return Session.get("loaded");
- },
- isAdmin: function() {
- if (Meteor.user() && Meteor.user().profile) {
- return Meteor.user().profile.rank === "admin";
- } else {
- return false;
- }
- },
- paused: function() {
- return Session.get("state") === "paused";
- },
- report: function() {
- return Session.get("reportObj");
- },
- reportSong: function() {
- return Session.get("reportSong");
- },
- reportTitle: function() {
- return Session.get("reportTitle");
- },
- reportAuthor: function() {
- return Session.get("reportAuthor");
- },
- reportDuration: function() {
- return Session.get("reportDuration");
- },
- reportAudio: function() {
- return Session.get("reportAudio");
- },
- reportAlbumart: function() {
- return Session.get("reportAlbumart");
- },
- reportOther: function() {
- return Session.get("reportOther");
- },
- currentSong: function() {
- return Session.get("currentSong");
- },
- previousSong: function() {
- return Session.get("previousSong");
- },
- currentSongR: function() {
- return Session.get("currentSongR");
- },
- previousSongR: function() {
- return Session.get("previousSongR");
- },
- reportingSong: function() {
- if (Session.get("reportPrevious")) {
- return Session.get("previousSongR");
- } else {
- return Session.get("currentSongR");
- }
- }
- });
- Template.admin.helpers({
- queues: function() {
- var queues = Queues.find({}).fetch();
- queues.map(function(queue) {
- if (Rooms.find({type: queue.type}).count() !== 1) {
- return;
- } else {
- queue.display = Rooms.findOne({type: queue.type}).display;
- return queue;
- }
- });
- return queues;
- },
- playlists: function() {
- var playlists = Playlists.find({}).fetch();
- playlists.map(function(playlist) {
- if (Rooms.find({type: playlist.type}).count() !== 1) {
- return;
- } else {
- playlist.display = Rooms.findOne({type: playlist.type}).display;
- return playlist;
- }
- });
- return playlists;
- },
- users: function(){
- Meteor.call("getUserNum", function(err, num){
- if(err){
- console.log(err);
- }
- Session.set("userNum", num);
- });
- return Session.get("userNum");
- }
- });
- var yt_player = undefined;
- var _sound = undefined;
- Template.admin.events({
- "click .preview-button": function(e){
- Session.set("song", this);
- },
- "click .edit-queue-button": function(e){
- Session.set("song", this);
- Session.set("genre", $(e.toElement).data("genre"));
- Session.set("type", "queue");
- $("#type").val(this.type);
- $("#artist").val(this.artist);
- $("#title").val(this.title);
- $("#img").val(this.img);
- $("#id").val(this.id);
- $("#duration").val(this.duration);
- },
- "click .edit-playlist-button": function(e){
- Session.set("song", this);
- Session.set("genre", $(e.toElement).data("genre"));
- Session.set("type", "playlist");
- $("#type").val(this.type);
- $("#artist").val(this.artist);
- $("#title").val(this.title);
- $("#img").val(this.img);
- $("#id").val(this.id);
- $("#duration").val(this.duration);
- },
- "click .add-song-button": function(e){
- var genre = $(e.toElement).data("genre") || $(e.toElement).parent().data("genre");
- Meteor.call("addSongToPlaylist", genre, this);
- },
- "click .deny-song-button": function(e){
- var genre = $(e.toElement).data("genre") || $(e.toElement).parent().data("genre");
- Meteor.call("removeSongFromQueue", genre, this.mid);
- },
- "click .remove-song-button": function(e){
- var genre = $(e.toElement).data("genre") || $(e.toElement).parent().data("genre");
- Meteor.call("removeSongFromPlaylist", genre, this.mid);
- },
- "click #play": function() {
- $("#play").attr("disabled", true);
- $("#stop").attr("disabled", false);
- var song = Session.get("song");
- var id = song.id;
- var type = song.type;
- var volume = localStorage.getItem("volume") || 20;
- if (type === "YouTube") {
- if (yt_player === undefined) {
- yt_player = new YT.Player("previewPlayer", {
- height: 540,
- width: 568,
- videoId: id,
- playerVars: {autoplay: 1, controls: 0, iv_load_policy: 3, showinfo: 0},
- events: {
- 'onReady': function(event) {
- event.target.playVideo();
- event.target.setVolume(volume);
- },
- 'onStateChange': function(event){
- if (event.data == YT.PlayerState.PAUSED) {
- event.target.playVideo();
- }
- if (event.data == YT.PlayerState.PLAYING) {
- $("#play").attr("disabled", true);
- $("#stop").attr("disabled", false);
- } else {
- $("#play").attr("disabled", false);
- $("#stop").attr("disabled", true);
- }
- }
- }
- });
- } else {
- yt_player.loadVideoById(id);
- }
- $("#previewPlayer").show();
- } else if (type === "SoundCloud") {
- SC.stream("/tracks/" + song.id, function(sound) {
- _sound = sound;
- sound.setVolume(volume / 100);
- sound.play();
- });
- }
- },
- "click #stop": function() {
- $("#play").attr("disabled", false);
- $("#stop").attr("disabled", true);
- if (yt_player !== undefined) {
- yt_player.stopVideo();
- }
- if (_sound !== undefined) {
- _sound.stop();
- }
- },
- "click #croom_create": function() {
- Meteor.call("createRoom", $("#croom_display").val(), $("#croom_tag").val(), function (err, res) {
- if (err) {
- alert("Error " + err.error + ": " + err.reason);
- } else {
- window.location = "/" + $("#croom_tag").val();
- }
- });
- },
- "click #get-spotify-info": function() {
- var search = $("#title").val();
- var artistName = $("#artist").val();
- getSpotifyInfo(search, function(data) {
- for(var i in data){
- for(var j in data[i].items){
- if(search.indexOf(data[i].items[j].name) !== -1 && artistName.indexOf(data[i].items[j].artists[0].name) !== -1){
- $("#img").val(data[i].items[j].album.images[1].url);
- $("#duration").val(data[i].items[j].duration_ms / 1000);
- return;
- }
- }
- }
- }, artistName);
- },
- "click #save-song-button": function() {
- var newSong = {};
- newSong.id = $("#id").val();
- newSong.title = $("#title").val();
- newSong.artist = $("#artist").val();
- newSong.img = $("#img").val();
- newSong.type = $("#type").val();
- newSong.duration = $("#duration").val();
- if (Session.get("type") === "playlist") {
- Meteor.call("updatePlaylistSong", Session.get("genre"), Session.get("song"), newSong, function() {
- $('#editModal').modal('hide');
- });
- } else {
- Meteor.call("updateQueueSong", Session.get("genre"), Session.get("song"), newSong, function() {
- $('#editModal').modal('hide');
- });
- }
- },
- "click .delete-room": function(){
- var typeDel = $(this)[0].type;
- Meteor.call("deleteRoom", typeDel);
- }
- });
- Template.admin.onCreated(function() {
- var tag = document.createElement("script");
- tag.src = "https://www.youtube.com/iframe_api";
- var firstScriptTag = document.getElementsByTagName('script')[0];
- firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
- });
- Template.admin.onRendered(function() {
- $("#previewModal").on("hidden.bs.modal", function() {
- if (yt_player !== undefined) {
- $("#play").attr("disabled", false);
- $("#stop").attr("disabled", true);
- $("#previewPlayer").hide();
- yt_player.loadVideoById("", 0);
- yt_player.seekTo(0);
- yt_player.stopVideo();
- }
- if (_sound !== undefined) {
- _sound.stop();
- $("#play").attr("disabled", false);
- $("#stop").attr("disabled", true);
- }
- });
- $(document).ready(function() {
- function makeSlider(){
- var slider = $("#volume-slider").slider();
- var volume = localStorage.getItem("volume") || 20;
- $("#volume-slider").slider("setValue", volume);
- if (slider.length === 0) {
- Meteor.setTimeout(function() {
- makeSlider();
- }, 500);
- } else {
- slider.on("slide", function(val) {
- localStorage.setItem("volume", val.value);
- if (yt_player !== undefined) {
- yt_player.setVolume(val.value);
- } else if (_sound !== undefined) {
- var volume = val.value / 100;
- _sound.setVolume(volume);
- }
- });
- }
- }
- makeSlider();
- });
- });
- Template.playlist.helpers({
- playlist_songs: function() {
- parts = location.href.split('/');
- id = parts.pop();
- type = id.toLowerCase();
- var data = Playlists.findOne({type: type});
- if (data !== undefined) {
- data.songs.map(function(song) {
- if (Session.get("currentSong") !== undefined && song.mid === Session.get("currentSong").mid) {
- song.current = true;
- } else {
- song.current = false;
- }
- return song;
- });
- return data.songs;
- } else {
- return [];
- }
- }
- });
- Meteor.subscribe("rooms");
- Template.room.onCreated(function () {
- Session.set("reportSong", false);
- Session.set("reportTitle", false);
- Session.set("reportAuthor", false);
- Session.set("reportDuration", false);
- Session.set("reportAudio", false);
- Session.set("reportAlbumart", false);
- Session.set("reportOther", false);
- if (resizeSeekerbarInterval !== undefined) {
- Meteor.clearInterval(resizeSeekerbarInterval);
- resizeSeekerbarInterval = undefined;
- }
- yt_player = undefined;
- _sound = undefined;
- Session.set("videoHidden", false);
- var tag = document.createElement("script");
- tag.src = "https://www.youtube.com/iframe_api";
- var firstScriptTag = document.getElementsByTagName('script')[0];
- firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
- var currentSong = undefined;
- var currentSongR = undefined;
- function getTimeElapsed() {
- if (currentSong !== undefined) {
- var room = Rooms.findOne({type: type});
- if (room !== undefined) {
- return Date.now() - currentSong.started - room.timePaused;
- }
- }
- return 0;
- }
- function getSongInfo(songData){
- Session.set("title", songData.title);
- Session.set("artist", songData.artist);
- Session.set("id", songData.id);
- $("#song-img").attr("src", songData.img);
- Session.set("duration", parseInt(songData.duration));
- var d = moment.duration(parseInt(songData.duration), 'seconds');
- $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
- }
- function resizeSeekerbar() {
- if (Session.get("state") === "playing") {
- $("#seeker-bar").width(((getTimeElapsed() / 1000) / Session.get("duration") * 100) + "%");
- }
- }
- function startSong() {
- $("#time-elapsed").text("0:00");
- if (currentSong !== undefined) {
- if (_sound !== undefined) _sound.stop();
- if (yt_player !== undefined && yt_player.stopVideo !== undefined) yt_player.stopVideo();
- var volume = localStorage.getItem("volume") || 20;
- $("#media-container").empty();
- yt_player = undefined;
- if (currentSong.type === "SoundCloud") {
- $("#media-container").append('<img src="/soundcloud-image.png" class="embed-responsive-item" />');
- getSongInfo(currentSong);
- SC.stream("/tracks/" + currentSong.id, function(sound){
- _sound = sound;
- sound.setVolume(volume / 100);
- sound.play();
- var interval = setInterval(function() {
- if (sound.getState() === "playing") {
- sound.seek(getTimeElapsed());
- window.clearInterval(interval);
- }
- }, 200);
- Session.set("duration", parseInt(currentSong.duration));
- var d = moment.duration(parseInt(currentSong.duration), 'seconds');
- $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
- resizeSeekerbar();
- });
- } else {
- $("#media-container").append('<div id="player" class="embed-responsive-item"></div>');
- if (yt_player === undefined) {
- yt_player = new YT.Player("player", {
- height: 540,
- width: 960,
- videoId: currentSong.id,
- playerVars: {controls: 0, iv_load_policy: 3, rel: 0, showinfo: 0},
- events: {
- 'onReady': function(event) {
- event.target.seekTo(getTimeElapsed() / 1000);
- event.target.playVideo();
- event.target.setVolume(volume);
- resizeSeekerbar();
- },
- 'onStateChange': function(event){
- if (event.data == YT.PlayerState.PAUSED && Session.get("state") === "playing") {
- event.target.seekTo(getTimeElapsed() / 1000);
- event.target.playVideo();
- }
- if (event.data == YT.PlayerState.PLAYING && Session.get("state") === "paused") {
- event.target.seekTo(getTimeElapsed() / 1000);
- event.target.pauseVideo();
- }
- }
- }
- });
- } else {
- yt_player.loadVideoById(currentSong.id);
- }
- getSongInfo(currentSong);
- }
- }
- }
- Session.set("loaded", false);
- Meteor.subscribe("rooms", function() {
- var parts = location.href.split('/');
- var id = parts.pop();
- var type = id.toLowerCase();
- Session.set("type", type);
- if (Rooms.find({type: type}).count() !== 1) {
- window.location = "/";
- } else {
- Session.set("loaded", true);
- minterval = Meteor.setInterval(function () {
- var room = Rooms.findOne({type: type});
- if (room !== undefined) {
- if (room.state === "paused") {
- Session.set("state", "paused");
- if (yt_player !== undefined && yt_player.getPlayerState !== undefined && yt_player.getPlayerState() === 1) {
- yt_player.pauseVideo();
- } else if (_sound !== undefined && _sound.getState().indexOf("playing") !== -1) {
- _sound.pause();
- }
- } else {
- Session.set("state", "playing");
- if (yt_player !== undefined && yt_player.getPlayerState !== undefined && yt_player.getPlayerState() !== 1) {
- yt_player.playVideo();
- } else if (_sound !== undefined && _sound.getState().indexOf("paused") !== -1) {
- _sound.play();
- }
- }
- }
- if (currentSongR === undefined || room.currentSong.started !== currentSongR.started) {
- Session.set("previousSong", currentSong);
- currentSongR = room.currentSong;
- currentSong = room.currentSong.song;
- currentSong.started = room.currentSong.started;
- Session.set("currentSong", currentSong);
- startSong();
- }
- if (currentSong !== undefined) {
- if (room !== undefined) {
- var duration = (Date.now() - currentSong.started - room.timePaused) / 1000;
- var d = moment.duration(duration, 'seconds');
- if (Session.get("state") === "playing") {
- $("#time-elapsed").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
- }
- }
- }
- }, 1000);
- resizeSeekerbarInterval = Meteor.setInterval(function () {
- resizeSeekerbar();
- }, 500);
- }
- });
- });
- }
- if (Meteor.isServer) {
- Meteor.startup(function() {
- reCAPTCHA.config({
- privatekey: '6LcVxg0TAAAAAI2fgIEEWHFxwNXeVIs8mzq5cfRM'
- });
- var stations = [{tag: "edm", display: "EDM"}, {tag: "pop", display: "Pop"}]; //Rooms to be set on server startup
- for(var i in stations){
- if(Rooms.find({type: stations[i]}).count() === 0){
- createRoom(stations[i].display, stations[i].tag);
- }
- }
- });
- var stations = [];
- var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_";
- function createUniqueSongId() {
- var code = "";
- for (var i = 0; i < 6; i++) {
- code += chars[Math.floor(Math.random() * chars.length)];
- }
- if (Playlists.find({"songs.mid": code}).count() > 0) {
- return createUniqueSongId();
- } else {
- return code;
- }
- }
- function getStation(type, cb) {
- stations.forEach(function(station) {
- if (station.type === type) {
- cb(station);
- return;
- }
- });
- }
- function createRoom(display, tag) {
- var type = tag;
- if (Rooms.find({type: type}).count() === 0) {
- Rooms.insert({display: display, type: type}, function(err) {
- if (err) {
- throw err;
- } else {
- if (Playlists.find({type: type}).count() === 1) {
- stations.push(new Station(type));
- } else {
- Playlists.insert({type: type, songs: getSongsByType(type)}, function (err2) {
- if (err2) {
- throw err2;
- } else {
- stations.push(new Station(type));
- }
- });
- }
- }
- });
- } else {
- return "Room already exists";
- }
- }
- function Station(type) {
- var _this = this;
- var startedAt = Date.now();
- var playlist = Playlists.findOne({type: type});
- var songs = playlist.songs;
- if (playlist.lastSong === undefined) {
- Playlists.update({type: type}, {$set: {lastSong: 0}});
- playlist = Playlists.findOne({type: type});
- songs = playlist.songs;
- }
- var currentSong = playlist.lastSong;
- var currentTitle = songs[currentSong].title;
- Rooms.update({type: type}, {$set: {currentSong: {song: songs[currentSong], started: startedAt}}});
- this.skipSong = function() {
- songs = Playlists.findOne({type: type}).songs;
- songs.forEach(function(song, index) {
- if (song.title === currentTitle) {
- currentSong = index;
- }
- });
- if (currentSong < (songs.length - 1)) {
- currentSong++;
- } else currentSong = 0;
- if (songs);
- if (currentSong === 0) {
- this.shufflePlaylist();
- } else {
- if (songs[currentSong].mid === undefined) {
- var newSong = songs[currentSong];
- newSong.mid = createUniqueSongId();
- songs[currentSong].mid = newSong.mid;
- Playlists.update({type: type, "songs": songs[currentSong]}, {$set: {"songs.$": newSong}});
- }
- if (songs[currentSong].likes === undefined) {
- var newSong = songs[currentSong];
- newSong.likes = 0;
- Playlists.update({type: type, "songs": newSong}, {$set: {"songs.$": newSong}});
- }
- if (songs[currentSong].dislikes === undefined) {
- var newSong = songs[currentSong];
- newSong.dislikes = 0;
- Playlists.update({type: type, "songs": newSong}, {$set: {"songs.$": newSong}});
- }
- currentTitle = songs[currentSong].title;
- Playlists.update({type: type}, {$set: {lastSong: currentSong}});
- Rooms.update({type: type}, {$set: {timePaused: 0}});
- this.songTimer();
- Rooms.update({type: type}, {$set: {currentSong: {song: songs[currentSong], started: startedAt}}});
- }
- };
- this.shufflePlaylist = function() {
- songs = Playlists.findOne({type: type}).songs;
- currentSong = 0;
- Playlists.update({type: type}, {$set: {"songs": []}});
- songs = shuffle(songs);
- songs.forEach(function(song) {
- if (song.mid === undefined) {
- song.mid = createUniqueSongId();
- }
- if (song.likes === undefined) {
- song.likes = 0;
- }
- if (song.dislikes === undefined) {
- song.dislikes = 0;
- }
- Playlists.update({type: type}, {$push: {"songs": song}});
- });
- currentTitle = songs[currentSong].title;
- Playlists.update({type: type}, {$set: {lastSong: currentSong}});
- Rooms.update({type: type}, {$set: {timePaused: 0}});
- this.songTimer();
- Rooms.update({type: type}, {$set: {currentSong: {song: songs[currentSong], started: startedAt}}});
- };
- Rooms.update({type: type}, {$set: {timePaused: 0}});
- var timer;
- this.songTimer = function() {
- startedAt = Date.now();
- if (timer !== undefined) {
- timer.pause();
- }
- timer = new Timer(function() {
- _this.skipSong();
- }, songs[currentSong].duration * 1000);
- };
- var state = Rooms.findOne({type: type}).state;
- this.pauseRoom = function() {
- if (state !== "paused") {
- timer.pause();
- Rooms.update({type: type}, {$set: {state: "paused"}});
- state = "paused";
- }
- };
- this.resumeRoom = function() {
- if (state !== "playing") {
- timer.resume();
- Rooms.update({type: type}, {$set: {state: "playing", timePaused: timer.timeWhenPaused()}});
- state = "playing";
- }
- };
- this.cancelTimer = function() {
- timer.pause();
- };
- this.getState = function() {
- return state;
- };
- this.type = type;
- this.songTimer();
- }
- function shuffle(array) {
- var currentIndex = array.length, temporaryValue, randomIndex ;
- // While there remain elements to shuffle...
- while (0 !== currentIndex) {
- // Pick a remaining element...
- randomIndex = Math.floor(Math.random() * currentIndex);
- currentIndex -= 1;
- // And swap it with the current element.
- temporaryValue = array[currentIndex];
- array[currentIndex] = array[randomIndex];
- array[randomIndex] = temporaryValue;
- }
- return array;
- }
- function Timer(callback, delay) {
- var timerId, start, remaining = delay;
- var timeWhenPaused = 0;
- var timePaused = new Date();
- this.pause = function() {
- Meteor.clearTimeout(timerId);
- remaining -= new Date() - start;
- timePaused = new Date();
- };
- this.resume = function() {
- start = new Date();
- Meteor.clearTimeout(timerId);
- timerId = Meteor.setTimeout(callback, remaining);
- timeWhenPaused += new Date() - timePaused;
- };
- this.timeWhenPaused = function() {
- return timeWhenPaused;
- };
- this.resume();
- }
- Meteor.users.deny({update: function () { return true; }});
- Meteor.users.deny({insert: function () { return true; }});
- Meteor.users.deny({remove: function () { return true; }});
- function getSongDuration(query, artistName){
- var duration;
- var search = query;
- query = query.toLowerCase().split(" ").join("%20");
- var res = Meteor.http.get('https://api.spotify.com/v1/search?q=' + query + '&type=track');
- for(var i in res.data){
- for(var j in res.data[i].items){
- if(search.indexOf(res.data[i].items[j].name) !== -1 && artistName.indexOf(res.data[i].items[j].artists[0].name) !== -1){
- duration = res.data[i].items[j].duration_ms / 1000;
- return duration;
- }
- }
- }
- }
- function getSongAlbumArt(query, artistName){
- var albumart;
- var search = query;
- query = query.toLowerCase().split(" ").join("%20");
- var res = Meteor.http.get('https://api.spotify.com/v1/search?q=' + query + '&type=track');
- for(var i in res.data){
- for(var j in res.data[i].items){
- if(search.indexOf(res.data[i].items[j].name) !== -1 && artistName.indexOf(res.data[i].items[j].artists[0].name) !== -1){
- albumart = res.data[i].items[j].album.images[1].url
- return albumart;
- }
- }
- }
- }
- //var room_types = ["edm", "nightcore"];
- var songsArr = [];
- function getSongsByType(type) {
- if (type === "edm") {
- return [
- {id: "aE2GCa-_nyU", mid: "fh6_Gf", title: "Radioactive", duration: getSongDuration("Radioactive - Lindsey Stirling and Pentatonix", "Lindsey Stirling, Pentatonix"), artist: "Lindsey Stirling, Pentatonix", type: "YouTube", img: "https://i.scdn.co/image/62167a9007cef2e8ef13ab1d93019312b9b03655"},
- {id: "aHjpOzsQ9YI", mid: "goG88g", title: "Crystallize", artist: "Lindsey Stirling", duration: getSongDuration("Crystallize", "Lindsey Stirling"), type: "YouTube", img: "https://i.scdn.co/image/b0c1ccdd0cd7bcda741ccc1c3e036f4ed2e52312"}
- ];
- } else if (type === "nightcore") {
- return [{id: "f7RKOP87tt4", mid: "5pGGog", title: "Monster (DotEXE Remix)", duration: getSongDuration("Monster (DotEXE Remix)", "Meg & Dia"), artist: "Meg & Dia", type: "YouTube", img: "https://i.scdn.co/image/35ecdfba9c31a6c54ee4c73dcf1ad474c560cd00"}];
- } else {
- return [{id: "dQw4w9WgXcQ", mid: "6_fdr4", title: "Never Gonna Give You Up", duration: getSongDuration("Never Gonna Give You Up", "Rick Astley"), artist: "Rick Astley", type: "YouTube", img: "https://i.scdn.co/image/5246898e19195715e65e261899baba890a2c1ded"}];
- }
- }
- Rooms.find({}).fetch().forEach(function(room) {
- var type = room.type;
- if (Playlists.find({type: type}).count() === 0) {
- if (type === "edm") {
- Playlists.insert({type: type, songs: getSongsByType(type)});
- } else if (type === "nightcore") {
- Playlists.insert({type: type, songs: getSongsByType(type)});
- } else {
- Playlists.insert({type: type, songs: getSongsByType(type)});
- }
- }
- if (Playlists.findOne({type: type}).songs.length === 0) {
- // Add a global video to Playlist so it can proceed
- } else {
- stations.push(new Station(type));
- }
- });
- Accounts.onCreateUser(function(options, user) {
- var username;
- if (user.services) {
- if (user.services.github) {
- username = user.services.github.username;
- } else if (user.services.facebook) {
- username = user.services.facebook.first_name;
- } else if (user.services.password) {
- username = user.username;
- }
- }
- if (Meteor.users.find({"profile.usernameL": username.toLowerCase()}).count() !== 0) {
- return false;
- } else {
- user.profile = {username: username, usernameL: username.toLowerCase(), rank: "default", liked: [], disliked: []};
- return user;
- }
- });
- ServiceConfiguration.configurations.remove({
- service: "facebook"
- });
- ServiceConfiguration.configurations.insert({
- service: "facebook",
- appId: "1496014310695890",
- secret: "9a039f254a08a1488c08bb0737dbd2a6"
- });
- ServiceConfiguration.configurations.remove({
- service: "github"
- });
- ServiceConfiguration.configurations.insert({
- service: "github",
- clientId: "dcecd720f47c0e4001f7",
- secret: "375939d001ef1a0ca67c11dbf8fb9aeaa551e01b"
- });
- Meteor.publish("playlists", function() {
- return Playlists.find({})
- });
- Meteor.publish("rooms", function() {
- return Rooms.find({});
- });
- Meteor.publish("queues", function() {
- return Queues.find({});
- });
- Meteor.publish("chat", function() {
- return Chat.find({});
- });
- Meteor.publish("userProfiles", function() {
- return Meteor.users.find({}, {fields: {profile: 1, createdAt: 1}});
- });
- Meteor.publish("isAdmin", function() {
- return Meteor.users.find({_id: this.userId, "profile.rank": "admin"});
- });
- function isAdmin() {
- var userData = Meteor.users.find(Meteor.userId());
- if (Meteor.userId() && userData.count !== 0 && userData.fetch()[0].profile.rank === "admin") {
- return true;
- } else {
- return false;
- }
- }
- Meteor.methods({
- likeSong: function(mid) {
- if (Meteor.userId()) {
- var user = Meteor.user();
- if (user.profile.liked.indexOf(mid) === -1) {
- Meteor.users.update({"profile.username": user.profile.username}, {$push: {"profile.liked": mid}});
- Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.likes": 1}})
- } else {
- Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.liked": mid}});
- Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.likes": -1}})
- }
-
- if (user.profile.disliked.indexOf(mid) !== -1) {
- Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.disliked": mid}});
- Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.dislikes": -1}})
- }
- return true;
- } else {
- throw new Meteor.Error(403, "Invalid permissions.");
- }
- },
- dislikeSong: function(mid) {
- if (Meteor.userId()) {
- var user = Meteor.user();
- if (user.profile.disliked.indexOf(mid) === -1) {
- Meteor.users.update({"profile.username": user.profile.username}, {$push: {"profile.disliked": mid}});
- Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.dislikes": 1}});
- } else {
- Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.disliked": mid}});
- Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.dislikes": -1}});
- }
- if (user.profile.liked.indexOf(mid) !== -1) {
- Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.liked": mid}});
- Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.likes": -1}});
- }
- return true;
- } else {
- throw new Meteor.Error(403, "Invalid permissions.");
- }
- },
- submitReport: function(report, id) {
- var obj = report;
- obj.id = id;
- Reports.insert(obj);
- },
- shufflePlaylist: function(type) {
- if (isAdmin()) {
- getStation(type, function(station) {
- if (station === undefined) {
- throw new Meteor.Error(404, "Station not found.");
- } else {
- station.cancelTimer();
- station.shufflePlaylist();
- }
- });
- }
- },
- skipSong: function(type) {
- if (isAdmin()) {
- getStation(type, function(station) {
- if (station === undefined) {
- throw new Meteor.Error(404, "Station not found.");
- } else {
- station.skipSong();
- }
- });
- }
- },
- pauseRoom: function(type) {
- if (isAdmin()) {
- getStation(type, function(station) {
- if (station === undefined) {
- throw new Meteor.Error(403, "Room doesn't exist.");
- } else {
- station.pauseRoom();
- }
- });
- } else {
- throw new Meteor.Error(403, "Invalid permissions.");
- }
- },
- resumeRoom: function(type) {
- if (isAdmin()) {
- getStation(type, function(station) {
- if (station === undefined) {
- throw new Meteor.Error(403, "Room doesn't exist.");
- } else {
- station.resumeRoom();
- }
- });
- } else {
- throw new Meteor.Error(403, "Invalid permissions.");
- }
- },
- createUserMethod: function(formData, captchaData) {
- var verifyCaptchaResponse = reCAPTCHA.verifyCaptcha(this.connection.clientAddress, captchaData);
- if (!verifyCaptchaResponse.success) {
- console.log('reCAPTCHA check failed!', verifyCaptchaResponse);
- throw new Meteor.Error(422, 'reCAPTCHA Failed: ' + verifyCaptchaResponse.error);
- } else {
- console.log('reCAPTCHA verification passed!');
- Accounts.createUser({
- username: formData.username,
- email: formData.email,
- password: formData.password
- });
- }
- return true;
- },
- addSongToQueue: function(type, songData) {
- if (Meteor.userId()) {
- type = type.toLowerCase();
- if (Rooms.find({type: type}).count() === 1) {
- if (Queues.find({type: type}).count() === 0) {
- Queues.insert({type: type, songs: []});
- }
- if (songData !== undefined && Object.keys(songData).length === 5 && songData.type !== undefined && songData.title !== undefined && songData.title !== undefined && songData.artist !== undefined && songData.img !== undefined) {
- songData.duration = getSongDuration(songData.title, songData.artist);
- songData.img = getSongAlbumArt(songData.title, songData.artist);
- var mid = createUniqueSongId();
- if (mid !== undefined) {
- songData.mid = mid;
- Queues.update({type: type}, {
- $push: {
- songs: {
- id: songData.id,
- mid: songData.mid,
- title: songData.title,
- artist: songData.artist,
- duration: songData.duration,
- img: songData.img,
- type: songData.type
- }
- }
- });
- return true;
- } else {
- throw new Meteor.Error(500, "Am error occured.");
- }
- } else {
- throw new Meteor.Error(403, "Invalid data.");
- }
- } else {
- throw new Meteor.Error(403, "Invalid genre.");
- }
- } else {
- throw new Meteor.Error(403, "Invalid permissions.");
- }
- },
- updateQueueSong: function(genre, oldSong, newSong) {
- if (isAdmin()) {
- newSong.mid = oldSong.mid;
- Queues.update({type: genre, "songs": oldSong}, {$set: {"songs.$": newSong}});
- return true;
- } else {
- throw new Meteor.Error(403, "Invalid permissions.");
- }
- },
- updatePlaylistSong: function(genre, oldSong, newSong) {
- if (isAdmin()) {
- newSong.mid = oldSong.mid;
- Playlists.update({type: genre, "songs": oldSong}, {$set: {"songs.$": newSong}});
- return true;
- } else {
- throw new Meteor.Error(403, "Invalid permissions.");
- }
- },
- removeSongFromQueue: function(type, mid) {
- if (isAdmin()) {
- type = type.toLowerCase();
- Queues.update({type: type}, {$pull: {songs: {mid: mid}}});
- } else {
- throw new Meteor.Error(403, "Invalid permissions.");
- }
- },
- removeSongFromPlaylist: function(type, mid) {
- if (isAdmin()) {
- type = type.toLowerCase();
- Playlists.update({type: type}, {$pull: {songs: {mid: mid}}});
- } else {
- throw new Meteor.Error(403, "Invalid permissions.");
- }
- },
- addSongToPlaylist: function(type, songData) {
- if (isAdmin()) {
- type = type.toLowerCase();
- if (Rooms.find({type: type}).count() === 1) {
- if (Playlists.find({type: type}).count() === 0) {
- Playlists.insert({type: type, songs: []});
- }
- if (songData !== undefined && Object.keys(songData).length === 7 && songData.type !== undefined && songData.mid !== undefined && songData.title !== undefined && songData.title !== undefined && songData.artist !== undefined && songData.duration !== undefined && songData.img !== undefined) {
- songData.likes = 0;
- songData.dislikes = 0
- Playlists.update({type: type}, {
- $push: {
- songs: {
- id: songData.id,
- mid: songData.mid,
- title: songData.title,
- artist: songData.artist,
- duration: songData.duration,
- img: songData.img,
- type: songData.type,
- likes: songData.likes,
- dislikes: songData.dislikes
- }
- }
- });
- Queues.update({type: type}, {$pull: {songs: {mid: songData.mid}}});
- return true;
- } else {
- throw new Meteor.Error(403, "Invalid data.");
- }
- } else {
- throw new Meteor.Error(403, "Invalid genre.");
- }
- } else {
- throw new Meteor.Error(403, "Invalid permissions.");
- }
- },
- createRoom: function(display, tag) {
- if (isAdmin()) {
- createRoom(display, tag);
- } else {
- throw new Meteor.Error(403, "Invalid permissions.");
- }
- },
- deleteRoom: function(type){
- if (isAdmin()) {
- Rooms.remove({type: type});
- Playlists.remove({type: type});
- Queues.remove({type: type});
- return true;
- } else {
- throw new Meteor.Error(403, "Invalid permissions.");
- }
- },
- getUserNum: function(){
- return Object.keys(Meteor.default_server.sessions).length;
- }
- });
- }
- /*Router.waitOn(function() {
- Meteor.subscribe("isAdmin", Meteor.userId());
- });*/
- /*Router.onBeforeAction(function() {
- /*Meteor.autorun(function () {
- if (admin.ready()) {
- this.next();
- }
- });*/
- /*this.next();
- });*/
- Router.onBeforeAction('loading');
- Router.configure({
- loadingTemplate: 'loading'
- });
- Router.route("/", {
- template: "home"
- });
- Router.route("/login", {
- template: "login"
- });
- Router.route("/signup", {
- template: "register"
- });
- Router.route("/terms", {
- template: "terms"
- });
- Router.route("/privacy", {
- template: "privacy"
- });
- Router.route("/about", {
- template: "about"
- });
- Router.route("/admin", {
- waitOn: function() {
- return Meteor.subscribe("isAdmin", Meteor.userId());
- },
- action: function() {
- var user = Meteor.users.findOne({});
- if (user !== undefined && user.profile !== undefined && user.profile.rank === "admin") {
- this.render("admin");
- } else {
- this.redirect("/");
- }
- }
- });
- Router.route("/vis", {
- template: "visualizer"
- });
- Router.route("/:type", {
- template: "room"
- });
- Router.route("/u/:user", {
- template: "profile"
- });
|