fix: websockets and vite

This commit is contained in:
Mat12143 2025-08-02 05:16:37 +02:00
parent 426a2706d8
commit 419fde1a10
4 changed files with 17 additions and 17 deletions

View file

@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import type { Suggestion } from "$lib/types" import type { Suggestion } from "$lib/types"
let { suggestions, roomId }: { suggestions: Suggestion[]; roomId: string } = $props() let { suggestions = $bindable(), roomId }: { suggestions: Suggestion[]; roomId: string } = $props()
async function vote(idx: number, amount: number, songId: string) { async function vote(idx: number, amount: number, songId: string) {
suggestions[idx].upvote += amount suggestions[idx].upvote += amount
@ -15,7 +15,7 @@
{/if} {/if}
{#each suggestions as sug, idx} {#each suggestions as sug, idx}
<div class="shadow-md hover:bg-indigo-400 duration-100 bg-indigo-500 flex h-[80px] w-full flex-row gap-2 rounded border-2 border-indigo-600 p-2"> <div class="flex h-[80px] w-full flex-row gap-2 rounded border-2 border-indigo-600 bg-indigo-500 p-2 shadow-md duration-100 hover:bg-indigo-400">
<div class="flex w-3/4 flex-row gap-2"> <div class="flex w-3/4 flex-row gap-2">
<img class="w-[60px] min-w-[60px] rounded" src={`https://lastfm.freetls.fastly.net/i/u/174s/${sug.image_id}.png`} alt="Song cover" /> <img class="w-[60px] min-w-[60px] rounded" src={`https://lastfm.freetls.fastly.net/i/u/174s/${sug.image_id}.png`} alt="Song cover" />
<div class="text-white"> <div class="text-white">
@ -30,9 +30,9 @@
vote(idx, 1, sug.uuid) vote(idx, 1, sug.uuid)
}}>👍</button }}>👍</button
> >
<p class="text-white font-semibold">{sug.upvote}</p> <p class="font-semibold text-white">{sug.upvote}</p>
<button <button
class="hover:scale-150 duration-100" class="duration-100 hover:scale-150"
onclick={() => { onclick={() => {
vote(idx, -1, sug.uuid) vote(idx, -1, sug.uuid)
}}><div class="rotate-180">👍</div></button }}><div class="rotate-180">👍</div></button

View file

@ -17,7 +17,6 @@
;[returnError, songs, index] = await getQueueSongs(data.roomId) ;[returnError, songs, index] = await getQueueSongs(data.roomId)
queueSongs = songs queueSongs = songs
playingIndex = index playingIndex = index
}) })

View file

@ -22,7 +22,6 @@
onMount(async () => { onMount(async () => {
// Join the room // Join the room
socket = io("/", { path: "/ws", transports: ["websocket"] })
let sugg, queue, index let sugg, queue, index
;[returnError] = await joinRoom(data.roomId) ;[returnError] = await joinRoom(data.roomId)
@ -42,6 +41,7 @@
playingIndex = index playingIndex = index
// Setup websocket connection // Setup websocket connection
socket = io("/", { path: "/ws", transports: ["websocket"] })
await socket.emitWithAck("join_room", { id: data.roomId }) await socket.emitWithAck("join_room", { id: data.roomId })
socket.on("queue_update", async (d) => { socket.on("queue_update", async (d) => {

View file

@ -1,21 +1,22 @@
import tailwindcss from '@tailwindcss/vite'; import tailwindcss from "@tailwindcss/vite"
import { sveltekit } from '@sveltejs/kit/vite'; import { sveltekit } from "@sveltejs/kit/vite"
import { defineConfig } from 'vite'; import { defineConfig } from "vite"
export default defineConfig({ export default defineConfig({
plugins: [tailwindcss(), sveltekit()], plugins: [tailwindcss(), sveltekit()],
server: { server: {
proxy: { proxy: {
'/api': { "/api": {
target: "http://backend:5000", target: "http://backend:5000",
changeOrigin: false, changeOrigin: false,
secure: false secure: false,
}, },
'/ws': { "/ws": {
target: "http://backend:5000", target: "http://backend:5000",
changeOrigin: false, changeOrigin: false,
secure: false secure: false,
} ws: true,
} },
} },
}); },
})