Index: remoting/webapp/me2mom/remoting.js |
diff --git a/remoting/webapp/me2mom/remoting.js b/remoting/webapp/me2mom/remoting.js |
index d88ad50b026fda136d248cd39501ee60f78e5dc9..d7586e380695785db9b663b8449eb859ff0d0f4f 100644 |
--- a/remoting/webapp/me2mom/remoting.js |
+++ b/remoting/webapp/me2mom/remoting.js |
@@ -157,6 +157,7 @@ remoting.init = function() { |
remoting.oauth2 = new remoting.OAuth2(); |
remoting.debug = |
new remoting.DebugLog(document.getElementById('debug-messages')); |
+ remoting.sessionId = 1; |
refreshEmail_(); |
var email = getEmail(); |
@@ -378,20 +379,20 @@ function onStateChanged_() { |
} |
/** |
-* This is the callback that the host plugin invokes to indicate that there |
-* is additional debug log info to display. |
-* @param {string} msg The message (which will not be localized) to be logged. |
-*/ |
+ * This is the callback that the host plugin invokes to indicate that there |
+ * is additional debug log info to display. |
+ * @param {string} msg The message (which will not be localized) to be logged. |
+ */ |
function debugInfoCallback_(msg) { |
remoting.debug.log('plugin: ' + msg); |
} |
/** |
-* Show a host-side error message. |
-* |
-* @param {string} errorTag The error message to be localized and displayed. |
-* @return {void} Nothing. |
-*/ |
+ * Show a host-side error message. |
+ * |
+ * @param {string} errorTag The error message to be localized and displayed. |
+ * @return {void} Nothing. |
+ */ |
function showShareError_(errorTag) { |
var errorDiv = document.getElementById('host-plugin-error'); |
l10n.localizeElementFromTag(errorDiv, errorTag); |
@@ -399,6 +400,11 @@ function showShareError_(errorTag) { |
remoting.setMode(remoting.AppMode.HOST_SHARE_FAILED); |
} |
+/** |
+ * Cancel an active or pending share operation. |
+ * |
+ * @return {void} Nothing. |
+ */ |
remoting.cancelShare = function() { |
remoting.debug.log('Canceling share...'); |
remoting.lastShareWasCancelled = true; |
@@ -418,6 +424,20 @@ remoting.cancelShare = function() { |
disableTimeoutCountdown_(); |
} |
+/** |
+ * Cancel an incomplete connect operation. |
+ * |
+ * @return {void} Nothing. |
+ */ |
+remoting.cancelConnect = function() { |
+ ++remoting.sessionId; |
+ if (remoting.session) { |
+ remoting.session.removePlugin(); |
+ remoting.session = null; |
+ } |
+ remoting.setMode(remoting.AppMode.HOME); |
+} |
+ |
function updateStatistics() { |
if (!remoting.session) |
return; |
@@ -460,6 +480,11 @@ function showToolbarPreview_() { |
} |
function onClientStateChange_(oldState) { |
+ if (!remoting.session) { |
+ // If the connection has been cancelled, then we no longer have a reference |
+ // to the session object and should ignore any state changes. |
+ return; |
+ } |
var state = remoting.session.state; |
if (state == remoting.ClientSession.State.CREATED) { |
remoting.debug.log('Created plugin'); |
@@ -470,12 +495,12 @@ function onClientStateChange_(oldState) { |
} else if (state == remoting.ClientSession.State.INITIALIZING) { |
remoting.debug.log('Initializing connection'); |
} else if (state == remoting.ClientSession.State.CONNECTED) { |
- remoting.setMode(remoting.AppMode.IN_SESSION); |
- recenterToolbar_(); |
- showToolbarPreview_(); |
- updateStatistics(); |
- var accessCode = document.getElementById('access-code-entry'); |
- accessCode.value = ''; |
+ if (remoting.session) { |
+ remoting.setMode(remoting.AppMode.IN_SESSION); |
+ recenterToolbar_(); |
+ showToolbarPreview_(); |
+ updateStatistics(); |
+ } |
} else if (state == remoting.ClientSession.State.CLOSED) { |
if (oldState == remoting.ClientSession.State.CONNECTED) { |
remoting.session.removePlugin(); |
@@ -515,6 +540,8 @@ function onClientStateChange_(oldState) { |
function startSession_() { |
remoting.debug.log('Starting session...'); |
+ var accessCode = document.getElementById('access-code-entry'); |
+ accessCode.value = ''; // The code has been validated and won't work again. |
remoting.username = |
/** @type {string} email must be non-NULL to get here */ getEmail(); |
remoting.session = |
@@ -547,7 +574,12 @@ function showConnectError_(errorTag) { |
remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED); |
} |
-function parseServerResponse_(xhr) { |
+function parseServerResponse_(xhr, sessionId) { |
+ if (sessionId != remoting.sessionId) { |
+ remoting.debug.log('ignoring request id ' + sessionId); |
+ return; |
+ } |
+ ++remoting.sessionId; |
Wez
2011/10/14 01:21:26
Consider tweaking the xhr.get() call to return the
Jamie
2011/10/14 18:17:07
Done.
|
remoting.debug.log('parseServerResponse: status = ' + xhr.status); |
if (xhr.status == 200) { |
var host = JSON.parse(xhr.responseText); |
@@ -582,15 +614,17 @@ function resolveSupportId(supportId) { |
'Authorization': 'OAuth ' + remoting.oauth2.getAccessToken() |
}; |
+ var sessionId = remoting.sessionId; |
remoting.xhr.get( |
'https://www.googleapis.com/chromoting/v1/support-hosts/' + |
encodeURIComponent(supportId), |
- parseServerResponse_, |
+ function(xhr) { parseServerResponse_(xhr, sessionId); }, |
'', |
headers); |
} |
remoting.tryConnect = function() { |
+ document.getElementById('cancel-button').disabled = false; |
if (remoting.oauth2.needsNewAccessToken()) { |
remoting.oauth2.refreshAccessToken(function(xhr) { |
if (remoting.oauth2.needsNewAccessToken()) { |
@@ -634,9 +668,14 @@ remoting.tryConnectWithWcs = function() { |
} |
remoting.cancelPendingOperation = function() { |
- document.getElementById('cancel-button').disabled = true; |
- if (remoting.getMajorMode() == remoting.AppMode.HOST) { |
+ document.getElementById('cancel-button').disabled = true; |
Wez
2011/10/14 01:21:26
nit: Indentation.
Jamie
2011/10/14 18:17:07
Done.
|
+ switch (remoting.getMajorMode()) { |
+ case remoting.AppMode.HOST: |
Wez
2011/10/14 01:21:26
nit: Is this the right indentation for case?
Jamie
2011/10/14 18:17:07
Apparently not. Fixed.
|
remoting.cancelShare(); |
+ break; |
+ case remoting.AppMode.CLIENT: |
+ remoting.cancelConnect(); |
+ break; |
} |
} |