mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
Update onerror for client. Add onerror for output stream. Handle abort instruction. Track streams by index.
This commit is contained in:
@@ -364,6 +364,14 @@ Guacamole.OutputStream = function(client, index) {
|
|||||||
*/
|
*/
|
||||||
this.index = index;
|
this.index = index;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired when the stream is being closed due to an error.
|
||||||
|
*
|
||||||
|
* @param {String} reason A human-readable reason describing the error.
|
||||||
|
* @param {Number} code The error code associated with the error.
|
||||||
|
*/
|
||||||
|
this.onerror = 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.
|
||||||
*
|
*
|
||||||
@@ -494,9 +502,12 @@ Guacamole.Client = function(tunnel) {
|
|||||||
// No initial streams
|
// No initial streams
|
||||||
var streams = [];
|
var streams = [];
|
||||||
|
|
||||||
// Pool of available streams
|
// Pool of available stream indices
|
||||||
var stream_indices = new Guacamole.IntegerPool();
|
var stream_indices = new Guacamole.IntegerPool();
|
||||||
|
|
||||||
|
// Array of allocated output streams by index
|
||||||
|
var output_streams = [];
|
||||||
|
|
||||||
tunnel.onerror = function(message) {
|
tunnel.onerror = function(message) {
|
||||||
if (guac_client.onerror)
|
if (guac_client.onerror)
|
||||||
guac_client.onerror(message);
|
guac_client.onerror(message);
|
||||||
@@ -682,13 +693,14 @@ Guacamole.Client = function(tunnel) {
|
|||||||
|
|
||||||
// Create new stream
|
// Create new stream
|
||||||
guac_client.beginFileStream(index, mimetype, filename);
|
guac_client.beginFileStream(index, mimetype, filename);
|
||||||
var stream = new Guacamole.OutputStream(guac_client, index);
|
var stream = output_streams[index] = new Guacamole.OutputStream(guac_client, index);
|
||||||
|
|
||||||
// Override close() of stream to automatically free index
|
// Override close() of stream to automatically free index
|
||||||
var old_close = stream.close;
|
var old_close = stream.close;
|
||||||
stream.close = function() {
|
stream.close = function() {
|
||||||
old_close();
|
old_close();
|
||||||
stream_indices.free(index);
|
stream_indices.free(index);
|
||||||
|
delete output_streams[index];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return new, overridden stream
|
// Return new, overridden stream
|
||||||
@@ -717,7 +729,8 @@ Guacamole.Client = function(tunnel) {
|
|||||||
* is being closed.
|
* is being closed.
|
||||||
*
|
*
|
||||||
* @event
|
* @event
|
||||||
* @param {String} error A human-readable description of the error.
|
* @param {String} reason A human-readable reason describing the error.
|
||||||
|
* @param {Number} code The error code associated with the error.
|
||||||
*/
|
*/
|
||||||
this.onerror = null;
|
this.onerror = null;
|
||||||
|
|
||||||
@@ -862,6 +875,28 @@ Guacamole.Client = function(tunnel) {
|
|||||||
*/
|
*/
|
||||||
var instructionHandlers = {
|
var instructionHandlers = {
|
||||||
|
|
||||||
|
"abort": function(parameters) {
|
||||||
|
|
||||||
|
var stream_index = parseInt(parameters[0]);
|
||||||
|
var reason = parameters[1];
|
||||||
|
var code = parameters[2];
|
||||||
|
|
||||||
|
// Get stream
|
||||||
|
var stream = output_streams[stream_index];
|
||||||
|
|
||||||
|
// Invalidate stream
|
||||||
|
if (stream) {
|
||||||
|
|
||||||
|
// Signal error if handler defined
|
||||||
|
if (stream.onerror)
|
||||||
|
stream.onerror(reason, code);
|
||||||
|
|
||||||
|
stream_indices.free(stream_index);
|
||||||
|
delete output_streams[stream_index];
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
"arc": function(parameters) {
|
"arc": function(parameters) {
|
||||||
|
|
||||||
var layer = getLayer(parseInt(parameters[0]));
|
var layer = getLayer(parseInt(parameters[0]));
|
||||||
@@ -1085,8 +1120,16 @@ Guacamole.Client = function(tunnel) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
"error": function(parameters) {
|
"error": function(parameters) {
|
||||||
if (guac_client.onerror) guac_client.onerror(parameters[0]);
|
|
||||||
|
var reason = parameters[0];
|
||||||
|
var code = parameters[1];
|
||||||
|
|
||||||
|
// Call handler if defined
|
||||||
|
if (guac_client.onerror)
|
||||||
|
guac_client.onerror(reason, code);
|
||||||
|
|
||||||
guac_client.disconnect();
|
guac_client.disconnect();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"end": function(parameters) {
|
"end": function(parameters) {
|
||||||
|
@@ -1104,12 +1104,21 @@ GuacUI.Client.attach = function(guac) {
|
|||||||
// Open file for writing
|
// Open file for writing
|
||||||
var stream = GuacUI.Client.attachedClient.createFileStream(file.type, file.name);
|
var stream = GuacUI.Client.attachedClient.createFileStream(file.type, file.name);
|
||||||
|
|
||||||
|
var valid = true;
|
||||||
var bytes = new Uint8Array(reader.result);
|
var bytes = new Uint8Array(reader.result);
|
||||||
var offset = 0;
|
var offset = 0;
|
||||||
|
|
||||||
|
// Invalidate stream on all errors
|
||||||
|
stream.onerror = function() {
|
||||||
|
valid = false;
|
||||||
|
};
|
||||||
|
|
||||||
// Create upload callback
|
// Create upload callback
|
||||||
function continueUpload() {
|
function continueUpload() {
|
||||||
|
|
||||||
|
// Abort upload if stream is invalid
|
||||||
|
if (!valid) return false;
|
||||||
|
|
||||||
// Encode packet as base64
|
// Encode packet as base64
|
||||||
var slice = bytes.subarray(offset, offset+4096);
|
var slice = bytes.subarray(offset, offset+4096);
|
||||||
var base64 = _get_base64(slice);
|
var base64 = _get_base64(slice);
|
||||||
|
Reference in New Issue
Block a user