summaryrefslogtreecommitdiff
path: root/server.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-02-13 13:14:04 +0100
committerTor Andersson <tor@ccxvii.net>2022-02-15 12:18:30 +0100
commitb967bfc72c54ceafe800e44568aa4fa20fabd675 (patch)
treea50c2f919c0f86f9cbd815e6680998e439c7c5fd /server.js
parent4fc9ac0a76f6137a40ec207f6b7e140dffb2768d (diff)
downloadserver-b967bfc72c54ceafe800e44568aa4fa20fabd675.tar.gz
Track and avoid sending no-op view changes to clients.
When state changes that cause no visible changes for a client, don't bother sending a new view object.
Diffstat (limited to 'server.js')
-rw-r--r--server.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/server.js b/server.js
index 1c8ebe8..2cc5cca 100644
--- a/server.js
+++ b/server.js
@@ -1648,7 +1648,11 @@ function send_state(socket, state) {
view.log = view.log.slice(view.log_start);
if (state.state === 'game_over')
view.game_over = 1;
- send_message(socket, 'state', view);
+ view = JSON.stringify(['state', view]);
+ if (socket.last_view !== view) {
+ socket.send(view);
+ socket.last_view = view;
+ }
} catch (err) {
console.log(err);
return send_message(socket, 'error', err.toString());