2025-08-02 00:52:13 +02:00
|
|
|
<script lang="ts">
|
|
|
|
import QueueSlider from "$lib/components/QueueSlider.svelte"
|
2025-08-02 03:54:26 +02:00
|
|
|
import { type Song } from "$lib/types"
|
|
|
|
import { onMount } from "svelte"
|
|
|
|
import type { FetchError } from "$lib/types"
|
2025-08-02 06:07:14 +02:00
|
|
|
import { getQueueSongs, getStreamingUrl, triggerPlayNext } from "$lib/utils.js"
|
2025-08-02 05:04:30 +02:00
|
|
|
import Error from "$lib/components/Error.svelte"
|
2025-08-02 00:52:13 +02:00
|
|
|
|
2025-08-02 03:54:26 +02:00
|
|
|
let { data } = $props()
|
|
|
|
|
|
|
|
let queueSongs = $state<Song[]>([])
|
2025-08-02 06:07:14 +02:00
|
|
|
let playingIndex = $state<number>(0)
|
2025-08-02 03:54:26 +02:00
|
|
|
let returnError = $state<FetchError | null>()
|
|
|
|
|
2025-08-02 06:07:14 +02:00
|
|
|
let currentPlaying = $derived<Song>(queueSongs[playingIndex])
|
|
|
|
let audioController = $state<HTMLAudioElement>()
|
|
|
|
|
|
|
|
async function playOnEnd() {
|
|
|
|
let url = await getStreamingUrl(currentPlaying.uuid)
|
|
|
|
if (audioController) {
|
|
|
|
audioController.src = url
|
2025-08-02 09:19:39 +02:00
|
|
|
await audioController.play()
|
2025-08-02 06:07:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-08-02 03:54:26 +02:00
|
|
|
onMount(async () => {
|
|
|
|
let songs, index
|
|
|
|
;[returnError, songs, index] = await getQueueSongs(data.roomId)
|
|
|
|
|
|
|
|
queueSongs = songs
|
|
|
|
playingIndex = index
|
2025-08-02 09:19:39 +02:00
|
|
|
})
|
2025-08-02 06:07:14 +02:00
|
|
|
|
2025-08-02 09:19:39 +02:00
|
|
|
$effect(() => {
|
|
|
|
playOnEnd()
|
2025-08-02 03:54:26 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
async function playNext() {
|
|
|
|
let songs, index
|
|
|
|
;[returnError, songs, index] = await triggerPlayNext(data.roomId)
|
|
|
|
|
|
|
|
if (returnError) return
|
|
|
|
|
2025-08-02 05:04:30 +02:00
|
|
|
queueSongs = songs
|
2025-08-02 03:54:26 +02:00
|
|
|
playingIndex = index
|
|
|
|
}
|
2025-08-02 00:52:13 +02:00
|
|
|
</script>
|
|
|
|
|
2025-08-02 05:04:30 +02:00
|
|
|
{#if returnError}
|
|
|
|
<Error {returnError} />
|
|
|
|
{:else}
|
|
|
|
<div class="flex w-full flex-col items-center justify-center p-4 lg:p-10">
|
|
|
|
<QueueSlider {queueSongs} {playingIndex} />
|
|
|
|
<button onclick={playNext}>Next</button>
|
2025-08-02 09:19:39 +02:00
|
|
|
<audio controls autoplay bind:this={audioController} onended={playNext}></audio>
|
2025-08-02 05:04:30 +02:00
|
|
|
</div>
|
|
|
|
{/if}
|