2
0
Эх сурвалжийг харах

Merge branch 'master' of https://github.com/AkiraLaine/music-app

unknown 9 жил өмнө
parent
commit
fe9c4fcd38
5 өөрчлөгдсөн 242 нэмэгдсэн , 110 устгасан
  1. 2 2
      app/.meteor/packages
  2. 2 2
      app/.meteor/versions
  3. 9 0
      app/app.css
  4. 5 0
      app/app.html
  5. 224 106
      app/app.js

+ 2 - 2
app/.meteor/packages

@@ -15,8 +15,6 @@ standard-minifiers      # JS/CSS minifiers run for production mode
 es5-shim                # ECMAScript 5 compatibility for older browsers.
 es5-shim                # ECMAScript 5 compatibility for older browsers.
 ecmascript              # Enable ECMAScript2015+ syntax in app code
 ecmascript              # Enable ECMAScript2015+ syntax in app code
 
 
-autopublish             # Publish all data to the clients (for prototyping)
-insecure                # Allow all DB writes from clients (for prototyping)
 accounts-password
 accounts-password
 accounts-facebook
 accounts-facebook
 accounts-github
 accounts-github
@@ -25,3 +23,5 @@ twbs:bootstrap
 jquery
 jquery
 iron:router
 iron:router
 ejson
 ejson
+joncursi:socket-io-client
+meteorhacks:async

+ 2 - 2
app/.meteor/versions

@@ -3,7 +3,6 @@ accounts-facebook@1.0.6
 accounts-github@1.0.6
 accounts-github@1.0.6
 accounts-oauth@1.1.7
 accounts-oauth@1.1.7
 accounts-password@1.1.3
 accounts-password@1.1.3
-autopublish@1.0.4
 autoupdate@1.2.3
 autoupdate@1.2.3
 babel-compiler@5.8.24_1
 babel-compiler@5.8.24_1
 babel-runtime@0.1.4
 babel-runtime@0.1.4
@@ -38,7 +37,6 @@ html-tools@1.0.5
 htmljs@1.0.5
 htmljs@1.0.5
 http@1.1.1
 http@1.1.1
 id-map@1.0.4
 id-map@1.0.4
-insecure@1.0.4
 iron:controller@1.0.8
 iron:controller@1.0.8
 iron:core@1.0.8
 iron:core@1.0.8
 iron:dynamic-template@1.0.8
 iron:dynamic-template@1.0.8
@@ -47,6 +45,7 @@ iron:location@1.0.9
 iron:middleware-stack@1.0.9
 iron:middleware-stack@1.0.9
 iron:router@1.0.9
 iron:router@1.0.9
 iron:url@1.0.9
 iron:url@1.0.9
+joncursi:socket-io-client@0.1.4
 jquery@1.11.4
 jquery@1.11.4
 launch-screen@1.0.4
 launch-screen@1.0.4
 livedata@1.0.15
 livedata@1.0.15
@@ -54,6 +53,7 @@ localstorage@1.0.5
 logging@1.0.8
 logging@1.0.8
 meteor@1.1.7
 meteor@1.1.7
 meteor-base@1.0.1
 meteor-base@1.0.1
+meteorhacks:async@1.0.0
 minifiers@1.1.7
 minifiers@1.1.7
 minimongo@1.0.9
 minimongo@1.0.9
 mobile-experience@1.0.1
 mobile-experience@1.0.1

+ 9 - 0
app/app.css

@@ -60,6 +60,15 @@ body :-ms-input-placeholder {
           transition-timing-function: ease-in-put;
           transition-timing-function: ease-in-put;
   font-weight: 200;
   font-weight: 200;
 }
 }
+.container p {
+  font-size: 10px;
+  color: white;
+  -webkit-transition-duration: 1s;
+          transition-duration: 1s;
+  -webkit-transition-timing-function: ease-in-put;
+          transition-timing-function: ease-in-put;
+  font-weight: 200;
+}
 form {
 form {
   padding: 20px 0;
   padding: 20px 0;
   position: relative;
   position: relative;

+ 5 - 0
app/app.html

@@ -26,6 +26,7 @@
       <input type="text" name="registerUsername" placeholder="Enter a username" onfocus="this.placeholder = ''" onblur="this.placeholder='Enter a username'" required/>
       <input type="text" name="registerUsername" placeholder="Enter a username" onfocus="this.placeholder = ''" onblur="this.placeholder='Enter a username'" required/>
       <input type="email" name="registerEmail" placeholder="Enter your email" onfocus="this.placeholder = ''" onblur="this.placeholder='Enter your email'" required>
       <input type="email" name="registerEmail" placeholder="Enter your email" onfocus="this.placeholder = ''" onblur="this.placeholder='Enter your email'" required>
       <input type="password" name="registerPassword" placeholder="Enter a password" onfocus="this.placeholder = ''" onblur="this.placeholder='Enter a password'" required/>
       <input type="password" name="registerPassword" placeholder="Enter a password" onfocus="this.placeholder = ''" onblur="this.placeholder='Enter a password'" required/>
+      <p>By registering, you agree to the Terms and Conditions and Privacy Policy.</p>
       <button type="submit">Sign Up</button>
       <button type="submit">Sign Up</button>
     </form>
     </form>
     <button class="btn-social" id="facebook-login"><i class="fa fa-facebook pull-left"></i>Signup with Facebook</button><p></p>
     <button class="btn-social" id="facebook-login"><i class="fa fa-facebook pull-left"></i>Signup with Facebook</button><p></p>
@@ -78,6 +79,7 @@
     	<li></li>
     	<li></li>
     </ul>
     </ul>
   </div>
   </div>
+{{> footer}}
 </template>
 </template>
 
 
 <template name="footer">
 <template name="footer">
@@ -123,4 +125,7 @@
 
 
 <template name="Room">
 <template name="Room">
     <h1>{{{type}}}</h1>
     <h1>{{{type}}}</h1>
+    
+    <h2>{{duration}}</h2>
+    <h2>{{song}}</h2>
 </template>
 </template>

+ 224 - 106
app/app.js

@@ -1,120 +1,238 @@
-if (Meteor.isClient) {  
-  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;
-        Accounts.createUser({
-            username: username,
-            email: email,
-            password: password
-        });
-    },
-
-    "click #facebook-login": function(){
-        Meteor.loginWithFacebook()
-    },
+History = new Mongo.Collection("history");
 
 
-    "click #github-login": function(){
-        Meteor.loginWithGithub()
-    },
-
-    "click #login": function(){
-      $("#register-view").hide();
-      $("#login-view").show();
+if (Meteor.isClient) {  
+    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;
+            Accounts.createUser({
+                username: username,
+                email: email,
+                password: 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();
+        },
+
+        "click .button-tunein": function(){
+            SC.stream("/tracks/172055891/", function(sound){
+                console.log(sound);
+                sound._player._volume = 0.3;
+                sound.play();
+            });
+        },
+
+        "click #play": function(){
+            $("#play").hide();
+            SC.stream("/tracks/172055891/", function(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;
+        },
+        duration: function() {
+            return Session.get("duration");
+        }
+    });
+  
+    var currentSong = undefined;
+    var _sound = undefined;
+    var size = 0;
+
+    function getTimeElapsed() {
+        if (currentSong !== undefined) {
+            return Date.now() - currentSong.started;
+        } 
+        return 0;
     }
     }
-  });
-
-  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"
-             });
-           })
+  
+    function startSong() {
+        if (currentSong !== undefined) {
+            if (_sound !== undefined)_sound.stop();
+            SC.stream("/tracks/" + currentSong.song.id + "/", function(sound){
+                _sound = sound;
+                sound._player._volume = 0.3;
+                sound.play();
+                setTimeout(function() { // HACK, otherwise seek doesn't work.
+                    sound._player.seek(getTimeElapsed());
+                }, 500);
+            });
+        }
+    }
+  
+    Template.Room.onCreated(function () {
+        /*var instance = this;
+        HTTP.get('/api/room/edm', function (err, data) {
+          instance.data = data;
+          console.log(data);
+          // PLAY SONG AND SUCH
+        });*/
+        
+        
+        /*console.log("Created!");
+        Meteor.call("getDuration", function(err, res) {
+            Session.set("duration", res);
+            console.log(res);
         });
         });
-    },
+        Meteor.call("getStart", function(err, res) {
+            Session.set("start", res);
+            console.log(res);
+        });
+        Meteor.call("getSong", function(err, res) {
+            Session.set("song", res);
+            console.log(res);
+            SC.stream("/tracks/" + res + "/", function(sound){
+              console.log(sound);
+              sound._player._volume = 0.3;
+              sound.play();
+              setTimeout(function() { // HACK, otherwise seek doesn't work.
+                  sound._player.seek(Date.now() - Session.get("start"));
+                  console.log((Date.now() - Session.get("start")) + "--");
+              }, 500);
+            });
+        });*/
+    });
+  
+    Meteor.subscribe("history");
+  
+  
+    Meteor.setInterval(function() {
+        var data = History.findOne();
+        if (data.history.length > size) {
+            currentSong = data.history[data.history.length-1];
+            size = data.history.length;
+            startSong();
+        }
+    }, 1000);
+    //console.log(History, "History");
+}
 
 
-    "click #facebook-login": function(){
-        Meteor.loginWithFacebook()
-    },
+if (Meteor.isServer) { 
+    var startedAt = Date.now();
+    var songs = [{id: 172055891, duration: 20}, {id: 101244339, duration: 60}];
+    var currentSong = 0;
+    addToHistory(songs[currentSong], startedAt);
 
 
-    "click #github-login": function(){
-        Meteor.loginWithGithub()
-    },
+    function addToHistory(song, startedAt) {
+        History.update({type: "edm"}, {$push: {history: {song: song, started: startedAt}}});
+    }
 
 
-    "click #register": function(){
-      $("#login-view").hide();
-      $("#register-view").show();
+    function skipSong() {
+        if (currentSong < (songs.length - 1)) {
+            currentSong++;
+        } else currentSong = 0;
+        songTimer();
+        addToHistory(songs[currentSong], startedAt);
     }
     }
-  });
-
-  Template.dashboard.events({
-    "click .logout": function(e){
-        e.preventDefault();
-        Meteor.logout();
-    },
-
-    "click .button-tunein": function(){
-      SC.stream("/tracks/172055891/", function(sound){
-        console.log(sound);
-        sound._player._volume = 0.3;
-        sound.play();
-      });
-    },
-
-    "click #play": function(){
-      $("#play").hide();
-      SC.stream("/tracks/172055891/", function(sound){
-        sound._player._volume = 0.3;
-        sound.play();
-        $("#stop").on("click", function(){
-          $("#stop").hide();
-          $("#play").show();
-          sound._player.pause();
-        })
-      });
-      $("#stop").show();
+
+    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"
+    });
   
   
-  Template.Room.helpers({
-      type: function() {
-        var parts = location.href.split('/');
-        var id = parts.pop();
-        return id;
+    songTimer();
+  
+    /*Meteor.methods({ 
+      getDuration: function() {
+          return "100 minutes";
+      },
+      getStart: function() {
+          return startedAt;
+      },
+      getSong: function() {
+          return songs[currentSong];
       }
       }
-  });
-}
+    });*/
 
 
-if (Meteor.isServer) {
-  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({type: "edm"})
+    });
 }
 }
 
 
 Router.route("/", {
 Router.route("/", {