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(', ')}`);