[Libreoffice-commits] online.git: loleaflet/js loleaflet/src
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Thu Mar 7 18:14:22 UTC 2019
loleaflet/js/global.js | 9 ++++++---
loleaflet/js/main.js | 10 ++--------
loleaflet/src/core/Socket.js | 22 ++++++++++------------
loleaflet/src/map/Map.js | 4 ++--
4 files changed, 20 insertions(+), 25 deletions(-)
New commits:
commit 2774a048332b5a430abc00aa904eec57f8f40efb
Author: Henry Castro <hcastro at collabora.com>
AuthorDate: Thu Mar 7 14:02:15 2019 -0400
Commit: Henry Castro <hcastro at collabora.com>
CommitDate: Thu Mar 7 14:13:52 2019 -0400
loleaflet: improve early "websocket" connection
Normally the "websocket" is created and start a connection when browser
evaluate "bundle.js" after download it.
So we create an early "websocket" connection after the browser parse
"loleaflet.html" and start receiving tiles to improve load page
performance
Change-Id: I56fca7a2da39031222c1d43781825997221385a1
diff --git a/loleaflet/js/global.js b/loleaflet/js/global.js
index f46f68a26..c6994ef84 100644
--- a/loleaflet/js/global.js
+++ b/loleaflet/js/global.js
@@ -118,9 +118,8 @@
}
}
+ global.queueMsg = [];
if (global.socket && global.socket.readyState !== 3) {
- global.queueMsg = [];
-
global.socket.onopen = function () {
if (global.socket.readyState === 1) {
var ProtocolVersionNumber = '0.1';
@@ -138,7 +137,11 @@
}
global.socket.onmessage = function (event) {
- global.queueMsg.push(event.data);
+ if (global.L && global.socket instanceof L.Socket) {
+ global.socket._onMessage(event);
+ } else {
+ global.queueMsg.push(event.data);
+ }
}
global.socket.binaryType = 'arraybuffer';
diff --git a/loleaflet/js/main.js b/loleaflet/js/main.js
index da0355451..ac25ff3f1 100644
--- a/loleaflet/js/main.js
+++ b/loleaflet/js/main.js
@@ -75,15 +75,9 @@ map.addControl(L.control.alertDialog());
map.addControl(L.control.lokDialog());
map.addControl(L.control.contextMenu());
map.addControl(L.control.infobar());
-if (global.socket && (global.socket.readyState === 1 || global.socket.readyState === 0)) {
- map._socket.attach(global.socket, global.queueMsg);
-} else {
- map.loadDocument();
-}
-
-delete global.socket;
-delete global.queueMsg;
+map.loadDocument(global.socket);
+global.socket = map._socket;
window.addEventListener('beforeunload', function () {
if (map && map._socket) {
map._socket.close();
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 5b0b48888..b48d33935 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -23,7 +23,7 @@ L.Socket = L.Class.extend({
this._msgQueue = [];
},
- connect: function() {
+ connect: function(socket) {
var map = this._map;
if (map.options.permission) {
map.options.docParams['permission'] = map.options.permission;
@@ -34,7 +34,9 @@ L.Socket = L.Class.extend({
if (window.ThisIsAMobileApp) {
this.socket = new window.FakeWebSocket();
window.TheFakeWebSocket = this.socket;
- } else {
+ } else if (socket && (socket.readyState === 1 || socket.readyState === 0)) {
+ this.socket = socket;
+ } else {
var wopiSrc = '';
if (map.options.wopiSrc != '') {
wopiSrc = '?WOPISrc=' + map.options.wopiSrc + '&compat=/ws';
@@ -78,17 +80,13 @@ L.Socket = L.Class.extend({
this._accessTokenExpireTimeout = setTimeout(L.bind(this._sessionExpiredWarning, this),
parseInt(map.options.docParams.access_token_ttl) - Date.now() - tokenExpiryWarning);
}
- },
- attach: function (socket, msgQueue) {
- this.socket = socket;
- this.socket.onerror = L.bind(this._onSocketError, this);
- this.socket.onclose = L.bind(this._onSocketClose, this);
- this.socket.onopen = L.bind(this._onSocketOpen, this);
- this.socket.onmessage = L.bind(this._onMessage, this);
-
- for (var it = 0; it < msgQueue.length; it++) {
- this._onMessage({data: msgQueue[it]});
+ // process messages for early socket connection
+ if (window.queueMsg && window.queueMsg.length > 0) {
+ for (var it = 0; it < window.queueMsg.length; it++) {
+ this._onMessage({data: window.queueMsg[it]});
+ }
+ window.queueMsg = [];
}
},
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index b0a5b9da5..deb38cb57 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -224,8 +224,8 @@ L.Map = L.Evented.extend({
}, this);
},
- loadDocument: function() {
- this._socket.connect();
+ loadDocument: function(socket) {
+ this._socket.connect(socket);
},
sendInitUNOCommands: function() {
More information about the Libreoffice-commits
mailing list