There is a overriding method called OnDisconnect method. In this method take the conectionId who disconnect .from the Context you can get the disconnected user connectionId
Context.ConnectionId and make the user as offline.
public override Task OnDisconnected()
{
}
Hope this helps