From b967bfc72c54ceafe800e44568aa4fa20fabd675 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 13 Feb 2022 13:14:04 +0100 Subject: 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. --- server.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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()); -- cgit v1.2.3