GUACAMOLE-250: Export client state asynchronously (display state may not match protocol state otherwise).

This commit is contained in:
Michael Jumper
2017-04-13 20:41:12 -07:00
parent 95968016c2
commit 9ba6a5f69b

View File

@@ -133,16 +133,18 @@ Guacamole.Client = function(tunnel) {
} }
/** /**
* Returns an opaque representation of Guacamole.Client state which can be * Produces an opaque representation of Guacamole.Client state which can be
* later imported through a call to importState(). This object is * later imported through a call to importState(). This object is
* effectively an independent, compressed snapshot of protocol and display * effectively an independent, compressed snapshot of protocol and display
* state. * state. Invoking this function implicitly flushes the display.
* *
* @returns {Object} * @param {function} callback
* An opaque representation of Guacamole.Client state which can be * Callback which should be invoked once the state object is ready. The
* imported through a call to importState(). * state object will be passed to the callback as the sole parameter.
* This callback may be invoked immediately, or later as the display
* finishes rendering and becomes ready.
*/ */
this.exportState = function exportState() { this.exportState = function exportState(callback) {
// Start with empty state // Start with empty state
var state = { var state = {
@@ -151,11 +153,21 @@ Guacamole.Client = function(tunnel) {
'layers' : {} 'layers' : {}
}; };
// Export each defined layer/buffer var layersSnapshot = {};
// Make a copy of all current layers (protocol state)
for (var key in layers) { for (var key in layers) {
layersSnapshot[key] = layers[key];
}
// Populate layers once data is available (display state, requires flush)
display.flush(function populateLayers() {
// Export each defined layer/buffer
for (var key in layersSnapshot) {
var index = parseInt(key); var index = parseInt(key);
var layer = layers[key]; var layer = layersSnapshot[key];
var canvas = layer.toCanvas(); var canvas = layer.toCanvas();
// Store layer/buffer dimensions // Store layer/buffer dimensions
@@ -183,7 +195,11 @@ Guacamole.Client = function(tunnel) {
} }
return state; // Invoke callback now that the state is ready
if (callback)
callback(state);
});
}; };