something

This commit is contained in:
fiatjaf
2025-07-19 10:41:48 -03:00
parent de1cf0ed60
commit 719462f041
5 changed files with 53 additions and 18 deletions

29
node-ws-relay.ts Normal file
View File

@@ -0,0 +1,29 @@
import WebSocket from 'ws'
import { verifyEvent } from './pure.ts'
import { AbstractRelay, WebSocketBase } from './abstract-relay.ts'
class NodeWs extends WebSocket implements WebSocketBase {
constructor(url: string | URL, protocols?: string | string[] | undefined) {
super(url, {
protocol: Array.isArray(protocols) ? protocols[0] : protocols,
})
setInterval(() => {
this.ping()
}, 29000)
}
}
export class NodeWsRelay extends AbstractRelay {
constructor(url: string) {
super(url, { verifyEvent, websocketImplementation: NodeWs })
}
static async connect(url: string): Promise<NodeWsRelay> {
const relay = new NodeWsRelay(url)
await relay.connect()
return relay
}
}
export * from './abstract-relay.ts'