loleaflet/js/global.js | 79 ++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 43 deletions(-)
New commits: commit 3f9b486903622538ea11762d95402567772a0e0c Author: Michael Meeks <[email protected]> AuthorDate: Fri Mar 20 16:38:14 2020 +0000 Commit: Jan Holesovsky <[email protected]> CommitDate: Fri Apr 24 14:25:48 2020 +0200 Proxy: send multiple messages in a single request. Change-Id: Ic0a303979478801bd23941e8893ce5721cf3e732 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92807 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Jan Holesovsky <[email protected]> diff --git a/loleaflet/js/global.js b/loleaflet/js/global.js index eba6852b8..f5c038b91 100644 --- a/loleaflet/js/global.js +++ b/loleaflet/js/global.js @@ -196,6 +196,7 @@ global.proxySocketCounter = 0; global.ProxySocket = function (uri) { + var that = this; this.uri = uri; this.binaryType = 'arraybuffer'; this.bufferedAmount = 0; @@ -255,56 +256,48 @@ i += size; // skip trailing '\n' in loop-increment } }; - this.parseIncoming = function(type, msg) { - if (type === 'blob') - { - var fileReader = new FileReader(); - var that = this; - fileReader.onload = function(event) { - that.parseIncomingArray(event.target.result); - }; - fileReader.readAsArrayBuffer(msg); - } - else if (type === 'arraybuffer') - { - this.parseIncomingArray(new Uint8Array(msg)); - } - else if (type === 'text' || type === '') - { - const encoder = new TextEncoder(); - const arr = encoder.encode(msg); - this.parseIncomingArray(arr); - } - else - console.debug('Unknown encoding type: ' + type); - }; - this.send = function(msg) { - console.debug('send msg "' + msg + '"'); + this.sendQueue = ''; + this.sendTimeout = undefined; + this.doSend = function () { + that.sendTimeout = undefined; + console.debug('send msg "' + that.sendQueue + '"'); var req = new XMLHttpRequest(); - req.open('POST', this.getEndPoint('write')); - req.setRequestHeader('SessionId', this.sessionId); - if (this.sessionId === 'fetchsession') - { - req.responseType = 'text'; - req.addEventListener('load', function() { - console.debug('got session: ' + this.responseText); - that.sessionId = this.responseText; - that.readyState = 1; - that.onopen(); - }); - } + req.open('POST', that.getEndPoint('write')); + req.setRequestHeader('SessionId', that.sessionId); + if (that.sessionId === 'fetchsession') + console.debug('session fetch not completed'); else { req.responseType = 'arraybuffer'; req.addEventListener('load', function() { if (this.status == 200) - that.parseIncoming(this.responseType, this.response); + that.parseIncomingArray(new Uint8Array(this.response)); else console.debug('Error on incoming response'); }); } - req.send('B0x' + msg.length.toString(16) + '\n' + msg + '\n'); - }, + req.send(that.sendQueue); + that.sendQueue = ''; + }; + this.getSessionId = function() { + var req = new XMLHttpRequest(); + req.open('POST', that.getEndPoint('write')); + req.setRequestHeader('SessionId', that.sessionId); + req.responseType = 'text'; + req.addEventListener('load', function() { + console.debug('got session: ' + this.responseText); + that.sessionId = this.responseText; + that.readyState = 1; + that.onopen(); + }); + req.send(''); + }; + this.send = function(msg) { + this.sendQueue = this.sendQueue.concat( + 'B0x' + msg.length.toString(16) + '\n' + msg + '\n'); + if (this.sessionId !== 'fetchsession' && this.sendTimeout === undefined) + this.sendTimeout = setTimeout(this.doSend, 2 /* ms */); + }; this.close = function() { console.debug('close socket'); this.readyState = 3; @@ -316,8 +309,8 @@ }; console.debug('New proxy socket ' + this.id + ' ' + this.uri); - this.send('fetchsession'); - var that = this; + // queue fetch of session id. + this.getSessionId(); // horrors ... this.readInterval = setInterval(function() { @@ -329,7 +322,7 @@ // fetch session id: req.addEventListener('load', function() { if (this.status == 200) - that.parseIncoming(this.responseType, this.response); + that.parseIncomingArray(new Uint8Array(this.response)); else console.debug('Handle error ' + this.status); that.readWaiting = false; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
