.join()-ing a swarm will execute the callback once the announcement to the bittorrent network went through. However, during the announcement-process peers are already added as they appear, making the network basically usable. To clarify the state I suggest the implementation of a "connection-state".
What I am thinking about looks something like this:
swarm.on('connection-state-change', state => {
switch (state) {
case 'disconnected': break; // Not connected
case 'connecting': break; // Join called but no peer connected
case 'connected-one-peer': break; // One peer is connected but not connected to wider network
case 'connected-many-peer': break; // Connected to more than one peer
case 'connected-wellknown-peer': break; // Connected to a well-known-peer - aka. the internet.
}
})
swarm.connectionState; // Current state available as property
swarm.join(); // No callback ... necessary?!
.join()
-ing a swarm will execute the callback once the announcement to the bittorrent network went through. However, during the announcement-process peers are already added as they appear, making the network basically usable. To clarify the state I suggest the implementation of a "connection-state".What I am thinking about looks something like this: