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'; |
11 | 11 |
12 /** | 12 /** |
13 * @param {remoting.Host} host | 13 * @param {remoting.Host} host |
| 14 * @param {remoting.HostList} hostList |
14 * | 15 * |
15 * @constructor | 16 * @constructor |
16 * @implements {remoting.Activity} | 17 * @implements {remoting.Activity} |
17 */ | 18 */ |
18 remoting.Me2MeActivity = function(host) { | 19 remoting.Me2MeActivity = function(host, hostList) { |
19 /** @private */ | 20 /** @private */ |
20 this.host_ = host; | 21 this.host_ = host; |
21 /** @private */ | 22 /** @private */ |
| 23 this.hostList_ = hostList; |
| 24 /** @private */ |
22 this.pinDialog_ = | 25 this.pinDialog_ = |
23 new remoting.PinDialog(document.getElementById('pin-dialog'), host); | 26 new remoting.PinDialog(document.getElementById('pin-dialog'), host); |
24 /** @private */ | 27 /** @private */ |
25 this.hostUpdateDialog_ = new remoting.HostNeedsUpdateDialog( | 28 this.hostUpdateDialog_ = new remoting.HostNeedsUpdateDialog( |
26 document.getElementById('host-needs-update-dialog'), this.host_); | 29 document.getElementById('host-needs-update-dialog'), this.host_); |
27 | 30 |
28 /** @private */ | 31 /** @private */ |
29 this.retryOnHostOffline_ = true; | 32 this.retryOnHostOffline_ = true; |
30 | 33 |
31 /** @private {remoting.SmartReconnector} */ | 34 /** @private {remoting.SmartReconnector} */ |
32 this.reconnector_ = null; | 35 this.reconnector_ = null; |
33 | 36 |
34 /** @private {remoting.DesktopRemotingActivity} */ | 37 /** @private {remoting.DesktopRemotingActivity} */ |
35 this.desktopActivity_ = null; | 38 this.desktopActivity_ = null; |
36 }; | 39 }; |
37 | 40 |
38 remoting.Me2MeActivity.prototype.dispose = function() { | 41 remoting.Me2MeActivity.prototype.dispose = function() { |
39 base.dispose(this.desktopActivity_); | 42 base.dispose(this.desktopActivity_); |
40 this.desktopActivity_ = null; | 43 this.desktopActivity_ = null; |
41 }; | 44 }; |
42 | 45 |
43 remoting.Me2MeActivity.prototype.start = function() { | 46 remoting.Me2MeActivity.prototype.start = function() { |
44 var webappVersion = chrome.runtime.getManifest().version; | 47 var webappVersion = chrome.runtime.getManifest().version; |
45 var that = this; | 48 var that = this; |
46 | 49 |
47 this.hostUpdateDialog_.showIfNecessary(webappVersion).then(function() { | 50 this.hostUpdateDialog_.showIfNecessary(webappVersion).then(function() { |
48 return that.host_.options.load(); | 51 return that.host_.options.load(); |
49 }).then(function() { | 52 }).then(function() { |
50 that.connect_(true); | 53 that.connect_(true); |
51 }).catch(function(/** remoting.Error */ error) { | 54 }).catch(remoting.Error.handler(function(/** remoting.Error */ error) { |
52 if (error.hasTag(remoting.Error.Tag.CANCELLED)) { | 55 if (error.hasTag(remoting.Error.Tag.CANCELLED)) { |
53 remoting.setMode(remoting.AppMode.HOME); | 56 remoting.setMode(remoting.AppMode.HOME); |
54 } | 57 } |
55 }); | 58 })); |
56 }; | 59 }; |
57 | 60 |
58 remoting.Me2MeActivity.prototype.stop = function() { | 61 remoting.Me2MeActivity.prototype.stop = function() { |
59 this.desktopActivity_.stop(); | 62 this.desktopActivity_.stop(); |
60 }; | 63 }; |
61 | 64 |
62 /** @return {remoting.DesktopRemotingActivity} */ | 65 /** @return {remoting.DesktopRemotingActivity} */ |
63 remoting.Me2MeActivity.prototype.getDesktopActivity = function() { | 66 remoting.Me2MeActivity.prototype.getDesktopActivity = function() { |
64 return this.desktopActivity_; | 67 return this.desktopActivity_; |
65 }; | 68 }; |
66 | 69 |
67 /** | 70 /** |
68 * @param {boolean} suppressHostOfflineError | 71 * @param {boolean} suppressHostOfflineError |
69 * @private | 72 * @private |
70 */ | 73 */ |
71 remoting.Me2MeActivity.prototype.connect_ = function(suppressHostOfflineError) { | 74 remoting.Me2MeActivity.prototype.connect_ = function(suppressHostOfflineError) { |
72 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | |
73 base.dispose(this.desktopActivity_); | 75 base.dispose(this.desktopActivity_); |
74 this.desktopActivity_ = new remoting.DesktopRemotingActivity(this); | 76 this.desktopActivity_ = new remoting.DesktopRemotingActivity(this); |
| 77 this.desktopActivity_.getConnectingDialog().show(); |
75 remoting.app.setConnectionMode(remoting.Application.Mode.ME2ME); | 78 remoting.app.setConnectionMode(remoting.Application.Mode.ME2ME); |
76 this.desktopActivity_.start(this.host_, this.createCredentialsProvider_(), | 79 this.desktopActivity_.start(this.host_, this.createCredentialsProvider_(), |
77 suppressHostOfflineError); | 80 suppressHostOfflineError); |
78 }; | 81 }; |
79 | 82 |
80 /** | 83 /** |
81 * @return {remoting.CredentialsProvider} | 84 * @return {remoting.CredentialsProvider} |
82 * @private | 85 * @private |
83 */ | 86 */ |
84 remoting.Me2MeActivity.prototype.createCredentialsProvider_ = function() { | 87 remoting.Me2MeActivity.prototype.createCredentialsProvider_ = function() { |
(...skipping 14 matching lines...) Expand all Loading... |
99 thirdPartyTokenFetcher.fetchToken(); | 102 thirdPartyTokenFetcher.fetchToken(); |
100 }; | 103 }; |
101 | 104 |
102 /** | 105 /** |
103 * @param {boolean} supportsPairing | 106 * @param {boolean} supportsPairing |
104 * @param {function(string):void} onPinFetched | 107 * @param {function(string):void} onPinFetched |
105 */ | 108 */ |
106 var requestPin = function(supportsPairing, onPinFetched) { | 109 var requestPin = function(supportsPairing, onPinFetched) { |
107 // Set time when PIN was requested. | 110 // Set time when PIN was requested. |
108 var authStartTime = new Date().getTime(); | 111 var authStartTime = new Date().getTime(); |
| 112 that.desktopActivity_.getConnectingDialog().hide(); |
109 that.pinDialog_.show(supportsPairing).then(function(/** string */ pin) { | 113 that.pinDialog_.show(supportsPairing).then(function(/** string */ pin) { |
110 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 114 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); |
111 // Done obtaining PIN information. Log time taken for PIN entry. | 115 // Done obtaining PIN information. Log time taken for PIN entry. |
112 var logToServer = that.desktopActivity_.getSession().getLogger(); | 116 var logToServer = that.desktopActivity_.getSession().getLogger(); |
113 logToServer.setAuthTotalTime(new Date().getTime() - authStartTime); | 117 logToServer.setAuthTotalTime(new Date().getTime() - authStartTime); |
114 onPinFetched(pin); | 118 onPinFetched(pin); |
115 }).catch(function(/** remoting.Error */ error) { | 119 }).catch(remoting.Error.handler(function(/** remoting.Error */ error) { |
116 base.debug.assert(error.hasTag(remoting.Error.Tag.CANCELLED)); | 120 base.debug.assert(error.hasTag(remoting.Error.Tag.CANCELLED)); |
117 remoting.setMode(remoting.AppMode.HOME); | 121 remoting.setMode(remoting.AppMode.HOME); |
118 }); | 122 that.stop(); |
| 123 })); |
119 }; | 124 }; |
120 | 125 |
121 return new remoting.CredentialsProvider({ | 126 return new remoting.CredentialsProvider({ |
122 fetchPin: requestPin, | 127 fetchPin: requestPin, |
123 pairingInfo: /** @type{remoting.PairingInfo} */ ( | 128 pairingInfo: /** @type{remoting.PairingInfo} */ ( |
124 base.deepCopy(host.options.pairingInfo)), | 129 base.deepCopy(host.options.pairingInfo)), |
125 fetchThirdPartyToken: fetchThirdPartyToken | 130 fetchThirdPartyToken: fetchThirdPartyToken |
126 }); | 131 }); |
127 }; | 132 }; |
128 | 133 |
129 /** | 134 /** |
130 * @param {!remoting.Error} error | 135 * @param {!remoting.Error} error |
131 */ | 136 */ |
132 remoting.Me2MeActivity.prototype.onConnectionFailed = function(error) { | 137 remoting.Me2MeActivity.prototype.onConnectionFailed = function(error) { |
133 if (error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE) && | 138 if (error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE) && |
134 this.retryOnHostOffline_) { | 139 this.retryOnHostOffline_) { |
135 var that = this; | 140 var that = this; |
136 var onHostListRefresh = function(/** boolean */ success) { | 141 var onHostListRefresh = function(/** boolean */ success) { |
137 if (success) { | 142 if (success) { |
138 // Get the host from the hostList for the refreshed JID. | 143 // Get the host from the hostList for the refreshed JID. |
139 that.host_ = remoting.hostList.getHostForId(that.host_.hostId); | 144 that.host_ = that.hostList_.getHostForId(that.host_.hostId); |
140 that.connect_(false); | 145 that.connect_(false); |
141 return; | 146 return; |
142 } | 147 } |
143 that.showErrorMessage_(error); | 148 that.showErrorMessage_(error); |
144 }; | 149 }; |
145 this.retryOnHostOffline_ = false; | 150 this.retryOnHostOffline_ = false; |
146 | 151 |
147 // The plugin will be re-created when the host finished refreshing | 152 // The plugin will be re-created when the host finished refreshing |
148 remoting.hostList.refresh(onHostListRefresh); | 153 this.hostList_.refresh(onHostListRefresh); |
149 } else if (!error.isNone()) { | 154 } else if (!error.isNone()) { |
150 this.showErrorMessage_(error); | 155 this.showErrorMessage_(error); |
151 } | 156 } |
152 | 157 |
153 base.dispose(this.desktopActivity_); | 158 base.dispose(this.desktopActivity_); |
154 this.desktopActivity_ = null; | 159 this.desktopActivity_ = null; |
155 }; | 160 }; |
156 | 161 |
157 /** | 162 /** |
158 * @param {!remoting.ConnectionInfo} connectionInfo | 163 * @param {!remoting.ConnectionInfo} connectionInfo |
159 */ | 164 */ |
160 remoting.Me2MeActivity.prototype.onConnected = function(connectionInfo) { | 165 remoting.Me2MeActivity.prototype.onConnected = function(connectionInfo) { |
161 // Reset the refresh flag so that the next connection will retry if needed. | 166 // Reset the refresh flag so that the next connection will retry if needed. |
162 this.retryOnHostOffline_ = true; | 167 this.retryOnHostOffline_ = true; |
163 | 168 |
164 var plugin = connectionInfo.plugin(); | 169 var plugin = connectionInfo.plugin(); |
165 if (plugin.hasCapability(remoting.ClientSession.Capability.CAST)) { | 170 if (plugin.hasCapability(remoting.ClientSession.Capability.CAST)) { |
166 plugin.extensions().register(new remoting.CastExtensionHandler()); | 171 plugin.extensions().register(new remoting.CastExtensionHandler()); |
167 } | 172 } |
168 plugin.extensions().register(new remoting.GnubbyAuthHandler()); | 173 plugin.extensions().register(new remoting.GnubbyAuthHandler()); |
169 this.pinDialog_.requestPairingIfNecessary(connectionInfo.plugin()); | 174 this.pinDialog_.requestPairingIfNecessary(connectionInfo.plugin()); |
170 | 175 |
171 base.dispose(this.reconnector_); | 176 base.dispose(this.reconnector_); |
172 this.reconnector_ = new remoting.SmartReconnector( | 177 this.reconnector_ = new remoting.SmartReconnector( |
| 178 this.desktopActivity_.getConnectingDialog(), |
173 this.connect_.bind(this, false), | 179 this.connect_.bind(this, false), |
174 this.stop.bind(this), | 180 this.stop.bind(this), |
175 connectionInfo.session()); | 181 connectionInfo.session()); |
176 }; | 182 }; |
177 | 183 |
178 remoting.Me2MeActivity.prototype.onDisconnected = function(error) { | 184 remoting.Me2MeActivity.prototype.onDisconnected = function(error) { |
179 if (error.isNone()) { | 185 if (error.isNone()) { |
180 this.showFinishDialog_(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME); | 186 this.showFinishDialog_(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME); |
181 } else { | 187 } else { |
182 this.reconnector_.onConnectionDropped(error); | 188 this.reconnector_.onConnectionDropped(error); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 clientName = 'Linux'; | 336 clientName = 'Linux'; |
331 } else { | 337 } else { |
332 console.log('Unrecognized client platform. Using navigator.platform.'); | 338 console.log('Unrecognized client platform. Using navigator.platform.'); |
333 clientName = navigator.platform; | 339 clientName = navigator.platform; |
334 } | 340 } |
335 plugin.requestPairing(clientName, onPairingComplete); | 341 plugin.requestPairing(clientName, onPairingComplete); |
336 } | 342 } |
337 }; | 343 }; |
338 | 344 |
339 })(); | 345 })(); |
OLD | NEW |