From 8f96b3dcfcb4e1a174c9417d530d9040397569a4 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Thu, 21 Nov 2024 14:13:08 +0100 Subject: [PATCH] fix: socket-io reconnection bug --- client/src/socket-io/index.ts | 2 +- src/api/routes/ws/channels/socket-io-channel.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/client/src/socket-io/index.ts b/client/src/socket-io/index.ts index 62578c7c0..3bba9f918 100644 --- a/client/src/socket-io/index.ts +++ b/client/src/socket-io/index.ts @@ -72,7 +72,7 @@ export class StacksApiSocketClient { handleSubscription(topic: Topic, subscribe = false, listener?: (...args: any[]) => void) { const subsQuery = this.socket.io.opts.query?.subscriptions as string | undefined; - const subscriptions = new Set(subsQuery?.split(',') ?? []); + const subscriptions = new Set(subsQuery ? subsQuery.split(',') : []); if (subscribe) { this.socket.emit('subscribe', topic, error => { if (error) console.error(`Error subscribing: ${error}`); diff --git a/src/api/routes/ws/channels/socket-io-channel.ts b/src/api/routes/ws/channels/socket-io-channel.ts index 9d373e281..963d871cc 100644 --- a/src/api/routes/ws/channels/socket-io-channel.ts +++ b/src/api/routes/ws/channels/socket-io-channel.ts @@ -90,7 +90,10 @@ export class SocketIOChannel extends WebSocketChannel { io.use((socket, next) => { const subscriptions = socket.handshake.query['subscriptions']; if (subscriptions) { - const topics = [...[subscriptions]].flat().flatMap(r => r.split(',')); + const topics = [...[subscriptions]] + .flat() + .flatMap(r => r.split(',')) + .filter(r => !!r); const invalidSubs = this.getInvalidSubscriptionTopics(topics as Topic[]); if (invalidSubs) { const error = new Error(`Invalid topic: ${invalidSubs.join(', ')}`);