add room scanner logic

This commit is contained in:
Simone Tesini 2025-08-02 10:06:31 +02:00
parent 244e49d311
commit 0c34586358
5 changed files with 45 additions and 56 deletions

View file

@ -1,16 +1,21 @@
import { get_coords } 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 resp = await fetch("/api/join?room=" + roomId)
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" }, ""]
if (resp.status != 200) {
let res = await fetch(`/api/join?room=${roomId}&lat=${coords.latitude}&lon=${coords.longitude}`)
if (res.status != 200) {
return [{ code: 400, message: "Cannot join the room" }, ""]
}
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) {
@ -31,7 +36,7 @@ export const getSuggestions = async function (roomId: string): Promise<[FetchErr
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]
@ -49,7 +54,7 @@ export const getQueueSongs = async function (roomId: string): Promise<[FetchErro
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) {
@ -66,7 +71,7 @@ export const triggerPlayNext = async function (roomId: string): Promise<[FetchEr
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()