Answers for "socket.io do sockets leave rooms on disconnect"

0

socket.io do sockets leave rooms on disconnect

/* Upon disconnection, sockets leave all the channels they were part of 
automatically, and no special teardown is needed on your part.

You can fetch the rooms the Socket was in by listening to the 
disconnecting event: */

io.on('connection', socket => {
  socket.on('disconnecting', () => {
    console.log(socket.rooms); // the Set contains at least the socket ID
  });

  socket.on('disconnect', () => {
    // socket.rooms.size === 0
  });
});
Posted by: Guest on May-09-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language