diff --git a/app/api/rooms/[code]/stream/route.ts b/app/api/rooms/[code]/stream/route.ts index 7f31a11..178272e 100644 --- a/app/api/rooms/[code]/stream/route.ts +++ b/app/api/rooms/[code]/stream/route.ts @@ -1,4 +1,4 @@ -// GET /api/rooms/[code]/stream — SSE : pousse l'état de la room en temps réel +// GET /api/rooms/[code]/stream - SSE : pousse l'état de la room en temps réel // Le client s'abonne une seule fois ; chaque saveRoom publie sur Redis et notifie ici. import { NextRequest } from "next/server"; @@ -47,7 +47,11 @@ export async function GET( sub.on("error", () => { clearInterval(keepAlive); - try { controller.close(); } catch { /* déjà fermé */ } + try { + controller.close(); + } catch { + /* déjà fermé */ + } sub.disconnect(); }); }, diff --git a/lib/useMultiGame.ts b/lib/useMultiGame.ts index a0539a2..a247402 100644 --- a/lib/useMultiGame.ts +++ b/lib/useMultiGame.ts @@ -97,25 +97,36 @@ export function useMultiGame() { es.onmessage = (e) => { try { setRoom(JSON.parse(e.data) as Room); - } catch { /* ignore */ } + } catch { + /* ignore */ + } }; es.onerror = () => { - // EventSource reconnecte automatiquement — pas besoin de gérer manuellement + // EventSource reconnecte automatiquement - pas besoin de gérer manuellement }; } // Quand le tab redevient visible : heartbeat immédiat pour rafraîchir l'état useEffect(() => { function onVisible() { - if (document.visibilityState === "visible" && sseCodeRef.current && ssePidRef.current) { + if ( + document.visibilityState === "visible" && + sseCodeRef.current && + ssePidRef.current + ) { fetch(`/api/rooms/${sseCodeRef.current}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ action: "heartbeat", playerId: ssePidRef.current }), + body: JSON.stringify({ + action: "heartbeat", + playerId: ssePidRef.current, + }), }) .then((r) => r.json()) - .then((d) => { if ((d as { room: Room }).room) setRoom((d as { room: Room }).room); }) + .then((d) => { + if ((d as { room: Room }).room) setRoom((d as { room: Room }).room); + }) .catch(() => {}); } }