mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
Added "heartbeat" for update throttling.
This commit is contained in:
@@ -26,6 +26,7 @@ import net.sourceforge.guacamole.event.PointerEvent;
|
|||||||
|
|
||||||
public abstract class Client {
|
public abstract class Client {
|
||||||
|
|
||||||
|
public abstract void ready() throws GuacamoleException;
|
||||||
public abstract void send(KeyEvent event) throws GuacamoleException;
|
public abstract void send(KeyEvent event) throws GuacamoleException;
|
||||||
public abstract void send(PointerEvent event) throws GuacamoleException;
|
public abstract void send(PointerEvent event) throws GuacamoleException;
|
||||||
public abstract void setClipboard(String clipboard) throws GuacamoleException;
|
public abstract void setClipboard(String clipboard) throws GuacamoleException;
|
||||||
|
@@ -57,6 +57,17 @@ public class GuacamoleClient extends Client {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ready() throws GuacamoleException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
output.write("ready;");
|
||||||
|
output.flush();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new GuacamoleException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static final int EVENT_DEADLINE = 500;
|
private static final int EVENT_DEADLINE = 500;
|
||||||
|
|
||||||
|
@@ -71,6 +71,10 @@ public class GuacamoleSession {
|
|||||||
client.setClipboard(clipboard);
|
client.setClipboard(clipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ready() throws GuacamoleException {
|
||||||
|
client.ready();
|
||||||
|
}
|
||||||
|
|
||||||
public void disconnect() throws GuacamoleException {
|
public void disconnect() throws GuacamoleException {
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.net.input;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
import net.sourceforge.guacamole.net.GuacamoleSession;
|
||||||
|
import net.sourceforge.guacamole.net.XMLGuacamoleServlet;
|
||||||
|
|
||||||
|
public class Ready extends XMLGuacamoleServlet {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleRequest(GuacamoleSession session, ServletRequest request, Element root) throws GuacamoleException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
session.getClient().ready();
|
||||||
|
}
|
||||||
|
catch (GuacamoleException e) {
|
||||||
|
throw new GuacamoleException("Error updating ready status: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -61,6 +61,15 @@
|
|||||||
<servlet-name>Clipboard</servlet-name>
|
<servlet-name>Clipboard</servlet-name>
|
||||||
<url-pattern>/clipboard</url-pattern>
|
<url-pattern>/clipboard</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
<servlet>
|
||||||
|
<description>Client "ready-to-receive" heartbeat</description>
|
||||||
|
<servlet-name>Ready</servlet-name>
|
||||||
|
<servlet-class>net.sourceforge.guacamole.net.input.Ready</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>Ready</servlet-name>
|
||||||
|
<url-pattern>/ready</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
<servlet>
|
<servlet>
|
||||||
<description>Key input servlet.</description>
|
<description>Key input servlet.</description>
|
||||||
<servlet-name>Key</servlet-name>
|
<servlet-name>Key</servlet-name>
|
||||||
|
@@ -540,7 +540,27 @@ function VNCClient(display) {
|
|||||||
handler(parameters);
|
handler(parameters);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function sendReady() {
|
||||||
|
|
||||||
|
// Start heartbeat signal
|
||||||
|
var heartbeat = new XMLHttpRequest();
|
||||||
|
heartbeat.open("GET", "ready");
|
||||||
|
|
||||||
|
heartbeat.onreadystatechange = function() {
|
||||||
|
|
||||||
|
if (heartbeat != null && heartbeat.readyState >= 2) {
|
||||||
|
heartbeat = null;
|
||||||
|
setTimeout(sendReady, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
heartbeat.send();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
this.connect = function() {
|
this.connect = function() {
|
||||||
|
|
||||||
@@ -555,6 +575,7 @@ function VNCClient(display) {
|
|||||||
var message = new GuacamoleMessage(connect_xmlhttprequest.responseXML);
|
var message = new GuacamoleMessage(connect_xmlhttprequest.responseXML);
|
||||||
if (!message.hasErrors()) {
|
if (!message.hasErrors()) {
|
||||||
setState(STATE_WAITING);
|
setState(STATE_WAITING);
|
||||||
|
sendReady();
|
||||||
handleResponse(makeRequest()); // Start stream if connection successful
|
handleResponse(makeRequest()); // Start stream if connection successful
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -85,12 +85,6 @@ void guac_start_client(guac_client* client) {
|
|||||||
/* VNC Client Loop */
|
/* VNC Client Loop */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
||||||
/* Handle server messages */
|
|
||||||
if (client->handle_messages) {
|
|
||||||
client->handle_messages(client);
|
|
||||||
guac_flush(client->io);
|
|
||||||
}
|
|
||||||
|
|
||||||
wait_result = guac_instructions_waiting(io);
|
wait_result = guac_instructions_waiting(io);
|
||||||
if (wait_result > 0) {
|
if (wait_result > 0) {
|
||||||
|
|
||||||
@@ -131,6 +125,12 @@ void guac_start_client(guac_client* client) {
|
|||||||
|
|
||||||
/* Otherwise, retval == 0 implies unfinished instruction */
|
/* Otherwise, retval == 0 implies unfinished instruction */
|
||||||
|
|
||||||
|
/* Handle server messages */
|
||||||
|
if (client->handle_messages) {
|
||||||
|
client->handle_messages(client);
|
||||||
|
guac_flush(client->io);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (wait_result < 0)
|
else if (wait_result < 0)
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user