add socketio in forntendt
This commit is contained in:
parent
57e6acb1ee
commit
a5b1943030
5 changed files with 17 additions and 206 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 }
|
|
@ -5,6 +5,7 @@
|
|||
import { parseSong, parseSuggestion, type Suggestion, type Song } from "$lib/types.js"
|
||||
import { onMount } from "svelte"
|
||||
import SuggestionList from "$lib/components/SuggestionList.svelte"
|
||||
import { io } from "socket.io-client"
|
||||
|
||||
let { data } = $props()
|
||||
|
||||
|
@ -25,9 +26,10 @@
|
|||
}
|
||||
|
||||
// Setup websocket connection
|
||||
let socket = io("/", { path: "/ws" })
|
||||
await socket.emitWithAck("join_room", { id: data.roomId })
|
||||
|
||||
// Get room suggestions
|
||||
|
||||
resp = await fetch("/api/room/suggestions?room=" + data.roomId)
|
||||
|
||||
if (resp.status != 200) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue