Fall back to normal relay connections if multiplexer fails to connect

This commit is contained in:
Jonathan Staab 2023-03-29 11:13:15 -05:00
parent 3ba160c123
commit 681d36d443
3 changed files with 17 additions and 6 deletions

BIN
package-lock.json generated

Binary file not shown.

View File

@ -46,7 +46,7 @@
"lru-cache": "^7.18.3",
"nostr-tools": "^1.7.4",
"npm-run-all": "^4.1.5",
"paravel": "^0.1.10",
"paravel": "^0.1.11",
"qr-scanner": "^1.4.2",
"qrcode": "^1.5.1",
"ramda": "^0.28.0",

View File

@ -159,11 +159,22 @@ function getExecutor(urls) {
urls = forceUrls
}
const executor = new Executor(
Config.multiplextrUrl
? new Plex(urls, pool.get(Config.multiplextrUrl))
: new Relays(urls.map(url => pool.get(url)))
)
let target
// Try to use our multiplexer, but if it fails to connect fall back to relays
if (Config.multiplextrUrl) {
const socket = pool.get(Config.multiplextrUrl)
if (!socket.error) {
target = new Plex(urls, pool.get(Config.multiplextrUrl))
}
}
if (!target) {
target = new Relays(urls.map(url => pool.get(url)))
}
const executor = new Executor(target)
executor.handleAuth({
onAuth(url, challenge) {