mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-10 00:33:47 +00:00
Fixes #45
This commit is contained in:
3 files changed
+72
-3
No files matched your search
@@ -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);
|
||||
},
|
||||
}
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user