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