feat(ui): FRO-34 Lobby (#21)

Started with Lobby Component

Co-authored-by: LQ63 <lkhermann@web.de>
Co-authored-by: Janis <janis-e@gmx.de>
Reviewed-on: #21
Reviewed-by: Janis <janis-e@gmx.de>
Co-authored-by: lq64 <lq@blackhole.local>
Co-committed-by: lq64 <lq@blackhole.local>
This commit is contained in:
2025-12-14 15:10:27 +01:00
committed by Janis
parent f0623dbfb2
commit bb6355d9ed
24 changed files with 408 additions and 140 deletions

View File

@@ -1,7 +1,8 @@
import {useIngame} from "@/composables/useIngame.ts";
import type {GameInfo, LobbyInfo, TieInfo, TrumpInfo, WonInfo} from "@/types/GameTypes.ts";
import router from "@/router";
const api = window.__RUNTIME_CONFIG__?.API_URL;
const api = "localhost:9000"
// ---------- Types ---------------------------------------------------------
@@ -33,10 +34,13 @@ let ws: WebSocket | null = null;
const pending = new Map<string, PendingEntry>();
const handlers = new Map<string, HandlerFn>();
const uState = useIngame();
let uState: ReturnType<typeof useIngame> | null = null;
let heartbeatTimer: ReturnType<typeof setInterval> | null = null;
export function initWebSocket(ingameStore: ReturnType<typeof useIngame>) {
uState = ingameStore;
}
let defaultHandler: HandlerFn | null = null;
function uuid(): string {
@@ -70,6 +74,10 @@ function stopHeartbeat() {
}
function setupSocketHandlers(socket: WebSocket) {
if (!uState) {
console.error("[WS] WebSocket module not initialized with Pinia store!");
return;
}
socket.onmessage = async (raw) => {
console.debug("[WS] MESSAGE:", raw.data);
@@ -100,7 +108,11 @@ function setupSocketHandlers(socket: WebSocket) {
}
if (state && stateData) {
uState.setIngame(state, stateData);
console.debug("[WS] State change:", state, stateData);
if(uState) {
console.debug("[WS] State change cascade:", state, stateData);
uState.setIngame(state, stateData);
}
}
// Server event → handler branch
@@ -155,7 +167,7 @@ function setupSocketHandlers(socket: WebSocket) {
}
// You redirect here — if you dont want auto reconnect, keep as is.
location.href = "/mainmenu";
router.replace("/");
};
}