mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 08:04:21 +00:00
Add timeout after 10 minutes of inactivity on socket
This commit is contained in:
parent
f48426623d
commit
b4f71e06b3
1 changed files with 18 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue