It's certainly not "black magic" even though sometimes it seems like it 😊
Realtime is a TCP based publish/subscribe (aka pub/sub) messaging system where publishers send messages to channels and subscribers receive messages from the channels they have subscribed (a publisher can also be a subscriber and vice-versa).
So when you connect to Realtime and subscribe to channel "chat-room-1" you're manifesting your "interest" in all messages sent through this channel.
When a publisher connected to Realtime sends a message to channel "chat-room-1", the Realtime server will send a copy of the message to all interested connections, so each subscriber will receive a copy of the message.
Even though sometimes it seems publisher P is sending messages directly to subscriber S, in fact this is what's happening under-the-hood:
Publisher P => Realtime server => Subscriber S
As you figured out by now, the most interesting behaviour that comes with pub/sub is that it's dead easy to perform a massive broadcast to millions of subscribers. You simply publish a message to a channel and all Realtime servers will work together to deliver your message to the connected subscribers, even if they are in five different continents.