M
M
MR.TOSTER Gipard Valerievich2016-09-05 16:17:05
Node.js
MR.TOSTER Gipard Valerievich, 2016-09-05 16:17:05

socket.io how to use rooms?

There is a channel id that broadcasts messages.
There are users.
How to create a room for this channel?
And how to subscribe a user to receive messages from this channel/room?
How to send messages to a room so that they refer to everyone who is subscribed to it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Maslov, 2016-09-06
@zoceb

socket.join('room3'); // подключить клиента к комнате room3

determine how many people are in the room
const clients = io.sockets.adapter.rooms['room3'];
const numClients = (typeof clients !== 'undefined') ? Object.keys(clients.sockets).length : 0;

send a message to everyone in room3
io.in('room3').emit('user_join_chat', socket.id);

D
Dmitry Entelis, 2016-09-06
@DmitriyEntelis

socket.io/docs/rooms-and-namespaces
Or what exactly is the question?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question