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