OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview |
| 7 * This class implements the functionality that is specific to desktop |
| 8 * remoting ("Chromoting" or CRD). |
| 9 */ |
| 10 |
| 11 'use strict'; |
| 12 |
| 13 /** @suppress {duplicate} */ |
| 14 var remoting = remoting || {}; |
| 15 |
| 16 /** |
| 17 * @param {remoting.Application} app The main app that owns this delegate. |
| 18 * @constructor |
| 19 * @implements {remoting.Application.Delegate} |
| 20 */ |
| 21 remoting.DesktopRemoting = function(app) { |
| 22 /** |
| 23 * TODO(garykac): Remove this reference to the Application. It's only |
| 24 * needed to get the current mode when reporting errors. So we should be |
| 25 * able to refactor and remove this reference cycle. |
| 26 * |
| 27 * @type {remoting.Application} |
| 28 * @private |
| 29 */ |
| 30 this.app_ = app; |
| 31 app.setDelegate(this); |
| 32 }; |
| 33 |
| 34 remoting.DesktopRemoting.prototype.init = function() { |
| 35 remoting.initGlobalObjects(); |
| 36 remoting.initIdentity(); |
| 37 remoting.initIdentityEmail(remoting.onEmailAvailable); |
| 38 |
| 39 remoting.initElementEventHandlers(); |
| 40 remoting.initGlobalEventHandlers(); |
| 41 |
| 42 if (base.isAppsV2()) { |
| 43 remoting.fullscreen = new remoting.FullscreenAppsV2(); |
| 44 remoting.windowFrame = new remoting.WindowFrame( |
| 45 document.getElementById('title-bar')); |
| 46 remoting.optionsMenu = remoting.windowFrame.createOptionsMenu(); |
| 47 } else { |
| 48 remoting.fullscreen = new remoting.FullscreenAppsV1(); |
| 49 remoting.toolbar = new remoting.Toolbar( |
| 50 document.getElementById('session-toolbar')); |
| 51 remoting.optionsMenu = remoting.toolbar.createOptionsMenu(); |
| 52 } |
| 53 |
| 54 remoting.initHostlist_(); |
| 55 |
| 56 var homeFeedback = new remoting.MenuButton( |
| 57 document.getElementById('help-feedback-main')); |
| 58 var toolbarFeedback = new remoting.MenuButton( |
| 59 document.getElementById('help-feedback-toolbar')); |
| 60 remoting.manageHelpAndFeedback( |
| 61 document.getElementById('title-bar')); |
| 62 remoting.manageHelpAndFeedback( |
| 63 document.getElementById('help-feedback-toolbar')); |
| 64 remoting.manageHelpAndFeedback( |
| 65 document.getElementById('help-feedback-main')); |
| 66 |
| 67 remoting.windowShape.updateClientWindowShape(); |
| 68 |
| 69 remoting.showOrHideIT2MeUi(); |
| 70 remoting.showOrHideMe2MeUi(); |
| 71 |
| 72 // For Apps v1, check the tab type to warn the user if they are not getting |
| 73 // the best keyboard experience. |
| 74 if (!base.isAppsV2() && !remoting.platformIsMac()) { |
| 75 /** @param {boolean} isWindowed */ |
| 76 var onIsWindowed = function(isWindowed) { |
| 77 if (!isWindowed) { |
| 78 document.getElementById('startup-mode-box-me2me').hidden = false; |
| 79 document.getElementById('startup-mode-box-it2me').hidden = false; |
| 80 } |
| 81 }; |
| 82 isWindowed_(onIsWindowed); |
| 83 } |
| 84 |
| 85 remoting.ClientPlugin.factory.preloadPlugin(); |
| 86 } |
| 87 |
| 88 /** |
| 89 * @param {remoting.ClientSession} clientSession |
| 90 */ |
| 91 remoting.DesktopRemoting.prototype.onConnected = function(clientSession) { |
| 92 // Set the text on the buttons shown under the error message so that they are |
| 93 // easy to understand in the case where a successful connection failed, as |
| 94 // opposed to the case where a connection never succeeded. |
| 95 // TODO(garykac): Investigate to see if these need to be reverted to their |
| 96 // original values in the onDisconnected method. |
| 97 var button1 = document.getElementById('client-reconnect-button'); |
| 98 l10n.localizeElementFromTag(button1, /*i18n-content*/'RECONNECT'); |
| 99 button1.removeAttribute('autofocus'); |
| 100 var button2 = document.getElementById('client-finished-me2me-button'); |
| 101 l10n.localizeElementFromTag(button2, /*i18n-content*/'OK'); |
| 102 button2.setAttribute('autofocus', 'autofocus'); |
| 103 |
| 104 document.getElementById('access-code-entry').value = ''; |
| 105 remoting.setMode(remoting.AppMode.IN_SESSION); |
| 106 if (!base.isAppsV2()) { |
| 107 remoting.toolbar.center(); |
| 108 remoting.toolbar.preview(); |
| 109 } |
| 110 |
| 111 if (remoting.pairingRequested) { |
| 112 /** |
| 113 * @param {string} clientId |
| 114 * @param {string} sharedSecret |
| 115 */ |
| 116 var onPairingComplete = function(clientId, sharedSecret) { |
| 117 var pairingInfo = { |
| 118 pairingInfo: { |
| 119 clientId: clientId, |
| 120 sharedSecret: sharedSecret |
| 121 } |
| 122 }; |
| 123 var connector = remoting.app.getSessionConnector(); |
| 124 remoting.HostSettings.save(connector.getHostId(), pairingInfo); |
| 125 connector.updatePairingInfo(clientId, sharedSecret); |
| 126 }; |
| 127 // Use the platform name as a proxy for the local computer name. |
| 128 // TODO(jamiewalch): Use a descriptive name for the local computer, for |
| 129 // example, its Chrome Sync name. |
| 130 var clientName = ''; |
| 131 if (remoting.platformIsMac()) { |
| 132 clientName = 'Mac'; |
| 133 } else if (remoting.platformIsWindows()) { |
| 134 clientName = 'Windows'; |
| 135 } else if (remoting.platformIsChromeOS()) { |
| 136 clientName = 'ChromeOS'; |
| 137 } else if (remoting.platformIsLinux()) { |
| 138 clientName = 'Linux'; |
| 139 } else { |
| 140 console.log('Unrecognized client platform. Using navigator.platform.'); |
| 141 clientName = navigator.platform; |
| 142 } |
| 143 clientSession.requestPairing(clientName, onPairingComplete); |
| 144 } |
| 145 }; |
| 146 |
| 147 remoting.DesktopRemoting.prototype.onDisconnected = function() { |
| 148 }; |
| 149 |
| 150 remoting.DesktopRemoting.prototype.onVideoStreamingStarted = function() { |
| 151 }; |
| 152 |
| 153 /** |
| 154 * @param {string} type The type of the extension message. |
| 155 * @param {string} data The payload of the extension message. |
| 156 * @return {boolean} Return true if the extension message was recognized. |
| 157 */ |
| 158 remoting.DesktopRemoting.prototype.onExtensionMessage = function(type, data) { |
| 159 if (remoting.clientSession) { |
| 160 return remoting.clientSession.handleExtensionMessage(type, data); |
| 161 } |
| 162 return false; |
| 163 }; |
| 164 |
| 165 /** |
| 166 * Show a client-side error message. |
| 167 * |
| 168 * @param {remoting.Error} errorTag The error to be localized and displayed. |
| 169 * @return {void} Nothing. |
| 170 */ |
| 171 remoting.DesktopRemoting.prototype.onError = function(errorTag) { |
| 172 console.error('Connection failed: ' + errorTag); |
| 173 remoting.accessCode = ''; |
| 174 |
| 175 var errorDiv = document.getElementById('connect-error-message'); |
| 176 l10n.localizeElementFromTag(errorDiv, /** @type {string} */ (errorTag)); |
| 177 |
| 178 var mode = remoting.clientSession ? remoting.clientSession.getMode() |
| 179 : this.app_.getSessionConnector().getConnectionMode(); |
| 180 if (mode == remoting.ClientSession.Mode.IT2ME) { |
| 181 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); |
| 182 remoting.hangoutSessionEvents.raiseEvent( |
| 183 remoting.hangoutSessionEvents.sessionStateChanged, |
| 184 remoting.ClientSession.State.FAILED |
| 185 ); |
| 186 } else { |
| 187 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_ME2ME); |
| 188 } |
| 189 }; |
OLD | NEW |