Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Side by Side Diff: remoting/webapp/me2mom/client_screen.js

Issue 8782001: Refactored HostList to better support bookmarking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Linter and rebase. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | remoting/webapp/me2mom/host_list.js » ('j') | remoting/webapp/me2mom/host_list.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Functions related to the 'client screen' for Chromoting. 7 * Functions related to the 'client screen' for Chromoting.
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
(...skipping 18 matching lines...) Expand all
29 * @type {string} The normalized access code. 29 * @type {string} The normalized access code.
30 */ 30 */
31 remoting.accessCode = ''; 31 remoting.accessCode = '';
32 32
33 /** 33 /**
34 * @type {string} The host's JID, returned by the server. 34 * @type {string} The host's JID, returned by the server.
35 */ 35 */
36 remoting.hostJid = ''; 36 remoting.hostJid = '';
37 37
38 /** 38 /**
39 * @type {string} For Me2Me connections, the id of the current host, used to
40 * facilitate refresh/reconnect if the cached host information is stale.
Wez 2011/12/03 01:26:33 nit: the Id is used when re-connecting, since the
Jamie 2011/12/05 20:49:08 Done.
41 */
42 remoting.hostId = '';
43
44 /**
39 * @type {string} The host's public key, returned by the server. 45 * @type {string} The host's public key, returned by the server.
40 */ 46 */
41 remoting.hostPublicKey = ''; 47 remoting.hostPublicKey = '';
42 48
43 /** 49 /**
44 * @type {XMLHttpRequest} The XHR object corresponding to the current 50 * @type {XMLHttpRequest} The XHR object corresponding to the current
45 * support-hosts request, if there is one outstanding. 51 * support-hosts request, if there is one outstanding.
46 */ 52 */
47 remoting.supportHostsXhr_ = null; 53 remoting.supportHostsXhr_ = null;
48 54
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // only with older client plugins. Current version should go the 248 // only with older client plugins. Current version should go the
243 // FAILED state when connection fails. 249 // FAILED state when connection fails.
244 showConnectError_(remoting.Error.INVALID_ACCESS_CODE); 250 showConnectError_(remoting.Error.INVALID_ACCESS_CODE);
245 } 251 }
246 252
247 } else if (newState == remoting.ClientSession.State.CONNECTION_FAILED) { 253 } else if (newState == remoting.ClientSession.State.CONNECTION_FAILED) {
248 remoting.debug.log('Client plugin reported connection failed: ' + 254 remoting.debug.log('Client plugin reported connection failed: ' +
249 remoting.clientSession.error); 255 remoting.clientSession.error);
250 if (remoting.clientSession.error == 256 if (remoting.clientSession.error ==
251 remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE) { 257 remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE) {
252 showConnectError_(remoting.Error.HOST_IS_OFFLINE); 258 retryConnectOrReportOffline_();
253 } else if (remoting.clientSession.error == 259 } else if (remoting.clientSession.error ==
254 remoting.ClientSession.ConnectionError.SESSION_REJECTED) { 260 remoting.ClientSession.ConnectionError.SESSION_REJECTED) {
255 showConnectError_(remoting.Error.INVALID_ACCESS_CODE); 261 showConnectError_(remoting.Error.INVALID_ACCESS_CODE);
256 } else if (remoting.clientSession.error == 262 } else if (remoting.clientSession.error ==
257 remoting.ClientSession.ConnectionError.INCOMPATIBLE_PROTOCOL) { 263 remoting.ClientSession.ConnectionError.INCOMPATIBLE_PROTOCOL) {
258 showConnectError_(remoting.Error.INCOMPATIBLE_PROTOCOL); 264 showConnectError_(remoting.Error.INCOMPATIBLE_PROTOCOL);
259 } else if (remoting.clientSession.error == 265 } else if (remoting.clientSession.error ==
260 remoting.ClientSession.ConnectionError.NETWORK_FAILURE) { 266 remoting.ClientSession.ConnectionError.NETWORK_FAILURE) {
261 showConnectError_(remoting.Error.GENERIC); 267 showConnectError_(remoting.Error.GENERIC);
262 } else { 268 } else {
263 showConnectError_(remoting.Error.GENERIC); 269 showConnectError_(remoting.Error.GENERIC);
264 } 270 }
265 271
266 } else { 272 } else {
267 remoting.debug.log('Unexpected client plugin state: ' + newState); 273 remoting.debug.log('Unexpected client plugin state: ' + newState);
268 // This should only happen if the web-app and client plugin get out of 274 // This should only happen if the web-app and client plugin get out of
269 // sync, and even then the version check should allow compatibility. 275 // sync, and even then the version check should allow compatibility.
270 showConnectError_(remoting.Error.MISSING_PLUGIN); 276 showConnectError_(remoting.Error.MISSING_PLUGIN);
271 } 277 }
272 } 278 }
273 279
274 /** 280 /**
281 * If we have a hostId to retry, try refreshing it and connecting again. If not,
282 * then show the 'host offline' error message.
283 *
284 * @return {void} Nothing.
285 */
286 function retryConnectOrReportOffline_() {
287 if (remoting.hostId) {
288 console.log('Connection failed. Retrying.');
289 /** @param {boolean} success True if the refresh was successful. */
290 var onDone = function(success) {
291 if (success) {
292 remoting.connectHost(remoting.hostId, false);
293 } else {
294 showConnectError_(remoting.Error.HOST_IS_OFFLINE);
295 }
296 };
297 remoting.hostList.refresh(onDone);
298 } else {
299 console.log('Connection failed. Not retrying.');
300 showConnectError_(remoting.Error.HOST_IS_OFFLINE);
301 }
302 }
303
304 /**
275 * Create the client session object and initiate the connection. 305 * Create the client session object and initiate the connection.
276 * 306 *
277 * @return {void} Nothing. 307 * @return {void} Nothing.
278 */ 308 */
279 function startSession_() { 309 function startSession_() {
280 remoting.debug.log('Starting session...'); 310 remoting.debug.log('Starting session...');
281 var accessCode = document.getElementById('access-code-entry'); 311 var accessCode = document.getElementById('access-code-entry');
282 accessCode.value = ''; // The code has been validated and won't work again. 312 accessCode.value = ''; // The code has been validated and won't work again.
283 remoting.clientSession = 313 remoting.clientSession =
284 new remoting.ClientSession( 314 new remoting.ClientSession(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 /** 435 /**
406 * Update the horizontal position of the tool-bar to center it. 436 * Update the horizontal position of the tool-bar to center it.
407 */ 437 */
408 function recenterToolbar_() { 438 function recenterToolbar_() {
409 var toolbar = document.getElementById('session-toolbar'); 439 var toolbar = document.getElementById('session-toolbar');
410 var toolbarX = (window.innerWidth - toolbar.clientWidth) / 2; 440 var toolbarX = (window.innerWidth - toolbar.clientWidth) / 2;
411 toolbar.style['left'] = toolbarX + 'px'; 441 toolbar.style['left'] = toolbarX + 'px';
412 } 442 }
413 443
414 /** 444 /**
415 * Start a connection to the specified host, using the stored details. 445 * Start a connection to the specified host, using the cached details.
416 * 446 *
417 * @param {string} hostJid The jabber Id of the host. 447 * @param {string} hostId The unique id of the host.
418 * @param {string} hostPublicKey The public key of the host. 448 * @param {boolean} retryIfOffline If true and the host can't be contacted,
419 * @param {string} hostName The name of the host. 449 * refresh the host list and try again. This allows bookmarked hosts to
450 * work even if they reregister with Talk and get a different Jid.
420 * @return {void} Nothing. 451 * @return {void} Nothing.
421 */ 452 */
422 remoting.connectHost = function(hostJid, hostPublicKey, hostName) { 453 remoting.connectHost = function(hostId, retryIfOffline) {
423 // TODO(jamiewalch): Instead of passing the jid in the URL, cache it in local
424 // storage so that host bookmarks can be implemented efficiently.
425 remoting.hostJid = hostJid;
426 remoting.hostPublicKey = hostPublicKey;
427 document.getElementById('connected-to').innerText = hostName;
428 document.title = document.title + ': ' + hostName;
429
430 remoting.debug.log('Connecting to host...'); 454 remoting.debug.log('Connecting to host...');
431 remoting.currentConnectionType = remoting.ConnectionType.Me2Me; 455 remoting.currentConnectionType = remoting.ConnectionType.Me2Me;
Wez 2011/12/03 01:26:33 nit: blank line here?
Jamie 2011/12/05 20:49:08 Done.
456 // Storing the hostId indicates that it should be retried on failure.
457 remoting.hostId = retryIfOffline ? hostId : '';
432 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); 458 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
433 459
460 var host = remoting.hostList.getHostForId(hostId);
Wez 2011/12/03 01:26:33 Presumably this will return null if the Host Id is
Jamie 2011/12/05 20:49:08 I'm not so sure. It's possible that a deleted host
Wez 2011/12/05 20:59:38 For a deleted host to "come back" it would have to
461 if (!host) {
462 retryConnectOrReportOffline_();
463 return;
464 }
465 remoting.hostJid = host.jabberId;
466 remoting.hostPublicKey = host.publicKey;
467 document.getElementById('connected-to').innerText = host.hostName;
468 document.title = document.title + ': ' + host.hostName;
469
434 if (!remoting.wcsLoader) { 470 if (!remoting.wcsLoader) {
435 remoting.wcsLoader = new remoting.WcsLoader(); 471 remoting.wcsLoader = new remoting.WcsLoader();
436 } 472 }
437 /** @param {function(string):void} setToken The callback function. */ 473 /** @param {function(string):void} setToken The callback function. */
438 var callWithToken = function(setToken) { 474 var callWithToken = function(setToken) {
439 remoting.oauth2.callWithToken(setToken); 475 remoting.oauth2.callWithToken(setToken);
440 }; 476 };
441 remoting.wcsLoader.startAsync(callWithToken, remoting.connectHostWithWcs); 477 remoting.wcsLoader.startAsync(callWithToken, remoting.connectHostWithWcs);
442 } 478 }
443 479
444 /** 480 /**
445 * Continue making the connection to a host, once WCS has initialized. 481 * Continue making the connection to a host, once WCS has initialized.
446 * 482 *
447 * @return {void} Nothing. 483 * @return {void} Nothing.
448 */ 484 */
449 remoting.connectHostWithWcs = function() { 485 remoting.connectHostWithWcs = function() {
450 remoting.clientSession = 486 remoting.clientSession =
451 new remoting.ClientSession( 487 new remoting.ClientSession(
452 remoting.hostJid, remoting.hostPublicKey, 488 remoting.hostJid, remoting.hostPublicKey,
453 '', /** @type {string} */ (remoting.oauth2.getCachedEmail()), 489 '', /** @type {string} */ (remoting.oauth2.getCachedEmail()),
454 onClientStateChange_); 490 onClientStateChange_);
455 /** @param {string} token The auth token. */ 491 /** @param {string} token The auth token. */
456 var createPluginAndConnect = function(token) { 492 var createPluginAndConnect = function(token) {
457 remoting.clientSession.createPluginAndConnect( 493 remoting.clientSession.createPluginAndConnect(
458 document.getElementById('session-mode'), 494 document.getElementById('session-mode'),
459 token); 495 token);
460 }; 496 };
461 497
462 remoting.oauth2.callWithToken(createPluginAndConnect); 498 remoting.oauth2.callWithToken(createPluginAndConnect);
463 } 499 }
464 500
465 }()); 501 }());
OLDNEW
« no previous file with comments | « no previous file | remoting/webapp/me2mom/host_list.js » ('j') | remoting/webapp/me2mom/host_list.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698