D
D
Dyadko_Orest2020-11-17 19:13:08
JavaScript
Dyadko_Orest, 2020-11-17 19:13:08

How to track a message from a large number of dialogs using socket.io?

Hey! I want to implement a chat page for my application. The logic will be as follows: when the user goes to the chat page, all his dialogs are displayed to him. After all the dialogs have been displayed by dialogId, I connect them all in sockets. My question is:
how can I catch a message if someone writes to me from my dialogs?

1) I get the Id of all dialogs
2) I connect to the rooms using these Ids
3) How can I track if someone writes me a message from any of these dialogs?
front end

useEffect(() => {
    const dialogsId = dialogList.map(value => value.dialogId)
   	socket.emit('joinDialogs',  dialogsId);
  }, [dialogList]);

backend
socket.on('joinDialogs', (dialogsId) => {
    socket.join(dialogsId);
  });

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