| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672 | 
							- History = new Mongo.Collection("history");
 
- Playlists = new Mongo.Collection("playlists");
 
- Rooms = new Mongo.Collection("rooms");
 
- if (Meteor.isClient) {
 
-     Meteor.startup(function() {
 
-         reCAPTCHA.config({
 
-             publickey: '6LcVxg0TAAAAAE18vBiH00UAyaJggsmLm890SjZl'
 
-         });
 
-     });
 
-     var hpSound = undefined;
 
-     var songsArr = [];
 
-     var ytArr = [];
 
-     var _sound = undefined;
 
-     var parts = location.href.split('/');
 
-     var id = parts.pop();
 
-     var type = id.toLowerCase();
 
-     function getSpotifyInfo(title, cb) {
 
-         $.ajax({
 
-             type: "GET",
 
-             url: 'https://api.spotify.com/v1/search?q=' + encodeURIComponent(title.toLowerCase()) + '&type=track',
 
-             applicationType: "application/json",
 
-             contentType: "json",
 
-             success: function (data) {
 
-                 cb(data);
 
-             }
 
-         });
 
-     }
 
-     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);
 
-                 } else {
 
-                     Meteor.loginWithPassword(username, password);
 
-                 }
 
-             });
 
-         },
 
-         "click #facebook-login": function(){
 
-             Meteor.loginWithFacebook()
 
-         },
 
-         "click #github-login": function(){
 
-             Meteor.loginWithGithub()
 
-         },
 
-         "click #login": function(){
 
-             $("#register-view").hide();
 
-             $("#login-view").show();
 
-         }
 
-     });
 
-     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.onLoginFailure(function(){
 
-                 $("input").css("background-color","indianred").addClass("animated shake");
 
-                     $("input").on("click",function(){
 
-                         $("input").css({
 
-                             "background-color": "transparent",
 
-                             "width": "250px"
 
-                      });
 
-                 })
 
-             });
 
-         },
 
-         "click #facebook-login": function(){
 
-             Meteor.loginWithFacebook()
 
-         },
 
-         "click #github-login": function(){
 
-             Meteor.loginWithGithub()
 
-         },
 
-         "click #register": function(){
 
-             $("#login-view").hide();
 
-             $("#register-view").show();
 
-         }
 
-     });
 
-     Template.dashboard.events({
 
-         "click .logout": function(e){
 
-             e.preventDefault();
 
-             Meteor.logout();
 
-             if (hpSound !== undefined) {
 
-                 hpSound.stop();
 
-             }
 
-         },
 
-         "click #croom_create": function() {
 
-             Meteor.call("createRoom", $("#croom").val(), function (err, res) {
 
-                 if (err) {
 
-                     alert("Error " + err.error + ": " + err.reason);
 
-                 } else {
 
-                     window.location = "/" + $("#croom").val();
 
-                 }
 
-             });
 
-         }
 
-     });
 
-     Template.dashboard.helpers({
 
-       rooms: function() {
 
-         return Rooms.find({});
 
-       }
 
-     })
 
-     Template.room.events({
 
-         "click #search-song": function(){
 
-             $("#song-results").empty()
 
-             $.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){
 
-                     console.log(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});
 
-                     }
 
-                     console.log(ytArr);
 
-                     $("#song-results p").click(function(){
 
-                         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"
 
-                                 };
 
-                                 console.log(ytArr[i].title);
 
-                                 console.log(ytArr[i].id);
 
-                                 // Set title field
 
-                                 $("#title").val(songObj.title);
 
-                                 // Set ID field
 
-                                 $("#id").val(songObj.id);
 
-                                 getSpotifyInfo(songObj.title.replace(/\[.*\]/g, ""), function(data) {
 
-                                     console.log(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);
 
-                                         });
 
-                                         console.log(artists);
 
-                                         console.log(artists.join(", "));
 
-                                         $("#artist").val(artists.join(", "));
 
-                                     }
 
-                                     // Set title field again if possible
 
-                                     // Set artist if possible
 
-                                 });
 
-                             }
 
-                         }
 
-                     })
 
-                 }
 
-             })
 
-             // SC.get('/tracks', { q: $("#song-input").val()}, function(tracks) {
 
-             //   console.log(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(){
 
-             //     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"
 
-             //         }
 
-             //       }
 
-             //     }
 
-             //     console.log(id);
 
-             //   })
 
-             // });
 
-         },
 
-         "click #add-songs": function(){
 
-           $("#add-songs-modal").show();
 
-         }
 
-     });
 
-     Template.room.helpers({
 
-         type: function() {
 
-           var parts = location.href.split('/');
 
-           var id = parts.pop();
 
-           return id.toUpperCase();
 
-         },
 
-         title: function(){
 
-           return Session.get("title");
 
-         },
 
-         artist: function(){
 
-           return Session.get("artist");
 
-         },
 
-         loaded: function() {
 
-           return Session.get("loaded");
 
-         }
 
-     });
 
-     Template.admin.helpers({
 
-         rooms: function() {
 
-             return Rooms.find({});
 
-         }
 
-     });
 
-     Template.playlist.helpers({
 
-         playlist_songs: function() {
 
-             var data = Playlists.find({type: type}).fetch();
 
-             if (data !== undefined && data.length > 0) {
 
-                 return data[0].songs;
 
-             } else {
 
-                 return [];
 
-             }
 
-         }
 
-     });
 
-     Meteor.subscribe("rooms");
 
-     Template.room.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);
 
-         var currentSong = undefined;
 
-         var _sound = undefined;
 
-         var yt_player = undefined;
 
-         var size = 0;
 
-         var artistStr;
 
-         var temp = "";
 
-         var currentArt;
 
-         function getTimeElapsed() {
 
-             if (currentSong !== undefined) {
 
-                 return Date.now() - currentSong.started;
 
-             }
 
-             return 0;
 
-         }
 
-         function getSongInfo(query, platform){
 
-             var search = query;
 
-             var titles = [];
 
-             getSpotifyInfo(query, function(data) {
 
-                 console.log(data);
 
-                 for(var i in data){
 
-                     for(var j in data[i].items){
 
-                         if(search.indexOf(data[i].items[j].name) !== -1){
 
-                             console.log(data[i].items[j].name);
 
-                             var info = data[i].items[j];
 
-                             Session.set("title", data[i].items[j].name);
 
-                             console.log("Info: " + info);
 
-                             if(platform === "youtube"){
 
-                                 Session.set("duration", data[i].items[j].duration_ms / 1000)
 
-                                 console.log(Session.get("duration"));
 
-                             }
 
-                             temp = "";
 
-                             if(data[i].items[j].artists.length >= 2){
 
-                                 for(var k in data[i].items[j].artists){
 
-                                     temp = temp + data[i].items[j].artists[k].name + ", ";
 
-                                 }
 
-                             } else{
 
-                                 for(var k in data[i].items[j].artists){
 
-                                     temp = temp + data[i].items[j].artists[k].name;
 
-                                 }
 
-                             }
 
-                             if(temp[temp.length-2] === ","){
 
-                                 artistStr = temp.substr(0,temp.length-2);
 
-                             } else{
 
-                                 artistStr = temp;
 
-                             }
 
-                             Session.set("artist", artistStr);
 
-                             $(".current").remove();
 
-                             $(".room-title").before("<img class='current' src='" + data[i].items[j].album.images[1].url + "' />");
 
-                             return true;
 
-                         }
 
-                     }
 
-                     //---------------------------------------------------------------//
 
-                 }
 
-             });
 
-         }
 
-         function resizeSeekerbar() {
 
-             $("#seeker-bar").width(((getTimeElapsed() / 1000) / Session.get("duration") * 100) + "%");
 
-         }
 
-         function startSong() {
 
-             if (currentSong !== undefined) {
 
-                 if (_sound !== undefined) _sound.stop();
 
-                 if (yt_player !== undefined && yt_player.stopVideo !== undefined) yt_player.stopVideo();
 
-                 if (currentSong.song.type === "soundcloud") {
 
-                   $("#player").attr("src", "")
 
-                   getSongInfo(currentSong.song.title);
 
-                   SC.stream("/tracks/" + currentSong.song.id + "#t=20s", function(sound){
 
-                     console.log(sound);
 
-                     _sound = sound;
 
-                     sound._player._volume = 0.3;
 
-                     sound.play();
 
-                     console.log(getTimeElapsed());
 
-                     var interval = setInterval(function() {
 
-                         if (sound.getState() === "playing") {
 
-                             sound.seek(getTimeElapsed());
 
-                             window.clearInterval(interval);
 
-                         }
 
-                     }, 200);
 
-                     // Session.set("title", currentSong.song.title || "Title");
 
-                     // Session.set("artist", currentSong.song.artist || "Artist");
 
-                     Session.set("duration", currentSong.song.duration);
 
-                     resizeSeekerbar();
 
-                   });
 
-                 } else {
 
-                     if (yt_player === undefined) {
 
-                         yt_player = new YT.Player("player", {
 
-                             height: 540,
 
-                             width: 960,
 
-                             videoId: currentSong.song.id,
 
-                             events: {
 
-                                 'onReady': function(event) {
 
-                                     event.target.seekTo(getTimeElapsed() / 1000);
 
-                                     event.target.playVideo();
 
-                                     resizeSeekerbar();
 
-                                 },
 
-                                 'onStateChange': function(event){
 
-                                     if (event.data == YT.PlayerState.PAUSED) {
 
-                                         event.target.seekTo(getTimeElapsed() / 1000);
 
-                                         event.target.playVideo();
 
-                                     }
 
-                                 }
 
-                             }
 
-                         });
 
-                     } else {
 
-                         yt_player.loadVideoById(currentSong.song.id);
 
-                     }
 
-                     // Session.set("title", currentSong.song.title || "Title");
 
-                     // Session.set("artist", currentSong.song.artist || "Artist");
 
-                     getSongInfo(currentSong.song.title, "youtube");
 
-                     //Session.set("duration", currentSong.song.duration);
 
-                 }
 
-             }
 
-         }
 
-         Meteor.subscribe("history");
 
-         Meteor.subscribe("playlists");
 
-         Session.set("loaded", false);
 
-         Meteor.subscribe("rooms", function() {
 
-             var parts = location.href.split('/');
 
-             var id = parts.pop();
 
-             var type = id.toLowerCase();
 
-             console.log(Rooms.find({type: type}).fetch().length);
 
-             if (Rooms.find({type: type}).count() !== 1) {
 
-                 window.location = "/";
 
-             } else {
 
-                 Session.set("loaded", true);
 
-                 Meteor.setInterval(function () {
 
-                     var data = undefined;
 
-                     var dataCursor = History.find({type: type});
 
-                     dataCursor.map(function (doc) {
 
-                         if (data === undefined) {
 
-                             data = doc;
 
-                         }
 
-                     });
 
-                     if (data !== undefined && data.history.length > size) {
 
-                         currentSong = data.history[data.history.length - 1];
 
-                         size = data.history.length;
 
-                         startSong();
 
-                     }
 
-                 }, 1000);
 
-                 Meteor.setInterval(function () {
 
-                     resizeSeekerbar();
 
-                 }, 50);
 
-             }
 
-         });
 
-     });
 
-     Template.admin.events({
 
-         "submit form": function(e){
 
-             e.preventDefault();
 
-             var genre = e.target.genre.value;
 
-             var type = e.target.type.value;
 
-             var id = e.target.id.value;
 
-             var title = e.target.title.value;
 
-             var artist = e.target.artist.value;
 
-             var songData = {type: type, id: id, title: title, artist: artist};
 
-             Meteor.call("addPlaylistSong", genre, songData, function(err, res) {
 
-                 console.log(err, res);
 
-             });
 
-         }
 
-     });
 
- }
 
- if (Meteor.isServer) {
 
-     Meteor.startup(function() {
 
-         reCAPTCHA.config({
 
-             privatekey: '6LcVxg0TAAAAAI2fgIEEWHFxwNXeVIs8mzq5cfRM'
 
-         });
 
-     });
 
-     Meteor.users.deny({update: function () { return true; }});
 
-     Meteor.users.deny({insert: function () { return true; }});
 
-     Meteor.users.deny({remove: function () { return true; }});
 
-     function getSongDuration(query){
 
-         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){
 
-                     duration = res.data[i].items[j].duration_ms / 1000;
 
-                     console.log(duration);
 
-                     return duration;
 
-                 }
 
-             }
 
-         }
 
-     }
 
-     function getSongAlbumArt(query){
 
-         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){
 
-                     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", title: "Radioactive - Lindsey Stirling and Pentatonix", duration: getSongDuration("Radioactive - Lindsey Stirling and Pentatonix"), albumart: getSongAlbumArt("Radioactive - Lindsey Stirling and Pentatonix"), type: "youtube"},
 
-                 {id: "aHjpOzsQ9YI", title: "Crystallize", artist: "Linsdey Stirling", duration: getSongDuration("Crystallize"), albumart: getSongAlbumArt("Crystallize"), type: "youtube"}
 
-             ];
 
-         } else if (type === "nightcore") {
 
-             return [{id: "f7RKOP87tt4", title: "Monster (DotEXE Remix)", duration: getSongDuration("Monster (DotEXE Remix)"), albumart: getSongAlbumArt("Monster (DotEXE Remix)"), type: "youtube"}];
 
-         } else {
 
-             return [{id: "dQw4w9WgXcQ", title: "Never Gonna Give You Up", duration: getSongDuration("Never Gonna Give You Up"), albumart: getSongAlbumArt("Never Gonna Give You Up"), type: "youtube"}];
 
-         }
 
-     }
 
-     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 (History.find({type: type}).count() === 0) {
 
-             History.insert({type: type, history: []});
 
-         }
 
-         if (Playlists.find({type: type}).fetch()[0].songs.length === 0) {
 
-             // Add a global video to Playlist so it can proceed
 
-         } else {
 
-             var startedAt = Date.now();
 
-             var songs = Playlists.find({type: type}).fetch()[0].songs;
 
-             var currentSong = 0;
 
-             addToHistory(songs[currentSong], startedAt);
 
-             function addToHistory(song, startedAt) {
 
-                 History.update({type: type}, {$push: {history: {song: song, started: startedAt}}});
 
-             }
 
-             function skipSong() {
 
-                 songs = Playlists.find({type: type}).fetch()[0].songs;
 
-                 if (currentSong < (songs.length - 1)) {
 
-                     currentSong++;
 
-                 } else currentSong = 0;
 
-                 songTimer();
 
-                 addToHistory(songs[currentSong], startedAt);
 
-             }
 
-             function songTimer() {
 
-                 startedAt = Date.now();
 
-                 Meteor.setTimeout(function() {
 
-                     skipSong();
 
-                 }, songs[currentSong].duration * 1000);
 
-             }
 
-             songTimer();
 
-         }
 
-     });
 
-     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("history", function() {
 
-         return History.find({})
 
-     });
 
-     Meteor.publish("playlists", function() {
 
-         return Playlists.find({})
 
-     });
 
-     Meteor.publish("rooms", function() {
 
-         return Rooms.find()
 
-     });
 
-     Meteor.methods({
 
-         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;
 
-         },
 
-         addPlaylistSong: function(type, songData) {
 
-             type = type.toLowerCase();
 
-             if (Rooms.find({type: type}).count() === 1) {
 
-                 if (songData !== undefined && Object.keys(songData).length === 4 && songData.type !== undefined && songData.title !== undefined && songData.title !== undefined && songData.artist !== undefined) {
 
-                     songData.duration = getSongDuration(songData.title);
 
-                     Playlists.update({type: type}, {$push: {songs: {id: songData.id, title: songData.title, artist: songData.artist, duration: songData.duration, type: songData.type}}});
 
-                     return true;
 
-                 } else {
 
-                     throw new Meteor.error(403, "Invalid data.");
 
-                 }
 
-             } else {
 
-                 throw new Meteor.error(403, "Invalid genre.");
 
-             }
 
-         },
 
-         createRoom: function(type) {
 
-             if (Rooms.find({type: type}).count() === 0) {
 
-                 Rooms.insert({type: type}, function(err) {
 
-                     if (err) {
 
-                         throw err;
 
-                     } else {
 
-                         if (Playlists.find({type: type}).count() === 1) {
 
-                             if (History.find({type: type}).count() === 0) {
 
-                                 History.insert({type: type, history: []}, function(err3) {
 
-                                     if (err3) {
 
-                                         throw err3;
 
-                                     } else {
 
-                                         startStation();
 
-                                         return true;
 
-                                     }
 
-                                 });
 
-                             } else {
 
-                                 startStation();
 
-                                 return true;
 
-                             }
 
-                         } else {
 
-                             Playlists.insert({type: type, songs: getSongsByType(type)}, function (err2) {
 
-                                 if (err2) {
 
-                                     throw err2;
 
-                                 } else {
 
-                                     if (History.find({type: type}).count() === 0) {
 
-                                         History.insert({type: type, history: []}, function(err3) {
 
-                                             if (err3) {
 
-                                                 throw err3;
 
-                                             } else {
 
-                                                 startStation();
 
-                                                 return true;
 
-                                             }
 
-                                         });
 
-                                     } else {
 
-                                         startStation();
 
-                                         return true;
 
-                                     }
 
-                                 }
 
-                             });
 
-                         }
 
-                     }
 
-                 });
 
-             } else {
 
-                 throw "Room already exists";
 
-             }
 
-             function startStation() {
 
-                 var startedAt = Date.now();
 
-                 var songs = Playlists.find({type: type}).fetch()[0].songs;
 
-                 var currentSong = 0;
 
-                 addToHistory(songs[currentSong], startedAt);
 
-                 function addToHistory(song, startedAt) {
 
-                     History.update({type: type}, {$push: {history: {song: song, started: startedAt}}});
 
-                 }
 
-                 function skipSong() {
 
-                     songs = Playlists.find({type: type}).fetch()[0].songs;
 
-                     if (currentSong < (songs.length - 1)) {
 
-                         currentSong++;
 
-                     } else currentSong = 0;
 
-                     songTimer();
 
-                     addToHistory(songs[currentSong], startedAt);
 
-                 }
 
-                 function songTimer() {
 
-                     startedAt = Date.now();
 
-                     Meteor.setTimeout(function() {
 
-                         skipSong();
 
-                     }, songs[currentSong].duration * 1000);
 
-                 }
 
-                 songTimer();
 
-             }
 
-         }
 
-     });
 
- }
 
- Router.route("/", {
 
-     template: "home"
 
- });
 
- Router.route("/admin", {
 
-     template: "admin"
 
- });
 
- Router.route("/:type", {
 
-     template: "room"
 
- });
 
 
  |