Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,31 @@ class WebsocketAdapterDefault extends AbstractAdapter implements IAdapter {
this.handle_nostr_event(data);
});
this.base.ws.on("close", (closeEvent: CloseEvent) => {
// Unexpected close during read/write after successful open means the
// server rejected our NIP-01 subscription → not NIP-01 compatible.
if (!this.base.hard_fail) {
const openResult = this.base.results?.get('open');
if ((this.base.current === 'read' || this.base.current === 'write') && openResult?.data === true) {
this.base.websocket_hard_fail(
this.notNip01Compat(`WebSocket closed with code ${closeEvent.code}: ${closeEvent.reason || 'no reason'} after ${this.base.current} check`)
);
return;
}
}
this.base.on_close();
});
this.base.ws.on("error", (error: Event) => {
this.abortController.abort();
// Error during read/write after successful open → server rejected NIP-01.
if (!this.base.hard_fail) {
const openResult = this.base.results?.get('open');
if ((this.base.current === 'read' || this.base.current === 'write') && openResult?.data === true) {
this.base.websocket_hard_fail(
this.notNip01Compat(`WebSocket connected but received error during ${this.base.current} check`)
);
return;
}
}
this.base.on_error(error);
})
} catch (e) {
Expand Down
4 changes: 4 additions & 0 deletions libraries/nocap/src/classes/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,10 @@ export default class Base {
}
else
message = "Check skipped because no connection could be made to relay's websocket."
// Don't overwrite checks that already completed successfully
// (e.g. open check passed before the websocket dropped during read)
const existing = this?.results?.get(key as keyof IResult);
if (existing?.data === true) return;
this?.results?.set(key as keyof IResult, { data: false, duration: -1, status: "error", message })
})
const promise = this?.promises?.get(this?.current ?? "")
Expand Down