diff --git a/cryptide_project/server/server.js b/cryptide_project/server/server.js index beeca22..725ea1a 100644 --- a/cryptide_project/server/server.js +++ b/cryptide_project/server/server.js @@ -52,6 +52,15 @@ io.on('connection', (socket) => { } io.to(room).emit("new player", map.get(room)) + const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value })) + const playerJson = JSON.stringify(playerArray); + io.to(socket.id).emit("request lobbies", playerJson) + }) + + socket.on("request lobbies", () => { + const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value })) + const playerJson = JSON.stringify(playerArray); + io.to(socket.id).emit("request lobbies", playerJson) }) @@ -63,6 +72,9 @@ io.on('connection', (socket) => { } } io.to(room).emit("new player", map.get(room)) + const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value })) + const playerJson = JSON.stringify(playerArray); + io.to(socket.id).emit("request lobbies", playerJson) }) diff --git a/cryptide_project/src/Components/LobbyContainer.tsx b/cryptide_project/src/Components/LobbyContainer.tsx index 9bb30fc..8a184f3 100644 --- a/cryptide_project/src/Components/LobbyContainer.tsx +++ b/cryptide_project/src/Components/LobbyContainer.tsx @@ -7,6 +7,7 @@ import { useNavigate } from 'react-router-dom'; import Modal from 'react-bootstrap/Modal'; import Offcanvas from 'react-bootstrap/Offcanvas'; import Button from 'react-bootstrap/Button'; +import { socket } from '../SocketConfig'; interface LobbyContainerProps { roomNum : string @@ -37,6 +38,7 @@ const LobbyContainer: React.FC = ({roomNum, HeadPlayer, nbP } else{ if (nbPlayer < 6) { + socket.off("request lobbies") navigate(dest); } else { handleShow() diff --git a/cryptide_project/src/Components/NavBar.tsx b/cryptide_project/src/Components/NavBar.tsx index 3118e17..7d42f5b 100644 --- a/cryptide_project/src/Components/NavBar.tsx +++ b/cryptide_project/src/Components/NavBar.tsx @@ -32,10 +32,6 @@ function AppNavbar({changeLocale}) { const navigate = useNavigate(); - useEffect(() => { - console.log(user) - }, [user]) - function navigateToProfile(){ navigate("/profile") } diff --git a/cryptide_project/src/Pages/EndGame.tsx b/cryptide_project/src/Pages/EndGame.tsx index 8728d12..3298e52 100644 --- a/cryptide_project/src/Pages/EndGame.tsx +++ b/cryptide_project/src/Pages/EndGame.tsx @@ -118,8 +118,6 @@ function EndGame() { } const theme = useTheme(); - console.log(winner) - console.log(indices) let indicenull = false; if (indices.length == 0){ diff --git a/cryptide_project/src/Pages/Lobbies.tsx b/cryptide_project/src/Pages/Lobbies.tsx index a73ad56..0ffd2ad 100644 --- a/cryptide_project/src/Pages/Lobbies.tsx +++ b/cryptide_project/src/Pages/Lobbies.tsx @@ -7,22 +7,31 @@ import { useTheme } from '../Style/ThemeContext'; import LobbyContainer from '../Components/LobbyContainer'; import Player from '../model/Player'; import User from '../model/User'; +import { socket } from '../SocketConfig'; +import JSONParser from '../JSONParser'; +import Person from '../model/Person'; +class LobbyDataProps { + roomNum : string + headPlayer: Player + nbPlayer: number + + constructor(roomNum: string, player: Player, nbPlayer: number){ + this.roomNum = roomNum + this.headPlayer = player + this.nbPlayer = nbPlayer + } +} + function Lobbies() { const theme=useTheme(); - const lobbyData = [ - { roomNum: '63194', headPlayer: new User('1', 'Emma', '', null, null), nbPlayer: 6 }, - { roomNum: '81194', headPlayer: new User('2', 'Ray', '', null, null), nbPlayer: 1 }, - { roomNum: '22194', headPlayer: new User('3', 'Norman', '', null, null), nbPlayer: 4 }, - { roomNum: 'null', headPlayer: new User('null', 'tnull', '', null, null), nbPlayer: 1 }, - { roomNum: '111111', headPlayer: new User('11', '1111111', '', null, null), nbPlayer: 1 }, - { roomNum: '741852963', headPlayer: new User('3', 'Guest_741852963', '', null, null), nbPlayer: 6 }, - ]; + const [lobbyData, setLobbyData] = useState([]) + const [searchTerm, setSearchTerm] = useState(''); const filteredLobbies = lobbyData.filter((lobby) => @@ -30,7 +39,19 @@ function Lobbies() { lobby.headPlayer.pseudo.toLowerCase().includes(searchTerm.toLowerCase()) ); - + useEffect(() => { + socket.emit("request lobbies") + + + socket.on("request lobbies", (map) => { + const jsonMap = JSON.parse(map) + const tmpTab: LobbyDataProps[]=[] + for(const item of jsonMap){ + tmpTab.push(new LobbyDataProps(item.key, JSONParser.JSONToPlayer(item.value[0]), item.value.length)) + } + setLobbyData(tmpTab ) + }) + }) return(
diff --git a/cryptide_project/src/Pages/Play.tsx b/cryptide_project/src/Pages/Play.tsx index 3615a13..5c28831 100644 --- a/cryptide_project/src/Pages/Play.tsx +++ b/cryptide_project/src/Pages/Play.tsx @@ -115,10 +115,6 @@ function Play() { socket.emit("lobby created") } - useEffect(() => { - console.log(user) - }, [user]) - function launchMastermind(){ const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(3, 30) setPersonData(choosenPerson) diff --git a/cryptide_project/src/Pages/Profile.tsx b/cryptide_project/src/Pages/Profile.tsx index 1e96b92..1a73e44 100644 --- a/cryptide_project/src/Pages/Profile.tsx +++ b/cryptide_project/src/Pages/Profile.tsx @@ -84,7 +84,6 @@ const Profile = () => { // Verification de la phrase if (confirmationPhrase.toLowerCase() === 'supprimer mon compte') { console.log('Compte supprimé !'); - console.log(user); if(user!= null){ const pseudo = user.pseudo;