Spaces:
Runtime error
Runtime error
File size: 692 Bytes
8d109db 3b048e4 8d109db d989d94 8d109db |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import { onDestroy } from "svelte";
import { writable, type Writable } from "svelte/store";
import type { RoomResponse } from '$lib/types';
import { PUBLIC_API_BASE } from '$env/static/public';
const INTERVAL = 10000
export function useRooms(): Writable<RoomResponse[]> {
const roomsStorage = writable<RoomResponse[]>([]);
const interval = setInterval(
() => {
refreshRooms().then((rooms) => roomsStorage.set(rooms))
}, INTERVAL);
refreshRooms().then((rooms) => roomsStorage.set(rooms))
onDestroy(() => {
clearInterval(interval);
});
return roomsStorage
}
async function refreshRooms() {
return fetch(PUBLIC_API_BASE + '/rooms').then((res) => res.json());
} |