Parcourir la source

Fixed some things with songs and added volume slider code back in.

KrisVos130 il y a 9 ans
Parent
commit
659dc7f338

+ 8 - 0
app/client/scripts/events.js

@@ -937,6 +937,14 @@ Template.news.events({
 });
 
 Template.room.events({
+    "input #volume_slider": function() {
+        console.log("Test3");
+        var volume = Number($("#volume_slider").val());
+        localStorage.setItem("volume", volume);
+        if (YTPlayer !== undefined) {
+            YTPlayer.setVolume(volume);
+        }
+    },
     "click #add-song-modal-button": function() {
         Session.set("songResults", []);
     },

+ 3 - 8
app/client/scripts/onCreated.js

@@ -256,13 +256,6 @@ Template.room.onCreated(function () {
         }
     }
 
-    function getSongAudio() {
-      var ytURL = "www.youtube.com/watch?v=" + currentSong.id;
-      Meteor.call('getSongAudio', ytURL);
-
-      startSong();
-    }
-
     Session.set("loaded", false);
     Meteor.subscribe("rooms", function() {
         var parts = location.href.split('/');
@@ -299,7 +292,7 @@ Template.room.onCreated(function () {
                     currentSong.started = room.currentSong.started;
                     Session.set("currentSong", currentSong);
                     Meteor.clearTimeout(Session.get("loadVideoTimeout"));
-                    getSongAudio();
+                    startSong();
                 }
 
                 if (currentSong !== undefined) {
@@ -307,6 +300,8 @@ Template.room.onCreated(function () {
                         var duration = (Date.now() - currentSong.started - room.timePaused) / 1000;
                         var song_duration = currentSong.duration;
                         if (song_duration <= duration) {
+                            console.log("True!!! ", duration, "  ", song_duration);
+                            console.log("True!!!222 ", currentSong.started, "  ", room.timePaused);
                             Session.set("pauseVideo", true);
                         }
                         var d = moment.duration(duration, 'seconds');

+ 0 - 31
app/client/scripts/onRendered.js

@@ -66,35 +66,4 @@ Template.room.onRendered(function() {
     rTimeInterval = Meteor.setInterval(function() {
         Session.set("time", new Date().getTime());
     }, 10000);
-    $(document).ready(function() {
-        function makeSlider(){
-            var slider = $("#volume-slider").slider();
-            var volume = Number(localStorage.getItem("volume"));
-            $("#volume-slider").slider("setValue", volume);
-            if (slider.length === 0) {
-                Meteor.setTimeout(function() {
-                    makeSlider();
-                }, 500);
-            } else {
-                if (volume === 0) {
-                    $("#volume-icon").removeClass("fa-volume-down").addClass("fa-volume-off")
-                } else {
-                    $("#volume-icon").removeClass("fa-volume-off").addClass("fa-volume-down")
-                }
-                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 (YTPlayer !== undefined) {
-                        YTPlayer.setVolume(val.value);
-                        localStorage.setItem("volume", val.value);
-                    }
-                });
-            }
-        }
-        makeSlider();
-    });
 });

+ 8 - 4
app/server/server.js

@@ -22,7 +22,7 @@ Meteor.startup(function () {
         sendVerificationEmail: true
     });
 
-    if (Songs.find().count() === 0) {
+    if (Songs.find().count() === 0 || Songs.find({mid: default_song.mid}).count() === 0) {
         Songs.insert(default_song);
     }
 });
@@ -141,6 +141,7 @@ function createRoom(display, tag, private, desc) {
 }
 
 function Station(type) {
+    console.log(type);
     if (Playlists.find({type: type}).count() === 0) {
         Playlists.insert({type: type, songs: [default_song.mid], lastSong: 0});
     }
@@ -169,12 +170,13 @@ function Station(type) {
     } else currentSong = 0;
     var currentMid = songs[currentSong];
 
-    var song = Songs.findOne({mid: songs[currentSong]});
+    var song = Songs.findOne({mid: currentMid});
     if (song === undefined) {
         Playlists.remove({}, {$pull: {songs: currentMid}});
         song = default_song;
     }
-
+console.log(startedAt);
+console.log(song);
     var res = Rooms.update({type: type}, {
         $set: {
             currentSong: {song: song, started: startedAt},
@@ -393,7 +395,9 @@ Rooms.find({}).fetch().forEach(function (room) {
         Playlists.insert({type: type, songs: []});
     }
     if (Playlists.findOne({type: type}).songs.length === 0) {
-        // Add a global video to Playlist so it can proceed
+        Playlists.update({type: type}, {$push: {songs: default_song.mid}}, function() {
+            stations.push(new Station(type));
+        });
     } else {
         stations.push(new Station(type));
     }