OLD | NEW |
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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 toolbar.style['left'] = toolbarX + 'px'; | 385 toolbar.style['left'] = toolbarX + 'px'; |
386 } | 386 } |
387 | 387 |
388 /** | 388 /** |
389 * Start a connection to the specified host, using the stored details. | 389 * Start a connection to the specified host, using the stored details. |
390 * | 390 * |
391 * @param {string} hostId The Id of the host to connect to. | 391 * @param {string} hostId The Id of the host to connect to. |
392 * @return {void} Nothing. | 392 * @return {void} Nothing. |
393 */ | 393 */ |
394 remoting.connectHost = function(hostId) { | 394 remoting.connectHost = function(hostId) { |
395 for (var i = 0; i < remoting.hostList.hosts.length; ++i) { | 395 var hostTableEntry = remoting.hostList.getHostForId(hostId); |
396 /** @type {remoting.Host} */ | 396 if (!hostTableEntry) { |
397 var host = remoting.hostList.hosts[i]; | 397 console.error('connectHost: Unrecognised hostId: ' + hostId); |
398 if (host.hostId != hostId) | 398 return; |
399 continue; | 399 } |
400 | 400 |
401 remoting.hostJid = host.jabberId; | 401 remoting.hostJid = hostTableEntry.host.jabberId; |
402 remoting.hostPublicKey = host.publicKey; | 402 remoting.hostPublicKey = hostTableEntry.host.publicKey; |
403 document.getElementById('connected-to').innerText = host.hostName; | 403 document.getElementById('connected-to').innerText = |
| 404 hostTableEntry.host.hostName; |
404 | 405 |
405 remoting.debug.log('Connecting to host...'); | 406 remoting.debug.log('Connecting to host...'); |
406 | 407 |
407 if (!remoting.wcsLoader) { | 408 if (!remoting.wcsLoader) { |
408 remoting.wcsLoader = new remoting.WcsLoader(); | 409 remoting.wcsLoader = new remoting.WcsLoader(); |
409 } | |
410 /** @param {function(string):void} setToken The callback function. */ | |
411 var callWithToken = function(setToken) { | |
412 remoting.oauth2.callWithToken(setToken); | |
413 }; | |
414 remoting.wcsLoader.start( | |
415 remoting.oauth2.getAccessToken(), | |
416 callWithToken, | |
417 remoting.connectHostWithWcs); | |
418 break; | |
419 } | 410 } |
| 411 /** @param {function(string):void} setToken The callback function. */ |
| 412 var callWithToken = function(setToken) { |
| 413 remoting.oauth2.callWithToken(setToken); |
| 414 }; |
| 415 remoting.wcsLoader.start( |
| 416 remoting.oauth2.getAccessToken(), |
| 417 callWithToken, |
| 418 remoting.connectHostWithWcs); |
420 } | 419 } |
421 | 420 |
422 /** | 421 /** |
423 * Continue making the connection to a host, once WCS has initialized. | 422 * Continue making the connection to a host, once WCS has initialized. |
424 * | 423 * |
425 * @return {void} Nothing. | 424 * @return {void} Nothing. |
426 */ | 425 */ |
427 remoting.connectHostWithWcs = function() { | 426 remoting.connectHostWithWcs = function() { |
428 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 427 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); |
429 | 428 |
430 remoting.clientSession = | 429 remoting.clientSession = |
431 new remoting.ClientSession( | 430 new remoting.ClientSession( |
432 remoting.hostJid, remoting.hostPublicKey, | 431 remoting.hostJid, remoting.hostPublicKey, |
433 '', /** @type {string} */ (remoting.oauth2.getCachedEmail()), | 432 '', /** @type {string} */ (remoting.oauth2.getCachedEmail()), |
434 onClientStateChange_); | 433 onClientStateChange_); |
435 /** @param {string} token The auth token. */ | 434 /** @param {string} token The auth token. */ |
436 var createPluginAndConnect = function(token) { | 435 var createPluginAndConnect = function(token) { |
437 remoting.clientSession.createPluginAndConnect( | 436 remoting.clientSession.createPluginAndConnect( |
438 document.getElementById('session-mode'), | 437 document.getElementById('session-mode'), |
439 token); | 438 token); |
440 }; | 439 }; |
441 | 440 |
442 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 441 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); |
443 remoting.oauth2.callWithToken(createPluginAndConnect); | 442 remoting.oauth2.callWithToken(createPluginAndConnect); |
444 } | 443 } |
445 | 444 |
446 }()); | 445 }()); |
OLD | NEW |