forked from nbd-wtf/nostr-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
relay.ts
37 lines (28 loc) · 850 Bytes
/
relay.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* global WebSocket */
import { verifyEvent } from './pure.ts'
import { AbstractRelay } from './abstract-relay.ts'
/**
* @deprecated use Relay.connect() instead.
*/
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, websocketImplementation: _WebSocket })
}
static async connect(url: string): Promise<Relay> {
const relay = new Relay(url)
await relay.connect()
return relay
}
}
export type RelayRecord = Record<string, { read: boolean; write: boolean }>
export * from './abstract-relay.ts'