N
N
nionly_quantum2021-01-12 18:00:04
JavaScript
nionly_quantum, 2021-01-12 18:00:04

Socket.io + node js Rooms How to split rooms on socket.io side?

Hello everyone, such a problem, I wrote a chat on socket.io + node js.
Divided into rooms using the usual checks in the blade.
All rooms are displayed in site/chats
Separate room site/chats/chat_number
The problem is that if any user writes to the chat, it will be displayed for everyone.
All IDs of chats and messages are stored in the database, I tried to check for IDs, it doesn’t work, maybe I didn’t do it right.
(Attached a screenshot to check that works!)
But this is not a solution, because this is done for a single chat, we checked that if the chat_id that we get by class from the blade will be equal to this chat ID, that is, 1 to 1, then let prints, when the socket wants to load this "Printing..." in another chat, the check fails.
And I don’t know how to substitute here, I can’t just do chat_id === chat_id otherwise it will load the same thing from the blade and it will display this word and messages exactly everywhere.
I'm on my second day and can't decide...
5ffdb9637ad47728675316.png5ffdb9697c533215048918.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
StasEx, 2021-01-13
@StasEx

room id on the server and on the client must match.
When sending a message from the client, you need to attach the ID of the current chat -> socket.id or site/chats//:id
Then this ID must be compared with the list of room IDs on the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question