diff --git a/truthseeker/routes/routes_ui.py b/truthseeker/routes/routes_ui.py index 9342c17..a439b70 100644 --- a/truthseeker/routes/routes_ui.py +++ b/truthseeker/routes/routes_ui.py @@ -24,7 +24,7 @@ def legal(): @routes_ui.route("/lobby/") def lobby(game_id): # rendered by the javascript client-side - return flask.render_template("lobby.html") + return flask.render_template("lobby.html",gameid=game_id) @routes_ui.route("/solo") def solo(): diff --git a/truthseeker/static/js/game_lobby.js b/truthseeker/static/js/game_lobby.js index c47c880..3cd4f50 100644 --- a/truthseeker/static/js/game_lobby.js +++ b/truthseeker/static/js/game_lobby.js @@ -1,5 +1,4 @@ // Display functions - /** * Display the invalid rounds count message element, by removing the hidden CSS class. * @@ -296,8 +295,8 @@ function getChallengeModeRoundsCount() { * @returns the code of the room */ function getRoomCode() { - //FIXME get the real room code - return "ABCDEF"; + gameid = document.getElementById("gameid") + return gameid; } // Lobby initialization @@ -317,6 +316,21 @@ function getRoomCode() { *

*/ function initLobby() { + + gameid = getRoomCode(); + socket = io({ + auth:{ + game_id: gameid + } + }); + + socket.on("connect", () => { + console.log("Connected !") + }) + + socket.on("playersjoin", (err) => { + console.log(`Failed to connect to socket: ${err.message}`); + }); if (hasJoinedRoom()) { displayRoomView(); if (isRoomOwner()) { diff --git a/truthseeker/static/js/game_start_page.js b/truthseeker/static/js/game_start_page.js index 8cc83b1..53f2b5a 100644 --- a/truthseeker/static/js/game_start_page.js +++ b/truthseeker/static/js/game_start_page.js @@ -125,7 +125,7 @@ function createMultiPlayerRoom() { hideInvalidInputErrorMessage(); - startGame() + startGame(); } function joinMultiPlayerRoom() { @@ -135,7 +135,7 @@ function joinMultiPlayerRoom() { hideInvalidInputErrorMessage(); - //TODO: code to join multi player game + joinGame(); } /** @@ -211,12 +211,36 @@ function changeTheme() { async function startGame(){ username = document.getElementById("game_username").value; let data = {} - data["username"] = username - await makeAPIRequest("createGame",data); + data["username"] = username; + response = makeAPIRequest("createGame",data); + response.then((value) => { + if (value["error"] != 0){ + alert(value["msg"]); + } + else{ + gameid = value["game_id"] + window.location.href = "/lobby/" + gameid; + } + }); + } async function joinGame(){ - username = document.getElementById("game_username").value(); - gameid = document.getElementById("game_room_code").value(); + username = document.getElementById("game_username").value; + gameid = document.getElementById("game_room_code").value; + console.log(username); + data = {} + data["username"] = username; + data["game_id"] = gameid; + response = makeAPIRequest("joinGame",data); + response.then((value)=>{ + console.log(value); + if (value["error"] != 0){ + //alert(value["msg"]); + } + else{ + //window.location.href = "/lobby/" + gameid; + } + }) } // Set event listeners diff --git a/truthseeker/templates/index.html b/truthseeker/templates/index.html index cf6dc02..2eff2bd 100644 --- a/truthseeker/templates/index.html +++ b/truthseeker/templates/index.html @@ -72,8 +72,8 @@ Mentions légales - + diff --git a/truthseeker/templates/lobby.html b/truthseeker/templates/lobby.html index 5e52138..e7602f2 100644 --- a/truthseeker/templates/lobby.html +++ b/truthseeker/templates/lobby.html @@ -61,10 +61,10 @@ - + - +