N
N
Nwton2016-06-21 20:50:09
Node.js
Nwton, 2016-06-21 20:50:09

How to detect that a socket.io user has disconnected?

Is there any way to know that the user has disconnected, for example by closing the browser or tab?
It is clear that you can periodically send a request and check for a response. But does socket.io itself have a ready-made solution, like io.on('connection'..., only on disconnect?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Kayun, 2016-06-21
@Nwton

You answered your own question.

io.on('connection', socket => {
  socket.on('disconnect', () => {
    // ваш код
  })
})

Everything is written in the documentation socket.io/docs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question