I want socket io to send an array to the client side. This is successful when the user first signs in, however when the user signs out and then sign back in, socket io sends out two of the same array. I can't seem to figure out why it does this. here is my code server side:
var object = [];
query.find({
success: function(results){
for(var i=0; i< results.length; i++){
var file = results[i].toJSON();
for(var k in file){
if (k ==="javaFile"){
for(var t in file[k]){
if (t === "name"){
temp = file[k][t];
var getname = temp.split("-").pop();
object[i] = getname;
}
}
}
}
}
}
});
io.on('connection', function(socket){
socket.emit("FileName", object);
console.log(object);
});
this is my client side:
socket.on('FileName', function(data){
var name = JSON.stringify(data);
console.log(data);
clients[socket.id] = socket;