mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-10 07:01:21 +00:00
Create dedicated object for streams.
This commit is contained in:
@@ -297,6 +297,45 @@ Guacamole.Blob = function(mimetype, name) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract stream which can receive data.
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
* @param {Guacamole.Client} client The client owning this stream.
|
||||||
|
* @param {Number} index The index of this stream.
|
||||||
|
*/
|
||||||
|
Guacamole.OutputStream = function(client, index) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to this stream.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
var guac_stream = this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The index of this stream.
|
||||||
|
* @type Number
|
||||||
|
*/
|
||||||
|
this.index = index;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the given base64-encoded data to this stream as a blob.
|
||||||
|
*
|
||||||
|
* @param {String} data The base64-encoded data to send.
|
||||||
|
*/
|
||||||
|
this.write = function(data) {
|
||||||
|
client.sendBlob(guac_stream.index, data);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes this stream.
|
||||||
|
*/
|
||||||
|
this.close = function() {
|
||||||
|
client.endStream(guac_stream.index);
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guacamole protocol client. Given a display element and {@link Guacamole.Tunnel},
|
* Guacamole protocol client. Given a display element and {@link Guacamole.Tunnel},
|
||||||
* automatically handles incoming and outgoing Guacamole instructions via the
|
* automatically handles incoming and outgoing Guacamole instructions via the
|
||||||
@@ -580,6 +619,20 @@ Guacamole.Client = function(tunnel) {
|
|||||||
tunnel.sendMessage("end", index);
|
tunnel.sendMessage("end", index);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a new file for writing, having the given index, mimetype and
|
||||||
|
* filename.
|
||||||
|
*
|
||||||
|
* @param {Number} index The index of the file to write to. This index must
|
||||||
|
* be unused.
|
||||||
|
* @param {String} mimetype The mimetype of the file being sent.
|
||||||
|
* @param {String} filename The filename of the file being sent.
|
||||||
|
*/
|
||||||
|
this.createFileStream = function(index, mimetype, filename) {
|
||||||
|
guac_client.beginFileStream(index, mimetype, filename);
|
||||||
|
return new Guacamole.OutputStream(guac_client, index);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired whenever the state of this Guacamole.Client changes.
|
* Fired whenever the state of this Guacamole.Client changes.
|
||||||
*
|
*
|
||||||
|
@@ -1088,7 +1088,7 @@ GuacUI.Client.attach = function(guac) {
|
|||||||
reader.onloadend = function() {
|
reader.onloadend = function() {
|
||||||
|
|
||||||
// Open file for writing
|
// Open file for writing
|
||||||
GuacUI.Client.attachedClient.beginFileStream(index, file.type, file.name);
|
var stream = GuacUI.Client.attachedClient.createFileStream(index, file.type, file.name);
|
||||||
|
|
||||||
var bytes = new Uint8Array(reader.result);
|
var bytes = new Uint8Array(reader.result);
|
||||||
var offset = 0;
|
var offset = 0;
|
||||||
@@ -1100,14 +1100,14 @@ GuacUI.Client.attach = function(guac) {
|
|||||||
var base64 = _get_base64(slice);
|
var base64 = _get_base64(slice);
|
||||||
|
|
||||||
// "Write" packet
|
// "Write" packet
|
||||||
GuacUI.Client.attachedClient.sendBlob(index, base64);
|
stream.write(base64);
|
||||||
|
|
||||||
// Advance to next packet, or close if EOF
|
// Advance to next packet, or close if EOF
|
||||||
offset += 4096;
|
offset += 4096;
|
||||||
if (offset < bytes.length)
|
if (offset < bytes.length)
|
||||||
window.setTimeout(continueUpload, 500);
|
window.setTimeout(continueUpload, 500);
|
||||||
else
|
else
|
||||||
GuacUI.Client.attachedClient.endStream(index);
|
stream.close();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user