[Libreoffice-commits] online.git: loleaflet/src
Marco Cecchetti (via logerrit)
logerrit at kemper.freedesktop.org
Thu Dec 12 10:09:37 UTC 2019
loleaflet/src/core/Socket.js | 52 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
New commits:
commit c4d27a2b8d5f7ebaacb701f18ac5278e0ce5ca14
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
AuthorDate: Thu Dec 12 10:50:19 2019 +0100
Commit: Marco Cecchetti <marco.cecchetti at collabora.com>
CommitDate: Thu Dec 12 11:09:19 2019 +0100
try to delay incoming messages when the js bundle is not yet loaded
Incoming message are stored and handled as soon as the js bundle is
loaded and the ui is ready.
At present this solution has been selectively enabled for the
following types of incoming messages: 'window', 'statechanged',
'celladdress'.
Change-Id: I22e98ff11c67140deb639295273be9533560536b
Reviewed-on: https://gerrit.libreoffice.org/85028
Reviewed-by: Marco Cecchetti <marco.cecchetti at collabora.com>
Tested-by: Marco Cecchetti <marco.cecchetti at collabora.com>
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index cdeeefe16..38c175d57 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -22,6 +22,8 @@ L.Socket = L.Class.extend({
console.debug('socket.initialize:');
this._map = map;
this._msgQueue = [];
+ this._delayedMessages = [];
+ this._handlingDelayedMessages = false;
},
getWebSocketBaseURI: function(map) {
@@ -817,11 +819,59 @@ L.Socket = L.Class.extend({
return;
}
- if (this._map._docLayer) {
+ var msgDelayed = false;
+ if (!this._isReady() || this._delayedMessages.length || this._handlingDelayedMessages) {
+ msgDelayed = this._tryToDelayMessage(textMsg);
+ }
+
+ if (this._map._docLayer && !msgDelayed) {
this._map._docLayer._onMessage(textMsg, img);
}
},
+ _tryToDelayMessage: function(textMsg) {
+ var delayed = false;
+ if (textMsg.startsWith('window:') ||
+ textMsg.startsWith('celladdress:') ||
+ textMsg.startsWith('statechanged:')) {
+ //console.log('_tryToDelayMessage: textMsg: ' + textMsg);
+ var message = {msg: textMsg};
+ this._delayedMessages.push(message);
+ delayed = true;
+ }
+
+ if (delayed && !this._delayedMsgHandlerTimeoutId) {
+ this._handleDelayedMessages();
+ }
+ return delayed;
+ },
+
+ _handleDelayedMessages: function() {
+ if (!this._isReady() || this._handlingDelayedMessages) {
+ var that = this;
+ // Retry in a bit.
+ this._delayedMsgHandlerTimeoutId = setTimeout(function() {
+ that._handleDelayedMessages();
+ }, 100);
+ return;
+ }
+ var messages = [];
+ for (var i = 0; i < this._delayedMessages.length; ++i) {
+ var message = this._delayedMessages[i];
+ if (message)
+ messages.push(message.msg);
+ }
+ this._delayedMessages = [];
+ this._delayedMsgHandlerTimeoutId = null;
+ this._handlingDelayedMessages = true;
+ if (this._map._docLayer) {
+ for (var k = 0; k < messages.length; ++k) {
+ this._map._docLayer._onMessage(messages[k]);
+ }
+ }
+ this._handlingDelayedMessages = false;
+ },
+
_delayedFitToScreen: function(height) {
if (this._map.getSize().y > 0) {
// If we have a presentation document and the zoom level has not been set
More information about the Libreoffice-commits
mailing list