From fe45cb4beb7b0c279108b4f6f9698fe5fb02ae52 Mon Sep 17 00:00:00 2001 From: ennmichael Date: Mon, 27 Feb 2023 00:00:08 +0100 Subject: [PATCH] refactoring from previous pr --- packages/nostr/src/client/conn.ts | 12 +++++----- packages/nostr/src/client/index.ts | 35 +++++++++++++++--------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/packages/nostr/src/client/conn.ts b/packages/nostr/src/client/conn.ts index 22e26bb..75ff313 100644 --- a/packages/nostr/src/client/conn.ts +++ b/packages/nostr/src/client/conn.ts @@ -122,8 +122,8 @@ export interface IncomingNotice { */ export type OutgoingMessage = | OutgoingEvent - | OutgoingSubscription - | OutgoingUnsubscription + | OutgoingOpenSubscription + | OutgoingCloseSubscription export const enum OutgoingKind { Event, @@ -140,18 +140,18 @@ export interface OutgoingEvent { } /** - * Outgoing "REQ" message, representing a subscription. + * Outgoing "REQ" message, which opens a subscription. */ -export interface OutgoingSubscription { +export interface OutgoingOpenSubscription { kind: OutgoingKind.Subscription id: SubscriptionId filters: Filters } /** - * Outgoing "CLOSE" message, representing an unsubscription. + * Outgoing "CLOSE" message, which closes a subscription. */ -export interface OutgoingUnsubscription { +export interface OutgoingCloseSubscription { kind: OutgoingKind.Unsubscription id: SubscriptionId } diff --git a/packages/nostr/src/client/index.ts b/packages/nostr/src/client/index.ts index 1d32f36..2fd7058 100644 --- a/packages/nostr/src/client/index.ts +++ b/packages/nostr/src/client/index.ts @@ -12,24 +12,7 @@ export class Nostr { /** * Open connections to relays. */ - readonly #conns: Map< - string, - { - conn: Conn - /** - * Has this connection been authenticated via NIP-44 AUTH? - */ - auth: boolean - /** - * Should this connection be used for receiving messages? - */ - read: boolean - /** - * Should this connection be used for publishing events? - */ - write: boolean - } - > = new Map() + readonly #conns: Map = new Map() /** * Mapping of subscription IDs to corresponding filters. @@ -236,6 +219,22 @@ export class Nostr { } } +interface ConnState { + conn: Conn + /** + * Has this connection been authenticated via NIP-44 AUTH? + */ + auth: boolean + /** + * Should this connection be used for receiving messages? + */ + read: boolean + /** + * Should this connection be used for publishing events? + */ + write: boolean +} + /** * A string uniquely identifying a client subscription. */