GUAC-1172: Add Guacamole.Object and handlers for object-related instructions.

This commit is contained in:
Michael Jumper
2015-06-19 21:38:56 -07:00
parent d37d3914c9
commit d332b028e3
2 changed files with 337 additions and 0 deletions

View File

@@ -86,6 +86,14 @@ Guacamole.Client = function(tunnel) {
// No initial streams
var streams = [];
/**
* All current objects. The index of each object is dictated by the
* Guacamole server.
*
* @type Guacamole.Object[]
*/
var objects = [];
// Pool of available stream indices
var stream_indices = new Guacamole.IntegerPool();
@@ -293,6 +301,67 @@ Guacamole.Client = function(tunnel) {
};
/**
* Creates a new output stream associated with the given object and having
* the given mimetype and name. The legality of a mimetype and name is
* dictated by the object itself.
*
* @param {Number} index
* The index of the object for which the output stream is being
* created.
*
* @param {String} mimetype
* The mimetype of the data which will be sent to the output stream.
*
* @param {String} name
* The defined name of an output stream within the given object.
*
* @returns {Guacamole.OutputStream}
* An output stream which will write blobs to the named output stream
* of the given object.
*/
this.createObjectOutputStream = function(index, mimetype, name) {
// Allocate index
var streamIndex = stream_indices.next();
// Create new stream
tunnel.sendMessage("put", index, streamIndex, mimetype, name);
var stream = output_streams[streamIndex] = new Guacamole.OutputStream(guac_client, streamIndex);
// Override sendEnd() of stream to automatically free index
var oldEnd = stream.sendEnd;
stream.sendEnd = function() {
oldEnd();
stream_indices.free(streamIndex);
delete output_streams[streamIndex];
};
// Return new, overridden stream
return stream;
};
/**
* Requests read access to the input stream having the given name. If
* successful, a new input stream will be created.
*
* @param {Number} index
* The index of the object from which the input stream is being
* requested.
*
* @param {String} name
* The name of the input stream to request.
*/
this.requestObjectInputStream = function(index, name) {
// Do not send requests if not connected
if (!isConnected())
return;
tunnel.sendMessage("get", index, name);
};
/**
* Acknowledge receipt of a blob on the stream with the given index.
*
@@ -388,6 +457,20 @@ Guacamole.Client = function(tunnel) {
*/
this.onfile = null;
/**
* Fired when a filesystem object is created. The object provided to this
* event handler will contain its own event handlers and functions for
* requesting and handling data.
*
* @event
* @param {Guacamole.Object} object
* The created filesystem object.
*
* @param {String} name
* The name of the filesystem.
*/
this.onfilesystem = null;
/**
* Fired when a pipe stream is created. The stream provided to this event
* handler will contain its own event handlers for received data;
@@ -562,6 +645,28 @@ Guacamole.Client = function(tunnel) {
},
"body": function(parameters) {
// Get object
var objectIndex = parseInt(parameters[0]);
var object = objects[objectIndex];
var streamIndex = parseInt(parameters[1]);
var mimetype = parameters[2];
var name = parameters[3];
// Create stream if handler defined
if (object && object.onbody) {
var stream = streams[streamIndex] = new Guacamole.InputStream(guac_client, streamIndex);
object.onbody(stream, mimetype, name);
}
// Otherwise, unsupported
else
guac_client.sendAck(streamIndex, "Receipt of body unsupported", 0x0100);
},
"cfill": function(parameters) {
var channelMask = parseInt(parameters[0]);
@@ -758,6 +863,21 @@ Guacamole.Client = function(tunnel) {
},
"filesystem": function(parameters) {
var objectIndex = parseInt(parameters[0]);
var name = parameters[1];
// Create object, if supported
if (guac_client.onfilesystem) {
var object = objects[objectIndex] = new Guacamole.Object(guac_client, objectIndex);
guac_client.onfilesystem(object, name);
}
// If unsupported, simply ignore the availability of the filesystem
},
"identity": function(parameters) {
var layer = getLayer(parseInt(parameters[0]));
@@ -998,6 +1118,18 @@ Guacamole.Client = function(tunnel) {
},
"undefine": function(parameters) {
// Get object
var objectIndex = parseInt(parameters[0]);
var object = objects[objectIndex];
// Signal end of object definition
if (object && object.onundefine)
object.onundefine();
},
"video": function(parameters) {
var stream_index = parseInt(parameters[0]);