A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
1
import {state} from '../main.js';1
import {state, SWIPE_THRESHOLD} from '../main.js';2
import {http, $lang} from '../utils.js';3
import VButton from '../element/button.js';4
import VIcon from '../element/icon.js';
13
title: null,14
interval: null,15
resume: false,16
state16
open: false17
};18
},19
components: {
21
VIcon22
},23
watch: {24
station: function(station) {24
station(value) {25
this.playing = false;26
this.error = false;27
if(station !== null) {27
if(value !== null) {28
this.loading = true;29
this.title = null;30
this.updateMediaSession();31
state.open = true;31
this.open = true;32
}33
},34
open(value) {35
state.open = value;36
}37
},38
methods: {
112
}113
await this.fetchSong();114
}, 10000);115
},116
onTouchStart(event) {117
this.touch = event.changedTouches[0];118
this.target = event.target;119
},120
onTouchEnd(event) {121
const touch = event.changedTouches[0];122
const diff = {123
x: touch.pageX - this.touch.pageX,124
y: touch.pageY - this.touch.pageY125
};126
const angle = Math.atan(diff.x / diff.y) * (180 / Math.PI);127
const index = state.tabs.indexOf(state.tab);128
if(this.open) {129
if(Math.abs(diff.y) >= SWIPE_THRESHOLD) {130
if(diff.y > 0 && angle >= -30 && angle <= 30) {131
this.open = false;132
}133
}134
return;135
}136
if(Math.abs(diff.y) >= SWIPE_THRESHOLD) {137
if(Math.abs(diff.y) >= SWIPE_THRESHOLD) {138
if(!this.open && this.target === this.$refs.button) {139
if(diff.y < 0 && angle >= -30 && angle <= 30) {140
this.open = true;141
}142
}143
}144
}145
}146
},147
created() {148
document.body.addEventListener('touchstart', this.onTouchStart);149
document.body.addEventListener('touchend', this.onTouchEnd);150
},151
onUnmounted() {152
document.body.removeEventListener('touchstart', this.onTouchStart);153
document.body.removeEventListener('touchend', this.onTouchEnd);154
},155
computed: {115
transform() {116
return {117
'transform': `translate(0, ${state.open ? 0 : 100}vh)`118
};119
},156
opacity() {157
return {122
'opacity': `${state.open ? 1 : 0}`,123
'pointer-events': `${state.open ? 'all' : 'none'}`158
'opacity': `${this.open === true ? 1 : 0}`,159
'pointer-events': `${this.open === true ? 'all' : 'none'}`160
};161
}162
},163
template: `164
<div class="z-30">165
<div130
@click="state.open = false"131
class="fixed top-0 bottom-0 left-0 right-0 bg-black/60 transition-opacity duration-300 ease-in-out"166
@click="open = false"167
class="fixed top-0 bottom-0 left-0 right-0 bg-black/60 transition-modal"168
:style="opacity"169
>170
</div>171
<div136
v-if="station"137
ref="button"138
class="fixed w-[18vw] h-[18vw] max-w-[80px] max-h-[80px] bg-zinc-900 rounded-md bottom-5 right-4 z-40 cursor-pointer shadow-2xl overflow-hidden"139
@click="state.open = !state.open"140
>141
<img142
v-if="station.icon"143
:src="station.icon"144
:alt="station.name"145
class="w-full h-full object-contain select-none pointer-events-none"146
>147
<v-icon148
v-else149
id="access-point"150
size="38px"151
class="text-gray-400 pointer-events-none"152
></v-icon>153
</div>154
<div155
class="w-full flex flex-col bg-black fixed left-0 right-0 top-0 h-[100vh] px-4 transition-transform duration-300 ease-in-out"156
:style="transform"172
ref="modal"173
class="w-full max-w-[1200px] mx-auto flex flex-col bg-black fixed left-0 right-0 top-[100vh] h-[100vh] px-4 sm:px-10 transition-modal"174
:class="{ 'modal-active': open }"175
>176
<audio177
v-if="station"
191
<div class="w-full h-[98px] py-6 flex gap-4 justify-between">192
<v-button193
icon="chevron-down"176
@click="state.open = false"194
@click="open = false"195
></v-button>196
<v-button197
icon="cast"198
></v-button>199
</div>182
<div v-if="station" class="flex gap-8 items-center relative flex-col sm:flex-row pt-12">183
<div class="w-[75vw] h-[75vw] min-w-[75vw] bg-zinc-900 rounded-lg overflow-hidden z-10">200
<div class="flex gap-8 items-center flex-col">201
<div202
ref="button"203
class="h-[75vw] max-h-[400px] aspect-square bg-zinc-900 rounded-lg overflow-hidden z-10 fixed right-[50%] translate-x-[50%] translate-y-[100%] bottom-[calc(100vh-98px)] transition-modal"204
:class="{ 'slide-active': !open, 'slide-hidden': !station }"205
@click="open = true"206
>207
<img185
v-if="station.icon"208
v-if="station?.icon"209
:src="station.icon"210
:alt="station.name"188
class="w-full h-full object-contain select-none"211
class="w-full h-full object-contain select-none pointer-events-none"212
>213
<v-icon214
v-else215
id="access-point"216
size="38px"194
class="text-gray-400"217
class="text-gray-400 pointer-events-none"218
></v-icon>219
</div>220
<div class="h-[75vw] max-h-[400px]"></div>221
<div198
class="flex flex-col flex-1 z-10 min-w-0 max-w-[75vw]"222
v-if="station"223
class="flex flex-col flex-1 z-10 min-w-0 w-[75vw] max-w-[400px] transition-modal"224
:style="opacity"225
>200
<p class="text-xl font-semibold text-white pb-1 overflow-hidden text-ellipsis whitespace-nowrap select-none pointer-events-none text-center sm:text-left">226
<p class="text-xl font-semibold text-white pb-1 overflow-hidden text-ellipsis whitespace-nowrap select-none pointer-events-none text-center">227
{{station.name}}228
</p>203
<p class="text-md text-gray-400 overflow-hidden text-ellipsis whitespace-nowrap select-none pointer-events-none text-center sm:text-left">229
<p class="text-md text-gray-400 overflow-hidden text-ellipsis whitespace-nowrap select-none pointer-events-none text-center">230
{{title ?? $lang('player.no-song-title')}}231
</p>232
</div>
234
<v-button235
:icon="[ error ? 'alert-circle' : (loading ? 'rotate-clockwise' : (playing ? 'player-pause' : 'player-play')) ]"236
:title="[ error ? $lang('global.error') : (playing ? $lang('global.pause') : $lang('global.play')) ]"237
size="28px"238
:animation="[ error ? '' : (loading ? 'animate-spin' : '') ]"239
class="bg-zinc-900 hover:bg-white focus:ring-[6px] ring-white/10 !min-w-[64px] !min-h-[64px]"240
@click="setPlaying(!playing)"
3
const TYPES = {};5
export default {6
props: ['text', 'icon', 'title', 'active', 'animation'],6
props: ['text', 'icon', 'title', 'active', 'animation', 'size'],7
emits: ['click'],8
components: {9
VIcon
18
<v-icon19
v-if="icon"20
:id="icon"21
:size="size"22
:class="[ active ? 'text-gray-100' : 'text-gray-400', text ? 'group-hover:text-gray-700' : '', animation ]"23
class="hover:text-gray-800"24
></v-icon>
7
import VFavorites from './page/favorites.js';8
import VAccount from './page/account.js';10
const VERSION = '{{version}}';11
const SWIPE_THRESHOLD = 70;10
export const VERSION = '{{version}}';11
export const SWIPE_THRESHOLD = 70;12
export const TOKEN_NAME = 'verbal-token';14
export const state = {
123
};124
const angle = Math.atan(diff.x / diff.y) * (180 / Math.PI);125
const index = state.tabs.indexOf(state.tab);127
if(state.open) {128
if(Math.abs(diff.y) >= SWIPE_THRESHOLD) {129
if(diff.y > 0 && angle >= -30 && angle <= 30) {130
state.open = false;131
}132
}126
if(state.open === true) {127
return;128
}129
if(Math.abs(diff.x) >= SWIPE_THRESHOLD) {
134
state.tab = state.tabs[index + 1];135
}136
}143
if(Math.abs(diff.y) >= SWIPE_THRESHOLD) {144
if(Math.abs(diff.y) >= SWIPE_THRESHOLD) {145
if(!state.open && this.target === this.$refs.player.$refs.button) {146
if(diff.y < 0 && angle >= -30 && angle <= 30) {147
state.open = true;148
}149
}150
}151
}137
}138
},139
computed: {
35
100% { width: 0% }36
}38
.transition-modal {39
transition: all ease-in-out 250ms;40
}42
.modal-active {43
top: 0 !important;44
}46
.slide-hidden {47
opacity: 0;48
pointer-events: none;49
}51
.slide-active {52
height: 22vw !important;53
bottom: 16px !important;54
transform: translate(0, 0) !important;55
right: 16px !important;56
max-height: 100px !important;57
cursor: pointer;58
box-shadow: 0 4px 16px 4px rgba(0, 0, 0, 0.5);59
}61
@font-face {62
font-family: 'Inter';63
font-style: normal;