Share state using session control object, add missing licenses, fix wrong license.

This commit is contained in:
Michael Jumper
2012-11-04 21:51:23 -08:00
parent a8cce89390
commit 695edad4c7
10 changed files with 196 additions and 54 deletions

View File

@@ -1,4 +1,21 @@
/*
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function Config(protocol, id) {
this.protocol = protocol;

View File

@@ -1,4 +1,22 @@
/*
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// UI Definition
var GuacamoleUI = {
@@ -530,9 +548,16 @@ GuacamoleUI.attach = function(guac) {
};
var state = new GuacamoleSessionState();
// Server copy handler
guac.onclipboard = function(data) {
window.opener.setClipboard(data);
state.setProperty("clipboard", data);
};
state.onchange = function(old_state, new_state, name) {
if (name == "clipboard")
guac.setClipboard(new_state[name]);
};
};

View File

@@ -0,0 +1,93 @@
/*
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Maintains state across multiple Guacamole pages via HTML5 Web Storage.
*/
function GuacamoleSessionState() {
/**
* Reference to this GuacamoleSessionState.
* @private
*/
var guac_state = this;
/**
* The last read state object.
* @private
*/
var state = localStorage.getItem("GUACAMOLE_STATE") || {};
/**
* Reloads the internal state, sending onchange events for all changed,
* deleted, or new properties.
*/
this.reload = function() {
// Pull current state
var new_state = JSON.parse(localStorage.getItem("GUACAMOLE_STATE") || "{}");
// Check if value is different
for (var name in new_state) {
// If value changed, call handler
var old = state[name];
if (old != new_state[name]) {
// Call change handler
if (guac_state.onchange)
guac_state.onchange(state, new_state, name);
}
}
// Assign new state
state = new_state;
};
/**
* Sets the given property to the given value.
*
* @param {String} name The name of the property to change.
* @param value An arbitrary value.
*/
this.setProperty = function(name, value) {
state[name] = value;
localStorage.setItem("GUACAMOLE_STATE", JSON.stringify(state));
};
/**
* Returns the value stored under the property having the given name.
*
* @param {String} name The name of the property to read.
* @return The value of the given property.
*/
this.getProperty = function(name) {
return state[name];
};
// Reload properties every 5 seconds
window.setInterval(guac_state.reload, 1000);
// Initial load
guac_state.reload();
}