From 43a823e5c8b5ffc9b656bcdba02e4c6d54fca70a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 26 Oct 2012 12:23:18 -0700 Subject: [PATCH] Add file instruction handler and event, modify parser to not drop length if only partially received. --- .../src/main/resources/guacamole.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 3003d2ce6..9f9fbf3ad 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -82,7 +82,7 @@ Guacamole.Parser = function() { this.receive = function(packet) { // Truncate buffer as necessary - if (start_index > 4096) { + if (start_index > 4096 && element_end >= start_index) { buffer = buffer.substring(start_index); @@ -473,6 +473,18 @@ Guacamole.Client = function(tunnel) { */ this.onresize = null; + /** + * Fired when a file is received. Note that this will contain the entire + * data of the file. + * + * @event + * @param {String} name A human-readable name describing the file. + * @param {String} mimetype The mimetype of the file received. + * @param {String} data The actual entire contents of the file, + * base64-encoded. + */ + this.onfile = null; + // Layers function getBufferLayer(index) { @@ -773,6 +785,15 @@ Guacamole.Client = function(tunnel) { guac_client.disconnect(); }, + "file": function(parameters) { + if (guac_client.onfile) + guac_client.onfile( + parameters[0], // Name + parameters[1], // Mimetype + parameters[2] // Data + ); + }, + "identity": function(parameters) { var layer = getLayer(parseInt(parameters[0]));