feat: currently playing + volume + seek position + toggle pause

This commit is contained in:
2024-11-24 23:35:14 +01:00
parent 7ae47d02f2
commit 2b471c6296
19 changed files with 1015 additions and 77 deletions

View File

@@ -5,8 +5,17 @@
import AppSidebar from '$lib/components/groove/AppSidebar.svelte';
import Footer from '$lib/components/groove/Footer.svelte';
import { ScrollArea } from '$lib/components/ui/scroll-area';
import { getPlayerState, setPlayerState } from '$lib/player.svelte';
import { onMount } from 'svelte';
let { children } = $props();
setPlayerState();
const player = getPlayerState();
onMount(() => {
return () => player.abort();
});
</script>
<ModeWatcher />

1
src/routes/+layout.ts Normal file
View File

@@ -0,0 +1 @@
export const ssr = false;

View File

@@ -1,4 +1,5 @@
import { PlayerClient } from '$lib/proto/player.client';
import { fail } from '@sveltejs/kit';
import { protoTransport } from '../../hooks.server';
import type { Actions } from './$types';
@@ -6,11 +7,55 @@ export const actions = {
resume: async () => {
const client = new PlayerClient(protoTransport);
await client.resumeTrack({});
const response = await client.resumeTrack({});
return {
isPaused: response.response.isPaused
};
},
pause: async () => {
const client = new PlayerClient(protoTransport);
await client.pauseTrack({});
const response = await client.pauseTrack({});
return {
isPaused: response.response.isPaused
};
},
seek: async ({ request }) => {
const formData = await request.formData();
const position = formData.get('position')?.toString();
if (!position) {
return fail(400);
}
const client = new PlayerClient(protoTransport);
const response = await client.seekPosition({ position: BigInt(position) });
return {
position: response.response.position
};
},
volume: async ({ request }) => {
const formData = await request.formData();
const volume = formData.get('volume')?.toString();
if (!volume) {
return fail(400);
}
const client = new PlayerClient(protoTransport);
const response = await client.setVolume({
volume: parseFloat(volume)
});
return {
volume: response.response.volume
};
}
} satisfies Actions;

View File

@@ -1,13 +1,22 @@
import { PlayerClient } from '$lib/proto/player.client';
import { fail } from '@sveltejs/kit';
import { protoTransport } from '../../../hooks.server';
import type { Actions } from './$types';
import { serializable } from '$lib/proto';
import type { PlayTrackResponse } from '$lib/proto/player';
export const actions = {
play: async ({ params }) => {
const client = new PlayerClient(protoTransport);
await client.playTrack({
const response = await client.playTrack({
hash: params.hash
});
if (response.response.track === undefined) {
return fail(500);
}
return serializable<PlayTrackResponse>(response.response);
}
} satisfies Actions;