mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
Implement ack, use instead of sync to signal continuing upload.
This commit is contained in:
@@ -372,6 +372,17 @@ Guacamole.OutputStream = function(client, index) {
|
|||||||
*/
|
*/
|
||||||
this.onerror = null;
|
this.onerror = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired whenever an acknowledgement is received from the server, indicating
|
||||||
|
* that a stream operation has completed.
|
||||||
|
*
|
||||||
|
* @event
|
||||||
|
* @param {String} message A human-readable status message related to the
|
||||||
|
* operation performed.
|
||||||
|
* @param {Number} code The error code associated with the operation.
|
||||||
|
*/
|
||||||
|
this.onack = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the given base64-encoded data to this stream as a blob.
|
* Writes the given base64-encoded data to this stream as a blob.
|
||||||
*
|
*
|
||||||
@@ -875,7 +886,7 @@ Guacamole.Client = function(tunnel) {
|
|||||||
*/
|
*/
|
||||||
var instructionHandlers = {
|
var instructionHandlers = {
|
||||||
|
|
||||||
"abort": function(parameters) {
|
"ack": function(parameters) {
|
||||||
|
|
||||||
var stream_index = parseInt(parameters[0]);
|
var stream_index = parseInt(parameters[0]);
|
||||||
var reason = parameters[1];
|
var reason = parameters[1];
|
||||||
@@ -883,16 +894,23 @@ Guacamole.Client = function(tunnel) {
|
|||||||
|
|
||||||
// Get stream
|
// Get stream
|
||||||
var stream = output_streams[stream_index];
|
var stream = output_streams[stream_index];
|
||||||
|
|
||||||
// Invalidate stream
|
|
||||||
if (stream) {
|
if (stream) {
|
||||||
|
|
||||||
// Signal error if handler defined
|
// If code is an error, invalidate stream
|
||||||
if (stream.onerror)
|
if (code >= 0x0100) {
|
||||||
stream.onerror(reason, code);
|
|
||||||
|
// Signal error
|
||||||
|
if (stream.onerror)
|
||||||
|
stream.onerror(reason, code);
|
||||||
|
|
||||||
|
stream_indices.free(stream_index);
|
||||||
|
delete output_streams[stream_index];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signal error if handler defined
|
||||||
|
else if (stream.onack)
|
||||||
|
stream.onack(reason, code);
|
||||||
|
|
||||||
stream_indices.free(stream_index);
|
|
||||||
delete output_streams[stream_index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@@ -673,9 +673,6 @@ 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.
|
||||||
*/
|
*/
|
||||||
@@ -773,18 +770,6 @@ 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.
|
||||||
*/
|
*/
|
||||||
@@ -1112,9 +1097,9 @@ GuacUI.Client.attach = function(guac) {
|
|||||||
stream.onerror = function() {
|
stream.onerror = function() {
|
||||||
valid = false;
|
valid = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create upload callback
|
// Continue upload when acknowledged
|
||||||
function continueUpload() {
|
stream.onack = function() {
|
||||||
|
|
||||||
// Abort upload if stream is invalid
|
// Abort upload if stream is invalid
|
||||||
if (!valid) return false;
|
if (!valid) return false;
|
||||||
@@ -1130,19 +1115,11 @@ GuacUI.Client.attach = function(guac) {
|
|||||||
offset += 4096;
|
offset += 4096;
|
||||||
|
|
||||||
// If at end, stop upload
|
// If at end, stop upload
|
||||||
if (offset >= bytes.length) {
|
if (offset >= bytes.length)
|
||||||
stream.close();
|
stream.close();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, continue
|
|
||||||
return true;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add to list, ready for sending
|
|
||||||
pending_uploads.push(continueUpload);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
reader.readAsArrayBuffer(file);
|
reader.readAsArrayBuffer(file);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user