9
votes

I am using socket.io,can I detect the disconnect reason from disconnect event ? I can see in log files like this

info: transport end (booted) info: transport end (close timeout) info: transport end (error)

I want to get the reason (booted,close timeout,error) I will use like this:

socket.on('disconnect', function(){
   console.log('User 1 disconnected because '+reason);
});

Can I get the reason ?

EDIT:I found the solution

socket.on('disconnect', function(reason){
   console.log('User 1 disconnected because '+reason);
});
1
If you found your solution, post it as a answer and accept and mark it as solved; this is for people in the future looking for the same answer. - GiveMeAllYourCats
Is there a specific reason for the user leaving the page? - Mohamed Hafez

1 Answers

13
votes
socket.on('disconnect', function(reason){
   console.log('User 1 disconnected because '+reason);
});

This is the solution.

Possible reasons for disconnect are now documented.