mafintosh / discovery-swarm

A network swarm that uses discovery-channel to find peers
MIT License
375 stars 57 forks source link

Clarify connection state. #41

Open martinheidegger opened 6 years ago

martinheidegger commented 6 years ago

.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?!
DennisSchwartz commented 6 years ago

I would very much appreciate this as well! +1