add room scanner logic
This commit is contained in:
parent
244e49d311
commit
0c34586358
5 changed files with 45 additions and 56 deletions
|
@ -3,8 +3,9 @@
|
|||
let { room }: { room: Room } = $props()
|
||||
</script>
|
||||
|
||||
<button
|
||||
<a
|
||||
class="flex w-82 cursor-pointer flex-row items-center rounded-md border border-dark-pine-muted bg-light-pine-overlay p-3 hover:bg-dark-pine-base/20 dark:bg-dark-pine-overlay hover:dark:bg-light-pine-base/20"
|
||||
href="/room/{room.id}"
|
||||
>
|
||||
<div class="flex flex-row">
|
||||
{room.name}
|
||||
|
@ -12,7 +13,7 @@
|
|||
</div>
|
||||
<div class="grow"></div>
|
||||
<div class="flex flex-row items-center gap-2">
|
||||
<div class="font-mono">64m</div>
|
||||
<div class="font-mono">{Math.round(room.distance)}m</div>
|
||||
<div class="rounded bg-light-pine-blue px-2 py-0.5 text-dark-pine-text dark:bg-dark-pine-blue">Join</div>
|
||||
</div>
|
||||
</button>
|
||||
</a>
|
||||
|
|
|
@ -37,11 +37,12 @@ export const parseSuggestion = async function(sugg: any): Promise<Suggestion> {
|
|||
}
|
||||
|
||||
const RoomSchema = z.object({
|
||||
id: z.string(),
|
||||
id: z.number(),
|
||||
name: z.string(),
|
||||
private: z.boolean(),
|
||||
coords: z.tuple([z.number(), z.number()]),
|
||||
range: z.number().int()
|
||||
coords: z.object({ latitude: z.number(), longitude: z.number() }),
|
||||
range: z.number().int(),
|
||||
distance: z.number()
|
||||
})
|
||||
export type Room = z.infer<typeof RoomSchema>
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue