From e4f045a2ccb59ccc837b7c329f879c8591a5a584 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Fri, 31 May 2024 22:09:43 +0200 Subject: [PATCH] Fixes #45 --- app/MindWork AI Studio/Components/App.razor | 3 +- app/MindWork AI Studio/Program.cs | 6 +- app/MindWork AI Studio/wwwroot/boot.js | 66 +++++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 app/MindWork AI Studio/wwwroot/boot.js diff --git a/app/MindWork AI Studio/Components/App.razor b/app/MindWork AI Studio/Components/App.razor index ae3b65b..152203c 100644 --- a/app/MindWork AI Studio/Components/App.razor +++ b/app/MindWork AI Studio/Components/App.razor @@ -17,7 +17,8 @@ - + + diff --git a/app/MindWork AI Studio/Program.cs b/app/MindWork AI Studio/Program.cs index ffd873f..38d72dc 100644 --- a/app/MindWork AI Studio/Program.cs +++ b/app/MindWork AI Studio/Program.cs @@ -30,9 +30,11 @@ builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddRazorComponents() .AddInteractiveServerComponents() - .AddHubOptions(x => + .AddHubOptions(options => { - x.MaximumReceiveMessageSize = null; + options.MaximumReceiveMessageSize = null; + options.ClientTimeoutInterval = TimeSpan.FromSeconds(1_200); + options.HandshakeTimeout = TimeSpan.FromSeconds(30); }); var port = args.Length > 0 ? args[0] : "5000"; diff --git a/app/MindWork AI Studio/wwwroot/boot.js b/app/MindWork AI Studio/wwwroot/boot.js new file mode 100644 index 0000000..d18dd7e --- /dev/null +++ b/app/MindWork AI Studio/wwwroot/boot.js @@ -0,0 +1,66 @@ +(() => { + const maximumRetryCount = 3; + const retryIntervalMilliseconds = 500; + const reconnectModal = document.getElementById('reconnect-modal'); + + const startReconnectionProcess = () => { + reconnectModal.style.display = 'block'; + + let isCanceled = false; + + (async () => { + for (let i = 0; i < maximumRetryCount; i++) { + reconnectModal.innerText = `Attempting to reconnect: ${i + 1} of ${maximumRetryCount}`; + + await new Promise(resolve => setTimeout(resolve, retryIntervalMilliseconds)); + + if (isCanceled) { + return; + } + + try { + const result = await Blazor.reconnect(); + if (!result) { + // The server was reached, but the connection was rejected; reload the page. + location.reload(); + return; + } + + // Successfully reconnected to the server. + return; + } catch { + // Didn't reach the server; try again. + } + } + + // Retried too many times; reload the page. + location.reload(); + })(); + + return { + cancel: () => { + isCanceled = true; + reconnectModal.style.display = 'none'; + }, + }; + }; + + let currentReconnectionProcess = null; + + Blazor.start({ + circuit: { + reconnectionHandler: { + onConnectionDown: () => currentReconnectionProcess ??= startReconnectionProcess(), + onConnectionUp: () => { + currentReconnectionProcess?.cancel(); + currentReconnectionProcess = null; + } + }, + + configureSignalR: function (builder) { + builder.withServerTimeout(1_200_000); + builder.withKeepAliveInterval(30_000); + }, + } + }); +})(); \ No newline at end of file