Read the room

Meaning: To understand the mood or feelings of the people around you and behave accordingly.

Example: He should have read the room before making that joke.