From 064b282ea1a3785e889ae59a8b5a9523f2200839 Mon Sep 17 00:00:00 2001 From: Gagan Suie Date: Sat, 4 May 2024 14:09:54 -0500 Subject: [PATCH] Fix: websocket reconnecting on error and 1006 in page --- src/routes/channel/[channelId]/+page.svelte | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/routes/channel/[channelId]/+page.svelte b/src/routes/channel/[channelId]/+page.svelte index 74214b84..479f23c2 100644 --- a/src/routes/channel/[channelId]/+page.svelte +++ b/src/routes/channel/[channelId]/+page.svelte @@ -253,13 +253,14 @@ console.log(data) clearInterval(platformPollingInterval) platformPollingInterval = null + attemptReconnect() }) channel.socket.addEventListener('close', (data: any) => { console.log('channel socket connection close') console.log(data) //if manually closed, don't reconnect - if (data.code === 1005 || channel.socket.readyState >= WebSocket.CLOSING) { + if (data.code === 1005 && channel.socket.readyState >= WebSocket.CLOSING) { clearInterval(platformPollingInterval) platformPollingInterval = null return @@ -275,9 +276,9 @@ const attemptReconnect = () => { setTimeout(async () => { if (!$page.params.channelId) return - console.log('Reconnecting to WebSocket...') channel = channels.find((ch: any) => ch._id === parseInt($page.params.channelId)) if (channel) { + console.log('Reconnecting to WebSocket...') channel.socket = null await handleWebsocket() }