http position logging

This commit is contained in:
catvayor 2023-06-05 17:51:32 +02:00
parent 094f2419ec
commit 081478fe16
2 changed files with 31 additions and 12 deletions

View file

@ -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) {

View file

@ -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)