LibRealmDetect-1.0 will attempt to detect the realm (or realm group for connected realms) a player is currently phased to when in a cross-realm group, through the use of automated /who queries done in the background.
Addons using this library can register to be notified when a realm change is detected, and what the name of this new realm is (or realmS, if it's a connected realm group).
Also... Due to the detection being based on /who queries, the information will not be available instantly at the moment of phasing, but rather when the /who results arrive and pass the minimum thresholds. Due to this reason, there is a moment when the name of the realm is unknown (of which the library will also notify). In case of low-populated (or dead!) realms, several queries may be needed. There's also the possibility that not enough local realm denizens are playing, so figuring out the realm's name is impossible. Guessing incorrectly can also happen, if enough cross-realmers are in the results (again, more likely on dead realms).