Suht osad asjad tootavad. client side ei saa returni peal requesti?

This commit is contained in:
eetnaviation
2024-03-16 00:08:38 +02:00
parent 8200619ebf
commit ed63dcafc9
2 changed files with 19 additions and 8 deletions

View File

@ -27,7 +27,7 @@
<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io();
var socket = io();
// Stuff for the map
var map = L.map('map').setView([59.4370, 24.7536], 12);
@ -42,6 +42,10 @@
socket.emit('takSearch', tak);
});
socket.on('takResults', () => {
console.log("yay :)");
});
</script>
</body>

13
main.js
View File

@ -28,16 +28,23 @@ server.listen(serverPort, () => {
io.on('connection', (socket) => {
socket.on('takSearch', (tak) => {
try {
console.log("Input tak: " + tak);
fetchData(tak);
let takSearchResults = fetchData(tak);
socket.emit('takResults', takSearchResults);
} catch {
}
});
});
async function triggerDataFetch() {
async function triggerConstantDataFetch() {
while (true) {
console.log("Fetching new data...");
await fetchData();
console.log("Data fetch completed. Wait 5 seconds before next fetch!");
//await sleep.usleep(5000000);
await sleep.usleep(5000000);
}
}
async function fetchData(takInput) {