Fixed a bug with an empty token being sent on a new connection

This commit is contained in:
Mitchell McCaffrey 2020-03-20 12:11:28 +11:00
parent 81d311eb7f
commit 1133fe2d2b

View File

@ -49,7 +49,8 @@ function Game() {
[token.id]: token [token.id]: token
})); }));
for (let connection of Object.values(connections)) { for (let connection of Object.values(connections)) {
connection.send({ id: "token", data: token }); const data = { [token.id]: token };
connection.send({ id: "token", data });
} }
} }
@ -61,10 +62,9 @@ function Game() {
setImageSource(URL.createObjectURL(imageDataRef.current)); setImageSource(URL.createObjectURL(imageDataRef.current));
} }
if (data.id === "token") { if (data.id === "token") {
const token = data.data;
setMapTokens(prevMapTokens => ({ setMapTokens(prevMapTokens => ({
...prevMapTokens, ...prevMapTokens,
[token.id]: token ...data.data
})); }));
} }
}); });