Skip to content

Commit

Permalink
fix: session socket dup events
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamerblue committed Nov 11, 2024
1 parent cf7372b commit 2cdf94c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib/socketHandlers/general/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export class GeneralSocketHandler {
socket.on(event, handler);
});
}

unbindEvents(socket: SocketIOClient.Socket) {
this.events.forEach(([event, handler]) => {
socket.off(event, handler);
});
}
}

export const globalGeneralSocketHandler = new GeneralSocketHandler();
1 change: 1 addition & 0 deletions src/models/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function createGeneralSocket() {
});
socket.on('disconnect', () => {
console.log('session socket disconnected');
globalGeneralSocketHandler.unbindEvents(socket);
});
return socket;
}
Expand Down

0 comments on commit 2cdf94c

Please sign in to comment.