[Libreoffice-commits] online.git: 3 commits - loleaflet/build loleaflet/src

Mihai Varga mihai.varga at collabora.com
Thu Jul 16 04:03:14 PDT 2015


 loleaflet/build/deps.js               |    1 
 loleaflet/src/control/Buttons.js      |    4 +-
 loleaflet/src/control/Parts.js        |   16 +++++-----
 loleaflet/src/control/Search.js       |    2 -
 loleaflet/src/core/Log.js             |   53 ++++++++++++++++++++++++++++++++++
 loleaflet/src/layer/tile/GridLayer.js |   18 +++++------
 loleaflet/src/layer/tile/TileLayer.js |   29 ++++++++++++------
 7 files changed, 94 insertions(+), 29 deletions(-)

New commits:
commit 71ff6dca641072b3f5d05d0d917bc48d402e555d
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Thu Jul 16 14:02:49 2015 +0300

    loleaflet: log server - client communication

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index b52d7df..b5c9e64 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -272,6 +272,11 @@ L.TileLayer = L.GridLayer.extend({
 			textMsg = String.fromCharCode.apply(null, bytes.subarray(0, index));
 		}
 
+		if (!textMsg.startsWith('tile:')) {
+			// log the tile msg separately as we need the tile coordinates
+			L.Log.log(textMsg, L.INCOMING);
+		}
+
 		if (textMsg.startsWith('cursorvisible:')) {
 			var command = textMsg.match('cursorvisible: true');
 			this._isCursorVisible = command ? true : false;
@@ -459,6 +464,7 @@ L.TileLayer = L.GridLayer.extend({
 			if (this._pendingTilesCount > 0) {
 				this._pendingTilesCount -= 1;
 			}
+			L.Log.log(textMsg, L.INCOMING, key);
 		}
 		else if (textMsg.startsWith('textselection:')) {
 			strTwips = textMsg.match(/\d+/g);
@@ -527,6 +533,7 @@ L.TileLayer = L.GridLayer.extend({
 	},
 
 	sendMessage: function (msg, coords) {
+		L.Log.log(msg, L.OUTGOING, coords);
 		this._map.socket.send(msg);
 	},
 
commit 51592a4c53f462385f418a671900920a1db0a5c7
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Thu Jul 16 13:55:53 2015 +0300

    loleaflet: log utility
    
    It's used to log communication between the server and the client
    It can print or download a csv formated file

diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index 7f22db1..c5927ba 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -1,6 +1,7 @@
 var deps = {
 	Core: {
 		src: ['Leaflet.js',
+		      'core/Log.js',
 		      'core/Util.js',
 		      'core/Class.js',
 		      'core/Events.js',
diff --git a/loleaflet/src/core/Log.js b/loleaflet/src/core/Log.js
new file mode 100644
index 0000000..e2a1355
--- /dev/null
+++ b/loleaflet/src/core/Log.js
@@ -0,0 +1,53 @@
+/*
+ * L.Log contains methods for logging the activity
+ */
+
+L.Log = {
+	log: function (msg, direction, tileCoords) {
+		var time = Date.now();
+		if (!this._logs) {
+			this._logs = [];
+		}
+		msg = msg.replace(/(\r\n|\n|\r)/gm,' ');
+		this._logs.push({msg : msg, direction : direction,
+			coords : tileCoords, time : time});
+	},
+
+	_getEntries: function () {
+		this._logs.sort(function (a, b) {
+			if (a.time < b.time) { return -1; }
+			if (a.time > b.time) { return 1; }
+			return 0;
+		});
+		var data = '';
+		for (var i = 0; i < this._logs.length; i++) {
+			data += this._logs[i].time + '.' + this._logs[i].direction + '.' +
+					this._logs[i].msg + '.' + this._logs[i].coords;
+			data += '\n';
+		}
+		return data;
+	},
+
+	print: function () {
+		console.log(this._getEntries());
+	},
+
+	save: function () {
+		var blob = new Blob([this._getEntries()], {type: 'text/csv'}),
+			e = document.createEvent('MouseEvents'),
+			a = document.createElement('a');
+
+		a.download = Date.now() + '.csv';
+		a.href = window.URL.createObjectURL(blob);
+		a.dataset.downloadurl =  ['text/csv', a.download, a.href].join(':');
+		e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
+		a.dispatchEvent(e);
+	},
+
+	clear: function () {
+		this._logs = [];
+	}
+};
+
+L.INCOMING = 'INCOMING';
+L.OUTGOING = 'OUTGOING';
commit d5f9250bd874d050b2e56d029c133ef045df1288
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Thu Jul 16 13:20:11 2015 +0300

    loleaflet: sendMessage method to replace map.socket.send

diff --git a/loleaflet/src/control/Buttons.js b/loleaflet/src/control/Buttons.js
index 1ce0c98..2f085f5 100644
--- a/loleaflet/src/control/Buttons.js
+++ b/loleaflet/src/control/Buttons.js
@@ -4,7 +4,7 @@
 L.Map.include({
 	toggleCommandState: function (unoState) {
 		if (this._docLayer._permission === 'edit') {
-			this.socket.send('uno .uno:' + unoState);
+			this._docLayer.sendMessage('uno .uno:' + unoState);
 		}
 	},
 
@@ -15,7 +15,7 @@ L.Map.include({
 		if (options === undefined || options === null) {
 			options = '';
 		}
-		this.socket.send('saveas ' +
+		this._docLayer.sendMessage('saveas ' +
 			'url=' + url + ' ' +
 			'format=' + format + ' ' +
 			'options=' + options);
diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
index 6f8c143..9ee871b 100644
--- a/loleaflet/src/control/Parts.js
+++ b/loleaflet/src/control/Parts.js
@@ -41,13 +41,13 @@ L.Map.include({
 		else {
 			maxHeight = Math.round(docLayer._docHeightTwips * maxWidth / docLayer._docWidthTwips);
 		}
-		this.socket.send('tile ' +
-				'part=' + part + ' ' +
-				'width=' + maxWidth + ' ' +
-				'height=' + maxHeight + ' ' +
-				'tileposx=0 tileposy=0 ' +
-				'tilewidth=' + docLayer._docWidthTwips + ' ' +
-				'tileheight=' + docLayer._docHeightTwips + ' ' +
-				'id=' + id);
+		docLayer.sendMessage('tile ' +
+							'part=' + part + ' ' +
+							'width=' + maxWidth + ' ' +
+							'height=' + maxHeight + ' ' +
+							'tileposx=0 tileposy=0 ' +
+							'tilewidth=' + docLayer._docWidthTwips + ' ' +
+							'tileheight=' + docLayer._docHeightTwips + ' ' +
+							'id=' + id);
 	}
 });
diff --git a/loleaflet/src/control/Search.js b/loleaflet/src/control/Search.js
index a60d9da..1526e99 100644
--- a/loleaflet/src/control/Search.js
+++ b/loleaflet/src/control/Search.js
@@ -29,6 +29,6 @@ L.Map.include({
 		searchCmd['SearchItem.SearchStartPointY'] = {};
 		searchCmd['SearchItem.SearchStartPointY'].type = 'long';
 		searchCmd['SearchItem.SearchStartPointY'].value = topLeftTwips.y;
-		this.socket.send('uno .uno:ExecuteSearch ' + JSON.stringify(searchCmd));
+		this._docLayer.sendMessage('uno .uno:ExecuteSearch ' + JSON.stringify(searchCmd));
 	}
 });
diff --git a/loleaflet/src/layer/tile/GridLayer.js b/loleaflet/src/layer/tile/GridLayer.js
index 7a59ae4..3016a78 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -516,7 +516,7 @@ L.GridLayer = L.Layer.extend({
 			if (newView) {
 				// we know that a new set of tiles that cover the whole view has been requested
 				// so we're able to cancel the previous requests that are being processed
-				this._map.socket.send('canceltiles');
+				this.sendMessage('canceltiles');
 				this._pendingTilesCount = 0;
 				for (key in this._tiles) {
 					if (!this._tiles[key].loaded) {
@@ -663,14 +663,14 @@ L.GridLayer = L.Layer.extend({
 			if (this.options.useSocket && this._map.socket) {
 				var twips = this._coordsToTwips(coords);
 				this._pendingTilesCount += 1;
-				this._map.socket.send('tile ' +
-										'part=' + this._currentPart + ' ' +
-										'width=' + this._tileSize + ' ' +
-										'height=' + this._tileSize + ' ' +
-										'tileposx=' + twips.x + ' '	+
-										'tileposy=' + twips.y + ' ' +
-										'tilewidth=' + this._tileWidthTwips + ' ' +
-										'tileheight=' + this._tileHeightTwips);
+				this.sendMessage('tile ' +
+								'part=' + this._currentPart + ' ' +
+								'width=' + this._tileSize + ' ' +
+								'height=' + this._tileSize + ' ' +
+								'tileposx=' + twips.x + ' '	+
+								'tileposy=' + twips.y + ' ' +
+								'tilewidth=' + this._tileWidthTwips + ' ' +
+								'tileheight=' + this._tileHeightTwips, key);
 			}
 		}
 		else {
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 2d23fbc..b52d7df 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -186,8 +186,8 @@ L.TileLayer = L.GridLayer.extend({
 			return;
 		}
 		if (this.options.doc) {
-			this._map.socket.send('load url=' + this.options.doc);
-			this._map.socket.send('status');
+			this.sendMessage('load url=' + this.options.doc);
+			this.sendMessage('status');
 		}
 		this._map._scrollContainer.onscroll = L.bind(this._onScroll, this);
 		this._map.on('zoomend resize', this._updateScrollOffset, this);
@@ -352,14 +352,14 @@ L.TileLayer = L.GridLayer.extend({
 					else {
 						this._tiles[key]._invalidCount = 1;
 					}
-					this._map.socket.send('tile ' +
+					this.sendMessage('tile ' +
 									'part=' + coords.part + ' ' +
 									'width=' + this._tileSize + ' ' +
 									'height=' + this._tileSize + ' ' +
 									'tileposx=' + point1.x + ' '    +
 									'tileposy=' + point1.y + ' ' +
 									'tilewidth=' + this._tileWidthTwips + ' ' +
-									'tileheight=' + this._tileHeightTwips);
+									'tileheight=' + this._tileHeightTwips, key);
 				}
 			}
 			for (var key in this._tileCache) {
@@ -501,7 +501,7 @@ L.TileLayer = L.GridLayer.extend({
 					clearTimeout(this._selectionContentRequest);
 				}
 				this._selectionContentRequest = setTimeout(L.bind(function () {
-					this._map.socket.send('gettextselection mimetype=text/plain;charset=utf-8');}, this), 100);
+					this.sendMessage('gettextselection mimetype=text/plain;charset=utf-8');}, this), 100);
 			}
 			this._onUpdateTextSelection();
 		}
@@ -526,6 +526,10 @@ L.TileLayer = L.GridLayer.extend({
 		}
 	},
 
+	sendMessage: function (msg, coords) {
+		this._map.socket.send(msg);
+	},
+
 	_tileOnLoad: function (done, tile) {
 		done(null, tile);
 	},
@@ -737,22 +741,22 @@ L.TileLayer = L.GridLayer.extend({
 	},
 
 	_postMouseEvent: function(type, x, y, count) {
-		this._map.socket.send('mouse type=' + type +
+		this.sendMessage('mouse type=' + type +
 				' x=' + x + ' y=' + y + ' count=' + count);
 	},
 
 	_postKeyboardEvent: function(type, charcode, keycode) {
-		this._map.socket.send('key type=' + type +
+		this.sendMessage('key type=' + type +
 				' char=' + charcode + ' key=' + keycode);
 	},
 
 	_postSelectGraphicEvent: function(type, x, y) {
-		this._map.socket.send('selectgraphic type=' + type +
+		this.sendMessage('selectgraphic type=' + type +
 				' x=' + x + ' y=' + y);
 	},
 
 	_postSelectTextEvent: function(type, x, y) {
-		this._map.socket.send('selecttext type=' + type +
+		this.sendMessage('selecttext type=' + type +
 				' x=' + x + ' y=' + y);
 	},
 


More information about the Libreoffice-commits mailing list