Send blobs in response to sync, rather than waiting an arbitrary time period.

This commit is contained in:
Michael Jumper
2013-09-27 17:04:41 -07:00
parent 56c6c1d637
commit 3b147096e6

View File

@@ -673,6 +673,9 @@ GuacUI.Client.attach = function(guac) {
// Get display element // Get display element
var guac_display = guac.getDisplay(); var guac_display = guac.getDisplay();
// Array of any pending uploads
var pending_uploads = [];
/* /*
* Update the scale of the display when the client display size changes. * Update the scale of the display when the client display size changes.
*/ */
@@ -770,6 +773,18 @@ GuacUI.Client.attach = function(guac) {
GuacUI.sessionState.setProperty("clipboard", data); GuacUI.sessionState.setProperty("clipboard", data);
}; };
// Handle any pending uploads when server is ready
guac.onsync = function() {
// Pull top pending upload from head of list
var pending_upload = pending_uploads.shift();
// If still more to upload, add to tail of list
if (pending_upload && pending_upload())
pending_uploads.push(pending_upload);
};
/* /*
* Prompt to download file when file received. * Prompt to download file when file received.
*/ */
@@ -1092,6 +1107,7 @@ GuacUI.Client.attach = function(guac) {
var bytes = new Uint8Array(reader.result); var bytes = new Uint8Array(reader.result);
var offset = 0; var offset = 0;
// Create upload callback
function continueUpload() { function continueUpload() {
// Encode packet as base64 // Encode packet as base64
@@ -1101,17 +1117,22 @@ GuacUI.Client.attach = function(guac) {
// Write packet // Write packet
stream.write(base64); stream.write(base64);
// Advance to next packet, or close if EOF // Advance to next packet
offset += 4096; offset += 4096;
if (offset < bytes.length)
window.setTimeout(continueUpload, 500); // If at end, stop upload
else if (offset >= bytes.length) {
stream.close(); stream.close();
return false;
}
// Otherwise, continue
return true;
}; };
// Start upload // Add to list, ready for sending
window.setTimeout(continueUpload, 500); pending_uploads.push(continueUpload);
}; };
reader.readAsArrayBuffer(file); reader.readAsArrayBuffer(file);