From 9e64efe78bb85af5176d6b655acfdd6349c064bb Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Fri, 22 Apr 2016 00:30:15 -0400 Subject: [PATCH] loleaflet: don't communicate with WSD when inactive to avoid confusing it Change-Id: I4c7f252264fba4a46c6be9e9592a2aec165813bd Reviewed-on: https://gerrit.libreoffice.org/24289 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian --- loleaflet/src/core/Socket.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js index 3b6ad4bb6..b8886d384 100644 --- a/loleaflet/src/core/Socket.js +++ b/loleaflet/src/core/Socket.js @@ -8,6 +8,7 @@ L.Socket = L.Class.extend({ initialize: function (map) { this._map = map; + this._active = true; try { this.socket = new WebSocket(map.options.server + '/' + map.options.doc); } catch (e) { @@ -30,6 +31,18 @@ L.Socket = L.Class.extend({ }, sendMessage: function (msg, coords) { + if (!msg.startsWith('useractive') && !msg.startsWith('userinactive') && !this._active) { + // Avoid communicating when we're inactive. + return; + } + + if (msg.startsWith('useractive')) { + this._active = true; + } + else if (msg.startsWith('userinactive')) { + this._active = false; + } + var socketState = this.socket.readyState; if (socketState === 2 || socketState === 3) { this.initialize(this._map);