mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
Autodetect whether polling should be stopped (whether browser supports multiple readyState==3 events).
This commit is contained in:
@@ -32,6 +32,7 @@ function GuacamoleClient(display, tunnelURL) {
|
|||||||
|
|
||||||
var currentState = STATE_IDLE;
|
var currentState = STATE_IDLE;
|
||||||
var stateChangeHandler = null;
|
var stateChangeHandler = null;
|
||||||
|
var pollResponse = 1; // Default to polling - will be turned off automatically if not needed
|
||||||
|
|
||||||
function setState(state) {
|
function setState(state) {
|
||||||
if (state != currentState) {
|
if (state != currentState) {
|
||||||
@@ -298,6 +299,7 @@ function GuacamoleClient(display, tunnelURL) {
|
|||||||
var interval = null;
|
var interval = null;
|
||||||
var nextRequest = null;
|
var nextRequest = null;
|
||||||
|
|
||||||
|
var dataUpdateEvents = 0;
|
||||||
var instructionStart = 0;
|
var instructionStart = 0;
|
||||||
var startIndex = 0;
|
var startIndex = 0;
|
||||||
|
|
||||||
@@ -312,10 +314,12 @@ function GuacamoleClient(display, tunnelURL) {
|
|||||||
xmlhttprequest.readyState == 4) {
|
xmlhttprequest.readyState == 4) {
|
||||||
|
|
||||||
// Also poll every 30ms (some browsers don't repeatedly call onreadystatechange for new data)
|
// Also poll every 30ms (some browsers don't repeatedly call onreadystatechange for new data)
|
||||||
if (xmlhttprequest.readyState == 3 && interval == null)
|
if (pollResponse == 1) {
|
||||||
interval = setInterval(parseResponse, 30);
|
if (xmlhttprequest.readyState == 3 && interval == null)
|
||||||
else if (xmlhttprequest.readyState == 4 && interval != null)
|
interval = setInterval(parseResponse, 30);
|
||||||
clearInterval(interval);
|
else if (xmlhttprequest.readyState == 4 && interval != null)
|
||||||
|
clearInterval(interval);
|
||||||
|
}
|
||||||
|
|
||||||
// Halt on error during request
|
// Halt on error during request
|
||||||
if (xmlhttprequest.status == 0) {
|
if (xmlhttprequest.status == 0) {
|
||||||
@@ -379,7 +383,29 @@ function GuacamoleClient(display, tunnelURL) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlhttprequest.onreadystatechange = parseResponse;
|
// If response polling enabled, attempt to detect if still
|
||||||
|
// necessary (via wrapping parseResponse())
|
||||||
|
if (pollResponse == 1) {
|
||||||
|
xmlhttprequest.onreadystatechange = function() {
|
||||||
|
|
||||||
|
// If we receive two or more readyState==3 events,
|
||||||
|
// there is no need to poll.
|
||||||
|
if (xmlhttprequest.readyState == 3) {
|
||||||
|
dataUpdateEvents++;
|
||||||
|
if (dataUpdateEvents >= 2) {
|
||||||
|
pollResponse = 0;
|
||||||
|
xmlhttprequest.onreadystatechange = parseResponse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parseResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, just parse
|
||||||
|
else
|
||||||
|
xmlhttprequest.onreadystatechange = parseResponse;
|
||||||
|
|
||||||
parseResponse();
|
parseResponse();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user