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 26 matching lines...) Expand all Loading... |
37 }; | 37 }; |
38 | 38 |
39 remoting.It2MeActivity.prototype.dispose = function() { | 39 remoting.It2MeActivity.prototype.dispose = function() { |
40 base.dispose(this.desktopActivity_); | 40 base.dispose(this.desktopActivity_); |
41 this.desktopActivity_ = null; | 41 this.desktopActivity_ = null; |
42 }; | 42 }; |
43 | 43 |
44 remoting.It2MeActivity.prototype.start = function() { | 44 remoting.It2MeActivity.prototype.start = function() { |
45 var that = this; | 45 var that = this; |
46 | 46 |
| 47 this.desktopActivity_ = new remoting.DesktopRemotingActivity(this); |
| 48 remoting.app.setConnectionMode(remoting.Application.Mode.IT2ME); |
| 49 |
47 this.accessCodeDialog_.show().then(function(/** string */ accessCode) { | 50 this.accessCodeDialog_.show().then(function(/** string */ accessCode) { |
48 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 51 that.desktopActivity_.getConnectingDialog().show(); |
49 return that.verifyAccessCode_(accessCode); | 52 return that.verifyAccessCode_(accessCode); |
50 }).then(function() { | 53 }).then(function() { |
51 return remoting.identity.getToken(); | 54 return remoting.identity.getToken(); |
52 }).then(function(/** string */ token) { | 55 }).then(function(/** string */ token) { |
53 return that.getHostInfo_(token); | 56 return that.getHostInfo_(token); |
54 }).then(function(/** !remoting.Xhr.Response */ response) { | 57 }).then(function(/** !remoting.Xhr.Response */ response) { |
55 return that.onHostInfo_(response); | 58 return that.onHostInfo_(response); |
56 }).then(function(/** remoting.Host */ host) { | 59 }).then(function(/** remoting.Host */ host) { |
57 that.connect_(host); | 60 that.connect_(host); |
58 }).catch(function(/** remoting.Error */ error) { | 61 }).catch(remoting.Error.handler(function(/** remoting.Error */ error) { |
59 if (error.hasTag(remoting.Error.Tag.CANCELLED)) { | 62 if (error.hasTag(remoting.Error.Tag.CANCELLED)) { |
60 remoting.setMode(remoting.AppMode.HOME); | 63 remoting.setMode(remoting.AppMode.HOME); |
61 } else { | 64 } else { |
62 var errorDiv = document.getElementById('connect-error-message'); | 65 var errorDiv = document.getElementById('connect-error-message'); |
63 l10n.localizeElementFromTag(errorDiv, error.getTag()); | 66 l10n.localizeElementFromTag(errorDiv, error.getTag()); |
64 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); | 67 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); |
65 } | 68 } |
66 }); | 69 })); |
67 }; | 70 }; |
68 | 71 |
69 remoting.It2MeActivity.prototype.stop = function() { | 72 remoting.It2MeActivity.prototype.stop = function() { |
70 this.desktopActivity_.stop(); | 73 this.desktopActivity_.stop(); |
71 }; | 74 }; |
72 | 75 |
73 /** | 76 /** |
74 * @param {!remoting.Error} error | 77 * @param {!remoting.Error} error |
75 */ | 78 */ |
76 remoting.It2MeActivity.prototype.onConnectionFailed = function(error) { | 79 remoting.It2MeActivity.prototype.onConnectionFailed = function(error) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } else { | 189 } else { |
187 return Promise.reject(translateSupportHostsError(xhrResponse.status)); | 190 return Promise.reject(translateSupportHostsError(xhrResponse.status)); |
188 } | 191 } |
189 }; | 192 }; |
190 | 193 |
191 /** | 194 /** |
192 * @param {remoting.Host} host | 195 * @param {remoting.Host} host |
193 * @private | 196 * @private |
194 */ | 197 */ |
195 remoting.It2MeActivity.prototype.connect_ = function(host) { | 198 remoting.It2MeActivity.prototype.connect_ = function(host) { |
196 base.dispose(this.desktopActivity_); | |
197 this.desktopActivity_ = new remoting.DesktopRemotingActivity(this); | |
198 remoting.app.setConnectionMode(remoting.Application.Mode.IT2ME); | |
199 this.desktopActivity_.start( | 199 this.desktopActivity_.start( |
200 host, new remoting.CredentialsProvider({ accessCode: this.passCode_ })); | 200 host, new remoting.CredentialsProvider({ accessCode: this.passCode_ })); |
201 }; | 201 }; |
202 | 202 |
203 /** | 203 /** |
204 * TODO(jrw): Replace with remoting.Error.fromHttpStatus. | 204 * TODO(jrw): Replace with remoting.Error.fromHttpStatus. |
205 * @param {number} error An HTTP error code returned by the support-hosts | 205 * @param {number} error An HTTP error code returned by the support-hosts |
206 * endpoint. | 206 * endpoint. |
207 * @return {remoting.Error} The equivalent remoting.Error code. | 207 * @return {remoting.Error} The equivalent remoting.Error code. |
208 */ | 208 */ |
209 function translateSupportHostsError(error) { | 209 function translateSupportHostsError(error) { |
210 switch (error) { | 210 switch (error) { |
211 case 0: return new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE); | 211 case 0: return new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE); |
212 case 404: return new remoting.Error(remoting.Error.Tag.INVALID_ACCESS_CODE); | 212 case 404: return new remoting.Error(remoting.Error.Tag.INVALID_ACCESS_CODE); |
213 case 502: // No break | 213 case 502: // No break |
214 case 503: return new remoting.Error(remoting.Error.Tag.SERVICE_UNAVAILABLE); | 214 case 503: return new remoting.Error(remoting.Error.Tag.SERVICE_UNAVAILABLE); |
215 default: return remoting.Error.unexpected(); | 215 default: return remoting.Error.unexpected(); |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 })(); | 219 })(); |
OLD | NEW |