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 <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
This commit is contained in:
Ashod Nakashian 2016-04-22 00:30:15 -04:00 committed by Ashod Nakashian
parent 3a4c02b71d
commit 9e64efe78b

View file

@ -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);