diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/connection-pool.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/connection-pool.js | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/connection-pool.js b/packages/meshbay-hub/src/meshbay_hub/static/connection-pool.js index 15d352a7..8a616c2a 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/connection-pool.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/connection-pool.js @@ -58,6 +58,12 @@ const SEARCH_MAX_MS = 30000; * opened fine from the sidebar. A refusal naming a state of this browser (a * code, a passphrase, a device) is the same from every node and stops the * walk; `not_hosted`, a timeout or a failed connection moves on. + * + * So does a node this device refuses to reach on the local network (Android + * 17, Chrome 155: transport.js localNetworkRefused): another node of the group + * may be elsewhere. Search gives up long before connect() would name it, so it + * is read from the connection when giving up, and it is what is thrown when + * no node answered: the page says what to change rather than "unreachable". */ async function connectToGroup(hubBase, groupId, token, bundleKey, username, userId) { const nodesData = await hubFetch(`/v1/groups/${groupId}/nodes`, { token }); @@ -65,6 +71,7 @@ async function connectToGroup(hubBase, groupId, token, bundleKey, username, user const live = (await ensureFreshToken()) || token; let lastErr = null; + let lanErr = null; for (const n of nodesData.nodes) { const transport = new window.MeshBayTransport(hubBase, live); transport.onNeedToken = async () => (await ensureFreshToken()) || token; @@ -96,11 +103,16 @@ async function connectToGroup(hubBase, groupId, token, bundleKey, username, user } catch (e) { stopTimers(); lastErr = e; + if (!e.reason && await transport.localNetworkRefused()) { + lastErr = new Error('This device refused to reach the local network'); + lastErr.reason = 'local_network_blocked'; + } try { transport.close(); } catch {} + if (lastErr.reason === 'local_network_blocked') { lanErr = lastErr; continue; } if (e.reason && e.reason !== 'not_hosted') throw e; } } - throw (lastErr || new Error('no node served this group')); + throw (lanErr || lastErr || new Error('no node served this group')); } // -- Connection pool ---------------------------------------------------------- |