[Libreoffice-commits] online.git: loleaflet/html loleaflet/js loleaflet/Makefile.am loleaflet/src

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Mar 5 17:56:10 UTC 2019


 loleaflet/Makefile.am            |    8 ++----
 loleaflet/html/loleaflet.html.m4 |    1 
 loleaflet/js/global.js           |   52 +++++++++++++++++++++++++++++++++++++++
 loleaflet/js/main.js             |    9 ++++++
 loleaflet/src/core/Socket.js     |   12 +++++++++
 5 files changed, 76 insertions(+), 6 deletions(-)

New commits:
commit d529a407311c692ecc84de674ded70853490bc38
Author:     Henry Castro <hcastro at collabora.com>
AuthorDate: Sun Jan 27 14:04:26 2019 -0400
Commit:     Henry Castro <hcastro at collabora.com>
CommitDate: Tue Mar 5 13:55:25 2019 -0400

    loleaflet: add javascript websocket bootstrap that...
    
    is executed after parsing html
    
    Change-Id: Ib62de3db2449bbe9dc474469c299036259f8f2de

diff --git a/loleaflet/Makefile.am b/loleaflet/Makefile.am
index a06a33c72..bc23ee763 100644
--- a/loleaflet/Makefile.am
+++ b/loleaflet/Makefile.am
@@ -121,9 +121,6 @@ endif
 NODE_MODULES_JS_SRC = $(patsubst %.js,$(builddir)/%.js,$(NODE_MODULES_JS))
 NODE_MODULES_JS_DST = $(patsubst %.js,$(builddir)/dist/%.js,$(NODE_MODULES_JS))
 
-GLOBAL_JS =\
-	global.js
-
 LOLEAFLET_JS = $(strip $(shell NODE_PATH=$(abs_builddir)/node_modules $(NODE) -e "try {console.log(require('$(1)').getFiles().join(' '))} catch(e) {}"))
 LOPLUGIN_JS = $(strip $(shell NODE_PATH=$(abs_builddir)/node_modules $(NODE) -e "try {console.log(require('$(1)').deps.join(' '))} catch(e) {}"))
 
@@ -231,7 +228,7 @@ $(builddir)/dist/bundle.css: $(LOLEAFLET_CSS)
 
 $(builddir)/dist/bundle.js: $(NODE_MODULES_JS_SRC) \
 	$(LOLEAFLET_PREFIX)/dist/loleaflet-src.js \
-	$(srcdir)/js/global.js \
+	$(builddir)/dist/global.js \
 	$(srcdir)/js/jquery.mCustomScrollbar.js \
 	$(srcdir)/js/w2ui-1.5.rc1.js \
 	$(srcdir)/js/toolbar.js \
@@ -259,7 +256,8 @@ $(builddir)/dist/loleaflet.html: $(srcdir)/html/loleaflet.html.m4 $(LOLEAFLET_HT
 		-DMOBILEAPPNAME="$(MOBILE_APP_NAME)" \
 		-DLOLEAFLET_CSS="$(subst $(SPACE),$(COMMA),$(LOLEAFLET_CSS_M4))" \
 		-DBUNDLE_CSS="$(abs_builddir)/dist/bundle.css" \
-		-DLOLEAFLET_JS="$(subst $(SPACE),$(COMMA),$(GLOBAL_JS) $(NODE_MODULES_JS) \
+		-DGLOBAL_JS="$(abs_builddir)/dist/global.js" \
+		-DLOLEAFLET_JS="$(subst $(SPACE),$(COMMA),$(NODE_MODULES_JS) \
 		$(call LOLEAFLET_JS,$(srcdir)/build/build.js) \
 		$(patsubst %.js,plugins/draw-$(DRAW_VERSION)/%.js,$(call LOLEAFLET_JS,$(srcdir)/plugins/draw-$(DRAW_VERSION)/build/build.js)) \
 		$(patsubst %.js,plugins/path-transform/%.js,$(call LOPLUGIN_JS,$(srcdir)/plugins/path-transform/build/deps.js)) \
diff --git a/loleaflet/html/loleaflet.html.m4 b/loleaflet/html/loleaflet.html.m4
index ed5cfa40a..46e4d7d9c 100644
--- a/loleaflet/html/loleaflet.html.m4
+++ b/loleaflet/html/loleaflet.html.m4
@@ -172,6 +172,7 @@ ifelse(MOBILEAPP,[true],
       window.outOfFocusTimeoutSecs = %OUT_OF_FOCUS_TIMEOUT_SECS%;
       window.idleTimeoutSecs = %IDLE_TIMEOUT_SECS%;
       window.tileSize = 256;])
+syscmd([cat ]GLOBAL_JS)dnl
     </script>
   <script defer>
 
diff --git a/loleaflet/js/global.js b/loleaflet/js/global.js
index a294ffae8..d384409f0 100644
--- a/loleaflet/js/global.js
+++ b/loleaflet/js/global.js
@@ -49,4 +49,56 @@
 		}
 	};
 
+	var docParams, wopiParams;
+	var filePath = global.getParameterByName('file_path');
+	var wopiSrc = global.getParameterByName('WOPISrc');
+	if (wopiSrc != '') {
+		wopiSrc = '?WOPISrc=' + wopiSrc + '&compat=/ws';
+		global.docURL = decodeURIComponent(wopiSrc);
+		if (global.accessToken !== '') {
+			wopiParams = { 'access_token': global.accessToken, 'access_token_ttl': global.accessTokenTTL };
+		}
+		else if (global.accessHeader !== '') {
+			wopiParams = { 'access_header': global.accessHeader };
+		}
+		docParams = Object.keys(wopiParams).map(function(key) {
+			return encodeURIComponent(key) + '=' + encodeURIComponent(wopiParams[key])
+		}).join('&');
+	} else {
+		global.docURL = filePath;
+	}
+
+	var websocketURI = global.host + global.serviceRoot + '/lool/' + encodeURIComponent(global.docURL + (docParams ? '?' + docParams : '')) + '/ws' + wopiSrc;
+
+	try {
+		global.socket = new WebSocket(websocketURI);
+	} catch (err) {
+		console.log(err);
+	}
+
+	if (global.socket && global.socket.readyState !== 3) {
+		global.queueMsg = [];
+
+		global.socket.onopen = function () {
+			if (global.socket.readyState === 1) {
+				var ProtocolVersionNumber = '0.1';
+				global.socket.send('loolclient ' + ProtocolVersionNumber);
+				global.socket.send('load url=' + encodeURIComponent(global.docURL));
+			}
+		}
+
+		global.socket.onerror = function (event) {
+			console.log(event);
+		}
+
+		global.socket.onclose = function (event) {
+			console.log(event);
+		}
+
+		global.socket.onmessage = function (event) {
+			global.queueMsg.push(event.data);
+		}
+
+		global.socket.binaryType = 'arraybuffer';
+	}
 }(window));
diff --git a/loleaflet/js/main.js b/loleaflet/js/main.js
index 67d88d714..da0355451 100644
--- a/loleaflet/js/main.js
+++ b/loleaflet/js/main.js
@@ -75,7 +75,14 @@ map.addControl(L.control.alertDialog());
 map.addControl(L.control.lokDialog());
 map.addControl(L.control.contextMenu());
 map.addControl(L.control.infobar());
-map.loadDocument();
+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;
 
 window.addEventListener('beforeunload', function () {
 	if (map && map._socket) {
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 19c49ddef..2009418af 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -107,6 +107,18 @@ L.Socket = L.Class.extend({
 		}
 	},
 
+	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]});
+		}
+	},
+
 	_sessionExpiredWarning: function() {
 		clearTimeout(this._accessTokenExpireTimeout);
 		var expirymsg = errorMessages.sessionexpiry;


More information about the Libreoffice-commits mailing list