diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-02-13 13:14:04 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-02-15 12:18:30 +0100 |
commit | b967bfc72c54ceafe800e44568aa4fa20fabd675 (patch) | |
tree | a50c2f919c0f86f9cbd815e6680998e439c7c5fd /server.js | |
parent | 4fc9ac0a76f6137a40ec207f6b7e140dffb2768d (diff) | |
download | server-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.js | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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()); |