mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 08:38:50 +00:00
Add missing "error" event to on and off type definitions
This commit is contained in:
10
relay.ts
10
relay.ts
@@ -3,6 +3,8 @@
|
|||||||
import {Event, verifySignature, validateEvent} from './event'
|
import {Event, verifySignature, validateEvent} from './event'
|
||||||
import {Filter, matchFilters} from './filter'
|
import {Filter, matchFilters} from './filter'
|
||||||
|
|
||||||
|
type RelayEvent = 'connect' | 'disconnect' | 'error' | 'notice'
|
||||||
|
|
||||||
export type Relay = {
|
export type Relay = {
|
||||||
url: string
|
url: string
|
||||||
status: number
|
status: number
|
||||||
@@ -10,8 +12,8 @@ export type Relay = {
|
|||||||
close: () => Promise<void>
|
close: () => Promise<void>
|
||||||
sub: (filters: Filter[], opts: SubscriptionOptions) => Sub
|
sub: (filters: Filter[], opts: SubscriptionOptions) => Sub
|
||||||
publish: (event: Event) => Pub
|
publish: (event: Event) => Pub
|
||||||
on: (type: 'connect' | 'disconnect' | 'notice', cb: any) => void
|
on: (type: RelayEvent, cb: any) => void
|
||||||
off: (type: 'connect' | 'disconnect' | 'notice', cb: any) => void
|
off: (type: RelayEvent, cb: any) => void
|
||||||
}
|
}
|
||||||
export type Pub = {
|
export type Pub = {
|
||||||
on: (type: 'ok' | 'seen' | 'failed', cb: any) => void
|
on: (type: 'ok' | 'seen' | 'failed', cb: any) => void
|
||||||
@@ -185,7 +187,7 @@ export function relayInit(url: string): Relay {
|
|||||||
url,
|
url,
|
||||||
sub,
|
sub,
|
||||||
on: (
|
on: (
|
||||||
type: 'connect' | 'disconnect' | 'error' | 'notice',
|
type: RelayEvent,
|
||||||
cb: any
|
cb: any
|
||||||
): void => {
|
): void => {
|
||||||
listeners[type].push(cb)
|
listeners[type].push(cb)
|
||||||
@@ -194,7 +196,7 @@ export function relayInit(url: string): Relay {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
off: (
|
off: (
|
||||||
type: 'connect' | 'disconnect' | 'error' | 'notice',
|
type: RelayEvent,
|
||||||
cb: any
|
cb: any
|
||||||
): void => {
|
): void => {
|
||||||
let index = listeners[type].indexOf(cb)
|
let index = listeners[type].indexOf(cb)
|
||||||
|
|||||||
Reference in New Issue
Block a user