initGame() changes

This commit is contained in:
LuckyLaszlo
2023-01-09 06:51:13 +01:00
parent d53b0998f0
commit 42e3e148b4

View File

@@ -60,7 +60,7 @@
showWaitPage = true; showWaitPage = true;
const matchOptions = pong.computeMatchOptions(options); const matchOptions = pong.computeMatchOptions(options);
const responseWhenGrantToken = fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/ticket`, { const response = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/ticket`, {
method : "POST", method : "POST",
headers : {'Content-Type': 'application/json'}, headers : {'Content-Type': 'application/json'},
body : JSON.stringify({ body : JSON.stringify({
@@ -70,16 +70,21 @@
isGameIsWithInvitation : options.isSomeoneIsInvited isGameIsWithInvitation : options.isSomeoneIsInvited
}) })
}); });
const responseFromServer = await responseWhenGrantToken; console.log("status : " + response.status);
const responseInjson = await responseFromServer.json(); const responseBody = await response.json();
const token : string = responseInjson.token; const token : string = responseBody.token;
showWaitPage = false; showWaitPage = false;
console.log("status : " + responseFromServer.status); if (response.ok && token)
if (responseFromServer.status != 200)
{ {
console.log(responseInjson); watchGameStateInterval = setInterval(watchGameState, watchGameStateIntervalRate);
pong.init(matchOptions, options, gameAreaId, token);
hiddenGame = false;
}
else
{
console.log(responseBody);
console.log("On refuse le ticket"); console.log("On refuse le ticket");
errorMessage = responseInjson.message; errorMessage = responseBody.message;
showError = true; showError = true;
options.reset(user.username); options.reset(user.username);
setTimeout(() => { setTimeout(() => {
@@ -88,14 +93,6 @@
errorMessage = ""; errorMessage = "";
}, 5000); }, 5000);
} }
else if (token)
{
watchGameStateInterval = setInterval(watchGameState, watchGameStateIntervalRate);
pong.init(matchOptions, options, gameAreaId, token);
hiddenGame = false;
}
// TODO: Un "else" peut-être ? Si pas de token on fait un truc ?
// Si on ne rentre pas dans le else if, du coup il ne se passe rien.
} }
const initGameForInvitedPlayer = async(invitation : any) => const initGameForInvitedPlayer = async(invitation : any) =>