2017-08-25 00:37:21 +00:00
|
|
|
<template>
|
2017-08-27 15:53:17 +00:00
|
|
|
<div id="app">
|
2017-08-27 16:25:01 +00:00
|
|
|
<div class="translucent" v-if="song" :style="{ backgroundImage: 'url('+song.album.cover+')' }">
|
|
|
|
</div>
|
|
|
|
<div id="main" v-if="authenticated">
|
2017-08-27 15:53:17 +00:00
|
|
|
<p class="collapse">
|
|
|
|
<i class="fa fa-angle-down"></i>
|
|
|
|
</p>
|
|
|
|
<div class="details" v-if="song">
|
|
|
|
<div class="cover">
|
|
|
|
<img :src="song.album.cover" alt="song.album.cover">
|
|
|
|
</div>
|
|
|
|
<div class="info">
|
|
|
|
<div class="wrap">
|
|
|
|
<p class="title text">{{ song.title }}</p>
|
|
|
|
<p class="artist text">{{ song.artist.name }}</p>
|
|
|
|
<p class="album text">{{ song.album.name }}</p>
|
|
|
|
</div>
|
2017-08-25 00:37:21 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-08-27 15:53:17 +00:00
|
|
|
<footer>
|
|
|
|
<a class="favorite" @click.prevent="toggleFavorite">
|
|
|
|
<i class="fa fa-heart yep" v-if="song && song.liked"></i>
|
|
|
|
<i class="fa fa-heart-o" v-else></i>
|
|
|
|
</a>
|
|
|
|
<a class="prev" @click="playPrev">
|
|
|
|
<i class="fa fa-step-backward"></i>
|
|
|
|
</a>
|
|
|
|
<a class="play-pause" @click.prevent="togglePlayback">
|
|
|
|
<i class="fa fa-pause" v-if="playing"></i>
|
|
|
|
<i class="fa fa-play" v-else></i>
|
|
|
|
</a>
|
|
|
|
<a class="next" @click="playNext">
|
|
|
|
<i class="fa fa-step-forward"></i>
|
|
|
|
</a>
|
|
|
|
<a class="volume">
|
|
|
|
<i class="fa fa-volume-up"></i>
|
|
|
|
</a>
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="login-wrapper" v-else>
|
|
|
|
<login-form @loggedin="onUserLoggedIn"/>
|
2017-08-25 00:37:21 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2017-08-27 15:53:17 +00:00
|
|
|
import { socket, ls } from '../services'
|
|
|
|
import { userStore } from '../stores'
|
|
|
|
import loginForm from '../components/auth/login-form.vue'
|
2017-08-25 00:37:21 +00:00
|
|
|
|
|
|
|
export default {
|
2017-08-27 15:53:17 +00:00
|
|
|
components: { loginForm },
|
|
|
|
|
2017-08-25 00:37:21 +00:00
|
|
|
data () {
|
|
|
|
return {
|
2017-08-27 15:53:17 +00:00
|
|
|
authenticated: false,
|
|
|
|
song: null,
|
|
|
|
lastActiveTime: new Date().getTime()
|
2017-08-25 00:37:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2017-08-27 15:53:17 +00:00
|
|
|
onUserLoggedIn () {
|
|
|
|
this.authenticated = true
|
|
|
|
this.init()
|
|
|
|
},
|
|
|
|
|
|
|
|
async init() {
|
|
|
|
try {
|
|
|
|
const user = await userStore.getProfile()
|
|
|
|
userStore.init([], user)
|
|
|
|
|
|
|
|
await socket.init()
|
|
|
|
|
|
|
|
socket.listen('song', ({ song }) => {
|
|
|
|
this.song = song
|
|
|
|
}).listen('playback:stopped', () => {
|
|
|
|
if (this.song) {
|
|
|
|
this.song.playbackState = 'stopped'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
this.getStatus()
|
|
|
|
} catch (e) {
|
|
|
|
this.authenticated = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-08-26 21:43:06 +00:00
|
|
|
toggleFavorite () {
|
|
|
|
if (!this.song) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.song.liked = !this.song.liked
|
|
|
|
socket.broadcast('favorite:toggle')
|
|
|
|
},
|
|
|
|
|
2017-08-25 00:37:21 +00:00
|
|
|
togglePlayback () {
|
|
|
|
if (this.song) {
|
2017-08-26 21:43:06 +00:00
|
|
|
this.song.playbackState = this.song.playbackState === 'playing' ? 'paused' : 'playing'
|
2017-08-25 00:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
socket.broadcast('playback:toggle')
|
|
|
|
},
|
|
|
|
|
|
|
|
playNext () {
|
|
|
|
socket.broadcast('playback:next')
|
|
|
|
},
|
|
|
|
|
|
|
|
playPrev () {
|
|
|
|
socket.broadcast('playback:prev')
|
|
|
|
},
|
|
|
|
|
2017-08-26 21:43:06 +00:00
|
|
|
getStatus() {
|
|
|
|
socket.broadcast('song:getcurrent')
|
2017-08-27 15:53:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* As iOS will put a web app into standby/sleep mode (and halt all JS execution),
|
|
|
|
* this method will keep track of the last active time and keep the status always fresh.
|
|
|
|
*/
|
|
|
|
handleStandingBy () {
|
|
|
|
const now = new Date().getTime()
|
|
|
|
if (now - this.lastActiveTime > 1000) {
|
|
|
|
this.getStatus()
|
|
|
|
}
|
|
|
|
this.lastActiveTime = now
|
|
|
|
window.setTimeout(this.handleStandingBy, 500)
|
2017-08-25 00:37:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
playing () {
|
|
|
|
return this.song && this.song.playbackState === 'playing'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-08-27 15:53:17 +00:00
|
|
|
created () {
|
|
|
|
this.handleStandingBy()
|
|
|
|
},
|
|
|
|
|
2017-08-26 21:43:06 +00:00
|
|
|
mounted () {
|
2017-08-27 15:53:17 +00:00
|
|
|
// The app has just been initialized, check if we can get the user data with an already existing token
|
|
|
|
const token = ls.get('jwt-token')
|
|
|
|
if (token) {
|
|
|
|
this.authenticated = true
|
|
|
|
this.init()
|
|
|
|
}
|
2017-08-25 00:37:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2017-08-27 15:53:17 +00:00
|
|
|
<style lang="scss">
|
2017-08-25 00:37:21 +00:00
|
|
|
@import "resources/assets/sass/partials/_vars.scss";
|
|
|
|
@import "resources/assets/sass/partials/_mixins.scss";
|
|
|
|
@import "resources/assets/sass/partials/_shared.scss";
|
|
|
|
|
2017-08-27 15:53:17 +00:00
|
|
|
#app {
|
|
|
|
height: 100%;
|
2017-08-25 00:37:21 +00:00
|
|
|
background: $colorMainBgr;
|
2017-08-27 15:53:17 +00:00
|
|
|
|
|
|
|
.login-wrapper {
|
|
|
|
display: flex;
|
|
|
|
min-height: 100vh;
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
|
|
@include vertical-center();
|
|
|
|
}
|
2017-08-27 16:25:01 +00:00
|
|
|
|
|
|
|
.translucent {
|
|
|
|
position: absolute;
|
|
|
|
top: -20px;
|
|
|
|
left: -20px;
|
|
|
|
right: -20px;
|
|
|
|
bottom: -20px;
|
|
|
|
filter: blur(20px);
|
|
|
|
opacity: .3;
|
|
|
|
z-index: 0;
|
|
|
|
overflow: hidden;
|
|
|
|
background-size: cover;
|
|
|
|
background-position: center;
|
|
|
|
transform: translateZ(0);
|
|
|
|
backface-visibility: hidden;
|
|
|
|
perspective: 1000;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
2017-08-27 15:53:17 +00:00
|
|
|
}
|
|
|
|
|
2017-08-27 16:25:01 +00:00
|
|
|
#main {
|
2017-08-26 21:43:06 +00:00
|
|
|
height: 100%;
|
2017-08-25 00:37:21 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: space-between;
|
|
|
|
text-align: center;
|
2017-08-27 16:25:01 +00:00
|
|
|
z-index: 1;
|
|
|
|
position: relative;
|
2017-08-25 00:37:21 +00:00
|
|
|
|
|
|
|
.collapse {
|
|
|
|
height: 12vmin;
|
|
|
|
line-height: 12vmin;
|
|
|
|
font-size: 5vmin;
|
|
|
|
}
|
|
|
|
|
|
|
|
.details {
|
|
|
|
flex: 1;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
2017-08-27 16:25:01 +00:00
|
|
|
justify-content: space-around;
|
2017-08-25 00:37:21 +00:00
|
|
|
|
|
|
|
.info {
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2017-08-26 21:43:06 +00:00
|
|
|
justify-content: space-around;
|
2017-08-25 00:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.cover {
|
2017-08-26 21:43:06 +00:00
|
|
|
margin: 0 auto;
|
|
|
|
width: calc(70vw);
|
|
|
|
height: calc(70vw);
|
|
|
|
border-radius: 50%;
|
|
|
|
border: 2px solid #fff;
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
img {
|
|
|
|
width: calc(70vw);
|
|
|
|
height: auto;
|
|
|
|
}
|
2017-08-25 00:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.text {
|
|
|
|
max-width: 90%;
|
|
|
|
margin: 0 auto;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
line-height: 1.3;
|
|
|
|
}
|
|
|
|
|
|
|
|
.title {
|
|
|
|
font-size: 6vmin;
|
|
|
|
font-weight: bold;
|
2017-08-26 21:43:06 +00:00
|
|
|
margin: 0 auto 10px;
|
2017-08-25 00:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.artist {
|
2017-08-26 21:43:06 +00:00
|
|
|
font-size: 5vmin;
|
2017-08-25 00:37:21 +00:00
|
|
|
margin: 0 auto 6px;
|
|
|
|
font-weight: 100;
|
|
|
|
opacity: .5;
|
|
|
|
}
|
|
|
|
|
|
|
|
.album {
|
2017-08-26 21:43:06 +00:00
|
|
|
font-size: 4vmin;
|
2017-08-25 00:37:21 +00:00
|
|
|
font-weight: 100;
|
|
|
|
opacity: .5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
footer {
|
2017-08-26 21:43:06 +00:00
|
|
|
height: 18vh;
|
2017-08-25 00:37:21 +00:00
|
|
|
display: flex;
|
2017-08-26 21:43:06 +00:00
|
|
|
justify-content: space-around;
|
2017-08-25 00:37:21 +00:00
|
|
|
align-items: center;
|
|
|
|
border-top: 1px solid rgba(255, 255, 255, .1);
|
|
|
|
font-size: 5vmin;
|
|
|
|
|
2017-08-26 21:43:06 +00:00
|
|
|
a {
|
|
|
|
color: #fff;
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
opacity: .8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.favorite {
|
|
|
|
.yep {
|
|
|
|
color: #bf2043;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-25 00:37:21 +00:00
|
|
|
.prev, .next {
|
|
|
|
font-size: 6vmin;
|
|
|
|
}
|
|
|
|
|
|
|
|
.play-pause {
|
|
|
|
display: inline-block;
|
|
|
|
width: 16vmin;
|
|
|
|
height: 16vmin;
|
|
|
|
border: 1px solid #fff;
|
|
|
|
border-radius: 50%;
|
|
|
|
line-height: 16vmin;
|
|
|
|
font-size: 7vmin;
|
2017-08-26 21:43:06 +00:00
|
|
|
|
|
|
|
&.fa-play {
|
|
|
|
margin-left: 4px;
|
|
|
|
}
|
2017-08-25 00:37:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-27 15:53:17 +00:00
|
|
|
}
|
2017-08-25 00:37:21 +00:00
|
|
|
</style>
|