Added comments for a few things, added button

This commit is contained in:
eetnaviation
2024-12-05 21:56:53 +02:00
parent d132c6da46
commit f94b42f936
2 changed files with 35 additions and 3 deletions

33
main.js
View File

@ -119,9 +119,9 @@ let requestedLatLong = "Unfetched";
let isRequestMode = false;
let requestModeIntervalId = null;
let lastFetchTime = 0;
const defaultFetchInterval = 120000;
const requestModeInterval = 30000;
const requestModeDuration = 120000;
const defaultFetchInterval = 120000; //120sec
const requestModeInterval = 30000; //30sec
const requestModeDuration = 120000; //120sec
console.log("Server initialized!");
@ -418,12 +418,39 @@ io.on('connection', (socket) => {
}
startRequestModeFetch();
fetchDataFromLocalFileByTransportType("BUS", socket);
fetchDataFromLocalFileByTransportType("NIGHTBUS", socket);
} catch (error) {
var caughtError = "Error processing busBulkSearch: ", error;
console.error(caughtError);
writeToLog('errors_log.txt', caughtError);
}
});
socket.on('continousAllReq', async () => {
console.log("Started continousAllReq for socket", socket);
saveRequestLogs(socket, "ContinousAllReq");
try {
if (isRequestMode) {
const currentTime = Date.now();
if (currentTime - lastFetchTime >= requestModeInterval) {
await fetchAndSaveData("Request Mode");
}
} else {
await fetchAndSaveData("Request Mode");
}
if (isRequestMode) {
clearInterval(requestModeIntervalId);
}
startRequestModeFetch();
fetchDataFromLocalFileByTransportType("BUS", socket);
fetchDataFromLocalFileByTransportType("TRAM", socket);
fetchDataFromLocalFileByTransportType("TROLL", socket);
fetchDataFromLocalFileByTransportType("NIGHTBUS", socket);
} catch (error) {
var caughtError = "Error processing continousAllReq: ", error;
console.error(caughtError);
writeToLog('errors_log.txt', caughtError);
}
});
});
function saveRequestLogs(socket, takInput) {