From f9c3e02f47b34ea558239430d07259e1a096ded4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 28 Dec 2014 20:01:01 -0800 Subject: [PATCH] GUAC-963: Remove managed client when view is destroyed if client is no longer connected. --- .../client/controllers/clientController.js | 15 +++++++++ .../app/client/services/guacClientManager.js | 33 +++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/guacamole/src/main/webapp/app/client/controllers/clientController.js b/guacamole/src/main/webapp/app/client/controllers/clientController.js index 56d310b6d..25990a0b6 100644 --- a/guacamole/src/main/webapp/app/client/controllers/clientController.js +++ b/guacamole/src/main/webapp/app/client/controllers/clientController.js @@ -709,6 +709,21 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams // Clean up when view destroyed $scope.$on('$destroy', function clientViewDestroyed() { + // Remove client from client manager if no longer connected + var managedClient = $scope.client; + if (managedClient) { + + // Get current connection state + var connectionState = managedClient.clientState.connectionState; + + // If disconnected, remove from management + if (connectionState === ManagedClientState.ConnectionState.DISCONNECTED + || connectionState === ManagedClientState.ConnectionState.TUNNEL_ERROR + || connectionState === ManagedClientState.ConnectionState.CLIENT_ERROR) + guacClientManager.removeManagedClient(managedClient.id); + + } + // Hide any status dialog $scope.showStatus(false); diff --git a/guacamole/src/main/webapp/app/client/services/guacClientManager.js b/guacamole/src/main/webapp/app/client/services/guacClientManager.js index 8e200e3ab..fc5482708 100644 --- a/guacamole/src/main/webapp/app/client/services/guacClientManager.js +++ b/guacamole/src/main/webapp/app/client/services/guacClientManager.js @@ -36,6 +36,36 @@ angular.module('client').factory('guacClientManager', ['ManagedClient', */ service.managedClients = {}; + /** + * Removes the existing ManagedClient associated with the connection having + * the given ID, if any. If no such a ManagedClient already exists, this + * function has no effect. + * + * @param {String} id + * The ID of the connection whose ManagedClient should be removed. + * + * @returns {Boolean} + * true if an existing client was removed, false otherwise. + */ + service.removeManagedClient = function replaceManagedClient(id) { + + // Remove client if it exists + if (id in service.managedClients) { + + // Disconnect and remove + service.managedClients[id].client.disconnect(); + delete service.managedClients[id]; + + // A client was removed + return true; + + } + + // No client was removed + return false; + + }; + /** * Creates a new ManagedClient associated with the connection having the * given ID. If such a ManagedClient already exists, it is disconnected and @@ -56,8 +86,7 @@ angular.module('client').factory('guacClientManager', ['ManagedClient', service.replaceManagedClient = function replaceManagedClient(id, connectionParameters) { // Disconnect any existing client - if (id in service.managedClients) - service.managedClients[id].client.disconnect(); + service.removeManagedClient(id); // Set new client return service.managedClients[id] = ManagedClient.getInstance(id, connectionParameters);