Socket.io detect disconnect reason

Issue

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);
});

Solution

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

This is the solution.

Possible reasons for disconnect are now documented.

Answered By – user2997295

Answer Checked By – Dawn Plyler (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.