Fix bug with reconnect not using the right gameId and password

This commit is contained in:
Mitchell McCaffrey 2020-07-17 12:43:54 +10:00
parent fc76e3690a
commit 1ac95e0a0f

View File

@ -16,6 +16,8 @@ import NetworkedParty from "../network/NetworkedParty";
import Session from "../helpers/Session"; import Session from "../helpers/Session";
const session = new Session();
function Game() { function Game() {
const { id: gameId } = useParams(); const { id: gameId } = useParams();
const { const {
@ -23,7 +25,6 @@ function Game() {
password, password,
setAuthenticationStatus, setAuthenticationStatus,
} = useContext(AuthContext); } = useContext(AuthContext);
const [session] = useState(new Session());
// Handle authentication status // Handle authentication status
useEffect(() => { useEffect(() => {
@ -40,7 +41,7 @@ function Game() {
session.off("authenticationSuccess", handleAuthSuccess); session.off("authenticationSuccess", handleAuthSuccess);
session.off("authenticationError", handleAuthError); session.off("authenticationError", handleAuthError);
}; };
}, [setAuthenticationStatus, session]); }, [setAuthenticationStatus]);
// Handle session errors // Handle session errors
const [peerError, setPeerError] = useState(null); const [peerError, setPeerError] = useState(null);
@ -57,7 +58,7 @@ function Game() {
return () => { return () => {
session.off("error", handlePeerError); session.off("error", handlePeerError);
}; };
}, [session]); }, []);
// Handle connection // Handle connection
const [connected, setConnected] = useState(false); const [connected, setConnected] = useState(false);
@ -77,12 +78,12 @@ function Game() {
session.off("connected", handleConnected); session.off("connected", handleConnected);
session.off("disconnected", handleDisconnected); session.off("disconnected", handleDisconnected);
}; };
}, [session]); }, []);
// Join game // Join game
useEffect(() => { useEffect(() => {
session.joinParty(gameId, password); session.joinParty(gameId, password);
}, [gameId, password, session]); }, [gameId, password]);
// A ref to the Konva stage // A ref to the Konva stage
// the ref will be assigned in the MapInteraction component // the ref will be assigned in the MapInteraction component