send old data to new client
This commit is contained in:
parent
6235e0c14e
commit
45be8fc777
1 changed files with 11 additions and 2 deletions
13
traque.js
13
traque.js
|
@ -59,6 +59,7 @@ io.sockets.on('connection', function(socket){
|
||||||
equipes.push(socket);
|
equipes.push(socket);
|
||||||
socket.shown = true;
|
socket.shown = true;
|
||||||
socket.color = 0;
|
socket.color = 0;
|
||||||
|
socket.position = [0,0];
|
||||||
socket.on('geoLoc', function(d){
|
socket.on('geoLoc', function(d){
|
||||||
socket.position = d.position;
|
socket.position = d.position;
|
||||||
if(socket.shown)
|
if(socket.shown)
|
||||||
|
@ -71,11 +72,11 @@ io.sockets.on('connection', function(socket){
|
||||||
socket.shown = false;
|
socket.shown = false;
|
||||||
else{
|
else{
|
||||||
if(!socket.shown)
|
if(!socket.shown)
|
||||||
for(i in equipes)
|
for(i in equipes)
|
||||||
equipes[i].emit('moving', {"id": socket.id, "position": socket.position});
|
equipes[i].emit('moving', {"id": socket.id, "position": socket.position});
|
||||||
socket.shown = true;
|
socket.shown = true;
|
||||||
}
|
}
|
||||||
for(i in equipes)
|
for(i in equipes)
|
||||||
equipes[i].emit('changeColor', {"id": socket.id, "color": d.color});
|
equipes[i].emit('changeColor', {"id": socket.id, "color": d.color});
|
||||||
});
|
});
|
||||||
socket.on('setName', function(d){
|
socket.on('setName', function(d){
|
||||||
|
@ -83,7 +84,15 @@ io.sockets.on('connection', function(socket){
|
||||||
for(i in equipes)
|
for(i in equipes)
|
||||||
equipes[i].emit('setName', {"id": socket.id, "name": d.name});
|
equipes[i].emit('setName', {"id": socket.id, "name": d.name});
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.emit('yourId', {"id": socket.id});
|
socket.emit('yourId', {"id": socket.id});
|
||||||
|
for(i in equipes){
|
||||||
|
if(!equipes[i].shown)
|
||||||
|
continue;
|
||||||
|
socket.emit('setName', {"id": i, "name": equipes[i].name});
|
||||||
|
socket.emit('changeColor', {"id": i, "color": equipes[i].color});
|
||||||
|
socket.emit('moving', {"id": i, "position": equipes[i].position});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Launch server");
|
console.log("Launch server");
|
||||||
|
|
Loading…
Add table
Reference in a new issue