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 remoting.app_capabilities());
33 /** @private {remoting.ClientSession} */
35 /** @private {remoting.ConnectingDialog} */
36 this.connectingDialog_ =
37 new remoting.ConnectingDialog(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 {boolean=} opt_suppressOfflineError
46 * @return {void} Nothing.
48 remoting.DesktopRemotingActivity.prototype.start =
49 function(host, credentialsProvider, opt_suppressOfflineError) {
51 this.sessionFactory_.createSession(this).then(
52 function(/** remoting.ClientSession */ session) {
53 that.session_ = session;
54 session.logHostOfflineErrors(!opt_suppressOfflineError);
55 session.getLogger().setHostVersion(host.hostVersion);
57 var mode = remoting.ServerLogEntry.VALUE_MODE_UNKNOWN;
58 if (that.parentActivity_ instanceof remoting.It2MeActivity) {
59 mode = remoting.ServerLogEntry.VALUE_MODE_IT2ME;
60 } else if (that.parentActivity_ instanceof remoting.Me2MeActivity) {
61 mode = remoting.ServerLogEntry.VALUE_MODE_ME2ME;
63 session.getLogger().setLogEntryMode(mode);
65 session.connect(host, credentialsProvider);
66 }).catch(remoting.Error.handler(
67 function(/** !remoting.Error */ error) {
68 that.parentActivity_.onConnectionFailed(error);
72 remoting.DesktopRemotingActivity.prototype.stop = function() {
74 this.session_.disconnect(remoting.Error.none());
75 console.log('Disconnected.');
80 * @param {remoting.ConnectionInfo} connectionInfo
82 remoting.DesktopRemotingActivity.prototype.onConnected =
83 function(connectionInfo) {
84 this.connectingDialog_.hide();
85 remoting.setMode(remoting.AppMode.IN_SESSION);
86 if (!base.isAppsV2()) {
87 remoting.toolbar.center();
88 remoting.toolbar.preview();
91 this.connectedView_ = new remoting.DesktopConnectedView(
92 document.getElementById('client-container'), connectionInfo);
94 // Apply the default or previously-specified keyboard remapping.
95 var remapping = connectionInfo.host().options.remapKeys;
96 if (remapping === '' && remoting.platformIsChromeOS()) {
97 // Under ChromeOS, remap the right Control key to the right Win/Cmd key.
98 remapping = '0x0700e4>0x0700e7';
100 connectionInfo.plugin().setRemapKeys(remapping);
102 if (connectionInfo.plugin().hasCapability(
103 remoting.ClientSession.Capability.VIDEO_RECORDER)) {
104 var recorder = new remoting.VideoFrameRecorder();
105 connectionInfo.plugin().extensions().register(recorder);
106 this.connectedView_.setVideoFrameRecorder(recorder);
109 this.parentActivity_.onConnected(connectionInfo);
112 remoting.DesktopRemotingActivity.prototype.onDisconnected = function(reason) {
113 if (this.handleError_(reason)) {
116 this.parentActivity_.onDisconnected(reason);
120 * @param {!remoting.Error} error
122 remoting.DesktopRemotingActivity.prototype.onConnectionFailed =
124 if (this.handleError_(error)) {
127 this.parentActivity_.onConnectionFailed(error);
131 * @param {!remoting.Error} error The error to be localized and displayed.
132 * @return {boolean} returns true if the error is handled.
135 remoting.DesktopRemotingActivity.prototype.handleError_ = function(error) {
136 if (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)) {
137 remoting.setMode(remoting.AppMode.HOME);
138 remoting.handleAuthFailureAndRelaunch();
144 remoting.DesktopRemotingActivity.prototype.dispose = function() {
145 base.dispose(this.connectedView_);
146 this.connectedView_ = null;
147 base.dispose(this.session_);
148 this.session_ = null;
149 this.connectingDialog_.hide();
152 /** @return {remoting.DesktopConnectedView} */
153 remoting.DesktopRemotingActivity.prototype.getConnectedView = function() {
154 return this.connectedView_;
158 * @return {remoting.ClientSession}.
160 remoting.DesktopRemotingActivity.prototype.getSession = function() {
161 return this.session_;
164 /** @return {remoting.ConnectingDialog} */
165 remoting.DesktopRemotingActivity.prototype.getConnectingDialog = function() {
166 return this.connectingDialog_;