mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-06 05:39:12 +00:00
Add timeout after 10 minutes of inactivity on socket
This commit is contained in:
@@ -48,6 +48,8 @@ To get started, just start typing below. You can also type / to see a list of co
|
||||
});
|
||||
}
|
||||
var websocket = null;
|
||||
var timeout = null;
|
||||
var timeoutDuration = 600000; // 10 minutes
|
||||
|
||||
let region = null;
|
||||
let city = null;
|
||||
@@ -861,12 +863,26 @@ To get started, just start typing below. You can also type / to see a list of co
|
||||
rawResponse: "",
|
||||
}
|
||||
|
||||
function resetTimeout() {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
|
||||
timeout = setTimeout(function() {
|
||||
if (websocket) {
|
||||
websocket.close();
|
||||
}
|
||||
}, timeoutDuration);
|
||||
}
|
||||
|
||||
if (chatBody.dataset.conversationId) {
|
||||
webSocketUrl += `?conversation_id=${chatBody.dataset.conversationId}`;
|
||||
webSocketUrl += `®ion=${region}&city=${city}&country=${countryName}`;
|
||||
|
||||
websocket = new WebSocket(webSocketUrl);
|
||||
websocket.onmessage = function(event) {
|
||||
resetTimeout();
|
||||
|
||||
// Get the last element in the chat-body
|
||||
let chunk = event.data;
|
||||
if (chunk == "start_llm_response") {
|
||||
@@ -952,6 +968,8 @@ To get started, just start typing below. You can also type / to see a list of co
|
||||
let greenDot = document.getElementById("connected-green-dot");
|
||||
greenDot.style.display = "flex";
|
||||
|
||||
// Setup the timeout to close the connection after inactivity.
|
||||
resetTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user