diff --git a/src/wsConnectionManager.ts b/src/wsConnectionManager.ts index 270002e..60928ea 100644 --- a/src/wsConnectionManager.ts +++ b/src/wsConnectionManager.ts @@ -36,6 +36,16 @@ async function main() { const channelSubscribers = new Map>(); const subscribedChannels = new Set(); + redisClient.client.on('connect', () => { + subscribedChannels.forEach(async (channel) => { + try { + await redisClient.client.subscribe(channel); + } catch (error) { + console.error(`Error subscribing to ${channel}:`, error); + } + }); + }); + redisClient.client.on('message', (subscribedChannel, message) => { const subscribers = channelSubscribers.get(subscribedChannel); subscribers.forEach((ws) => { @@ -132,7 +142,6 @@ async function main() { // Listen for pong messages ws.on('pong', () => { - console.log('poooooooong'); isAlive = true; clearTimeout(pongTimeoutId); }); @@ -146,6 +155,7 @@ async function main() { if (subscribers.delete(ws) && subscribers.size === 0) { redisClient.client.unsubscribe(channel); channelSubscribers.delete(channel); + subscribedChannels.delete(channel); } }); });