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) { |
77 this.onError(error); | 80 this.showErrorMessage_(error); |
| 81 base.dispose(this.desktopActivity_); |
| 82 this.desktopActivity_ = null; |
78 }; | 83 }; |
79 | 84 |
80 /** | 85 /** |
81 * @param {!remoting.ConnectionInfo} connectionInfo | 86 * @param {!remoting.ConnectionInfo} connectionInfo |
82 */ | 87 */ |
83 remoting.It2MeActivity.prototype.onConnected = function(connectionInfo) { | 88 remoting.It2MeActivity.prototype.onConnected = function(connectionInfo) { |
84 this.accessCodeDialog_.inputField().value = ''; | 89 this.accessCodeDialog_.inputField().value = ''; |
85 }; | 90 }; |
86 | 91 |
87 remoting.It2MeActivity.prototype.onDisconnected = function() { | 92 remoting.It2MeActivity.prototype.onDisconnected = function(error) { |
88 this.showFinishDialog_(remoting.AppMode.CLIENT_SESSION_FINISHED_IT2ME); | 93 if (error.isNone()) { |
| 94 this.showFinishDialog_(remoting.AppMode.CLIENT_SESSION_FINISHED_IT2ME); |
| 95 } else { |
| 96 this.showErrorMessage_(error); |
| 97 } |
| 98 |
| 99 base.dispose(this.desktopActivity_); |
| 100 this.desktopActivity_ = null; |
89 }; | 101 }; |
90 | 102 |
91 /** | 103 /** |
92 * @param {!remoting.Error} error | 104 * @param {!remoting.Error} error |
| 105 * @private |
93 */ | 106 */ |
94 remoting.It2MeActivity.prototype.onError = function(error) { | 107 remoting.It2MeActivity.prototype.showErrorMessage_ = function(error) { |
95 var errorDiv = document.getElementById('connect-error-message'); | 108 var errorDiv = document.getElementById('connect-error-message'); |
96 l10n.localizeElementFromTag(errorDiv, error.getTag()); | 109 l10n.localizeElementFromTag(errorDiv, error.getTag()); |
97 this.showFinishDialog_(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); | 110 this.showFinishDialog_(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); |
98 }; | 111 }; |
99 | 112 |
100 /** @return {remoting.DesktopRemotingActivity} */ | 113 /** @return {remoting.DesktopRemotingActivity} */ |
101 remoting.It2MeActivity.prototype.getDesktopActivityForTesting = function() { | 114 remoting.It2MeActivity.prototype.getDesktopActivityForTesting = function() { |
102 return this.desktopActivity_; | 115 return this.desktopActivity_; |
103 }; | 116 }; |
104 | 117 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } else { | 189 } else { |
177 return Promise.reject(translateSupportHostsError(xhrResponse.status)); | 190 return Promise.reject(translateSupportHostsError(xhrResponse.status)); |
178 } | 191 } |
179 }; | 192 }; |
180 | 193 |
181 /** | 194 /** |
182 * @param {remoting.Host} host | 195 * @param {remoting.Host} host |
183 * @private | 196 * @private |
184 */ | 197 */ |
185 remoting.It2MeActivity.prototype.connect_ = function(host) { | 198 remoting.It2MeActivity.prototype.connect_ = function(host) { |
186 base.dispose(this.desktopActivity_); | |
187 this.desktopActivity_ = new remoting.DesktopRemotingActivity(this); | |
188 remoting.app.setConnectionMode(remoting.Application.Mode.IT2ME); | |
189 this.desktopActivity_.start( | 199 this.desktopActivity_.start( |
190 host, new remoting.CredentialsProvider({ accessCode: this.passCode_ })); | 200 host, new remoting.CredentialsProvider({ accessCode: this.passCode_ })); |
191 }; | 201 }; |
192 | 202 |
193 /** | 203 /** |
194 * TODO(jrw): Replace with remoting.Error.fromHttpStatus. | 204 * TODO(jrw): Replace with remoting.Error.fromHttpStatus. |
195 * @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 |
196 * endpoint. | 206 * endpoint. |
197 * @return {remoting.Error} The equivalent remoting.Error code. | 207 * @return {remoting.Error} The equivalent remoting.Error code. |
198 */ | 208 */ |
199 function translateSupportHostsError(error) { | 209 function translateSupportHostsError(error) { |
200 switch (error) { | 210 switch (error) { |
201 case 0: return new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE); | 211 case 0: return new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE); |
202 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); |
203 case 502: // No break | 213 case 502: // No break |
204 case 503: return new remoting.Error(remoting.Error.Tag.SERVICE_UNAVAILABLE); | 214 case 503: return new remoting.Error(remoting.Error.Tag.SERVICE_UNAVAILABLE); |
205 default: return remoting.Error.unexpected(); | 215 default: return remoting.Error.unexpected(); |
206 } | 216 } |
207 } | 217 } |
208 | 218 |
209 })(); | 219 })(); |
OLD | NEW |