OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 /** @suppress {duplicate} */ | 5 /** @suppress {duplicate} */ |
6 var remoting = remoting || {}; | 6 var remoting = remoting || {}; |
7 | 7 |
8 (function() { | 8 (function() { |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 12 matching lines...) Expand all Loading... |
23 /** @private */ | 23 /** @private */ |
24 this.parentActivity_ = parentActivity; | 24 this.parentActivity_ = parentActivity; |
25 /** @private {remoting.DesktopConnectedView} */ | 25 /** @private {remoting.DesktopConnectedView} */ |
26 this.connectedView_ = null; | 26 this.connectedView_ = null; |
27 /** @private */ | 27 /** @private */ |
28 this.sessionFactory_ = new remoting.ClientSessionFactory( | 28 this.sessionFactory_ = new remoting.ClientSessionFactory( |
29 document.querySelector('#client-container .client-plugin-container'), | 29 document.querySelector('#client-container .client-plugin-container'), |
30 remoting.app_capabilities()); | 30 remoting.app_capabilities()); |
31 /** @private {remoting.ClientSession} */ | 31 /** @private {remoting.ClientSession} */ |
32 this.session_ = null; | 32 this.session_ = null; |
| 33 /** @private {remoting.ConnectingDialog} */ |
| 34 this.connectingDialog_ = |
| 35 new remoting.ConnectingDialog(parentActivity.stop.bind(parentActivity)); |
33 }; | 36 }; |
34 | 37 |
35 /** | 38 /** |
36 * Initiates a connection. | 39 * Initiates a connection. |
37 * | 40 * |
38 * @param {remoting.Host} host the Host to connect to. | 41 * @param {remoting.Host} host the Host to connect to. |
39 * @param {remoting.CredentialsProvider} credentialsProvider | 42 * @param {remoting.CredentialsProvider} credentialsProvider |
40 * @param {boolean=} opt_suppressOfflineError | 43 * @param {boolean=} opt_suppressOfflineError |
41 * @return {void} Nothing. | 44 * @return {void} Nothing. |
42 */ | 45 */ |
43 remoting.DesktopRemotingActivity.prototype.start = | 46 remoting.DesktopRemotingActivity.prototype.start = |
44 function(host, credentialsProvider, opt_suppressOfflineError) { | 47 function(host, credentialsProvider, opt_suppressOfflineError) { |
45 var that = this; | 48 var that = this; |
46 this.sessionFactory_.createSession(this).then( | 49 this.sessionFactory_.createSession(this).then( |
47 function(/** remoting.ClientSession */ session) { | 50 function(/** remoting.ClientSession */ session) { |
48 that.session_ = session; | 51 that.session_ = session; |
49 session.logHostOfflineErrors(!opt_suppressOfflineError); | 52 session.logHostOfflineErrors(!opt_suppressOfflineError); |
| 53 session.getLogger().setHostVersion(host.hostVersion); |
50 session.connect(host, credentialsProvider); | 54 session.connect(host, credentialsProvider); |
51 }); | 55 }).catch(remoting.Error.handler( |
| 56 function(/** !remoting.Error */ error) { |
| 57 that.parentActivity_.onConnectionFailed(error); |
| 58 })); |
52 }; | 59 }; |
53 | 60 |
54 remoting.DesktopRemotingActivity.prototype.stop = function() { | 61 remoting.DesktopRemotingActivity.prototype.stop = function() { |
55 if (this.session_) { | 62 if (this.session_) { |
56 this.session_.disconnect(remoting.Error.none()); | 63 this.session_.disconnect(remoting.Error.none()); |
57 console.log('Disconnected.'); | 64 console.log('Disconnected.'); |
58 } | 65 } |
59 }; | 66 }; |
60 | 67 |
61 /** | 68 /** |
62 * @param {remoting.ConnectionInfo} connectionInfo | 69 * @param {remoting.ConnectionInfo} connectionInfo |
63 */ | 70 */ |
64 remoting.DesktopRemotingActivity.prototype.onConnected = | 71 remoting.DesktopRemotingActivity.prototype.onConnected = |
65 function(connectionInfo) { | 72 function(connectionInfo) { |
| 73 this.connectingDialog_.hide(); |
66 remoting.setMode(remoting.AppMode.IN_SESSION); | 74 remoting.setMode(remoting.AppMode.IN_SESSION); |
67 if (!base.isAppsV2()) { | 75 if (!base.isAppsV2()) { |
68 remoting.toolbar.center(); | 76 remoting.toolbar.center(); |
69 remoting.toolbar.preview(); | 77 remoting.toolbar.preview(); |
70 } | 78 } |
71 | 79 |
72 this.connectedView_ = new remoting.DesktopConnectedView( | 80 this.connectedView_ = new remoting.DesktopConnectedView( |
73 document.getElementById('client-container'), connectionInfo); | 81 document.getElementById('client-container'), connectionInfo); |
74 | 82 |
75 // By default, under ChromeOS, remap the right Control key to the right | 83 // By default, under ChromeOS, remap the right Control key to the right |
76 // Win / Cmd key. | 84 // Win / Cmd key. |
77 if (remoting.platformIsChromeOS()) { | 85 if (remoting.platformIsChromeOS()) { |
78 connectionInfo.plugin().setRemapKeys('0x0700e4>0x0700e7'); | 86 connectionInfo.plugin().setRemapKeys('0x0700e4>0x0700e7'); |
79 } | 87 } |
80 | 88 |
81 if (connectionInfo.plugin().hasCapability( | 89 if (connectionInfo.plugin().hasCapability( |
82 remoting.ClientSession.Capability.VIDEO_RECORDER)) { | 90 remoting.ClientSession.Capability.VIDEO_RECORDER)) { |
83 var recorder = new remoting.VideoFrameRecorder(); | 91 var recorder = new remoting.VideoFrameRecorder(); |
84 connectionInfo.plugin().extensions().register(recorder); | 92 connectionInfo.plugin().extensions().register(recorder); |
85 this.connectedView_.setVideoFrameRecorder(recorder); | 93 this.connectedView_.setVideoFrameRecorder(recorder); |
86 } | 94 } |
87 | 95 |
88 this.parentActivity_.onConnected(connectionInfo); | 96 this.parentActivity_.onConnected(connectionInfo); |
89 }; | 97 }; |
90 | 98 |
91 remoting.DesktopRemotingActivity.prototype.onDisconnected = function() { | 99 remoting.DesktopRemotingActivity.prototype.onDisconnected = function(reason) { |
92 this.parentActivity_.onDisconnected(); | 100 if (this.handleError_(reason)) { |
93 this.dispose(); | 101 return; |
| 102 } |
| 103 this.parentActivity_.onDisconnected(reason); |
94 }; | 104 }; |
95 | 105 |
96 /** | 106 /** |
97 * @param {!remoting.Error} error | 107 * @param {!remoting.Error} error |
98 */ | 108 */ |
99 remoting.DesktopRemotingActivity.prototype.onConnectionFailed = | 109 remoting.DesktopRemotingActivity.prototype.onConnectionFailed = |
100 function(error) { | 110 function(error) { |
| 111 if (this.handleError_(error)) { |
| 112 return; |
| 113 } |
101 this.parentActivity_.onConnectionFailed(error); | 114 this.parentActivity_.onConnectionFailed(error); |
102 }; | 115 }; |
103 | 116 |
104 /** | 117 /** |
105 * @param {!remoting.Error} error The error to be localized and displayed. | 118 * @param {!remoting.Error} error The error to be localized and displayed. |
| 119 * @return {boolean} returns true if the error is handled. |
| 120 * @private |
106 */ | 121 */ |
107 remoting.DesktopRemotingActivity.prototype.onError = function(error) { | 122 remoting.DesktopRemotingActivity.prototype.handleError_ = function(error) { |
108 console.error('Connection failed: ' + error.toString()); | |
109 | |
110 if (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)) { | 123 if (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)) { |
111 remoting.setMode(remoting.AppMode.HOME); | 124 remoting.setMode(remoting.AppMode.HOME); |
112 remoting.handleAuthFailureAndRelaunch(); | 125 remoting.handleAuthFailureAndRelaunch(); |
113 return; | 126 return true; |
114 } | 127 } |
115 | 128 return false; |
116 this.parentActivity_.onError(error); | |
117 | |
118 this.dispose(); | |
119 }; | 129 }; |
120 | 130 |
121 remoting.DesktopRemotingActivity.prototype.dispose = function() { | 131 remoting.DesktopRemotingActivity.prototype.dispose = function() { |
122 base.dispose(this.connectedView_); | 132 base.dispose(this.connectedView_); |
123 this.connectedView_ = null; | 133 this.connectedView_ = null; |
124 base.dispose(this.session_); | 134 base.dispose(this.session_); |
125 this.session_ = null; | 135 this.session_ = null; |
| 136 this.connectingDialog_.hide(); |
126 }; | 137 }; |
127 | 138 |
128 /** @return {remoting.DesktopConnectedView} */ | 139 /** @return {remoting.DesktopConnectedView} */ |
129 remoting.DesktopRemotingActivity.prototype.getConnectedView = function() { | 140 remoting.DesktopRemotingActivity.prototype.getConnectedView = function() { |
130 return this.connectedView_; | 141 return this.connectedView_; |
131 }; | 142 }; |
132 | 143 |
133 /** | 144 /** |
134 * @return {remoting.ClientSession}. | 145 * @return {remoting.ClientSession}. |
135 */ | 146 */ |
136 remoting.DesktopRemotingActivity.prototype.getSession = function() { | 147 remoting.DesktopRemotingActivity.prototype.getSession = function() { |
137 return this.session_; | 148 return this.session_; |
138 }; | 149 }; |
139 | 150 |
| 151 /** @return {remoting.ConnectingDialog} */ |
| 152 remoting.DesktopRemotingActivity.prototype.getConnectingDialog = function() { |
| 153 return this.connectingDialog_; |
| 154 }; |
| 155 |
140 })(); | 156 })(); |
OLD | NEW |