| 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 20 matching lines...) Expand all Loading... |
| 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 it2meLogger = createLogger_(); | 39 it2meLogger = createLogger_(); |
| 40 it2meLogger.logSessionStateChange( | 40 it2meLogger.logSessionStateChange( |
| 41 remoting.ChromotingEvent.SessionState.STARTED, | 41 remoting.ChromotingEvent.SessionState.STARTED); |
| 42 remoting.ChromotingEvent.ConnectionError.NONE, | |
| 43 null); | |
| 44 | 42 |
| 45 /** @type {remoting.It2MeHostFacade} */ | 43 /** @type {remoting.It2MeHostFacade} */ |
| 46 var hostFacade = new remoting.It2MeHostFacade(); | 44 var hostFacade = new remoting.It2MeHostFacade(); |
| 47 | 45 |
| 48 /** @type {remoting.HostInstallDialog} */ | 46 /** @type {remoting.HostInstallDialog} */ |
| 49 var hostInstallDialog = null; | 47 var hostInstallDialog = null; |
| 50 | 48 |
| 51 var tryInitializeFacade = function() { | 49 var tryInitializeFacade = function() { |
| 52 hostFacade.initialize(onFacadeInitialized, onFacadeInitializationFailed); | 50 hostFacade.initialize(onFacadeInitialized, onFacadeInitializationFailed); |
| 53 }; | 51 }; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 * @param {remoting.It2MeHostFacade} hostFacade An initialized | 85 * @param {remoting.It2MeHostFacade} hostFacade An initialized |
| 88 * It2MeHostFacade. | 86 * It2MeHostFacade. |
| 89 * @param {string} token The OAuth access token. | 87 * @param {string} token The OAuth access token. |
| 90 * @private | 88 * @private |
| 91 */ | 89 */ |
| 92 remoting.tryShareWithToken_ = function(hostFacade, token) { | 90 remoting.tryShareWithToken_ = function(hostFacade, token) { |
| 93 lastShareWasCancelled_ = false; | 91 lastShareWasCancelled_ = false; |
| 94 onNatTraversalPolicyChanged_(true); // Hide warning by default. | 92 onNatTraversalPolicyChanged_(true); // Hide warning by default. |
| 95 remoting.setMode(remoting.AppMode.HOST_WAITING_FOR_CODE); | 93 remoting.setMode(remoting.AppMode.HOST_WAITING_FOR_CODE); |
| 96 it2meLogger.logSessionStateChange( | 94 it2meLogger.logSessionStateChange( |
| 97 remoting.ChromotingEvent.SessionState.CONNECTING, | 95 remoting.ChromotingEvent.SessionState.CONNECTING); |
| 98 remoting.ChromotingEvent.ConnectionError.NONE, | |
| 99 null); | |
| 100 document.getElementById('cancel-share-button').disabled = false; | 96 document.getElementById('cancel-share-button').disabled = false; |
| 101 disableTimeoutCountdown_(); | 97 disableTimeoutCountdown_(); |
| 102 | 98 |
| 103 console.assert(hostSession_ === null, '|hostSession_| already exists.'); | 99 console.assert(hostSession_ === null, '|hostSession_| already exists.'); |
| 104 hostSession_ = new remoting.HostSession(); | 100 hostSession_ = new remoting.HostSession(); |
| 105 remoting.identity.getEmail().then( | 101 remoting.identity.getEmail().then( |
| 106 function(/** string */ email) { | 102 function(/** string */ email) { |
| 107 hostSession_.connect( | 103 hostSession_.connect( |
| 108 hostFacade, email, token, onHostStateChanged_, | 104 hostFacade, email, token, onHostStateChanged_, |
| 109 onNatTraversalPolicyChanged_, logDebugInfo_, it2meConnectFailed_); | 105 onNatTraversalPolicyChanged_, logDebugInfo_, it2meConnectFailed_); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 /** | 199 /** |
| 204 * Show a host-side error message. | 200 * Show a host-side error message. |
| 205 * | 201 * |
| 206 * @param {!remoting.Error} error The error to be localized and displayed. | 202 * @param {!remoting.Error} error The error to be localized and displayed. |
| 207 * @return {void} Nothing. | 203 * @return {void} Nothing. |
| 208 */ | 204 */ |
| 209 function showShareError_(error) { | 205 function showShareError_(error) { |
| 210 if (error.hasTag(remoting.Error.Tag.CANCELLED)) { | 206 if (error.hasTag(remoting.Error.Tag.CANCELLED)) { |
| 211 remoting.setMode(remoting.AppMode.HOME); | 207 remoting.setMode(remoting.AppMode.HOME); |
| 212 it2meLogger.logSessionStateChange( | 208 it2meLogger.logSessionStateChange( |
| 213 remoting.ChromotingEvent.SessionState.CONNECTION_CANCELED, | 209 remoting.ChromotingEvent.SessionState.CONNECTION_CANCELED); |
| 214 remoting.ChromotingEvent.ConnectionError.NONE, | |
| 215 null); | |
| 216 } else { | 210 } else { |
| 217 var errorDiv = document.getElementById('host-plugin-error'); | 211 var errorDiv = document.getElementById('host-plugin-error'); |
| 218 l10n.localizeElementFromTag(errorDiv, error.getTag()); | 212 l10n.localizeElementFromTag(errorDiv, error.getTag()); |
| 219 console.error('Sharing error: ' + error.toString()); | 213 console.error('Sharing error: ' + error.toString()); |
| 220 remoting.setMode(remoting.AppMode.HOST_SHARE_FAILED); | 214 remoting.setMode(remoting.AppMode.HOST_SHARE_FAILED); |
| 221 it2meLogger.logSessionStateChange( | 215 it2meLogger.logSessionStateChange( |
| 222 remoting.ChromotingEvent.SessionState.CONNECTION_FAILED, | 216 remoting.ChromotingEvent.SessionState.CONNECTION_FAILED, error); |
| 223 error.toConnectionError(), | |
| 224 null); | |
| 225 } | 217 } |
| 226 | 218 |
| 227 cleanUp(); | 219 cleanUp(); |
| 228 } | 220 } |
| 229 | 221 |
| 230 /** | 222 /** |
| 231 * Show a sharing error with error code UNEXPECTED . | 223 * Show a sharing error with error code UNEXPECTED . |
| 232 * | 224 * |
| 233 * @return {void} Nothing. | 225 * @return {void} Nothing. |
| 234 */ | 226 */ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 246 * | 238 * |
| 247 * @return {void} Nothing. | 239 * @return {void} Nothing. |
| 248 */ | 240 */ |
| 249 remoting.cancelShare = function() { | 241 remoting.cancelShare = function() { |
| 250 document.getElementById('cancel-share-button').disabled = true; | 242 document.getElementById('cancel-share-button').disabled = true; |
| 251 console.log('Canceling share...'); | 243 console.log('Canceling share...'); |
| 252 remoting.lastShareWasCancelled = true; | 244 remoting.lastShareWasCancelled = true; |
| 253 try { | 245 try { |
| 254 hostSession_.disconnect(); | 246 hostSession_.disconnect(); |
| 255 it2meLogger.logSessionStateChange( | 247 it2meLogger.logSessionStateChange( |
| 256 remoting.ChromotingEvent.SessionState.CONNECTION_CANCELED, | 248 remoting.ChromotingEvent.SessionState.CONNECTION_CANCELED); |
| 257 remoting.ChromotingEvent.ConnectionError.NONE, | |
| 258 null); | |
| 259 } catch (/** @type {*} */ error) { | 249 } catch (/** @type {*} */ error) { |
| 260 console.error('Error disconnecting: ' + error + | 250 console.error('Error disconnecting: ' + error + |
| 261 '. The host probably crashed.'); | 251 '. The host probably crashed.'); |
| 262 // TODO(jamiewalch): Clean this up. We should have a class representing | 252 // TODO(jamiewalch): Clean this up. We should have a class representing |
| 263 // the host plugin, like we do for the client, which should handle crash | 253 // the host plugin, like we do for the client, which should handle crash |
| 264 // reporting and it should use a more detailed error message than the | 254 // reporting and it should use a more detailed error message than the |
| 265 // default 'generic' one. See crbug.com/94624 | 255 // default 'generic' one. See crbug.com/94624 |
| 266 showShareError_(remoting.Error.unexpected()); | 256 showShareError_(remoting.Error.unexpected()); |
| 267 } | 257 } |
| 268 disableTimeoutCountdown_(); | 258 disableTimeoutCountdown_(); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 function createLogger_() { | 362 function createLogger_() { |
| 373 // Create a new logger for each session to refresh the session id. | 363 // Create a new logger for each session to refresh the session id. |
| 374 var logger = new remoting.SessionLogger( | 364 var logger = new remoting.SessionLogger( |
| 375 remoting.ChromotingEvent.Role.HOST, | 365 remoting.ChromotingEvent.Role.HOST, |
| 376 remoting.TelemetryEventWriter.Client.write); | 366 remoting.TelemetryEventWriter.Client.write); |
| 377 logger.setLogEntryMode(remoting.ChromotingEvent.Mode.IT2ME); | 367 logger.setLogEntryMode(remoting.ChromotingEvent.Mode.IT2ME); |
| 378 return logger; | 368 return logger; |
| 379 } | 369 } |
| 380 | 370 |
| 381 })(); | 371 })(); |
| OLD | NEW |