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.
7 * This class implements the functionality that is specific to desktop
8 * remoting ("Chromoting" or CRD).
13 /** @suppress {duplicate} */
14 var remoting
= remoting
|| {};
17 * @param {remoting.Application} app The main app that owns this delegate.
19 * @implements {remoting.Application.Delegate}
21 remoting
.DesktopRemoting = function(app
) {
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.
27 * @type {remoting.Application}
31 app
.setDelegate(this);
34 remoting
.DesktopRemoting
.prototype.init = function() {
35 remoting
.initGlobalObjects();
36 remoting
.initIdentity();
37 remoting
.initIdentityEmail(remoting
.onEmailAvailable
);
39 remoting
.initElementEventHandlers();
40 remoting
.initGlobalEventHandlers();
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();
48 remoting
.fullscreen
= new remoting
.FullscreenAppsV1();
49 remoting
.toolbar
= new remoting
.Toolbar(
50 document
.getElementById('session-toolbar'));
51 remoting
.optionsMenu
= remoting
.toolbar
.createOptionsMenu();
54 remoting
.initHostlist_();
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'));
67 remoting
.windowShape
.updateClientWindowShape();
69 remoting
.showOrHideIT2MeUi();
70 remoting
.showOrHideMe2MeUi();
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
) {
78 document
.getElementById('startup-mode-box-me2me').hidden
= false;
79 document
.getElementById('startup-mode-box-it2me').hidden
= false;
82 isWindowed_(onIsWindowed
);
85 remoting
.ClientPlugin
.factory
.preloadPlugin();
89 * @return {string} The default remap keys for the current platform.
91 remoting
.DesktopRemoting
.prototype.getDefaultRemapKeys = function() {
93 // By default, under ChromeOS, remap the right Control key to the right
95 if (remoting
.platformIsChromeOS()) {
96 remapKeys
= '0x0700e4>0x0700e7';
102 * @return {Array.<string>} A list of |ClientSession.Capability|s required
103 * by this application.
105 remoting
.DesktopRemoting
.prototype.getRequiredCapabilities = function() {
107 remoting
.ClientSession
.Capability
.SEND_INITIAL_RESOLUTION
,
108 remoting
.ClientSession
.Capability
.RATE_LIMIT_RESIZE_REQUESTS
,
109 remoting
.ClientSession
.Capability
.VIDEO_RECORDER
,
110 // TODO(aiguha): Add this capability based on a gyp/command-line flag,
111 // rather than by default.
112 remoting
.ClientSession
.Capability
.CAST
,
113 remoting
.ClientSession
.Capability
.GNUBBY_AUTH
118 * @param {remoting.ClientSession} clientSession
120 remoting
.DesktopRemoting
.prototype.onConnected = function(clientSession
) {
121 // Set the text on the buttons shown under the error message so that they are
122 // easy to understand in the case where a successful connection failed, as
123 // opposed to the case where a connection never succeeded.
124 // TODO(garykac): Investigate to see if these need to be reverted to their
125 // original values in the onDisconnected method.
126 var button1
= document
.getElementById('client-reconnect-button');
127 l10n
.localizeElementFromTag(button1
, /*i18n-content*/'RECONNECT');
128 button1
.removeAttribute('autofocus');
129 var button2
= document
.getElementById('client-finished-me2me-button');
130 l10n
.localizeElementFromTag(button2
, /*i18n-content*/'OK');
131 button2
.setAttribute('autofocus', 'autofocus');
133 document
.getElementById('access-code-entry').value
= '';
134 remoting
.setMode(remoting
.AppMode
.IN_SESSION
);
135 if (!base
.isAppsV2()) {
136 remoting
.toolbar
.center();
137 remoting
.toolbar
.preview();
140 if (remoting
.pairingRequested
) {
142 * @param {string} clientId
143 * @param {string} sharedSecret
145 var onPairingComplete = function(clientId
, sharedSecret
) {
149 sharedSecret
: sharedSecret
152 var connector
= remoting
.app
.getSessionConnector();
153 remoting
.HostSettings
.save(connector
.getHostId(), pairingInfo
);
154 connector
.updatePairingInfo(clientId
, sharedSecret
);
156 // Use the platform name as a proxy for the local computer name.
157 // TODO(jamiewalch): Use a descriptive name for the local computer, for
158 // example, its Chrome Sync name.
160 if (remoting
.platformIsMac()) {
162 } else if (remoting
.platformIsWindows()) {
163 clientName
= 'Windows';
164 } else if (remoting
.platformIsChromeOS()) {
165 clientName
= 'ChromeOS';
166 } else if (remoting
.platformIsLinux()) {
167 clientName
= 'Linux';
169 console
.log('Unrecognized client platform. Using navigator.platform.');
170 clientName
= navigator
.platform
;
172 clientSession
.requestPairing(clientName
, onPairingComplete
);
176 remoting
.DesktopRemoting
.prototype.onDisconnected = function() {
179 remoting
.DesktopRemoting
.prototype.onVideoStreamingStarted = function() {
183 * @param {string} type The type of the extension message.
184 * @param {string} data The payload of the extension message.
185 * @return {boolean} Return true if the extension message was recognized.
187 remoting
.DesktopRemoting
.prototype.onExtensionMessage = function(type
, data
) {
192 * Show a client-side error message.
194 * @param {remoting.Error} errorTag The error to be localized and displayed.
195 * @return {void} Nothing.
197 remoting
.DesktopRemoting
.prototype.onError = function(errorTag
) {
198 console
.error('Connection failed: ' + errorTag
);
199 remoting
.accessCode
= '';
201 var errorDiv
= document
.getElementById('connect-error-message');
202 l10n
.localizeElementFromTag(errorDiv
, /** @type {string} */ (errorTag
));
204 var mode
= remoting
.clientSession
? remoting
.clientSession
.getMode()
205 : this.app_
.getSessionConnector().getConnectionMode();
206 if (mode
== remoting
.ClientSession
.Mode
.IT2ME
) {
207 remoting
.setMode(remoting
.AppMode
.CLIENT_CONNECT_FAILED_IT2ME
);
208 remoting
.hangoutSessionEvents
.raiseEvent(
209 remoting
.hangoutSessionEvents
.sessionStateChanged
,
210 remoting
.ClientSession
.State
.FAILED
213 remoting
.setMode(remoting
.AppMode
.CLIENT_CONNECT_FAILED_ME2ME
);