This quote means that being able to see and laugh at the humor in a difficult situation helps us to cope and prevents us from feeling too sad. It is saying that our ability to recognize and find the humor in a tough situation (the joke which is on oneself) gives us relief and keeps our hearts from breaking. In other words, irony can be a powerful tool for dealing with difficult situations.