merge: websockets & refactoring
This commit is contained in:
commit
7020a334a2
8 changed files with 218 additions and 26 deletions
1
frontend/src/lib/util.ts
Normal file
1
frontend/src/lib/util.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export type FetchError = { code: number, message: string }
|
|
@ -7,6 +7,7 @@
|
|||
import SuggestionList from "$lib/components/SuggestionList.svelte"
|
||||
import { getQueueSongs, getSuggestions, joinRoom } from "$lib/utils.js"
|
||||
import type { FetchError } from "$lib/types.js"
|
||||
import { io } from "socket.io-client"
|
||||
|
||||
let { data } = $props()
|
||||
|
||||
|
@ -29,10 +30,11 @@
|
|||
}
|
||||
|
||||
;[returnError, sugg] = await getSuggestions(data.roomId)
|
||||
if (returnError) {
|
||||
return
|
||||
}
|
||||
if (returnError) return
|
||||
|
||||
// Setup websocket connection
|
||||
let socket = io("/", { path: "/ws" })
|
||||
await socket.emitWithAck("join_room", { id: data.roomId })
|
||||
;[returnError, queue, index] = await getQueueSongs(data.roomId)
|
||||
if (returnError) {
|
||||
return
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { error, type Load, type ServerLoad } from "@sveltejs/kit"
|
||||
import type { PageLoad } from "./$types"
|
||||
import type { FetchError } from "$lib/util"
|
||||
import { parseSuggestion, type Suggestion } from "$lib/types"
|
||||
|
||||
export const load: PageLoad = async ({ params }) => {
|
||||
if (params.id) {
|
||||
|
|
8
frontend/src/routes/zesty/wsio/+page.svelte
Normal file
8
frontend/src/routes/zesty/wsio/+page.svelte
Normal file
|
@ -0,0 +1,8 @@
|
|||
<script lang="ts">
|
||||
import { io } from "socket.io-client"
|
||||
const socket = io("/", { path: "/ws" })
|
||||
socket.on("connect", () => {
|
||||
console.log("successfully connected to socket.io server")
|
||||
socket.emit("join_room", { id: "gang" })
|
||||
})
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue