mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
Merge pull request #271 from glyptodon/check-once
GUAC-1305: Only test for supported images when guacImage is initially loaded. No need to retest.
This commit is contained in:
@@ -64,6 +64,31 @@ angular.module('client').factory('guacImage', ['$injector', function guacImage($
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Deferred which tracks the progress and ultimate result of all pending
|
||||
* image format tests.
|
||||
*
|
||||
* @type Deferred
|
||||
*/
|
||||
var deferredSupportedMimetypes = $q.defer();
|
||||
|
||||
/**
|
||||
* Array of all promises associated with pending image tests. Each image
|
||||
* test promise MUST be guaranteed to resolve and MUST NOT be rejected.
|
||||
*
|
||||
* @type Promise[]
|
||||
*/
|
||||
var pendingTests = [];
|
||||
|
||||
/**
|
||||
* The array of supported image formats. This will be gradually populated
|
||||
* by the various image tests that occur in the background, and will not be
|
||||
* fully populated until all promises within pendingTests are resolved.
|
||||
*
|
||||
* @type String[]
|
||||
*/
|
||||
var supported = [];
|
||||
|
||||
/**
|
||||
* Return a promise which resolves with to an array of image mimetypes
|
||||
* supported by the browser, once those mimetypes are known. The returned
|
||||
@@ -74,11 +99,8 @@ angular.module('client').factory('guacImage', ['$injector', function guacImage($
|
||||
* by the browser.
|
||||
*/
|
||||
service.getSupportedMimetypes = function getSupportedMimetypes() {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
var supported = [];
|
||||
var pendingTests = [];
|
||||
return deferredSupportedMimetypes.promise;
|
||||
};
|
||||
|
||||
// Test each possibly-supported image
|
||||
angular.forEach(testImages, function testImageSupport(data, mimetype) {
|
||||
@@ -108,13 +130,9 @@ angular.module('client').factory('guacImage', ['$injector', function guacImage($
|
||||
// When all image tests are complete, resolve promise with list of
|
||||
// supported formats
|
||||
$q.all(pendingTests).then(function imageTestsCompleted() {
|
||||
deferred.resolve(supported);
|
||||
deferredSupportedMimetypes.resolve(supported);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
|
||||
};
|
||||
|
||||
return service;
|
||||
|
||||
}]);
|
||||
|
Reference in New Issue
Block a user