KrisVos130 9 年之前
父節點
當前提交
522c5ca0cc
共有 2 個文件被更改,包括 3 次插入325 次删除
  1. 0 325
      app/client/scripts/events.js
  2. 3 0
      app/client/scripts/onCreated.js

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

@@ -1345,331 +1345,6 @@ Template.room.events({
         $("#playlist-import").hide();
     }
 });
-
-Template.room.helpers({
-    singleVideo: function() {
-        return true;
-    },
-    chat: function() {
-        Meteor.setTimeout(function() {
-            var elem = document.getElementById('chat');
-            if (elem !== undefined && elem !== null) {
-                elem.scrollTop = elem.scrollHeight;
-            }
-        }, 100);
-        return Chat.find({type: Session.get("type")}, {sort: {time: -1}, limit: 50 }).fetch().reverse();
-    },
-    globalChat: function() {
-        Meteor.setTimeout(function() {
-            var elem = document.getElementById('global-chat');
-            if (elem !== undefined && elem !== null) {
-                elem.scrollTop = elem.scrollHeight;
-            }
-        }, 100);
-        return Chat.find({type: "global"}, {sort: {time: -1}, limit: 50 }).fetch().reverse();
-    },
-    likes: function() {
-        var playlist = Playlists.findOne({type: Session.get("type")});
-        var likes = 0;
-        playlist.songs.forEach(function(song) {
-            if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
-                likes = song.likes;
-                return;
-            }
-        });
-        return likes;
-    },
-    dislikes: function() {
-        var playlist = Playlists.findOne({type: Session.get("type")});
-        var dislikes = 0;
-        playlist.songs.forEach(function(song) {
-            if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
-                dislikes = song.dislikes;
-                return;
-            }
-        });
-        return dislikes;
-    },
-    liked: function() {
-        if (Meteor.userId()) {
-            var currentSong = Session.get("currentSong");
-            if (currentSong && Meteor.user().profile.liked.indexOf(currentSong.mid) !== -1) {
-                return "active";
-            } else {
-                return "";
-            }
-        } else {
-            "";
-        }
-    },
-    disliked: function() {
-        if (Meteor.userId()) {
-            var currentSong = Session.get("currentSong");
-            if (currentSong && Meteor.user().profile.disliked.indexOf(currentSong.mid) !== -1) {
-                return "active";
-            } else {
-                return "";
-            }
-        } else {
-            "";
-        }
-    },
-    type: function() {
-        var parts = location.href.split('/');
-        var id = parts.pop().toLowerCase();
-        return Rooms.findOne({type: id}).display;
-    },
-    users: function() {
-        var parts = location.href.split('/');
-        var id = parts.pop().toLowerCase();
-        return Rooms.findOne({type: id}).users;
-    },
-    title: function(){
-        return Session.get("title");
-    },
-    artist: function(){
-        return Session.get("artist");
-    },
-    loaded: function() {
-        return Session.get("loaded");
-    },
-    paused: function() {
-        return Session.get("state") === "paused";
-    },
-    private: function() {
-        return Rooms.findOne({type: Session.get("type")}).private === true;
-    },
-    report: function() {
-        return Session.get("reportObj");
-    },
-    reportSong: function() {
-        return Session.get("reportSong");
-    },
-    reportTitle: function() {
-        return Session.get("reportTitle");
-    },
-    reportAuthor: function() {
-        return Session.get("reportAuthor");
-    },
-    reportDuration: function() {
-        return Session.get("reportDuration");
-    },
-    reportAudio: function() {
-        return Session.get("reportAudio");
-    },
-    reportAlbumart: function() {
-        return Session.get("reportAlbumart");
-    },
-    reportOther: function() {
-        return Session.get("reportOther");
-    },
-    currentSong: function() {
-        return Session.get("currentSong");
-    },
-    previousSong: function() {
-        return Session.get("previousSong");
-    },
-    currentSongR: function() {
-        return Session.get("currentSongR");
-    },
-    previousSongR: function() {
-        return Session.get("previousSongR");
-    },
-    reportingSong: function() {
-        if (Session.get("reportPrevious")) {
-            return Session.get("previousSongR");
-        } else {
-            return Session.get("currentSongR");
-        }
-    },
-    votes: function(){
-        return Rooms.findOne({type: Session.get("type")}).votes;
-    }
-});
-Template.room.onCreated(function () {
-    Chat.after.find(function(userId, selector) {
-        if (selector.type === "global") {
-            if (!$("#global-chat-tab").hasClass("active")) {
-                $("#global-chat-tab").addClass("unread-messages");
-            }
-        } else if(selector.type === Session.get("type")) {
-            if (!$("#chat-tab").hasClass("active")) {
-                $("#chat-tab").addClass("unread-messages");
-            }
-        }
-    });
-    Session.set("reportSong", false);
-    Session.set("reportTitle", false);
-    Session.set("reportAuthor", false);
-    Session.set("reportDuration", false);
-    Session.set("reportAudio", false);
-    Session.set("reportAlbumart", false);
-    Session.set("reportOther", false);
-    /*if (resizeSeekerbarInterval !== undefined) {
-        Meteor.clearInterval(resizeSeekerbarInterval);
-        resizeSeekerbarInterval = undefined;
-    }*/
-    YTPlayer = undefined;
-    Session.set("videoHidden", false);
-    var tag = document.createElement("script");
-    tag.src = "https://www.youtube.com/iframe_api";
-    var firstScriptTag = document.getElementsByTagName('script')[0];
-    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
-
-    Session.set("singleVideo", true);
-
-    var currentSong = undefined;
-    var currentSongR = undefined;
-
-    function getTimeElapsed() {
-        if (currentSong !== undefined) {
-            var room = Rooms.findOne({type: type});
-            if (room !== undefined) {
-                return Date.now() - currentSong.started - room.timePaused;
-            }
-        }
-        return 0;
-    }
-
-    function getSongInfo(songData){
-        Session.set("title", songData.title);
-        Session.set("artist", songData.artist);
-        Session.set("id", songData.id);
-        $("#song-img").attr("src", songData.img);
-        Session.set("duration", parseInt(songData.duration));
-        var d = moment.duration(parseInt(songData.duration), 'seconds');
-        $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
-        Session.set("timeFormat", d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
-    }
-
-    function resizeSeekerbar() {
-        if (Session.get("state") === "playing") {
-            $("#seeker-bar").width(((getTimeElapsed() / 1000) / Session.get("duration") * 100) + "%");
-        }
-    }
-
-    function startSong() {
-        $("#time-elapsed").text("0:00");
-        $("#vote-skip").attr("disabled", false);
-        if (currentSong !== undefined) {
-            if (YTPlayer !== undefined && YTPlayer.stopVideo !== undefined) YTPlayer.stopVideo();
-
-            var volume = localStorage.getItem("volume") || 20;
-
-            if ($("#player").length !== 1) {
-                $("#media-container").append('<div id="player" class="embed-responsive-item"></div>');
-            }
-            $("#player").show();
-            function loadVideo() {
-                if (!Session.get("YTLoaded")) {
-                    Session.set("loadVideoTimeout", Meteor.setTimeout(function () {
-                        loadVideo();
-                    }, 500));
-                } else {
-                    if (YTPlayer === undefined) {
-                        YTPlayer = 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 (Session.get("YTLoaded")) {
-                                        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 {
-                        YTPlayer.loadVideoById(currentSong.id);
-                        if (currentSong.skipDuration === undefined) {
-                            currentSong.skipDuration = 0;
-                        }
-                        YTPlayer.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
-                    }
-                    Session.set("pauseVideo", false);
-                    getSongInfo(currentSong);
-                }
-            }
-            loadVideo();
-        }
-    }
-
-    Session.set("loaded", false);
-    Meteor.subscribe("rooms", function() {
-        var parts = location.href.split('/');
-        var id = parts.pop();
-        var type = id.toLowerCase();
-        Session.set("type", type);
-        if (Rooms.find({type: type}).count() !== 1) {
-            window.location = "/";
-        } else {
-            StationSubscription = Meteor.subscribe(type);
-            Session.set("loaded", true);
-            minterval = Meteor.setInterval(function () {
-                var room = Rooms.findOne({type: type});
-                if (room !== undefined) {
-                    if (room.state === "paused" || Session.get("pauseVideo")) {
-                        Session.set("state", "paused");
-                        // TODO Fix issue where sometimes nothing loads with the YT is not defined error. The error points to around this.
-                        if (YTPlayer !== undefined && YTPlayer.getPlayerState !== undefined && YTPlayer.getPlayerState() === 1) {
-                            YTPlayer.pauseVideo();
-                        }
-                    } else {
-                        Session.set("state", "playing");
-                        if (YTPlayer !== undefined && YTPlayer.getPlayerState !== undefined && YTPlayer.getPlayerState() !== 1) {
-                            YTPlayer.playVideo();
-                        }
-                    }
-                }
-
-                if (room.currentSong.song !== undefined && (currentSongR === undefined || room.currentSong.started !== currentSongR.started)) {
-                    Session.set("previousSong", currentSong);
-                    currentSongR = room.currentSong;
-
-                    currentSong = room.currentSong.song;
-                    currentSong.started = room.currentSong.started;
-                    Session.set("currentSong", currentSong);
-                    Meteor.clearTimeout(Session.get("loadVideoTimeout"));
-                    startSong();
-                }
-
-                if (currentSong !== undefined) {
-                    if (room !== undefined) {
-                        var duration = (Date.now() - currentSong.started - room.timePaused) / 1000;
-                        var song_duration = currentSong.duration;
-                            if (song_duration <= duration) {
-                                Session.set("pauseVideo", true);
-                            }
-                        var d = moment.duration(duration, 'seconds');
-                        if (Session.get("state") === "playing") {
-                            $("#time-elapsed").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
-                        }
-                    }
-                }
-            }, 100);
-            resizeSeekerbarInterval = Meteor.setInterval(function () {
-                resizeSeekerbar();
-            }, 500);
-        }
-    });
-});
 // Settings Template
 Template.settings.events({
     "click #save-settings": function() {

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

@@ -134,6 +134,9 @@ Template.room.onCreated(function () {
     Session.set("reportAudio", false);
     Session.set("reportAlbumart", false);
     Session.set("reportOther", false);
+    var parts = location.href.split('/');
+    var id = parts.pop();
+    var type = id.toLowerCase();
     if (resizeSeekerbarInterval !== undefined) {
         Meteor.clearInterval(resizeSeekerbarInterval);
         resizeSeekerbarInterval = undefined;