Rotate camera if player is about to go out of its view?

I updated my answer.