Skip to content

Sometimes, a custom property on socket object is undefined inside disconnect event handler #4082

Answered by bartversluijs
awesomelike asked this question in Q&A
Discussion options

You must be logged in to vote

Are you sure that register is triggered for that socket client before it disconnects?
For debugging purposes, you could log the socket.id when the register function is called and check if that socket.id has a user ID defined on disconnect.

I think the register event is never triggered, and thus mo user ID is set for that client, before it disconnects.

Another approach would be to save data in a Map, with the socket ID as key and data (like the user ID) as value and removing the key on disconnect. This way, you’ll never be dependent on the socket.io library to handle custom properties.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by awesomelike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants