From f94b42f936bab9ffe96e3d8ba89e6d02fb37c291 Mon Sep 17 00:00:00 2001 From: eetnaviation Date: Thu, 5 Dec 2024 21:56:53 +0200 Subject: [PATCH] Added comments for a few things, added button --- client/index.html | 5 +++++ main.js | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/client/index.html b/client/index.html index 61bccec..d4c9573 100644 --- a/client/index.html +++ b/client/index.html @@ -43,6 +43,7 @@
+
@@ -120,6 +121,10 @@ document.getElementById('a40Search').addEventListener('click', function () { socket.emit('a40BulkSearch'); }); + + document.getElementById('continousAll').addEventListener('click', function () { + socket.emit('continousAllReq'); + }); socket.on('takResults', (typeR, lineR, latR, longR, takR, latlongR, vehicleTypeR) => { diff --git a/main.js b/main.js index c0499c3..f869ff4 100644 --- a/main.js +++ b/main.js @@ -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) {