From b60e84d29bb7f348c797fccd5fdcd4eab29dc828 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 25 Aug 2023 15:00:48 -0500 Subject: [PATCH] relay: only send if socket is open --- src/controllers/api/streaming.ts | 1 - src/controllers/nostr/relay.ts | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/controllers/api/streaming.ts b/src/controllers/api/streaming.ts index 76a23c16..071c1fa5 100644 --- a/src/controllers/api/streaming.ts +++ b/src/controllers/api/streaming.ts @@ -1,5 +1,4 @@ import { AppController } from '@/app.ts'; -import { type Event } from '@/deps.ts'; import { type DittoFilter } from '@/filter.ts'; import { TOKEN_REGEX } from '@/middleware/auth19.ts'; import { streamSchema, ws } from '@/stream.ts'; diff --git a/src/controllers/nostr/relay.ts b/src/controllers/nostr/relay.ts index 3e03f490..ca659cf9 100644 --- a/src/controllers/nostr/relay.ts +++ b/src/controllers/nostr/relay.ts @@ -90,7 +90,9 @@ function connectStream(socket: WebSocket) { /** Send a message back to the client. */ function send(msg: RelayMsg): void { - return socket.send(JSON.stringify(msg)); + if (socket.readyState === WebSocket.OPEN) { + socket.send(JSON.stringify(msg)); + } } }