2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2022-05-04 22:41:47 +00:00
|
|
|
<span id="volume" class="volume control">
|
2022-07-15 07:23:55 +00:00
|
|
|
<icon
|
|
|
|
v-if="level === 'muted'"
|
|
|
|
:icon="faVolumeMute"
|
|
|
|
fixed-width
|
|
|
|
role="button"
|
|
|
|
tabindex="0"
|
|
|
|
title="Unmute"
|
|
|
|
@click="unmute"
|
|
|
|
/>
|
|
|
|
<icon
|
|
|
|
v-else
|
|
|
|
:icon="level === 'discreet' ? faVolumeLow : faVolumeHigh"
|
|
|
|
fixed-width
|
|
|
|
role="button"
|
|
|
|
tabindex="0"
|
|
|
|
title="Mute"
|
|
|
|
@click="mute"
|
|
|
|
/>
|
|
|
|
|
2022-04-15 14:24:30 +00:00
|
|
|
<input
|
2022-05-12 17:03:06 +00:00
|
|
|
id="volumeInput"
|
2022-05-04 22:41:47 +00:00
|
|
|
class="plyr__volume"
|
2022-04-15 14:24:30 +00:00
|
|
|
max="10"
|
2022-05-12 17:03:06 +00:00
|
|
|
role="slider"
|
2022-04-15 14:24:30 +00:00
|
|
|
step="0.1"
|
|
|
|
title="Volume"
|
|
|
|
type="range"
|
2022-05-04 22:41:47 +00:00
|
|
|
@change="broadcastVolume"
|
|
|
|
@input="setVolume"
|
2022-04-15 14:24:30 +00:00
|
|
|
>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
2022-07-15 07:23:55 +00:00
|
|
|
import { faVolumeHigh, faVolumeLow, faVolumeMute } from '@fortawesome/free-solid-svg-icons'
|
2022-04-15 17:00:08 +00:00
|
|
|
import { ref } from 'vue'
|
2022-04-24 08:50:45 +00:00
|
|
|
import { playbackService, socketService } from '@/services'
|
2022-07-15 07:23:55 +00:00
|
|
|
import { preferenceStore as preferences } from '@/stores'
|
|
|
|
import { eventBus } from '@/utils'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-15 07:23:55 +00:00
|
|
|
const level = ref<'muted' | 'discreet' | 'loud'>()
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const mute = () => {
|
2022-04-24 08:50:45 +00:00
|
|
|
playbackService.mute()
|
2022-07-15 07:23:55 +00:00
|
|
|
level.value = 'muted'
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const unmute = () => {
|
2022-04-24 08:50:45 +00:00
|
|
|
playbackService.unmute()
|
2022-07-15 07:23:55 +00:00
|
|
|
level.value = preferences.volume < 3 ? 'discreet' : 'loud'
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const setVolume = (e: InputEvent) => {
|
|
|
|
const volume = parseFloat((e.target as HTMLInputElement).value)
|
2022-04-24 08:50:45 +00:00
|
|
|
playbackService.setVolume(volume)
|
2022-07-15 07:23:55 +00:00
|
|
|
setLevel(volume)
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-15 07:23:55 +00:00
|
|
|
const setLevel = (volume: number) => (level.value = volume === 0 ? 'muted' : volume < 3 ? 'discreet' : 'loud')
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
/**
|
|
|
|
* Broadcast the volume changed event to remote controller.
|
|
|
|
*/
|
|
|
|
const broadcastVolume = (e: InputEvent) => {
|
2022-04-24 08:50:45 +00:00
|
|
|
socketService.broadcast('SOCKET_VOLUME_CHANGED', parseFloat((e.target as HTMLInputElement).value))
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
2022-07-15 07:23:55 +00:00
|
|
|
|
|
|
|
eventBus.on('KOEL_READY', () => setLevel(preferences.volume))
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
#volume {
|
|
|
|
position: relative;
|
|
|
|
z-index: 99;
|
|
|
|
|
|
|
|
// More tweaks
|
|
|
|
[type=range] {
|
2022-07-15 07:23:55 +00:00
|
|
|
margin: 0 0 0 8px;
|
2022-04-15 14:24:30 +00:00
|
|
|
transform: rotate(270deg);
|
|
|
|
transform-origin: 0;
|
|
|
|
position: absolute;
|
2022-07-15 07:23:55 +00:00
|
|
|
bottom: -22px;
|
2022-04-15 14:24:30 +00:00
|
|
|
border: 14px solid var(--color-bg-primary);
|
|
|
|
border-left-width: 30px;
|
|
|
|
z-index: 0;
|
|
|
|
width: 140px;
|
|
|
|
border-radius: 4px;
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover [type=range] {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
2022-07-15 07:23:55 +00:00
|
|
|
[role=button] {
|
2022-04-15 14:24:30 +00:00
|
|
|
position: relative;
|
|
|
|
z-index: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@media only screen and (max-width: 768px) {
|
|
|
|
display: none !important;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|