fix(multi): add periodic heartbeat every 20s to prevent players being pruned in lobby

This commit is contained in:
jessy-david-dev
2026-04-17 15:20:42 +02:00
parent e86f65d6af
commit 2e2d22fc39
+13
View File
@@ -107,6 +107,19 @@ export function useMultiGame() {
}; };
} }
// Heartbeat toutes les 20s pour rester dans la room (évite le pruning)
useEffect(() => {
const id = setInterval(() => {
if (!sseCodeRef.current || !ssePidRef.current) return;
fetch(`/api/rooms/${sseCodeRef.current}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action: "heartbeat", playerId: ssePidRef.current }),
}).catch(() => {});
}, 20_000);
return () => clearInterval(id);
}, []);
// Quand le tab redevient visible : heartbeat immédiat pour rafraîchir l'état // Quand le tab redevient visible : heartbeat immédiat pour rafraîchir l'état
useEffect(() => { useEffect(() => {
function onVisible() { function onVisible() {