Loading socket.js +6 −6 Original line number Diff line number Diff line Loading @@ -83,10 +83,9 @@ server.on('connection',function(socket){ const req = JSON.parse(data); hf.addMapToClient(clients, socket, req['mapId'], newClientList => { clients = newClientList.slice(); if (hf.checkIfRequestHasVote(data)) { sendToAllClientsAtSameMap(res, req['mapId']); } else { socket.write(JSON.stringify(res.data) + '\n'); if (hf.checkIfRequestHasVote(data)) { sendToAllClientsAtSameMap(res, req['mapId'], socket); } }); //var is_kernel_buffer_full = socket.write(JSON.stringify(res.data) + '\n'); Loading Loading @@ -151,11 +150,12 @@ server.on('connection',function(socket){ } // Send a message to all clients playing the same map function sendToAllClientsAtSameMap(res, mapId) { function sendToAllClientsAtSameMap(res, mapId, currentClient) { console.log("JSON: ", JSON.stringify(res.data)); clients.forEach(function (client) { // Don't want to send it to sender if (client.mapId === mapId) client.write(JSON.stringify(res.data) + '\n'); const resJson = res.data; delete resJson['vote']; if (client.mapId === mapId && client.name !== currentClient) client.write(JSON.stringify(resJson) + '\n'); }); console.log("Write Message to all at " + mapId +": " + JSON.stringify(res.data)); } Loading Loading
socket.js +6 −6 Original line number Diff line number Diff line Loading @@ -83,10 +83,9 @@ server.on('connection',function(socket){ const req = JSON.parse(data); hf.addMapToClient(clients, socket, req['mapId'], newClientList => { clients = newClientList.slice(); if (hf.checkIfRequestHasVote(data)) { sendToAllClientsAtSameMap(res, req['mapId']); } else { socket.write(JSON.stringify(res.data) + '\n'); if (hf.checkIfRequestHasVote(data)) { sendToAllClientsAtSameMap(res, req['mapId'], socket); } }); //var is_kernel_buffer_full = socket.write(JSON.stringify(res.data) + '\n'); Loading Loading @@ -151,11 +150,12 @@ server.on('connection',function(socket){ } // Send a message to all clients playing the same map function sendToAllClientsAtSameMap(res, mapId) { function sendToAllClientsAtSameMap(res, mapId, currentClient) { console.log("JSON: ", JSON.stringify(res.data)); clients.forEach(function (client) { // Don't want to send it to sender if (client.mapId === mapId) client.write(JSON.stringify(res.data) + '\n'); const resJson = res.data; delete resJson['vote']; if (client.mapId === mapId && client.name !== currentClient) client.write(JSON.stringify(resJson) + '\n'); }); console.log("Write Message to all at " + mapId +": " + JSON.stringify(res.data)); } Loading