Added comments for a few things, added button
This commit is contained in:
@ -43,6 +43,7 @@
|
||||
<div>
|
||||
<button type="click" id="tramSearch">Show all trams</button>
|
||||
<button type="click" id="busSearch">Show all buses</button>
|
||||
<button type="click" id="continousAll">Show all vehicles live</button>
|
||||
</div>
|
||||
</form>
|
||||
<form id="recievedData">
|
||||
@ -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) => {
|
||||
|
33
main.js
33
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) {
|
||||
|
Reference in New Issue
Block a user