123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- History = new Mongo.Collection("history");
- if (Meteor.isClient) {
- Meteor.startup(function() {
- reCAPTCHA.config({
- publickey: '6LcVxg0TAAAAAE18vBiH00UAyaJggsmLm890SjZl'
- });
- });
- var hpSound = undefined;
- 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 .button-tunein": function(){
- SC.stream("/tracks/172055891/", function(sound){
- sound._player._volume = 0.3;
- sound.play();
- });
- },
- "click #play": function(){
- $("#play").hide();
- SC.stream("/tracks/172055891/", function(sound){
- hpSound = sound;
- sound._player._volume = 0.3;
- sound.play();
- $("#stop").on("click", function(){
- $("#stop").hide();
- $("#play").show();
- sound._player.pause();
- })
- });
- $("#stop").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");
- }
- });
- Template.room.onCreated(function () {
- var currentSong = undefined;
- var _sound = undefined;
- var size = 0;
- function getTimeElapsed() {
- if (currentSong !== undefined) {
- return Date.now() - currentSong.started;
- }
- return 0;
- }
- function startSong() {
- if (currentSong !== undefined) {
- if (_sound !== undefined)_sound.stop();
- if (currentSong.song.type === "soundcloud") {
- $("#player").attr("src", "")
- SC.stream("/tracks/" + currentSong.song.id + "/", function(sound){
- _sound = sound;
- sound._player._volume = 0.3;
- console.log(sound);
- sound.play();
- Session.set("title", currentSong.song.title || "Title");
- Session.set("artist", currentSong.song.artist || "Artist");
- Session.set("albumArt", currentSong.song.albumArt);
- Session.set("duration", currentSong.song.duration)
- $("#seeker-bar").css("transition", Session.get("duration") + "s")
- $("#seeker-bar").width(1400);
- setTimeout(function() { // HACK, otherwise seek doesn't work.
- sound._player.seek(getTimeElapsed());
- }, 500);
- });
- } else {
- console.log("YT!");
- $("#player").attr("src", "http://www.youtube.com/embed/" + currentSong.song.id + "?autoplay=1&controls=0&autohide=1");
- }
- }
- }
- Meteor.subscribe("history");
- Meteor.setInterval(function() {
- var data = undefined;
- var dataCursor = History.find({type: "edm"});
- dataCursor.map(function(doc) {
- if (data === undefined) {
- data = doc;
- }
- });
- if (data.history.length > size) {
- currentSong = data.history[data.history.length-1];
- size = data.history.length;
- startSong();
- }
- }, 1000);
- });
- }
- 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; }});
- var startedAt = Date.now();
- var songs = [{id: "jofNR_WkoCE", title: "The Fox", artist: "Ylvis", duration: 15, type: "youtube"}, {id: 216112412, title: "How Deep Is Your Love", artist: "Calvin Harris", duration: 193, type: "soundcloud"}];
- var currentSong = 0;
- addToHistory(songs[currentSong], startedAt);
- function addToHistory(song, startedAt) {
- History.update({type: "edm"}, {$push: {history: {song: song, started: startedAt}}});
- }
- function skipSong() {
- 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);
- }
- 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"
- });
- songTimer();
- Meteor.publish("history", function() {
- return History.find({type: "edm"})
- });
- 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;
- }
- });
- }
- Router.route("/", {
- template: "home"
- });
- Router.route("/:type", {
- template: "room"
- });
|