1 // Copyright 2015 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.
5 /** @suppress {duplicate} */
6 var remoting = remoting || {};
13 * This class provides common functionality to Me2MeActivity and It2MeActivity,
14 * e.g. constructing the relevant UX, and delegate the custom handling of the
15 * session state changes to the |parentActivity|.
17 * @param {remoting.Activity} parentActivity
18 * @implements {remoting.ClientSession.EventHandler}
19 * @implements {base.Disposable}
22 remoting.DesktopRemotingActivity = function(parentActivity) {
24 this.parentActivity_ = parentActivity;
25 /** @private {remoting.DesktopConnectedView} */
26 this.connectedView_ = null;
29 this.sessionFactory_ = new remoting.ClientSessionFactory(
30 document.querySelector('#client-container .client-plugin-container'),
31 [/* No special capabilities required. */]);
33 /** @private {remoting.ClientSession} */
35 /** @private {remoting.ConnectingDialog} */
36 this.connectingDialog_ = remoting.modalDialogFactory.createConnectingDialog(
37 parentActivity.stop.bind(parentActivity));
41 * Initiates a connection.
43 * @param {remoting.Host} host the Host to connect to.
44 * @param {remoting.CredentialsProvider} credentialsProvider
45 * @param {remoting.SessionLogger} logger
46 * @return {void} Nothing.
48 remoting.DesktopRemotingActivity.prototype.start =
49 function(host, credentialsProvider, logger) {
51 var useApiaryForLogging = host.loggingChannel === 'APIARY';
52 this.sessionFactory_.createSession(this, logger, useApiaryForLogging).then(
53 function(/** remoting.ClientSession */ session) {
54 that.session_ = session;
56 // Update the host version and the Mode for the legacy XMPP logger.
57 // TODO(kelvinp): Remove this block of code when we have migrated away
58 // from XMPP-based logging (crbug.com/523423).
59 session.getLogger().setHostVersion(host.hostVersion);
60 var Mode = remoting.ChromotingEvent.Mode;
61 if (that.parentActivity_ instanceof remoting.It2MeActivity) {
62 session.getLogger().setLogEntryMode(Mode.IT2ME);
63 } else if (that.parentActivity_ instanceof remoting.Me2MeActivity) {
64 session.getLogger().setLogEntryMode(Mode.ME2ME);
67 session.connect(host, credentialsProvider);
68 }).catch(remoting.Error.handler(
69 function(/** !remoting.Error */ error) {
70 that.parentActivity_.onConnectionFailed(error);
74 remoting.DesktopRemotingActivity.prototype.stop = function() {
76 this.session_.disconnect(remoting.Error.none());
77 console.log('Disconnected.');
82 * @param {remoting.ConnectionInfo} connectionInfo
84 remoting.DesktopRemotingActivity.prototype.onConnected =
85 function(connectionInfo) {
86 this.connectingDialog_.hide();
87 remoting.setMode(remoting.AppMode.IN_SESSION);
88 if (!base.isAppsV2()) {
89 remoting.toolbar.center();
90 remoting.toolbar.preview();
93 this.connectedView_ = remoting.DesktopConnectedView.create(
94 document.getElementById('client-container'), connectionInfo);
96 // Apply the default or previously-specified keyboard remapping.
97 var remapping = connectionInfo.host().options.remapKeys;
98 if (base.isEmptyObject(remapping) && remoting.platformIsChromeOS()) {
99 // Under ChromeOS, remap the right Control key to the right Win/Cmd key.
100 remapping = {0x0700e4: 0x0700e7};
102 connectionInfo.plugin().setRemapKeys(remapping);
104 if (connectionInfo.plugin().hasCapability(
105 remoting.ClientSession.Capability.VIDEO_RECORDER)) {
106 var recorder = new remoting.VideoFrameRecorder();
107 connectionInfo.plugin().extensions().register(recorder);
108 this.connectedView_.setVideoFrameRecorder(recorder);
111 this.parentActivity_.onConnected(connectionInfo);
114 remoting.DesktopRemotingActivity.prototype.onDisconnected = function(reason) {
115 if (this.handleError_(reason)) {
118 this.parentActivity_.onDisconnected(reason);
122 * @param {!remoting.Error} error
124 remoting.DesktopRemotingActivity.prototype.onConnectionFailed =
126 if (this.handleError_(error)) {
129 this.parentActivity_.onConnectionFailed(error);
133 * @param {!remoting.Error} error The error to be localized and displayed.
134 * @return {boolean} returns true if the error is handled.
137 remoting.DesktopRemotingActivity.prototype.handleError_ = function(error) {
138 if (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)) {
139 remoting.setMode(remoting.AppMode.HOME);
140 remoting.handleAuthFailureAndRelaunch();
146 remoting.DesktopRemotingActivity.prototype.dispose = function() {
147 base.dispose(this.connectedView_);
148 this.connectedView_ = null;
149 base.dispose(this.session_);
150 this.session_ = null;
151 this.connectingDialog_.hide();
154 /** @return {remoting.DesktopConnectedView} */
155 remoting.DesktopRemotingActivity.prototype.getConnectedView = function() {
156 return this.connectedView_;
160 * @return {remoting.ClientSession}.
162 remoting.DesktopRemotingActivity.prototype.getSession = function() {
163 return this.session_;
166 /** @return {remoting.ConnectingDialog} */
167 remoting.DesktopRemotingActivity.prototype.getConnectingDialog = function() {
168 return this.connectingDialog_;