From 2fb4d3356cbf3173b5d9b6d50f080538063d7967 Mon Sep 17 00:00:00 2001 From: Sylvere Richard Date: Wed, 7 Aug 2024 16:33:24 +0200 Subject: [PATCH] fix: #4158 allow reconnection when websocket is closed log reconnection attempts mark session_id as mandatory on client-side --- src/lib/apis/index.ts | 1 + src/routes/+layout.svelte | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index c2e90855b..c4778cadb 100644 --- a/src/lib/apis/index.ts +++ b/src/lib/apis/index.ts @@ -69,6 +69,7 @@ type ChatCompletedForm = { model: string; messages: string[]; chat_id: string; + session_id: string; }; export const chatCompleted = async (token: string, body: ChatCompletedForm) => { diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index b306c57e3..df7208393 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -111,6 +111,10 @@ if ($config) { const _socket = io(`${WEBUI_BASE_URL}` || undefined, { + reconnection: true, + reconnectionDelay: 1000, + reconnectionDelayMax: 5000, + randomizationFactor: 0.5 path: '/ws/socket.io', auth: { token: localStorage.token } }); @@ -119,6 +123,21 @@ console.log('connected'); }); + _socket.on("reconnect_attempt", (attempt) => { + console.log('reconnect_attempt', attempt); + }); + + _socket.on("reconnect_failed", () => { + console.log('reconnect_failed'); + }); + + _socket.on("disconnect", (reason, details) => { + console.log(`Socket ${socket.id} disconnected due to ${reason}`); + if (details) { + console.log('Additional details:', details); + } + }); + await socket.set(_socket); _socket.on('user-count', (data) => {