OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
9 | 9 |
10 /** @constructor */ | 10 /** @constructor */ |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 } | 166 } |
167 | 167 |
168 /** | 168 /** |
169 * @param {string} hostName | 169 * @param {string} hostName |
170 * @param {string} publicKey | 170 * @param {string} publicKey |
171 * @param {string} privateKey | 171 * @param {string} privateKey |
172 * @param {string} xmppLogin | 172 * @param {string} xmppLogin |
173 * @param {string} refreshToken | 173 * @param {string} refreshToken |
174 * @param {string} hostSecretHash | 174 * @param {string} hostSecretHash |
175 */ | 175 */ |
176 function startHostWithHash(hostName, publicKey, privateKey, | 176 function startHostWithHash(hostName, publicKey, privateKey, xmppLogin, |
177 xmppLogin, refreshToken, hostSecretHash) { | 177 refreshToken, clientJid, hostSecretHash) { |
178 var hostConfig = { | 178 var hostConfig = { |
179 xmpp_login: xmppLogin, | 179 xmpp_login: xmppLogin, |
180 oauth_refresh_token: refreshToken, | 180 oauth_refresh_token: refreshToken, |
181 host_id: newHostId, | 181 host_id: newHostId, |
182 host_name: hostName, | 182 host_name: hostName, |
183 host_secret_hash: hostSecretHash, | 183 host_secret_hash: hostSecretHash, |
184 private_key: privateKey | 184 private_key: privateKey |
185 }; | 185 }; |
186 var hostOwner = remoting.identity.getCachedEmail(); | 186 var hostOwner = clientJid; |
187 var hostOwnerEmail = remoting.identity.getCachedEmail(); | |
187 if (hostOwner != xmppLogin) { | 188 if (hostOwner != xmppLogin) { |
188 hostConfig['host_owner'] = hostOwner; | 189 hostConfig['host_owner'] = hostOwner; |
190 if (hostOwnerEmail != hostOwner) { | |
191 hostConfig['host_owner_email'] = hostOwnerEmail; | |
192 } | |
189 } | 193 } |
190 that.hostDaemonFacade_.startDaemon( | 194 that.hostDaemonFacade_.startDaemon( |
191 hostConfig, consent, onStarted.bind(null, hostName, publicKey), | 195 hostConfig, consent, onStarted.bind(null, hostName, publicKey), |
192 onStartError); | 196 onStartError); |
193 } | 197 } |
194 | 198 |
195 /** | 199 /** |
196 * @param {string} hostName | 200 * @param {string} hostName |
197 * @param {string} publicKey | 201 * @param {string} publicKey |
198 * @param {string} privateKey | 202 * @param {string} privateKey |
199 * @param {string} email | 203 * @param {string} email |
200 * @param {string} refreshToken | 204 * @param {string} refreshToken |
201 */ | 205 */ |
202 function onServiceAccountCredentials( | 206 function onClientBaseJid( |
203 hostName, publicKey, privateKey, email, refreshToken) { | 207 hostName, publicKey, privateKey, email, refreshToken, clientBaseJid) { |
204 that.hostDaemonFacade_.getPinHash( | 208 that.hostDaemonFacade_.getPinHash( |
205 newHostId, hostPin, | 209 newHostId, hostPin, |
206 startHostWithHash.bind( | 210 startHostWithHash.bind(null, hostName, publicKey, privateKey, |
207 null, hostName, publicKey, privateKey, email, refreshToken), | 211 email, refreshToken, clientBaseJid), |
208 onError); | 212 onError); |
209 } | 213 } |
210 | 214 |
211 /** | 215 /** |
212 * @param {string} hostName | 216 * @param {string} hostName |
213 * @param {string} publicKey | 217 * @param {string} publicKey |
214 * @param {string} privateKey | 218 * @param {string} privateKey |
219 * @param {string} email | |
220 * @param {string} refreshToken | |
221 */ | |
222 function onServiceAccountCredentials( | |
223 hostName, publicKey, privateKey, email, refreshToken) { | |
224 | |
225 // Find out the client JID that should be allowed to connect to this host. | |
226 var signalStrategy = null; | |
227 | |
228 var onState = function(state) { | |
Sergey Ulanov
2014/09/25 02:28:46
HostController.start() is hard to parse already an
rmsousa
2014/09/27 01:42:17
I agree about HostController.start(), but I'm not
Sergey Ulanov
2014/09/27 01:46:02
Yes. Thank you!
| |
229 switch (state) { | |
230 case remoting.SignalStrategy.State.CONNECTED: | |
231 var jid = signalStrategy.getJid().split('/')[0].toLowerCase(); | |
232 base.dispose(signalStrategy); | |
233 signalStrategy = null; | |
234 onClientBaseJid( | |
235 hostName, publicKey, privateKey, email, refreshToken, jid); | |
236 break; | |
237 | |
238 case remoting.SignalStrategy.State.FAILED: | |
239 var error = signalStrategy.getError(); | |
240 base.dispose(signalStrategy); | |
241 signalStrategy = null; | |
242 onStartError(error); | |
243 break; | |
244 } | |
245 }; | |
246 | |
247 signalStrategy = remoting.SignalStrategy.create(onState); | |
248 | |
249 /** @param {string} token */ | |
250 function connectSignalingWithToken(token) { | |
251 remoting.identity.getEmail( | |
252 connectSignalingWithTokenAndEmail.bind(null, token), onStartError); | |
253 } | |
254 | |
255 /** | |
256 * @param {string} token | |
257 * @param {string} email | |
258 */ | |
259 function connectSignalingWithTokenAndEmail(token, email) { | |
260 signalStrategy.connect( | |
261 remoting.settings.XMPP_SERVER_ADDRESS, email, token); | |
262 } | |
263 | |
264 remoting.identity.callWithToken(connectSignalingWithToken, onStartError); | |
265 } | |
266 | |
267 /** | |
268 * @param {string} hostName | |
269 * @param {string} publicKey | |
270 * @param {string} privateKey | |
215 * @param {XMLHttpRequest} xhr | 271 * @param {XMLHttpRequest} xhr |
216 */ | 272 */ |
217 function onRegistered( | 273 function onRegistered( |
218 hostName, publicKey, privateKey, xhr) { | 274 hostName, publicKey, privateKey, xhr) { |
219 var success = (xhr.status == 200); | 275 var success = (xhr.status == 200); |
220 | 276 |
221 if (success) { | 277 if (success) { |
222 var result = jsonParseSafe(xhr.responseText); | 278 var result = jsonParseSafe(xhr.responseText); |
223 if ('data' in result && 'authorizationCode' in result['data']) { | 279 if ('data' in result && 'authorizationCode' in result['data']) { |
224 that.hostDaemonFacade_.getCredentialsFromAuthCode( | 280 that.hostDaemonFacade_.getCredentialsFromAuthCode( |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 * @param {function(remoting.Error):void} onError Error callback. | 550 * @param {function(remoting.Error):void} onError Error callback. |
495 * @return {void} | 551 * @return {void} |
496 */ | 552 */ |
497 remoting.HostController.prototype.clearPairedClients = function( | 553 remoting.HostController.prototype.clearPairedClients = function( |
498 onDone, onError) { | 554 onDone, onError) { |
499 this.hostDaemonFacade_.clearPairedClients(onDone, onError); | 555 this.hostDaemonFacade_.clearPairedClients(onDone, onError); |
500 }; | 556 }; |
501 | 557 |
502 /** @type {remoting.HostController} */ | 558 /** @type {remoting.HostController} */ |
503 remoting.hostController = null; | 559 remoting.hostController = null; |
OLD | NEW |