This commit is contained in:
parent
338c4eb18a
commit
5ea7cd17d8
@ -13,6 +13,7 @@ import { ConnectionSyncModule, DefaultSyncModule } from "./sync/connection";
|
|||||||
export interface ConnectionTypeEvents {
|
export interface ConnectionTypeEvents {
|
||||||
change: () => void;
|
change: () => void;
|
||||||
connected: (wasReconnect: boolean) => void;
|
connected: (wasReconnect: boolean) => void;
|
||||||
|
error: () => void;
|
||||||
event: (sub: string, e: TaggedNostrEvent) => void;
|
event: (sub: string, e: TaggedNostrEvent) => void;
|
||||||
eose: (sub: string) => void;
|
eose: (sub: string) => void;
|
||||||
closed: (sub: string, reason: string) => void;
|
closed: (sub: string, reason: string) => void;
|
||||||
|
@ -150,7 +150,10 @@ export class Connection extends EventEmitter<ConnectionTypeEvents> implements Co
|
|||||||
this.Socket.onerror = e => this.#onError(e);
|
this.Socket.onerror = e => this.#onError(e);
|
||||||
this.Socket.onclose = e => this.#onClose(e);
|
this.Socket.onclose = e => this.#onClose(e);
|
||||||
if (awaitOpen) {
|
if (awaitOpen) {
|
||||||
await new Promise(resolve => this.once("connected", resolve));
|
await new Promise((resolve, reject) => {
|
||||||
|
this.once("connected", resolve);
|
||||||
|
this.once("error", reject);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.#connectStarted = false;
|
this.#connectStarted = false;
|
||||||
@ -276,6 +279,7 @@ export class Connection extends EventEmitter<ConnectionTypeEvents> implements Co
|
|||||||
#onError(e: WebSocket.Event) {
|
#onError(e: WebSocket.Event) {
|
||||||
this.#log("Error: %O", e);
|
this.#log("Error: %O", e);
|
||||||
this.emit("change");
|
this.emit("change");
|
||||||
|
this.emit("error");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user