In this answer I have explained how to manage connectionIds. The question was specific so I will summarize.
OnConnected
and OnReconnected
add user with connectionId (plus grup info if you have), but just check connectionId uniqueness (One user have many connectionIds at the same time).
OnDisconnected
remove record/row with that connectionId. If user doesn't have any record in this group,that's mean user left the group. If user does not have any record left at all, that's mean user has disconnected.
You should use shared storage for keeping this records. Because if you have more than 1 instance, they need to share same data. I suggest you to use database, but you can use cache or session(if it's shared like redis).
I hope this help.