S
S
squadbrodyaga2020-11-11 21:56:54
Node.js
squadbrodyaga, 2020-11-11 21:56:54

How to deal with individual sockets in socket.io?

Hello.

There is such a Socket.io room in which there are two users. The first column always shows
its name (already implemented), but the second column should show the name of the second socket.
But I don't know how to transfer the username of one user to another, please help.

5fac2f2c0370d515698148.png

This is how I connect the socket to the room and assign my name to the player1 variable,
which is shown in the first column.

socket.on('JoinToBet', data => {
    socket.join(data.url)
    socket.emit('Players', {
       player1: session.user.login,
       player2: // как узнать???
    })
})

But now I want to create a player2 variable where the name of the second user will be

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question