mike-jumper commented on code in PR #1001: URL: https://github.com/apache/guacamole-client/pull/1001#discussion_r1823383851
########## guacamole/src/main/frontend/src/app/client/types/ManagedClient.js: ########## @@ -1004,6 +1076,72 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector', }; + + /** + * Register a handler that will be automatically invoked for any deferred + * pipe stream with the provided name, either when a pipe stream with a + * name matching a registered handler is received, or immediately when this + * function is called, if such a pipe stream has already been received. + * + * NOTE: Pipe streams are automatically deferred by the default onpipe + * implementation. To preserve this behavior when using a custom onpipe + * callback, make sure to defer to the default implementation as needed. + * + * @param {ManagedClient} managedClient + * The client for which the deferred pipe stream handler should be set. + * + * @param {String} name + * The name of the pipe stream that should be handeled by the provided + * handler. If another handler is already registered for this name, it + * will be replaced by the handler provided to this function. + * + * @param {Function} handler + * The handler that should handle any deferred pipe stream with the + * provided name. This function must take the same arguments as the + * standard onpipe handler - namely, the stream itself, the mimetype, + * and the name. + */ + ManagedClient.registerDeferredPipeHandler = function registerDeferredPipeHandler( + managedClient, name, handler) { + managedClient.deferredPipeStreamHandlers[name] = handler; + + // Invoke the handler now, if the pipestream has already been received + if (managedClient.deferredPipeStreams[name]) { + + // Invoke the handler with the deferred pipe stream + var deferredStream = managedClient.deferredPipeStreams[name]; + handler(deferredStream.stream, + deferredStream.mimetype, + deferredStream.name); + + // Clean up the now-consumed pipe stream + delete managedClient.deferredPipeStreams[name]; + } + }; + + /** + * Detach the provided deferred pipe stream handler, if it is currently + * registered for the provided pipe stream name. + * + * @param {String} name + * The name of the associated pipe stream for the handler that should + * be detached. + * + * @param {Function} handler + * The handler that should be detached. + * + * @param {ManagedClient} managedClient + * The client for which the deferred pipe stream handler should be + * detached. + */ + ManagedClient.detachDeferredPipeHandler = function detachDeferredPipeHandler( + managedClient, name, handler) { + + // Remove the handler if found + if (managedClient.deferredPipeStreamHandlers[name] === handler) + delete managedClient.deferredPipeStreamHandlers[name]; + } Review Comment: Missing semicolon here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@guacamole.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org