initGame() changes
This commit is contained in:
@@ -60,7 +60,7 @@
|
||||
showWaitPage = true;
|
||||
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",
|
||||
headers : {'Content-Type': 'application/json'},
|
||||
body : JSON.stringify({
|
||||
@@ -70,16 +70,21 @@
|
||||
isGameIsWithInvitation : options.isSomeoneIsInvited
|
||||
})
|
||||
});
|
||||
const responseFromServer = await responseWhenGrantToken;
|
||||
const responseInjson = await responseFromServer.json();
|
||||
const token : string = responseInjson.token;
|
||||
console.log("status : " + response.status);
|
||||
const responseBody = await response.json();
|
||||
const token : string = responseBody.token;
|
||||
showWaitPage = false;
|
||||
console.log("status : " + responseFromServer.status);
|
||||
if (responseFromServer.status != 200)
|
||||
if (response.ok && token)
|
||||
{
|
||||
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");
|
||||
errorMessage = responseInjson.message;
|
||||
errorMessage = responseBody.message;
|
||||
showError = true;
|
||||
options.reset(user.username);
|
||||
setTimeout(() => {
|
||||
@@ -88,14 +93,6 @@
|
||||
errorMessage = "";
|
||||
}, 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) =>
|
||||
|
||||
Reference in New Issue
Block a user