Github user jmuehlner commented on a diff in the pull request:

    
https://github.com/apache/incubator-guacamole-client/pull/139#discussion_r111062649
  
    --- Diff: guacamole-common-js/src/main/webapp/modules/Client.js ---
    @@ -133,6 +133,124 @@ Guacamole.Client = function(tunnel) {
         }
     
         /**
    +     * Returns an opaque representation of Guacamole.Client state which 
can be
    +     * later imported through a call to importState(). This object is
    +     * effectively an independent, compressed snapshot of protocol and 
display
    +     * state.
    +     *
    +     * @returns {Object}
    +     *     An opaque representation of Guacamole.Client state which can be
    +     *     imported through a call to importState().
    +     */
    +    this.exportState = function exportState() {
    +
    +        // Start with empty state
    +        var state = {
    +            'currentState' : currentState,
    +            'currentTimestamp' : currentTimestamp,
    +            'layers' : {}
    +        };
    +
    +        // Export each defined layer/buffer
    +        for (var key in layers) {
    +
    +            var index = parseInt(key);
    +            var layer = layers[key];
    +            var canvas = layer.toCanvas();
    +
    +            // Store common layer/buffer data (dimensions and image 
contents)
    +            var exportLayer = {
    +                'width'  : layer.width,
    +                'height' : layer.height,
    +                'url'    : canvas.toDataURL('image/png')
    +            };
    +
    +            // Add layer properties if not a buffer nor the default layer
    +            if (index > 0) {
    +                exportLayer.x = layer.x;
    +                exportLayer.y = layer.y;
    +                exportLayer.z = layer.z;
    +                exportLayer.alpha = layer.alpha;
    +                exportLayer.matrix = layer.matrix;
    +                exportLayer.parent = getLayerIndex(layer.parent);
    +            }
    +
    +            // Store exported layer
    +            state.layers[key] = exportLayer;
    +
    +        }
    +
    +        return state;
    +
    +    };
    +
    +    /**
    +     * Restores Guacamole.Client protocol and display state based on an 
opaque
    +     * object from a prior call to exportState(). The Guacamole.Client 
instance
    +     * used to export that state need not be the same as this instance.
    +     *
    +     * @param {Object} state
    +     *     An opaque representation of Guacamole.Client state from a prior 
call
    +     *     to exportState().
    +     *
    +     * @param {function} [callback]
    +     *     The function to invoke when state has finished being imported. 
This
    +     *     may happen immediately, or later as images within the provided 
state
    +     *     object are loaded.
    +     */
    +    this.importState = function importState(state, callback) {
    +
    +        var key;
    +        var index;
    +
    +        currentState = state.currentState;
    +        currentTimestamp = state.currentTimestamp;
    +
    +        // Dispose of all layers
    +        for (key in layers) {
    +            index = parseInt(key);
    +            if (index > 0)
    +                display.dispose(layers[key]);
    +        }
    +
    +        layers = {};
    +
    +        // Import state of each layer/buffer
    +        for (key in state.layers) {
    +
    +            index = parseInt(key);
    +
    +            var importLayer = state.layers[key];
    +            var layer = getLayer(index);
    +
    +            // Initialize new layer with imported data
    +            display.resize(layer, importLayer.width, importLayer.height);
    +            display.setChannelMask(layer, Guacamole.Layer.SRC);
    +            display.draw(layer, 0, 0, importLayer.url);
    +
    +            // Set position if not a buffer nor the default layer
    --- End diff --
    
    This comment seems a bit inaccurate.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to