RIO DE JANEIRO — “Edge of Desire,” a popular prime-time soap opera chronicling the transition of a transgender man, was about to start, and the residents at a shelter seemed oblivious to the sirens wailing outside and the cockroaches navigating a maze of dirty feet and popcorn bowls on the floor.

Gathering nightly to watch the television show in a graffiti-covered living room has become a ritual for the residents at Casa Nem, a refuge in downtown Rio de Janeiro for transgender and gender-nonconforming Brazilians, who view the story of Ivana’s transition to Ivan as the first dignified and nuanced portrayal of people like them in the country’s mainstream media.

“Look, she’s got a cute little beard now!” said Letthycia Siqueira, one of the residents, referring to the Ivan character. “You think they’ll give her a full mustache?”

The hit show, which draws about 50 million viewers per night, has also struck a broader chord in Brazil, at a time when gay and transgender issues have become more prominent in the country.