Просмотр исходного кода

Merge branch 'master' of https://github.com/Musare/Musare

Wesley McCann 9 лет назад
Родитель
Сommit
edc459e990
6 измененных файлов с 140 добавлено и 53 удалено
  1. 5 1
      README.md
  2. 5 1
      app/client/app.css
  3. 60 39
      app/client/client.js
  4. 3 2
      app/client/routes.js
  5. 22 6
      app/client/templates/room.html
  6. 45 4
      app/server/server.js

+ 5 - 1
README.md

@@ -2,6 +2,10 @@
 
 ### http://musare.com/
 
+You can also find us on:
+* Twitter: https://twitter.com/musareapp
+* Facebook: https://www.facebook.com/MusareMusic
+
 ##Does the site not load?
 
 Try these methods first before reporting an issue:
@@ -43,4 +47,4 @@ Once that is done:
  2. Fork the repository
  3. Clone your forked repo to your local machine
 
-Navigate to "../app" and run "meteor". Go to localhost:3000 and you're set!
+Navigate to "../app" and run "meteor". Go to localhost:3000 and you're set!

+ 5 - 1
app/client/app.css

@@ -1148,7 +1148,7 @@ nav form input[type="image"]{
 .about a{
     color: white;
 }
-#play, #pause, #skip, #shuffle, #sync {
+#play, #pause, #skip, #shuffle, #sync, #unlock, #lock {
     cursor: pointer;
 }
 .delete-room {
@@ -1402,4 +1402,8 @@ nav form input[type="image"]{
     height: 40px;*/
     margin-right: 5px;
     float: left;
+}
+
+#doorbell-email{
+    color: black;
 }

+ 60 - 39
app/client/client.js

@@ -456,6 +456,12 @@ Template.room.events({
             }
         }
     },
+    "click #lock": function() {
+        Meteor.call("lockRoom", Session.get("type"));
+    },
+    "click #unlock": function() {
+        Meteor.call("unlockRoom", Session.get("type"));
+    },
     "click #side-panel": function(e) {
         Meteor.setTimeout(function() {
         var elem = document.getElementById('chat');
@@ -465,12 +471,14 @@ Template.room.events({
     "click #submit": function() {
         sendMessage();
     },
-    //"keyup #chat-input": function(e) {
-    //    if (e.type === "keyup" && e.which === 13) {
-    //        e.preventDefault();
-    //        sendMessage()
-    //    }
-    //},
+    "keyup #chat-input": function(e) {
+        if (e.type === "keyup" && e.which === 13) {
+            e.preventDefault();
+            if (!$('#chat-input').data('dropdownshown')) {
+                sendMessage();
+            }
+        }
+    },
     "click #like": function(e) {
         $("#like").blur();
         Meteor.call("likeSong", Session.get("currentSong").mid);
@@ -884,6 +892,9 @@ Template.room.helpers({
     paused: function() {
         return Session.get("state") === "paused";
     },
+    private: function() {
+        return Rooms.findOne({type: Session.get("type")}).private === true;
+    },
     report: function() {
         return Session.get("reportObj");
     },
@@ -1671,43 +1682,52 @@ Template.room.onCreated(function () {
                     $("#soundcloud-image").hide();
                 }
                 $("#player").show();
-                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) {
-                                if(currentSong.skipDuration === undefined){
-                                    currentSong.skipDuration = 0;
-                                }
-                                event.target.seekTo(Number(currentSong.skipDuration) + 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(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
-                                    event.target.playVideo();
-                                }
-                                if (event.data == YT.PlayerState.PLAYING && Session.get("state") === "paused") {
-                                    event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
-                                    event.target.pauseVideo();
+                function loadVideo() {
+                    if (YT.loaded === 0 && YT.loading === 1) {
+                        Session.set("loadVideoTimeout", Meteor.setTimeout(function() {
+                            loadVideo();
+                        }, 500));
+                    } else {
+                        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) {
+                                        if(currentSong.skipDuration === undefined){
+                                            currentSong.skipDuration = 0;
+                                        }
+                                        event.target.seekTo(Number(currentSong.skipDuration) + 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(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
+                                            event.target.playVideo();
+                                        }
+                                        if (event.data == YT.PlayerState.PLAYING && Session.get("state") === "paused") {
+                                            event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
+                                            event.target.pauseVideo();
+                                        }
+                                    }
                                 }
+                            });
+                        } else {
+                            yt_player.loadVideoById(currentSong.id);
+                            if(currentSong.skipDuration === undefined){
+                                currentSong.skipDuration = 0;
                             }
+                            yt_player.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
                         }
-                    });
-                } else {
-                    yt_player.loadVideoById(currentSong.id);
-                    if(currentSong.skipDuration === undefined){
-                        currentSong.skipDuration = 0;
+                        Session.set("pauseVideo", false);
+                        getSongInfo(currentSong);
                     }
-                    yt_player.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
-                }
-                Session.set("pauseVideo", false);
-                getSongInfo(currentSong);
+                };
+                loadVideo();
             }
         }
     }
@@ -1750,6 +1770,7 @@ Template.room.onCreated(function () {
                     currentSong = room.currentSong.song;
                     currentSong.started = room.currentSong.started;
                     Session.set("currentSong", currentSong);
+                    Meteor.clearTimeout(Session.get("loadVideoTimeout"));
                     startSong();
                 }
 

+ 3 - 2
app/client/routes.js

@@ -132,11 +132,12 @@ Router.route("/admin/alerts", {
 
 Router.route("/:type", {
     waitOn: function() {
-        return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
+        return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId()), Meteor.subscribe("rooms")];
     },
     action: function() {
         var user = Meteor.users.findOne({});
-        if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
+        var room = Rooms.findOne({type: this.params.type});
+        if ((room.private === true && user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) || room.private === false) {
             this.render("room");
         } else {
             this.redirect("/");

+ 22 - 6
app/client/templates/room.html

@@ -6,16 +6,21 @@
                 <div class="col-md-9" id="station-main">
                     <nav>
                         <div id="room-icons">
-                            <a class="back" href="/"><i class="fa fa-chevron-left"></i></a>
-                            <i class="fa fa-refresh fa-1" id="sync"></i>
+                            <a class="back" href="/"><i class="fa fa-chevron-left" title="Go back to the dashboard."></i></a>
+                            <i class="fa fa-refresh fa-1" id="sync" title="Synchronise to the proper duration in this video."></i>
                             {{#if isAdmin}}
                                 {{#if paused}}
-                                    <i class="fa fa-play fa-1" id="play"></i>
+                                    <i class="fa fa-play fa-1" id="play" title="Un-pause this room."></i>
                                 {{else}}
-                                    <i class="fa fa-pause fa-1" id="pause"></i>
+                                    <i class="fa fa-pause fa-1" id="pause" title="Pause this room."></i>
+                                {{/if}}
+                                <i class="fa fa-step-forward fa-1" id="skip" title="Skip this song."></i>
+                                <i class="fa fa-random fa-1" id="shuffle" title="Shuffle this room's playlist."></i>
+                                {{#if private}}
+                                    <i class="fa fa-lock fa-1" id="unlock" title="Unlock this room."></i>
+                                {{else}}
+                                    <i class="fa fa-unlock fa-1" id="lock" title="Lock this room."></i>
                                 {{/if}}
-                                <i class="fa fa-step-forward fa-1" id="skip"></i>
-                                <i class="fa fa-random fa-1" id="shuffle"></i>
                             {{/if}}
                         </div>
 
@@ -478,6 +483,17 @@
                 }
                 ], {
                     footer: '<a href="http://www.emoji.codes" target="_blank">Browse All<span class="arrow">»</span></a>'
+                }).on('textComplete:show', function () {
+                    console.log("show");
+                    $(this).data('dropdownshown', true);
+                }).on('textComplete:hide', function () {
+                    console.log("hide");
+                    var self = this;
+                    Meteor.setTimeout(function () {
+                        console.log("really hiden");
+                        console.log(self);
+                        $(self).data('dropdownshown', false);
+                    }, 200); // adhoc
                 });
             } else {
                 Meteor.setTimeout(function () {

+ 45 - 4
app/server/server.js

@@ -115,7 +115,7 @@ function Station(type) {
     Meteor.publish(type, function() {
         return undefined;
     });
-    var _this = this;
+    var self = this;
     var startedAt = Date.now();
     var playlist = Playlists.findOne({type: type});
     var songs = playlist.songs;
@@ -134,7 +134,7 @@ function Station(type) {
     Rooms.update({type: type}, {$set: {currentSong: {song: songs[currentSong], started: startedAt}, users: 0}});
 
     this.skipSong = function() {
-        _this.voted = [];
+        self.voted = [];
         voteNum = 0;
         Rooms.update({type: type}, {$set: {votes: 0}});
         songs = Playlists.findOne({type: type}).songs;
@@ -167,7 +167,7 @@ function Station(type) {
     this.shufflePlaylist = function() {
         voteNum = 0;
         Rooms.update({type: type}, {$set: {votes: 0}});
-        _this.voted = [];
+        self.voted = [];
         songs = Playlists.findOne({type: type}).songs;
         currentSong = 0;
         Playlists.update({type: type}, {$set: {"songs": []}});
@@ -196,7 +196,7 @@ function Station(type) {
             timer.pause();
         }
         timer = new Timer(function() {
-            _this.skipSong();
+            self.skipSong();
         }, songs[currentSong].duration * 1000);
     };
 
@@ -224,6 +224,29 @@ function Station(type) {
     };
     this.type = type;
 
+    var private = Rooms.findOne({type: type}).private;
+
+    if (typeof private !== "boolean") {
+        Rooms.update({type: type}, {$set: {"private": false}});
+        private = false;
+    }
+
+    this.private = private;
+
+    this.unlock = function() {
+        if (self.private) {
+            self.private = false;
+            Rooms.update({type: type}, {$set: {"private": false}});
+        }
+    };
+
+    this.lock = function() {
+        if (!self.private) {
+            self.private = true;
+            Rooms.update({type: type}, {$set: {"private": true}});
+        }
+    };
+
     this.songTimer();
     this.voted = [];
 }
@@ -464,6 +487,24 @@ function isBanned() {
 
 
 Meteor.methods({
+    lockRoom: function(type) {
+        if (isAdmin() && !isBanned()) {
+            getStation(type, function(station){
+                station.lock();
+            });
+        } else {
+            throw new Meteor.Error(403, "Invalid permissions.");
+        }
+    },
+    unlockRoom: function(type) {
+        if (isAdmin() && !isBanned()) {
+            getStation(type, function(station){
+                station.unlock();
+            });
+        } else {
+            throw new Meteor.Error(403, "Invalid permissions.");
+        }
+    },
     banUser: function(username, period, reason) {
         if (isAdmin() && !isBanned()) {
             var user = Meteor.user();