@
@
@scripty2017-12-18 19:17:46
Node.js
@scripty, 2017-12-18 19:17:46

How to leave all connected rooms?

Implemented a mini chat at the bottom of each page as in VK. There are names of friends, when clicked is made socket.join(id диалога в базе этих двух юзеров);. Therefore, when you click on another friend, the same thing will happen, only the connection to the previous room will remain. Tell me how, on the server side of node.js, before connecting to a room, leave all the rooms to which the user is connected? I searched on the Internet and in the Socket.io documentation, but I did not find a sensible example.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Skibin, 2017-12-18
_

Option 1:
Send "disconnect" before connecting to another chat
Option2.
https://socket.io/docs/server-api/#socket-rooms - all rooms to which the current socket is connected, and then select unnecessary ones and make a leave for them

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question