@@ -86,6 +86,14 @@ Guacamole.Client = function(tunnel) {
86
86
// No initial streams
87
87
var streams = [ ] ;
88
88
89
+ /**
90
+ * All current objects. The index of each object is dictated by the
91
+ * Guacamole server.
92
+ *
93
+ * @type Guacamole.Object[]
94
+ */
95
+ var objects = [ ] ;
96
+
89
97
// Pool of available stream indices
90
98
var stream_indices = new Guacamole . IntegerPool ( ) ;
91
99
@@ -293,6 +301,67 @@ Guacamole.Client = function(tunnel) {
293
301
294
302
} ;
295
303
304
+ /**
305
+ * Creates a new output stream associated with the given object and having
306
+ * the given mimetype and name. The legality of a mimetype and name is
307
+ * dictated by the object itself.
308
+ *
309
+ * @param {Number } index
310
+ * The index of the object for which the output stream is being
311
+ * created.
312
+ *
313
+ * @param {String } mimetype
314
+ * The mimetype of the data which will be sent to the output stream.
315
+ *
316
+ * @param {String } name
317
+ * The defined name of an output stream within the given object.
318
+ *
319
+ * @returns {Guacamole.OutputStream }
320
+ * An output stream which will write blobs to the named output stream
321
+ * of the given object.
322
+ */
323
+ this . createObjectOutputStream = function createObjectOutputStream ( index , mimetype , name ) {
324
+
325
+ // Allocate index
326
+ var streamIndex = stream_indices . next ( ) ;
327
+
328
+ // Create new stream
329
+ tunnel . sendMessage ( "put" , index , streamIndex , mimetype , name ) ;
330
+ var stream = output_streams [ streamIndex ] = new Guacamole . OutputStream ( guac_client , streamIndex ) ;
331
+
332
+ // Override sendEnd() of stream to automatically free index
333
+ var oldEnd = stream . sendEnd ;
334
+ stream . sendEnd = function freeStreamIndex ( ) {
335
+ oldEnd ( ) ;
336
+ stream_indices . free ( streamIndex ) ;
337
+ delete output_streams [ streamIndex ] ;
338
+ } ;
339
+
340
+ // Return new, overridden stream
341
+ return stream ;
342
+
343
+ } ;
344
+
345
+ /**
346
+ * Requests read access to the input stream having the given name. If
347
+ * successful, a new input stream will be created.
348
+ *
349
+ * @param {Number } index
350
+ * The index of the object from which the input stream is being
351
+ * requested.
352
+ *
353
+ * @param {String } name
354
+ * The name of the input stream to request.
355
+ */
356
+ this . requestObjectInputStream = function requestObjectInputStream ( index , name ) {
357
+
358
+ // Do not send requests if not connected
359
+ if ( ! isConnected ( ) )
360
+ return ;
361
+
362
+ tunnel . sendMessage ( "get" , index , name ) ;
363
+ } ;
364
+
296
365
/**
297
366
* Acknowledge receipt of a blob on the stream with the given index.
298
367
*
@@ -388,6 +457,20 @@ Guacamole.Client = function(tunnel) {
388
457
*/
389
458
this . onfile = null ;
390
459
460
+ /**
461
+ * Fired when a filesystem object is created. The object provided to this
462
+ * event handler will contain its own event handlers and functions for
463
+ * requesting and handling data.
464
+ *
465
+ * @event
466
+ * @param {Guacamole.Object } object
467
+ * The created filesystem object.
468
+ *
469
+ * @param {String } name
470
+ * The name of the filesystem.
471
+ */
472
+ this . onfilesystem = null ;
473
+
391
474
/**
392
475
* Fired when a pipe stream is created. The stream provided to this event
393
476
* handler will contain its own event handlers for received data;
@@ -562,6 +645,28 @@ Guacamole.Client = function(tunnel) {
562
645
563
646
} ,
564
647
648
+ "body" : function handleBody ( parameters ) {
649
+
650
+ // Get object
651
+ var objectIndex = parseInt ( parameters [ 0 ] ) ;
652
+ var object = objects [ objectIndex ] ;
653
+
654
+ var streamIndex = parseInt ( parameters [ 1 ] ) ;
655
+ var mimetype = parameters [ 2 ] ;
656
+ var name = parameters [ 3 ] ;
657
+
658
+ // Create stream if handler defined
659
+ if ( object && object . onbody ) {
660
+ var stream = streams [ streamIndex ] = new Guacamole . InputStream ( guac_client , streamIndex ) ;
661
+ object . onbody ( stream , mimetype , name ) ;
662
+ }
663
+
664
+ // Otherwise, unsupported
665
+ else
666
+ guac_client . sendAck ( streamIndex , "Receipt of body unsupported" , 0x0100 ) ;
667
+
668
+ } ,
669
+
565
670
"cfill" : function ( parameters ) {
566
671
567
672
var channelMask = parseInt ( parameters [ 0 ] ) ;
@@ -758,6 +863,21 @@ Guacamole.Client = function(tunnel) {
758
863
759
864
} ,
760
865
866
+ "filesystem" : function handleFilesystem ( parameters ) {
867
+
868
+ var objectIndex = parseInt ( parameters [ 0 ] ) ;
869
+ var name = parameters [ 1 ] ;
870
+
871
+ // Create object, if supported
872
+ if ( guac_client . onfilesystem ) {
873
+ var object = objects [ objectIndex ] = new Guacamole . Object ( guac_client , objectIndex ) ;
874
+ guac_client . onfilesystem ( object , name ) ;
875
+ }
876
+
877
+ // If unsupported, simply ignore the availability of the filesystem
878
+
879
+ } ,
880
+
761
881
"identity" : function ( parameters ) {
762
882
763
883
var layer = getLayer ( parseInt ( parameters [ 0 ] ) ) ;
@@ -998,6 +1118,18 @@ Guacamole.Client = function(tunnel) {
998
1118
999
1119
} ,
1000
1120
1121
+ "undefine" : function handleUndefine ( parameters ) {
1122
+
1123
+ // Get object
1124
+ var objectIndex = parseInt ( parameters [ 0 ] ) ;
1125
+ var object = objects [ objectIndex ] ;
1126
+
1127
+ // Signal end of object definition
1128
+ if ( object && object . onundefine )
1129
+ object . onundefine ( ) ;
1130
+
1131
+ } ,
1132
+
1001
1133
"video" : function ( parameters ) {
1002
1134
1003
1135
var stream_index = parseInt ( parameters [ 0 ] ) ;
0 commit comments