2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2022-04-25 13:07:38 +00:00
|
|
|
<div id="wrapper" :class="{ 'standalone' : inStandaloneMode }">
|
2022-04-15 14:24:30 +00:00
|
|
|
<template v-if="authenticated">
|
2022-12-02 16:17:37 +00:00
|
|
|
<AlbumArtOverlay v-if="showAlbumArtOverlay && song" :album="song.album_id" />
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
|
|
<main>
|
|
|
|
<template v-if="connected">
|
2022-07-24 10:53:49 +00:00
|
|
|
<div v-if="song" class="details">
|
2022-12-02 16:17:37 +00:00
|
|
|
<div :style="{ backgroundImage: `url(${song.album_cover || defaultCover})` }" class="cover" />
|
2022-04-15 14:24:30 +00:00
|
|
|
<div class="info">
|
|
|
|
<div class="wrap">
|
|
|
|
<p class="title text">{{ song.title }}</p>
|
2022-06-10 10:47:46 +00:00
|
|
|
<p class="artist text">{{ song.artist_name }}</p>
|
|
|
|
<p class="album text">{{ song.album_name }}</p>
|
2022-04-15 14:24:30 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-12-02 16:17:37 +00:00
|
|
|
<p v-else class="none text-secondary">No song is playing.</p>
|
2022-04-15 14:24:30 +00:00
|
|
|
<footer>
|
2022-07-24 10:53:49 +00:00
|
|
|
<a class="favorite" :class="song?.liked ? 'yep' : ''" @click.prevent="toggleFavorite">
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="song?.liked ? faHeart : faEmptyHeart" />
|
2022-04-15 14:24:30 +00:00
|
|
|
</a>
|
|
|
|
<a class="prev" @click="playPrev">
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="faStepBackward" />
|
2022-04-15 14:24:30 +00:00
|
|
|
</a>
|
|
|
|
<a class="play-pause" @click.prevent="togglePlayback">
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="playing ? faPause : faPlay" />
|
2022-04-15 14:24:30 +00:00
|
|
|
</a>
|
|
|
|
<a class="next" @click.prevent="playNext">
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="faStepForward" />
|
2022-04-15 14:24:30 +00:00
|
|
|
</a>
|
|
|
|
<span class="volume">
|
2022-04-25 13:07:38 +00:00
|
|
|
<span
|
|
|
|
v-show="showingVolumeSlider"
|
|
|
|
id="volumeSlider"
|
2022-12-02 16:17:37 +00:00
|
|
|
ref="volumeSlider"
|
2022-04-25 13:07:38 +00:00
|
|
|
v-koel-clickaway="closeVolumeSlider"
|
|
|
|
/>
|
2022-04-15 14:24:30 +00:00
|
|
|
<span class="icon" @click.stop="toggleVolumeSlider">
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="muted ? faVolumeMute : faVolumeHigh" fixed-width />
|
2022-04-15 14:24:30 +00:00
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</footer>
|
|
|
|
</template>
|
|
|
|
<div v-else class="loader">
|
|
|
|
<div v-if="!maxRetriesReached">
|
|
|
|
<p>Searching for Koel…</p>
|
2022-12-02 16:17:37 +00:00
|
|
|
<div class="signal" />
|
2022-04-15 14:24:30 +00:00
|
|
|
</div>
|
|
|
|
<p v-else>
|
|
|
|
No active Koel instance found.
|
2022-07-15 07:23:55 +00:00
|
|
|
<a class="rescan text-highlight" @click.prevent="rescan">Rescan</a>
|
2022-04-15 14:24:30 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</main>
|
|
|
|
</template>
|
|
|
|
|
2022-12-02 16:17:37 +00:00
|
|
|
<div v-else class="login-wrapper">
|
|
|
|
<LoginForm @loggedin="onUserLoggedIn" />
|
2022-04-15 14:24:30 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
<script lang="ts" setup>
|
2022-07-15 07:23:55 +00:00
|
|
|
import {
|
|
|
|
faHeart,
|
|
|
|
faPause,
|
|
|
|
faPlay,
|
|
|
|
faStepBackward,
|
|
|
|
faStepForward,
|
|
|
|
faVolumeHigh,
|
|
|
|
faVolumeMute
|
|
|
|
} from '@fortawesome/free-solid-svg-icons'
|
|
|
|
|
|
|
|
import { faHeart as faEmptyHeart } from '@fortawesome/free-regular-svg-icons'
|
2022-04-15 14:24:30 +00:00
|
|
|
import noUISlider from 'nouislider'
|
2022-04-25 13:07:38 +00:00
|
|
|
import { authService, socketService } from '@/services'
|
|
|
|
import { preferenceStore, userStore } from '@/stores'
|
|
|
|
import { computed, defineAsyncComponent, nextTick, onMounted, ref, toRef, watch } from 'vue'
|
2022-07-24 10:53:49 +00:00
|
|
|
import { defaultCover, logger } from '@/utils'
|
2022-04-25 13:07:38 +00:00
|
|
|
|
2022-04-15 14:24:30 +00:00
|
|
|
const MAX_RETRIES = 10
|
|
|
|
const DEFAULT_VOLUME = 7
|
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
const AlbumArtOverlay = defineAsyncComponent(() => import('@/components/ui/AlbumArtOverlay.vue'))
|
2022-07-07 18:05:46 +00:00
|
|
|
const LoginForm = defineAsyncComponent(() => import('@/components/auth/LoginForm.vue'))
|
2022-04-25 13:07:38 +00:00
|
|
|
|
2022-11-02 19:25:22 +00:00
|
|
|
const volumeSlider = ref<EqualizerBandElement>()
|
2022-04-25 13:07:38 +00:00
|
|
|
const authenticated = ref(false)
|
2022-07-24 10:53:49 +00:00
|
|
|
const song = ref<Song>()
|
2022-04-25 13:07:38 +00:00
|
|
|
const connected = ref(false)
|
|
|
|
const muted = ref(false)
|
|
|
|
const showingVolumeSlider = ref(false)
|
|
|
|
const retries = ref(0)
|
|
|
|
const showAlbumArtOverlay = toRef(preferenceStore.state, 'showAlbumArtOverlay')
|
|
|
|
const volume = ref(DEFAULT_VOLUME)
|
|
|
|
|
|
|
|
const inStandaloneMode = ref(
|
|
|
|
(window.navigator as any).standalone || window.matchMedia('(display-mode: standalone)').matches
|
|
|
|
)
|
|
|
|
|
|
|
|
watch(connected, async () => {
|
|
|
|
await nextTick()
|
|
|
|
|
|
|
|
if (!volumeSlider.value) return
|
|
|
|
|
|
|
|
noUISlider.create(volumeSlider.value, {
|
|
|
|
orientation: 'vertical',
|
|
|
|
connect: [true, false],
|
|
|
|
start: volume.value || DEFAULT_VOLUME,
|
|
|
|
range: { min: 0, max: 10 },
|
|
|
|
direction: 'rtl'
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!volumeSlider.value.noUiSlider) {
|
|
|
|
throw new Error('Failed to initialize noUISlider on element #volumeSlider')
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-12-02 16:17:37 +00:00
|
|
|
volumeSlider.value.noUiSlider.on('change', (values: string[], handle: number) => {
|
2022-04-25 13:07:38 +00:00
|
|
|
const volume = values[handle]
|
|
|
|
muted.value = !volume
|
2022-07-24 10:53:49 +00:00
|
|
|
socketService.broadcast('SOCKET_SET_VOLUME', volume)
|
2022-04-25 13:07:38 +00:00
|
|
|
})
|
|
|
|
})
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-24 10:53:49 +00:00
|
|
|
watch(volume, () => volumeSlider.value?.noUiSlider!.set(volume.value ?? DEFAULT_VOLUME))
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-24 10:53:49 +00:00
|
|
|
const onUserLoggedIn = async () => {
|
2022-04-25 13:07:38 +00:00
|
|
|
authenticated.value = true
|
2022-07-24 10:53:49 +00:00
|
|
|
await init()
|
2022-04-25 13:07:38 +00:00
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
const init = async () => {
|
|
|
|
try {
|
2022-06-10 10:47:46 +00:00
|
|
|
userStore.init(await userStore.getProfile())
|
2022-04-25 13:07:38 +00:00
|
|
|
|
|
|
|
await socketService.init()
|
|
|
|
|
|
|
|
socketService
|
2022-07-24 10:53:49 +00:00
|
|
|
.listen('SOCKET_SONG', _song => (song.value = _song))
|
2022-06-10 10:47:46 +00:00
|
|
|
.listen('SOCKET_PLAYBACK_STOPPED', () => song.value && (song.value.playback_state = 'Stopped'))
|
2022-04-25 13:07:38 +00:00
|
|
|
.listen('SOCKET_VOLUME_CHANGED', (volume: number) => volumeSlider.value?.noUiSlider?.set(volume))
|
2022-07-24 10:53:49 +00:00
|
|
|
.listen('SOCKET_STATUS', (data: { song?: Song, volume: number }) => {
|
|
|
|
song.value = data.song
|
|
|
|
volume.value = data.volume || DEFAULT_VOLUME
|
2022-04-25 13:07:38 +00:00
|
|
|
connected.value = true
|
|
|
|
})
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
scan()
|
|
|
|
} catch (e) {
|
2022-07-20 08:00:02 +00:00
|
|
|
logger.error(e)
|
2022-04-25 13:07:38 +00:00
|
|
|
authenticated.value = false
|
|
|
|
}
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
const toggleVolumeSlider = () => (showingVolumeSlider.value = !showingVolumeSlider.value)
|
|
|
|
const closeVolumeSlider = () => (showingVolumeSlider.value = false)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
const toggleFavorite = () => {
|
|
|
|
if (!song.value) {
|
|
|
|
return
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
song.value.liked = !song.value.liked
|
|
|
|
socketService.broadcast('SOCKET_TOGGLE_FAVORITE')
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
const togglePlayback = () => {
|
|
|
|
if (song.value) {
|
2022-06-10 10:47:46 +00:00
|
|
|
song.value.playback_state = song.value.playback_state === 'Playing' ? 'Paused' : 'Playing'
|
2022-04-25 13:07:38 +00:00
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
socketService.broadcast('SOCKET_TOGGLE_PLAYBACK')
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
const playNext = () => socketService.broadcast('SOCKET_PLAY_NEXT')
|
|
|
|
const playPrev = () => socketService.broadcast('SOCKET_PLAY_PREV')
|
|
|
|
const getStatus = () => socketService.broadcast('SOCKET_GET_STATUS')
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
const scan = () => {
|
|
|
|
if (!connected.value) {
|
|
|
|
if (!maxRetriesReached.value) {
|
|
|
|
getStatus()
|
|
|
|
retries.value++
|
|
|
|
window.setTimeout(scan, 1000)
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
2022-04-25 13:07:38 +00:00
|
|
|
} else {
|
|
|
|
retries.value = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const rescan = () => {
|
|
|
|
retries.value = 0
|
|
|
|
scan()
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
const playing = computed(() => Boolean(song.value?.playback_state === 'Playing'))
|
2022-04-25 13:07:38 +00:00
|
|
|
const maxRetriesReached = computed(() => retries.value >= MAX_RETRIES)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-24 10:53:49 +00:00
|
|
|
onMounted(async () => {
|
2022-04-25 13:07:38 +00:00
|
|
|
// The app has just been initialized, check if we can get the user data with an already existing token
|
2022-11-16 17:57:38 +00:00
|
|
|
if (authService.hasApiToken()) {
|
2022-04-25 13:07:38 +00:00
|
|
|
authenticated.value = true
|
2022-07-24 10:53:49 +00:00
|
|
|
await init()
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2022-07-04 15:57:08 +00:00
|
|
|
@import "#/remote.scss";
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
|
|
body, html {
|
|
|
|
height: 100vh;
|
2022-07-04 16:10:58 +00:00
|
|
|
position: relative;
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
#wrapper {
|
2022-04-15 14:24:30 +00:00
|
|
|
height: 100vh;
|
|
|
|
background: var(--color-bg-primary);
|
|
|
|
|
|
|
|
.login-wrapper {
|
|
|
|
display: flex;
|
|
|
|
min-height: 100vh;
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
|
|
@include vertical-center();
|
|
|
|
}
|
|
|
|
|
|
|
|
.loader {
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
flex: 1;
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
p {
|
|
|
|
position: absolute;
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
padding-bottom: 40px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.signal {
|
|
|
|
border: 1px solid var(--color-highlight);
|
|
|
|
border-radius: 50%;
|
|
|
|
height: 0;
|
|
|
|
opacity: 0;
|
|
|
|
width: 50vw;
|
|
|
|
animation: pulsate 1.5s ease-out;
|
|
|
|
animation-iteration-count: infinite;
|
|
|
|
transform: translate(-50%, -50%);
|
|
|
|
}
|
|
|
|
|
|
|
|
.rescan {
|
|
|
|
margin-left: 5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
@keyframes pulsate {
|
|
|
|
0% {
|
|
|
|
transform: scale(.1);
|
|
|
|
opacity: 0.0;
|
|
|
|
}
|
|
|
|
50% {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
100% {
|
|
|
|
transform: scale(1.2);
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main {
|
2022-04-25 13:07:38 +00:00
|
|
|
height: 100vh;
|
2022-04-15 14:24:30 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: space-between;
|
|
|
|
text-align: center;
|
|
|
|
z-index: 1;
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
.none, .details {
|
|
|
|
flex: 1;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-around;
|
|
|
|
}
|
|
|
|
|
|
|
|
.details {
|
|
|
|
.info {
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: space-around;
|
|
|
|
}
|
|
|
|
|
|
|
|
.cover {
|
|
|
|
margin: 0 auto;
|
|
|
|
width: calc(70vw + 4px);
|
|
|
|
height: calc(70vw + 4px);
|
|
|
|
border-radius: 50%;
|
|
|
|
border: 2px solid var(--color-text-primary);
|
|
|
|
background-position: center center;
|
|
|
|
background-size: cover;
|
|
|
|
background-color: var(--color-bg-secondary);
|
|
|
|
}
|
|
|
|
|
|
|
|
.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;
|
|
|
|
margin: 0 auto 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.artist {
|
|
|
|
font-size: 5vmin;
|
|
|
|
margin: 0 auto 6px;
|
|
|
|
opacity: .5;
|
|
|
|
}
|
|
|
|
|
|
|
|
.album {
|
|
|
|
font-size: 4vmin;
|
|
|
|
opacity: .5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
footer {
|
|
|
|
height: 18vh;
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-around;
|
|
|
|
align-items: center;
|
|
|
|
border-top: 1px solid rgba(255, 255, 255, .1);
|
2022-07-24 10:53:49 +00:00
|
|
|
padding: 1rem 0;
|
2022-04-15 14:24:30 +00:00
|
|
|
font-size: 5vmin;
|
|
|
|
|
|
|
|
a {
|
|
|
|
color: var(--color-text-primary);
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
opacity: .8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-24 10:53:49 +00:00
|
|
|
.favorite.yep {
|
|
|
|
color: var(--color-maroon);
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.prev, .next {
|
|
|
|
font-size: 6vmin;
|
|
|
|
}
|
|
|
|
|
|
|
|
.play-pause {
|
|
|
|
width: 16vmin;
|
|
|
|
height: 16vmin;
|
|
|
|
border: 1px solid var(--color-text-primary);
|
|
|
|
border-radius: 50%;
|
|
|
|
font-size: 7vmin;
|
2022-04-25 13:07:38 +00:00
|
|
|
display: flex;
|
|
|
|
place-content: center;
|
|
|
|
place-items: center;
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-24 10:53:49 +00:00
|
|
|
.fa-play {
|
2022-04-15 14:24:30 +00:00
|
|
|
margin-left: 4px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
#wrapper.standalone {
|
2022-04-15 14:24:30 +00:00
|
|
|
padding-top: 20px;
|
|
|
|
|
2022-04-25 13:07:38 +00:00
|
|
|
main {
|
2022-04-15 14:24:30 +00:00
|
|
|
.details {
|
|
|
|
.cover {
|
|
|
|
width: calc(80vw - 4px);
|
|
|
|
height: calc(80vw - 4px);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.footer {
|
|
|
|
height: 20vh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.volume {
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
width: 20px;
|
|
|
|
display: inline-block;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#volumeSlider {
|
|
|
|
height: 80px;
|
|
|
|
position: absolute;
|
|
|
|
bottom: calc(50% + 26px);
|
|
|
|
}
|
|
|
|
|
|
|
|
.noUi-target {
|
|
|
|
background: var(--color-text-primary);
|
|
|
|
border-radius: 4px;
|
|
|
|
border: 0;
|
|
|
|
box-shadow: none;
|
|
|
|
left: 7px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.noUi-base {
|
|
|
|
height: calc(100% - 16px);
|
|
|
|
border-radius: 4px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.noUi-vertical {
|
|
|
|
width: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.noUi-vertical .noUi-handle {
|
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
|
|
|
border-radius: 50%;
|
|
|
|
border: 0;
|
2022-04-25 13:07:38 +00:00
|
|
|
left: -12px;
|
2022-04-15 14:24:30 +00:00
|
|
|
top: 0;
|
|
|
|
background: var(--color-highlight);
|
|
|
|
box-shadow: none;
|
|
|
|
|
|
|
|
&::after, &::before {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.noUi-connect {
|
|
|
|
background: transparent;
|
|
|
|
box-shadow: none;
|
|
|
|
}
|
|
|
|
</style>
|