Skip to content

Commit

Permalink
fix: socket-io reconnection bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Nov 21, 2024
1 parent c75e9fb commit 8f96b3d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/src/socket-io/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
5 changes: 4 additions & 1 deletion src/api/routes/ws/channels/socket-io-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ')}`);
Expand Down

0 comments on commit 8f96b3d

Please sign in to comment.