John
John

Reputation: 3

Is possible do things when user leave from Socket.io connection?

I'm using node js and socket.io, I need to manage the users when they leave from application, what is the best practice to do this?

Upvotes: 0

Views: 49

Answers (1)

viniciuswebdev
viniciuswebdev

Reputation: 1346

Try this:

io.sockets.on('connection', function (socket) {
  socket.on('disconnect', function () {
    console.log(socket.id);
  });

  socket.on('connect', function () {
    console.log(socket.id);
  });
});

You can get the socket.id when users enter and leave from your app. I hope it is useful

Upvotes: 1

Related Questions