diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts index 29fc5fc..6450247 100644 --- a/frontend/src/lib/utils.ts +++ b/frontend/src/lib/utils.ts @@ -1,11 +1,7 @@ -import { get_coords } from "./gps" +import { get_coords, type Coordinates } from "./gps" import { parseSong, parseSuggestion, type FetchError, type Song, type Suggestion } from "./types" -export const joinRoom = async function(roomId: string): Promise<[FetchError | null, string]> { - let { coords, error } = await get_coords() - if (error != null) return [{ code: 400, message: "Cannot join the room due to GPS error" }, ""] - if (coords == null) return [{ code: 400, message: "Cannot join the room due to GPS error" }, ""] - +export const joinRoom = async function (roomId: string, coords: Coordinates): Promise<[FetchError | null, string]> { let res = await fetch(`/api/join?room=${roomId}&lat=${coords.latitude}&lon=${coords.longitude}`) if (res.status != 200) { @@ -15,7 +11,7 @@ export const joinRoom = async function(roomId: string): Promise<[FetchError | nu return [null, "test"] } -export const getSuggestions = async function(roomId: string): Promise<[FetchError | null, Suggestion[]]> { +export const getSuggestions = async function (roomId: string): Promise<[FetchError | null, Suggestion[]]> { let resp = await fetch("/api/room/suggestions?room=" + roomId) if (resp.status != 200) { @@ -36,7 +32,7 @@ export const getSuggestions = async function(roomId: string): Promise<[FetchErro return [null, suggestions] } -export const getQueueSongs = async function(roomId: string): Promise<[FetchError | null, Song[], number]> { +export const getQueueSongs = async function (roomId: string): Promise<[FetchError | null, Song[], number]> { let resp = await fetch("/api/queue?room=" + roomId) if (resp.status != 200) { return [{ code: 400, message: "Failed to load queue songs" }, [], 0] @@ -54,7 +50,7 @@ export const getQueueSongs = async function(roomId: string): Promise<[FetchError return [null, songs, playingId] } -export const triggerPlayNext = async function(roomId: string): Promise<[FetchError | null, Song[], number]> { +export const triggerPlayNext = async function (roomId: string): Promise<[FetchError | null, Song[], number]> { let resp = await fetch("/api/queue/next?room=" + roomId, { method: "POST" }) if (resp.status != 200) { @@ -71,7 +67,7 @@ export const triggerPlayNext = async function(roomId: string): Promise<[FetchErr return [null, songs, json["index"]] } -export const getStreamingUrl = async function(uuid: string) { +export const getStreamingUrl = async function (uuid: string) { let resp = await fetch("/api/song/audio?song=" + uuid) let json = await resp.json() diff --git a/frontend/src/routes/room/[id]/+page.svelte b/frontend/src/routes/room/[id]/+page.svelte index 95acdf5..839d5a7 100644 --- a/frontend/src/routes/room/[id]/+page.svelte +++ b/frontend/src/routes/room/[id]/+page.svelte @@ -32,7 +32,7 @@ } let sugg, queue, index - ;[returnError] = await joinRoom(data.roomId, coords.latitude, coords.longitude) + ;[returnError] = await joinRoom(data.roomId, coords) if (returnError) { return }