When you see your friend and their dog from a distance, ask them to stop while your dog is still calm. Ask your dog to sit/stay. Have the other dog approach. When your dog gets up and starts to act excited, your friend and the other dog should stop, turn around and walk away.