How to leave all rooms that the socket is connecte

2019-02-12 01:02发布

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..

1条回答
地球回转人心会变
2楼-- · 2019-02-12 01:31

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);

查看更多
登录 后发表回答