@johnhenry/browsermesh-discovery 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnhenry/browsermesh-discovery",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "DHT, peer discovery, naming, swarm coordination, and stealth networking for BrowserMesh",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
@@ -19,7 +19,7 @@
19
19
  "directory": "packages/browsermesh-discovery"
20
20
  },
21
21
  "peerDependencies": {
22
- "@johnhenry/browsermesh-primitives": ">=0.0.0"
22
+ "@johnhenry/browsermesh-primitives": ">=0.0.1 <1.0.0"
23
23
  },
24
24
  "scripts": {
25
25
  "test": "node --import ./test/_setup-globals.mjs --test test/*.test.mjs"
package/src/discovery.mjs CHANGED
@@ -518,6 +518,7 @@ export class RelayStrategy extends DiscoveryStrategy {
518
518
  this.#ws = ws;
519
519
 
520
520
  await new Promise((resolve, reject) => {
521
+ const timeoutId = setTimeout(() => reject(new Error('WebSocket connection timeout')), 10000);
521
522
  ws.onopen = async () => {
522
523
  try {
523
524
  const regMsg = { type: 'register', podId: this.#podId };
@@ -527,13 +528,17 @@ export class RelayStrategy extends DiscoveryStrategy {
527
528
  regMsg.signature = signature;
528
529
  }
529
530
  ws.send(JSON.stringify(regMsg));
531
+ clearTimeout(timeoutId);
530
532
  resolve();
531
533
  } catch (err) {
534
+ clearTimeout(timeoutId);
532
535
  reject(err);
533
536
  }
534
537
  };
535
- ws.onerror = () => reject(new Error('WebSocket connection failed'));
536
- setTimeout(() => reject(new Error('WebSocket connection timeout')), 10000);
538
+ ws.onerror = () => {
539
+ clearTimeout(timeoutId);
540
+ reject(new Error('WebSocket connection failed'));
541
+ };
537
542
  });
538
543
 
539
544
  ws.onmessage = (event) => {