Remove client-side timeouts for the khoj socket

This commit is contained in:
sabaimran 2024-04-10 13:35:25 +05:30
parent 312528d471
commit a4afada746

View file

@ -48,9 +48,6 @@ To get started, just start typing below. You can also type / to see a list of co
}); });
} }
var websocket = null; var websocket = null;
var timeout = null;
var timeoutDuration = 600000; // 10 minutes
let region = null; let region = null;
let city = null; let city = null;
let countryName = null; let countryName = null;
@ -874,25 +871,12 @@ To get started, just start typing below. You can also type / to see a list of co
rawResponse: "", rawResponse: "",
} }
function resetTimeout() {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(function() {
if (websocket) {
websocket.close();
}
}, timeoutDuration);
}
if (chatBody.dataset.conversationId) { if (chatBody.dataset.conversationId) {
webSocketUrl += `?conversation_id=${chatBody.dataset.conversationId}`; webSocketUrl += `?conversation_id=${chatBody.dataset.conversationId}`;
webSocketUrl += (!!region && !!city && !!countryName) ? `&region=${region}&city=${city}&country=${countryName}` : ''; webSocketUrl += (!!region && !!city && !!countryName) ? `&region=${region}&city=${city}&country=${countryName}` : '';
websocket = new WebSocket(webSocketUrl); websocket = new WebSocket(webSocketUrl);
websocket.onmessage = function(event) { websocket.onmessage = function(event) {
resetTimeout();
// Get the last element in the chat-body // Get the last element in the chat-body
let chunk = event.data; let chunk = event.data;
@ -986,9 +970,6 @@ To get started, just start typing below. You can also type / to see a list of co
let statusDotText = document.getElementById("connection-status-text"); let statusDotText = document.getElementById("connection-status-text");
statusDotText.style.marginTop = "10px"; statusDotText.style.marginTop = "10px";
statusDotText.textContent = "Connected to Server"; statusDotText.textContent = "Connected to Server";
// Setup the timeout to close the connection after inactivity.
resetTimeout();
} }
} }