automatic rejoin on reload or server restart

This commit is contained in:
Vinzenz Schroeter 2024-04-13 19:50:37 +02:00
parent feaf96c10e
commit 64a61ef2b3
11 changed files with 141 additions and 58 deletions

View file

@ -3,8 +3,9 @@ import useWebSocket from 'react-use-websocket';
import {useEffect} from 'react';
import {statusTextForReadyState} from './statusTextForReadyState.tsx';
export default function Controls({playerId}: {
playerId: string
export default function Controls({playerId, logout}: {
playerId: string,
logout: () => void
}) {
const url = new URL(import.meta.env.VITE_TANK_CONTROLS_URL);
url.searchParams.set('playerId', playerId);
@ -13,7 +14,7 @@ export default function Controls({playerId}: {
getWebSocket,
readyState
} = useWebSocket(url.toString(), {
shouldReconnect: () => true,
onError: logout
});
const socket = getWebSocket();