Skip to content

Commit

Permalink
Server opt: do not redistributed unchanged state
Browse files Browse the repository at this point in the history
  • Loading branch information
eile committed Nov 16, 2023
1 parent 0f1a049 commit 90cfc87
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,21 @@ wss.on("connection", (socket) => {
process.stdout.write(type);

switch (type) {
default:
default: {
const oldState = state.get(type);
if (oldState === data) {
break;
}

wss.clients.forEach((client) => {
if (client !== socket && client.readyState === WebSocket.OPEN) {
client.send(data, { binary });
}
});
state.delete(type); // preserve order
state.set(type, buffer.toString());
state.set(type, data);
break;

}
case "T": {
const tile = message.split(",");
width = Math.max(width, Math.abs(parseFloat(tile[0]) * 2 + 1));
Expand Down

0 comments on commit 90cfc87

Please sign in to comment.