From 081478fe162103605820169a8f4c8e5f70e52c0e Mon Sep 17 00:00:00 2001 From: catvayor Date: Mon, 5 Jun 2023 17:51:32 +0200 Subject: [PATCH] http position logging --- static/utils.js | 2 +- traque.js | 41 ++++++++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/static/utils.js b/static/utils.js index 9b5515a..6288122 100644 --- a/static/utils.js +++ b/static/utils.js @@ -133,7 +133,7 @@ function setup_socket_not_admin(){ function setup_geoLoc(){ function geoLoc_success(pos) { - socket.emit("geoLoc", {"position": [pos.coords.latitude, pos.coords.longitude]}); + fetch("/log?id="+id+"&lat="+pos.coords.latitude+"&lon="+pos.coords.longitude); } function geoLoc_error(err) { diff --git a/traque.js b/traque.js index 92648fc..b1b2ba7 100644 --- a/traque.js +++ b/traque.js @@ -47,11 +47,40 @@ const option = { // The server var server = http.createServer(option, function(req, res){ var q = url.parse(req.url, true); + // + // todo : utiliser ?id pour changer des chose dans la page, ou faire ça en fesant croire + // qu'il y a plein de fichiers sous le dossier "conscrit", alors que c'est juste une page html; + // la page conscrit seul renvoyant 404 ou random page erreur "utilise les lien qu'on donne petit conscrit" + // var filename = "static" + q.pathname; if(q.pathname.includes("..")) filename = "static/dotdot.html"; + if(q.pathname == "/") filename = "static/conscrit.html"; + + if(q.pathname == "/log"){ + //position logging + console.log("team " + q.query.id + " moved to (" + q.query.lat + "," + q.query.lon + ")"); + + //current impl (to be changed) + var socket = equipes[q.query.id]; + var position = [q.query.lat, q.query.lon]; + socket.position = position; + if(socket.shown) + for(i in equipes) + equipes[i].emit('moving', {"id": socket.id, "position": position}); + else { + socket.emit('moving', {"id": socket.id, "position": position}); + for(i in admins) + admins[i].emit('moving', {"id": socket.id, "position": position}) + } + + + //return empty page + res.writeHead(200, {'Content-Type': 'text/html'}); + return res.end(); + } fs.readFile(filename, function(err, data) { if (err) { console.log("404: ", q.pathname, filename); @@ -71,6 +100,7 @@ var io = new Server(server); console.log("Setup handlers"); io.sockets.on('connection', function(socket){ console.log("connection !"); +//ici essentiellement tout est a refaire socket.id = equipes.length; equipes.push(socket); socket.shown = true; @@ -88,17 +118,6 @@ io.sockets.on('connection', function(socket){ equipes[i].emit('newTracker', d); }); }); - socket.on('geoLoc', function(d){ - socket.position = d.position; - if(socket.shown) - for(i in equipes) - equipes[i].emit('moving', {"id": socket.id, "position": d.position}); - else { - socket.emit('moving', {"id": socket.id, "position": d.position}); - for(i in admins) - admins[i].emit('moving', {"id": socket.id, "position": d.position}) - } - }); socket.on('changeColor', function(d){ socket.color = d.color - 0; if(d.color == -1)