fix useWebSocketImplementation so it works with pool on nodejs esm.

This commit is contained in:
fiatjaf
2024-05-29 13:37:45 -03:00
parent 4f1dc9ef1c
commit 87a91c2daf
8 changed files with 60 additions and 23 deletions

View File

@@ -1,3 +1,5 @@
/* global WebSocket */
import { verifyEvent } from './pure.ts'
import { AbstractRelay } from './abstract-relay.ts'
@@ -8,9 +10,19 @@ export function relayConnect(url: string): Promise<Relay> {
return Relay.connect(url)
}
var _WebSocket: typeof WebSocket
try {
_WebSocket = WebSocket
} catch {}
export function useWebSocketImplementation(websocketImplementation: any) {
_WebSocket = websocketImplementation
}
export class Relay extends AbstractRelay {
constructor(url: string) {
super(url, { verifyEvent })
super(url, { verifyEvent, websocketImplementation: _WebSocket })
}
static async connect(url: string): Promise<Relay> {