From 13cefc929650db27892a615c513a9fe8f42183f3 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 8 Apr 2014 12:49:17 -0700 Subject: [PATCH] GUAC-608: Automatically divide outbound data into roughly 8K (max) blobs. --- .../main/webapp/modules/ArrayBufferWriter.js | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/webapp/modules/ArrayBufferWriter.js b/guacamole-common-js/src/main/webapp/modules/ArrayBufferWriter.js index feda39017..bee537540 100644 --- a/guacamole-common-js/src/main/webapp/modules/ArrayBufferWriter.js +++ b/guacamole-common-js/src/main/webapp/modules/ArrayBufferWriter.js @@ -45,13 +45,14 @@ Guacamole.ArrayBufferWriter = function(stream) { }; /** - * Sends the given data. + * Encodes the given data as base64, sending it as a blob. The data must + * be small enough to fit into a single blob instruction. * - * @param {ArrayBuffer} data The data to send. + * @private + * @param {Uint8Array} bytes The data to send. */ - this.sendData = function(data) { + function __send_blob(bytes) { - var bytes = new Uint8Array(data); var binary = ""; // Produce binary string from bytes in buffer @@ -61,6 +62,27 @@ Guacamole.ArrayBufferWriter = function(stream) { // Send as base64 stream.sendBlob(window.btoa(binary)); + } + + /** + * Sends the given data. + * + * @param {ArrayBuffer|TypedArray} data The data to send. + */ + this.sendData = function(data) { + + var bytes = new Uint8Array(data); + + // If small enough to fit into single instruction, send as-is + if (bytes.length <= 8064) + __send_blob(bytes); + + // Otherwise, send as multiple instructions + else { + for (var offset=0; offset