Answer the question
In order to leave comments, you need to log in
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
You answered your own question.
io.on('connection', socket => {
socket.on('disconnect', () => {
// ваш код
})
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question