diff options
author | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-13 18:25:23 +0000 |
---|---|---|
committer | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-13 18:25:23 +0000 |
commit | 2e095c8217b83f2daab9f1b970e943790de6b794 (patch) | |
tree | 85f0b21c22b070185100124624f13a6006469a1e /remoting | |
parent | 699ea7ea271a2ba861ebdd78226fac567d24ba7e (diff) | |
download | chromium_src-2e095c8217b83f2daab9f1b970e943790de6b794.zip chromium_src-2e095c8217b83f2daab9f1b970e943790de6b794.tar.gz chromium_src-2e095c8217b83f2daab9f1b970e943790de6b794.tar.bz2 |
Implementation of id-to-jid logic.
BUG=None
TEST=Manual
Review URL: http://codereview.chromium.org/7014029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85295 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/webapp/me2mom/choice.html | 34 | ||||
-rw-r--r-- | remoting/webapp/me2mom/manifest.json | 3 | ||||
-rw-r--r-- | remoting/webapp/me2mom/remoting.js | 67 |
3 files changed, 80 insertions, 24 deletions
diff --git a/remoting/webapp/me2mom/choice.html b/remoting/webapp/me2mom/choice.html index 8662b0e..421d286 100644 --- a/remoting/webapp/me2mom/choice.html +++ b/remoting/webapp/me2mom/choice.html @@ -115,11 +115,10 @@ found in the LICENSE file. To connect to another computer, enter the access code provided to you by that computer's user. </p> - <form action=""> + <form action="" onsubmit="tryConnect(this); return false;"> <input type="text" id="access_code_entry"/> - <button type="submit" - onclick="tryConnect(this.form);"> + <button type="submit"> Connect </button> </form> @@ -133,16 +132,33 @@ found in the LICENSE file. <div id="connecting"> <p class="message"> Verifying access code... + <!-- TODO(jamiewalch): Implement Cancel, being careful when ignoring + the eventual server response not to ignore responses for any + subsequent requests. <button type="button" class="cancel" onclick="cancelConnect();"> Cancel </button> + --> + </p> + </div> + <div id="connect_failed"> + <p class="message" + id="invalid_access_code"> + Invalid access code. </p> - <p class="message mock"> - (For this mock-up, this message will disappear automatically.) + <p class="message" + id="other_connect_error"> + An error occurred. The server response was + <strong id="server_response"></strong>. </p> + <button type="button" + class="ok" + onclick="setClientMode('unconnected');"> + OK + </button> </div> </div> @@ -150,9 +166,13 @@ found in the LICENSE file. <!-- In-session UI --> <div id="session"> <p class="message"> - Congratulations! You have connected successfully. Your access code was - <em id="access_code_proof"></em>. + Congratulations! You have connected successfully. The JID corresponding + to your access code is + <strong id="host_jid_debug"></strong>. </p> + <div id="plugin_container"> + <!-- The plugin will be placed here once a JID has been obtained. --> + </div> </div> </body> diff --git a/remoting/webapp/me2mom/manifest.json b/remoting/webapp/me2mom/manifest.json index 8fa75fd..110f8dc 100644 --- a/remoting/webapp/me2mom/manifest.json +++ b/remoting/webapp/me2mom/manifest.json @@ -13,7 +13,8 @@ }, "permissions": [ "tabs", - "https://www.google.com/accounts/*" + "https://www.google.com/accounts/*", + "https://www.googleapis.com/chromoting/*" ], "PLUGINS": "PLACEHOLDER" } diff --git a/remoting/webapp/me2mom/remoting.js b/remoting/webapp/me2mom/remoting.js index 81daa86..50ca3c3 100644 --- a/remoting/webapp/me2mom/remoting.js +++ b/remoting/webapp/me2mom/remoting.js @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(jamiewalch): Clean up terminology in this web app regarding supportId, +// sessionId and accessCode. + var remoting = {}; XMPP_TOKEN_NAME = 'xmpp_token'; OAUTH2_TOKEN_NAME = 'oauth2_token'; @@ -11,10 +14,10 @@ function updateAuthStatus_() { var oauth1_status = document.getElementById('oauth1_status'); if (remoting.oauth.hasToken()) { oauth1_status.innerText = 'OK'; - oauth1_status.style.color='green'; + oauth1_status.style.color = 'green'; } else { oauth1_status.innerText = 'Unauthorized'; - oauth1_status.style.color='red'; + oauth1_status.style.color = 'red'; } var xmpp_status = document.getElementById('xmpp_status'); if (remoting.getItem(XMPP_TOKEN_NAME)) { @@ -179,7 +182,7 @@ function setHostMode(mode) { } function setClientMode(mode) { - setMode_(mode, ['unconnected', 'connecting']); + setMode_(mode, ['unconnected', 'connecting', 'connect_failed']); } function tryShare() { @@ -189,11 +192,11 @@ function tryShare() { plugin.setAttribute('hidden', 'true'); plugin.setAttribute('id', HOST_PLUGIN_ID); div.appendChild(plugin); - plugin.onStateChanged = onStateChanged; + plugin.onStateChanged = onStateChanged_; plugin.connect('uid', 'authtoken'); } -function onStateChanged() { +function onStateChanged_() { var plugin = document.getElementById(HOST_PLUGIN_ID); var state = plugin.state; if (state == plugin.REQUESTED_SUPPORT_ID) { @@ -201,7 +204,7 @@ function onStateChanged() { } else if (state == plugin.RECEIVED_SUPPORT_ID) { var support_id = plugin.supportID; var access_code = document.getElementById('access_code_display'); - access_code.innerHTML = support_id; + access_code.innerText = support_id; setHostMode('ready_to_share'); } else if (state == plugin.CONNECTED) { setHostMode('shared'); @@ -209,7 +212,7 @@ function onStateChanged() { setHostMode('unshared'); plugin.parentNode.removeChild(plugin); } else { - window.alert("Unknown state -> " + state); + window.alert('Unknown state -> ' + state); } } @@ -218,20 +221,52 @@ function cancelShare() { plugin.disconnect(); } +function startSession_() { + var div = document.getElementById('plugin_container'); + var plugin = document.createElement('embed'); + plugin.setAttribute('type', 'pepper-application/x-chromoting'); + plugin.setAttribute('id', 'chromoting_client_plugin'); + div.appendChild(plugin); + remoting.plugin = plugin; + setGlobalMode('session'); +} + +function sessionIdToJid_(reply, xhr) { + if (xhr.status == 200) { + var host = JSON.parse(xhr.responseText); + if (host.data && host.data.jabberId) { + remoting.jid = host.data.jabberId; + var proof = document.getElementById('host_jid_debug'); + proof.innerText = remoting.jid; + startSession_(); + return; + } + } + var invalid = document.getElementById('invalid_access_code'); + var other = document.getElementById('other_connect_error'); + if (xhr.status == 404) { + invalid.style.display = 'block'; + other.style.display = 'none'; + } else { + invalid.style.display = 'none'; + other.style.display = 'block'; + var responseNode = document.getElementById('server_response'); + responseNode.innerText = xhr.responseText + ' (' + xhr.status + ')'; + } + setClientMode('connect_failed'); +} + function tryConnect(form) { - remoting.accessCode = form['access_code_entry'].value; + remoting.supportId = form['access_code_entry'].value; setClientMode('connecting'); - remoting.clientTimer = setTimeout( - function() { - var code = document.getElementById('access_code_proof'); - code.innerHTML = remoting.accessCode; - setGlobalMode('session'); - }, - 3000); + var urlBase = 'https://www.googleapis.com/chromoting/v1/support-hosts/'; + remoting.oauth.sendSignedRequest( + urlBase + '' + encodeURIComponent(remoting.supportId) + '', + sessionIdToJid_); + return true; } function cancelConnect() { remoting.accessCode = ''; setClientMode('unconnected'); - clearTimeout(remoting.clientTimer); } |