OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 'host screen' for Chromoting. | 7 * Functions related to the 'host screen' for Chromoting. |
8 */ | 8 */ |
9 | 9 |
10 /** @suppress {duplicate} */ | 10 /** @suppress {duplicate} */ |
(...skipping 18 matching lines...) Expand all Loading... |
29 */ | 29 */ |
30 var it2meLogger = null; | 30 var it2meLogger = null; |
31 | 31 |
32 /** | 32 /** |
33 * Start a host session. This is the main entry point for the host screen, | 33 * Start a host session. This is the main entry point for the host screen, |
34 * called directly from the onclick action of a button on the home screen. | 34 * called directly from the onclick action of a button on the home screen. |
35 * It first verifies that the native host components are installed and asks | 35 * It first verifies that the native host components are installed and asks |
36 * to install them if necessary. | 36 * to install them if necessary. |
37 */ | 37 */ |
38 remoting.tryShare = function() { | 38 remoting.tryShare = function() { |
39 ensureIT2MeLogger_().then(tryShareWithLogger_); | 39 ensureIT2MeLogger_(); |
40 }; | |
41 | |
42 function tryShareWithLogger_() { | |
43 it2meLogger.setSessionId(); | 40 it2meLogger.setSessionId(); |
44 it2meLogger.logClientSessionStateChange( | 41 it2meLogger.logClientSessionStateChange( |
45 remoting.ClientSession.State.INITIALIZING, remoting.Error.none(), null); | 42 remoting.ClientSession.State.INITIALIZING, remoting.Error.none(), null); |
46 | 43 |
47 /** @type {remoting.It2MeHostFacade} */ | 44 /** @type {remoting.It2MeHostFacade} */ |
48 var hostFacade = new remoting.It2MeHostFacade(); | 45 var hostFacade = new remoting.It2MeHostFacade(); |
49 | 46 |
50 /** @type {remoting.HostInstallDialog} */ | 47 /** @type {remoting.HostInstallDialog} */ |
51 var hostInstallDialog = null; | 48 var hostInstallDialog = null; |
52 | 49 |
(...skipping 19 matching lines...) Expand all Loading... |
72 }; | 69 }; |
73 | 70 |
74 tryInitializeFacade(); | 71 tryInitializeFacade(); |
75 }; | 72 }; |
76 | 73 |
77 /** | 74 /** |
78 * @param {remoting.It2MeHostFacade} hostFacade An initialized It2MeHostFacade. | 75 * @param {remoting.It2MeHostFacade} hostFacade An initialized It2MeHostFacade. |
79 */ | 76 */ |
80 remoting.startHostUsingFacade_ = function(hostFacade) { | 77 remoting.startHostUsingFacade_ = function(hostFacade) { |
81 console.log('Attempting to share...'); | 78 console.log('Attempting to share...'); |
82 setHostVersion_() | 79 it2meLogger.setHostVersion(hostFacade.getHostVersion()); |
83 .then(remoting.identity.getToken.bind(remoting.identity)) | 80 remoting.identity.getToken().then( |
84 .then(remoting.tryShareWithToken_.bind(null, hostFacade), | 81 remoting.tryShareWithToken_.bind(null, hostFacade), |
85 remoting.Error.handler(showShareError_)); | 82 remoting.Error.handler(showShareError_)); |
86 } | 83 }; |
87 | 84 |
88 /** | 85 /** |
89 * @param {remoting.It2MeHostFacade} hostFacade An initialized | 86 * @param {remoting.It2MeHostFacade} hostFacade An initialized |
90 * It2MeHostFacade. | 87 * It2MeHostFacade. |
91 * @param {string} token The OAuth access token. | 88 * @param {string} token The OAuth access token. |
92 * @private | 89 * @private |
93 */ | 90 */ |
94 remoting.tryShareWithToken_ = function(hostFacade, token) { | 91 remoting.tryShareWithToken_ = function(hostFacade, token) { |
95 lastShareWasCancelled_ = false; | 92 lastShareWasCancelled_ = false; |
96 onNatTraversalPolicyChanged_(true); // Hide warning by default. | 93 onNatTraversalPolicyChanged_(true); // Hide warning by default. |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 var natBox = document.getElementById('nat-box'); | 354 var natBox = document.getElementById('nat-box'); |
358 if (enabled) { | 355 if (enabled) { |
359 natBox.classList.add('traversal-enabled'); | 356 natBox.classList.add('traversal-enabled'); |
360 } else { | 357 } else { |
361 natBox.classList.remove('traversal-enabled'); | 358 natBox.classList.remove('traversal-enabled'); |
362 } | 359 } |
363 } | 360 } |
364 | 361 |
365 /** | 362 /** |
366 * Create an IT2Me LogToServer instance if one does not already exist. | 363 * Create an IT2Me LogToServer instance if one does not already exist. |
367 * | |
368 * @return {Promise} Promise that resolves when the host version (if available), | |
369 * has been set on the logger instance. | |
370 */ | 364 */ |
371 function ensureIT2MeLogger_() { | 365 function ensureIT2MeLogger_() { |
372 if (it2meLogger) { | 366 if (it2meLogger) { |
373 return Promise.resolve(); | 367 return; |
374 } | 368 } |
375 | 369 |
376 var xmppConnection = new remoting.XmppConnection(); | 370 var xmppConnection = new remoting.XmppConnection(); |
377 var tokenPromise = remoting.identity.getToken(); | 371 var tokenPromise = remoting.identity.getToken(); |
378 var emailPromise = remoting.identity.getEmail(); | 372 var emailPromise = remoting.identity.getEmail(); |
379 tokenPromise.then(function(/** string */ token) { | 373 tokenPromise.then(function(/** string */ token) { |
380 emailPromise.then(function(/** string */ email) { | 374 emailPromise.then(function(/** string */ email) { |
381 xmppConnection.connect(remoting.settings.XMPP_SERVER, email, token); | 375 xmppConnection.connect(remoting.settings.XMPP_SERVER, email, token); |
382 }); | 376 }); |
383 }); | 377 }); |
384 | 378 |
385 var bufferedSignalStrategy = | 379 var bufferedSignalStrategy = |
386 new remoting.BufferedSignalStrategy(xmppConnection); | 380 new remoting.BufferedSignalStrategy(xmppConnection); |
387 it2meLogger = new remoting.LogToServer(bufferedSignalStrategy, true); | 381 it2meLogger = new remoting.LogToServer(bufferedSignalStrategy, true); |
388 it2meLogger.setLogEntryMode(remoting.ChromotingEvent.Mode.IT2ME); | 382 it2meLogger.setLogEntryMode(remoting.ChromotingEvent.Mode.IT2ME); |
389 | 383 } |
390 return setHostVersion_(); | |
391 }; | |
392 | |
393 /** | |
394 * @return {Promise} Promise that resolves when the host version (if available), | |
395 * has been set on the logger instance. | |
396 */ | |
397 function setHostVersion_() { | |
398 return remoting.hostController.getLocalHostVersion().then( | |
399 function(/** string */ version) { | |
400 it2meLogger.setHostVersion(version); | |
401 }).catch( | |
402 base.doNothing | |
403 ); | |
404 }; | |
405 | 384 |
406 })(); | 385 })(); |
OLD | NEW |