3 ms·
When you join a room the room name is hashed and you join a WebTorrent swarm based on that hash. So it's a collection of WebRTC peers who are connected to eacho
by chr15m 8y ago
When you join a room the room name is hashed and you join a WebTorrent swarm based on that hash. So it's a collection of WebRTC peers who are connected to eachother based upon the shared hash of the room name. Not every peer is connected to every other peer.
So "when a new room is created, this has to be broadcast to all users" is not quite right. A new swarm is created when a user joins a room-hash for the first time and anybody who joins that same room-hash will be introduced to the same swarm. People who have not joined the room-hash will not be part of the p2p swarm.
Currently the hash-based WebRTC signalling that WebTorrent does to introduce peers is quite centralized but the actual communication channels are decentralized. The communication layer is implemented as a WebTorrent "extension protocol" extension. This is the same model dreamtime: https://github.com/chr15m/dreamtime https://github.com/chr15m/dreamtime
You are correct that every chat line is broadcast to everyone in the same swarm. In fact, every message is re-broadcast multiple times redundantly by every peer who receives it for the first time, because the WebRTC swarm can be fragmented. Not every peer can directly see every other peer so we must re-broadcast everything to make sure everyone sees each line.
So basically for each room you have a set of peers (browsers) connected together loosely with WebRTC data links and messages between them are sent multiple times redundantly.
Thank you very much for your interest and for trying it out.