socket = io();

const form = document.querySelector("#form");


socket.on("connect", () => {
    socket.on("players",(socket) => {
        data = new Map(JSON.parse(socket));
        console.log(data);
        const player = document.querySelector("#players")
        player.innerHTML=''
        data.forEach((it,key) => {
            let p = document.createElement("p");
            p.innerHTML = `joueur : ${key}   points : ${it}`;
            player.appendChild(p);
        })
    })
})




form.addEventListener('submit',function(e){
    e.preventDefault();
    value = form.querySelector("input[name=pseudo]").value;

    if(value)
    {
        perso = {
            id: value,
            nom: socket.id,
            test: "coucou"
        }
        data = JSON.stringify(perso);
        console.log(`[Client Side] inputValue : ${data}`);
        socket.emit('testing',data);
    }
})



