Spaces:
Runtime error
Runtime error
File size: 768 Bytes
8d109db |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import { onDestroy } from "svelte";
import { writable, type Writable } from "svelte/store";
import { useRoom } from "./useRoom";
enum ConnectionStatus {
"closed" = "closed",
"authenticating" = "authenticating",
"unavailable" = "unavailable",
"failed" = "failed",
"open" = "open",
"connecting" = "connecting",
}
type TConnectionStatus = keyof typeof ConnectionStatus
export function useConnectionStatus(): Writable<TConnectionStatus> {
const room = useRoom();
const statusStorage = writable<TConnectionStatus>(ConnectionStatus.closed);
const unsubscribeConnection = room.subscribe("connection", (status: TConnectionStatus) => {
statusStorage.set(status);
});
onDestroy(() => {
unsubscribeConnection();
});
return statusStorage;
}
|