Improve consistency of interface
This commit is contained in:
+3
-16
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user