diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/search-page.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/search-page.js | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/search-page.js b/packages/meshbay-hub/src/meshbay_hub/static/search-page.js index 5ac3ab6..e61dcd8 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/search-page.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/search-page.js @@ -17,6 +17,7 @@ import { transfers } from './transfers.js'; const BATCH_SIZE = 3; const MAX_POOL_SIZE = 3; const DEBOUNCE_MS = 200; +const SEARCH_TIMEOUT = 10000; const SEARCH_VIDEO_ROOT = '__search__'; const SEARCH_AUDIO_ROOT = '__search__'; const SEARCH_PHOTO_ROOTS = ['__search_photos__']; @@ -58,9 +59,22 @@ class ConnectionPool { const transport = new window.MeshBayTransport(this._hubBase, live); transport.onNeedToken = async () => (await ensureFreshToken()) || token; - await transport.connect( - nodesData.nodes[0].node_id, live, groupId, null, null, bundleKey, - username, userId, null); + let timer; + try { + await Promise.race([ + transport.connect( + nodesData.nodes[0].node_id, live, groupId, null, null, bundleKey, + username, userId, null), + new Promise((_, reject) => { + timer = setTimeout(() => reject(new Error('Connection timeout')), SEARCH_TIMEOUT); + }), + ]); + clearTimeout(timer); + } catch (e) { + clearTimeout(timer); + try { transport.close(); } catch {} + throw e; + } let gek = null; if (transport.gekRaw && window.MeshBayCrypto) { @@ -106,9 +120,16 @@ async function fetchGroupIndex(groupId, token, bundleKey, username, userId) { transport.onNeedToken = async () => (await ensureFreshToken()) || token; try { - const ack = await transport.connect( - nodesData.nodes[0].node_id, live, groupId, null, null, bundleKey, - username, userId, null); + let timer; + const ack = await Promise.race([ + transport.connect( + nodesData.nodes[0].node_id, live, groupId, null, null, bundleKey, + username, userId, null), + new Promise((_, reject) => { + timer = setTimeout(() => reject(new Error('Connection timeout')), SEARCH_TIMEOUT); + }), + ]); + clearTimeout(timer); const indexMsg = await transport.fetchIndex(); const roots = { |