Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to leave all rooms that the socket is connected to at one go in Socket.IO [closed]

I have some code where a socket is made to join multiple rooms. At some point in the code, i want to leave all the rooms at one go, without disconnecting the socket. Is it possible to do this? If yes, then how can i do this? Thanks in advance..

I am using socket.IO

like image 951
Seeker Avatar asked Jun 05 '12 10:06

Seeker


People also ask

Does Socket.IO auto reconnect?

In the first case, the Socket will automatically try to reconnect, after a given delay.

How do you check if Socket.IO client is connected or not?

You can check the socket. connected property: var socket = io. connect(); console.


1 Answers

That's possible. You can leave rooms without disconnecting the socket. The socket disconnects only when you make a call to socket.disconnect().

To do this you'll have to maintain a list of rooms each client joins and leaves. To leave all rooms iterate through this list and make a call to socket.leave(roomname);

like image 167
almypal Avatar answered Nov 16 '22 00:11

almypal