mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-08 06:01:22 +00:00
GUAC-1161: Store managed clients in session storage.
This commit is contained in:
@@ -30,18 +30,34 @@ angular.module('client').factory('guacClientManager', ['$injector',
|
|||||||
var ManagedClient = $injector.get('ManagedClient');
|
var ManagedClient = $injector.get('ManagedClient');
|
||||||
|
|
||||||
// Required services
|
// Required services
|
||||||
var $window = $injector.get('$window');
|
var $window = $injector.get('$window');
|
||||||
var $rootScope = $injector.get('$rootScope');
|
var sessionStorageFactory = $injector.get('sessionStorageFactory');
|
||||||
|
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of all active managed clients. Each key is the ID of the connection
|
* Getter/setter which retrieves or sets the map of all active managed
|
||||||
* used by that client.
|
* clients. Each key is the ID of the connection used by that client.
|
||||||
*
|
*
|
||||||
* @type Object.<String, ManagedClient>
|
* @type Function
|
||||||
*/
|
*/
|
||||||
service.managedClients = {};
|
var storedManagedClients = sessionStorageFactory.create({}, function destroyClientStorage() {
|
||||||
|
|
||||||
|
// Disconnect all clients when storage is destroyed
|
||||||
|
service.clear();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a map of all active managed clients. Each key is the ID of the
|
||||||
|
* connection used by that client.
|
||||||
|
*
|
||||||
|
* @returns {Object.<String, ManagedClient>}
|
||||||
|
* A map of all active managed clients.
|
||||||
|
*/
|
||||||
|
service.getManagedClients = function getManagedClients() {
|
||||||
|
return storedManagedClients();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the existing ManagedClient associated with the connection having
|
* Removes the existing ManagedClient associated with the connection having
|
||||||
@@ -55,13 +71,15 @@ angular.module('client').factory('guacClientManager', ['$injector',
|
|||||||
* true if an existing client was removed, false otherwise.
|
* true if an existing client was removed, false otherwise.
|
||||||
*/
|
*/
|
||||||
service.removeManagedClient = function replaceManagedClient(id) {
|
service.removeManagedClient = function replaceManagedClient(id) {
|
||||||
|
|
||||||
|
var managedClients = storedManagedClients();
|
||||||
|
|
||||||
// Remove client if it exists
|
// Remove client if it exists
|
||||||
if (id in service.managedClients) {
|
if (id in managedClients) {
|
||||||
|
|
||||||
// Disconnect and remove
|
// Disconnect and remove
|
||||||
service.managedClients[id].client.disconnect();
|
managedClients[id].client.disconnect();
|
||||||
delete service.managedClients[id];
|
delete managedClients[id];
|
||||||
|
|
||||||
// A client was removed
|
// A client was removed
|
||||||
return true;
|
return true;
|
||||||
@@ -96,7 +114,7 @@ angular.module('client').factory('guacClientManager', ['$injector',
|
|||||||
service.removeManagedClient(id);
|
service.removeManagedClient(id);
|
||||||
|
|
||||||
// Set new client
|
// Set new client
|
||||||
return service.managedClients[id] = ManagedClient.getInstance(id, connectionParameters);
|
return storedManagedClients()[id] = ManagedClient.getInstance(id, connectionParameters);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -119,12 +137,14 @@ angular.module('client').factory('guacClientManager', ['$injector',
|
|||||||
*/
|
*/
|
||||||
service.getManagedClient = function getManagedClient(id, connectionParameters) {
|
service.getManagedClient = function getManagedClient(id, connectionParameters) {
|
||||||
|
|
||||||
|
var managedClients = storedManagedClients();
|
||||||
|
|
||||||
// Create new managed client if it doesn't already exist
|
// Create new managed client if it doesn't already exist
|
||||||
if (!(id in service.managedClients))
|
if (!(id in managedClients))
|
||||||
service.managedClients[id] = ManagedClient.getInstance(id, connectionParameters);
|
managedClients[id] = ManagedClient.getInstance(id, connectionParameters);
|
||||||
|
|
||||||
// Return existing client
|
// Return existing client
|
||||||
return service.managedClients[id];
|
return managedClients[id];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -133,23 +153,20 @@ angular.module('client').factory('guacClientManager', ['$injector',
|
|||||||
*/
|
*/
|
||||||
service.clear = function clear() {
|
service.clear = function clear() {
|
||||||
|
|
||||||
|
var managedClients = storedManagedClients();
|
||||||
|
|
||||||
// Disconnect each managed client
|
// Disconnect each managed client
|
||||||
for (var id in service.managedClients)
|
for (var id in managedClients)
|
||||||
service.managedClients[id].client.disconnect();
|
managedClients[id].client.disconnect();
|
||||||
|
|
||||||
// Clear managed clients
|
// Clear managed clients
|
||||||
service.managedClients = {};
|
storedManagedClients({});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Disconnect all clients when window is unloaded
|
// Disconnect all clients when window is unloaded
|
||||||
$window.addEventListener('unload', service.clear);
|
$window.addEventListener('unload', service.clear);
|
||||||
|
|
||||||
// Clear clients on logout
|
|
||||||
$rootScope.$on('guacLogout', function handleLogout() {
|
|
||||||
service.clear();
|
|
||||||
});
|
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
@@ -137,11 +137,13 @@ angular.module('home').directive('guacRecentConnections', [function guacRecentCo
|
|||||||
if (rootGroup)
|
if (rootGroup)
|
||||||
addVisibleConnectionGroup(rootGroup);
|
addVisibleConnectionGroup(rootGroup);
|
||||||
|
|
||||||
|
var managedClients = guacClientManager.getManagedClients();
|
||||||
|
|
||||||
// Add all active connections
|
// Add all active connections
|
||||||
for (var id in guacClientManager.managedClients) {
|
for (var id in managedClients) {
|
||||||
|
|
||||||
// Get corresponding managed client
|
// Get corresponding managed client
|
||||||
var client = guacClientManager.managedClients[id];
|
var client = managedClients[id];
|
||||||
|
|
||||||
// Add active connections for clients with associated visible objects
|
// Add active connections for clients with associated visible objects
|
||||||
if (id in visibleObjects) {
|
if (id in visibleObjects) {
|
||||||
@@ -157,7 +159,7 @@ angular.module('home').directive('guacRecentConnections', [function guacRecentCo
|
|||||||
guacHistory.recentConnections.forEach(function addRecentConnection(historyEntry) {
|
guacHistory.recentConnections.forEach(function addRecentConnection(historyEntry) {
|
||||||
|
|
||||||
// Add recent connections for history entries with associated visible objects
|
// Add recent connections for history entries with associated visible objects
|
||||||
if (historyEntry.id in visibleObjects && !(historyEntry.id in guacClientManager.managedClients)) {
|
if (historyEntry.id in visibleObjects && !(historyEntry.id in managedClients)) {
|
||||||
|
|
||||||
var object = visibleObjects[historyEntry.id];
|
var object = visibleObjects[historyEntry.id];
|
||||||
$scope.recentConnections.push(new RecentConnection(object.name, historyEntry));
|
$scope.recentConnections.push(new RecentConnection(object.name, historyEntry));
|
||||||
|
Reference in New Issue
Block a user