rework client auth

This commit is contained in:
Jon Staab
2026-06-16 13:06:29 -07:00
parent 87d8a0832d
commit 2e12010e26
5 changed files with 58 additions and 68 deletions
+2 -15
View File
@@ -5,28 +5,15 @@ import {defaultSocketPolicies} from "./policy.js"
export type PoolSubscription = (socket: Socket) => void
export type PoolOptions = {
makeSocket?: (url: string) => Socket
}
export class Pool {
socketPolicies = [...defaultSocketPolicies]
_data = new Map<string, Socket>()
_subs: PoolSubscription[] = []
constructor(readonly options: PoolOptions = {}) {}
has(url: string) {
return this._data.has(normalizeRelayUrl(url))
}
makeSocket(url: string) {
if (this.options.makeSocket) {
return this.options.makeSocket(url)
}
return new Socket(url, defaultSocketPolicies)
}
get(_url: string): Socket {
const url = normalizeRelayUrl(_url)
const socket = this._data.get(url)
@@ -35,7 +22,7 @@ export class Pool {
return socket
}
const newSocket = this.makeSocket(url)
const newSocket = new Socket(url, this.socketPolicies)
this._data.set(url, newSocket)