Improve consistency of interface

This commit is contained in:
Jonathan Staab
2023-03-27 15:05:34 -05:00
parent 853b42c1c9
commit 9b6a779397
9 changed files with 223 additions and 165 deletions
+3 -16
View File
@@ -1,9 +1,7 @@
import {Relay} from "./Relay"
const normalizeUrl = url => url.replace(/\/+$/, "").toLowerCase().trim()
import {Socket} from "./util/Socket"
export class Pool {
relays: Map<string, Relay>
relays: Map<string, Socket>
constructor() {
this.relays = new Map()
this.interval = setInterval(() => {
@@ -13,17 +11,13 @@ export class Pool {
}, 30_000)
}
add(url) {
url = normalizeUrl(url)
if (!this.relays.has(url)) {
this.relays.set(url, new Relay(url))
this.relays.set(url, new Socket(url))
}
return this.relays.get(url)
}
remove(url) {
url = normalizeUrl(url)
this.relays.get(url)?.disconnect()
this.relays.delete(url)
}
@@ -34,11 +28,4 @@ export class Pool {
this.remove(url)
}
}
async waitFor(url) {
const relay = this.add(url)
await relay.connect()
return relay.status === Relay.STATUS.READY ? relay : null
}
}