@johnhenry/browsermesh-discovery 0.0.2 → 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 +1 -1
- package/src/discovery.mjs +7 -2
package/package.json
CHANGED
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 = () =>
|
|
536
|
-
|
|
538
|
+
ws.onerror = () => {
|
|
539
|
+
clearTimeout(timeoutId);
|
|
540
|
+
reject(new Error('WebSocket connection failed'));
|
|
541
|
+
};
|
|
537
542
|
});
|
|
538
543
|
|
|
539
544
|
ws.onmessage = (event) => {
|