OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
Sergey Ulanov
2014/09/20 00:35:25
Technically this is a new file, so I guess it shou
| |
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 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Connect set-up state machine for Me2Me and IT2Me | 7 * Connect set-up state machine for Me2Me and IT2Me |
Sergey Ulanov
2014/09/20 00:35:25
update this comment please. E.g. something like "D
Jamie
2014/09/20 00:54:22
Done.
| |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
11 | 11 |
12 /** @suppress {duplicate} */ | 12 /** @suppress {duplicate} */ |
13 var remoting = remoting || {}; | 13 var remoting = remoting || {}; |
14 | 14 |
15 /** | 15 /** |
16 * @param {HTMLElement} clientContainer Container element for the client view. | 16 * @param {HTMLElement} clientContainer Container element for the client view. |
17 * @param {function(remoting.ClientSession):void} onConnected Callback on | 17 * @param {function(remoting.ClientSession):void} onConnected Callback on |
18 * success. | 18 * success. |
19 * @param {function(remoting.Error):void} onError Callback on error. | 19 * @param {function(remoting.Error):void} onError Callback on error. |
20 * @param {function(string, string):boolean} onExtensionMessage The handler for | 20 * @param {function(string, string):boolean} onExtensionMessage The handler for |
21 * protocol extension messages. Returns true if a message is recognized; | 21 * protocol extension messages. Returns true if a message is recognized; |
22 * false otherwise. | 22 * false otherwise. |
23 * @constructor | 23 * @constructor |
24 * @implements {remoting.SessionConnector} | |
24 */ | 25 */ |
25 remoting.SessionConnector = function(clientContainer, onConnected, onError, | 26 remoting.SessionConnectorImpl = function(clientContainer, onConnected, onError, |
26 onExtensionMessage) { | 27 onExtensionMessage) { |
27 /** | 28 /** |
28 * @type {HTMLElement} | 29 * @type {HTMLElement} |
29 * @private | 30 * @private |
30 */ | 31 */ |
31 this.clientContainer_ = clientContainer; | 32 this.clientContainer_ = clientContainer; |
32 | 33 |
33 /** | 34 /** |
34 * @type {function(remoting.ClientSession):void} | 35 * @type {function(remoting.ClientSession):void} |
35 * @private | 36 * @private |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 }; | 81 }; |
81 | 82 |
82 // Initialize/declare per-connection state. | 83 // Initialize/declare per-connection state. |
83 this.reset(); | 84 this.reset(); |
84 }; | 85 }; |
85 | 86 |
86 /** | 87 /** |
87 * Reset the per-connection state so that the object can be re-used for a | 88 * Reset the per-connection state so that the object can be re-used for a |
88 * second connection. Note the none of the shared WCS state is reset. | 89 * second connection. Note the none of the shared WCS state is reset. |
89 */ | 90 */ |
90 remoting.SessionConnector.prototype.reset = function() { | 91 remoting.SessionConnectorImpl.prototype.reset = function() { |
91 /** | |
92 * Set to true to indicate that the user requested pairing when entering | |
93 * their PIN for a Me2Me connection. | |
94 * | |
95 * @type {boolean} | |
96 */ | |
97 this.pairingRequested = false; | |
98 | |
99 /** | 92 /** |
100 * String used to identify the host to which to connect. For IT2Me, this is | 93 * String used to identify the host to which to connect. For IT2Me, this is |
101 * the first 7 digits of the access code; for Me2Me it is the host identifier. | 94 * the first 7 digits of the access code; for Me2Me it is the host identifier. |
102 * | 95 * |
103 * @type {string} | 96 * @type {string} |
104 * @private | 97 * @private |
105 */ | 98 */ |
106 this.hostId_ = ''; | 99 this.hostId_ = ''; |
107 | 100 |
108 /** | 101 /** |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 * @param {function(string, string, string, | 189 * @param {function(string, string, string, |
197 * function(string, string): void): void} | 190 * function(string, string): void): void} |
198 * fetchThirdPartyToken Function to obtain a token from a third party | 191 * fetchThirdPartyToken Function to obtain a token from a third party |
199 * authenticaiton server. | 192 * authenticaiton server. |
200 * @param {string} clientPairingId The client id issued by the host when | 193 * @param {string} clientPairingId The client id issued by the host when |
201 * this device was paired, if it is already paired. | 194 * this device was paired, if it is already paired. |
202 * @param {string} clientPairedSecret The shared secret issued by the host when | 195 * @param {string} clientPairedSecret The shared secret issued by the host when |
203 * this device was paired, if it is already paired. | 196 * this device was paired, if it is already paired. |
204 * @return {void} Nothing. | 197 * @return {void} Nothing. |
205 */ | 198 */ |
206 remoting.SessionConnector.prototype.connectMe2Me = | 199 remoting.SessionConnectorImpl.prototype.connectMe2Me = |
207 function(host, fetchPin, fetchThirdPartyToken, | 200 function(host, fetchPin, fetchThirdPartyToken, |
208 clientPairingId, clientPairedSecret) { | 201 clientPairingId, clientPairedSecret) { |
209 this.connectMe2MeInternal_( | 202 this.connectMe2MeInternal_( |
210 host.hostId, host.jabberId, host.publicKey, host.hostName, | 203 host.hostId, host.jabberId, host.publicKey, host.hostName, |
211 fetchPin, fetchThirdPartyToken, | 204 fetchPin, fetchThirdPartyToken, |
212 clientPairingId, clientPairedSecret, true); | 205 clientPairingId, clientPairedSecret, true); |
213 }; | 206 }; |
214 | 207 |
215 /** | 208 /** |
216 * Update the pairing info so that the reconnect function will work correctly. | 209 * Update the pairing info so that the reconnect function will work correctly. |
217 * | 210 * |
218 * @param {string} clientId The paired client id. | 211 * @param {string} clientId The paired client id. |
219 * @param {string} sharedSecret The shared secret. | 212 * @param {string} sharedSecret The shared secret. |
220 */ | 213 */ |
221 remoting.SessionConnector.prototype.updatePairingInfo = | 214 remoting.SessionConnectorImpl.prototype.updatePairingInfo = |
222 function(clientId, sharedSecret) { | 215 function(clientId, sharedSecret) { |
223 this.clientPairingId_ = clientId; | 216 this.clientPairingId_ = clientId; |
224 this.clientPairedSecret_ = sharedSecret; | 217 this.clientPairedSecret_ = sharedSecret; |
225 }; | 218 }; |
226 | 219 |
227 /** | 220 /** |
228 * Initiate a Me2Me connection. | 221 * Initiate a Me2Me connection. |
229 * | 222 * |
230 * @param {string} hostId ID of the Me2Me host. | 223 * @param {string} hostId ID of the Me2Me host. |
231 * @param {string} hostJid XMPP JID of the host. | 224 * @param {string} hostJid XMPP JID of the host. |
232 * @param {string} hostPublicKey Public Key of the host. | 225 * @param {string} hostPublicKey Public Key of the host. |
233 * @param {string} hostDisplayName Display name (friendly name) of the host. | 226 * @param {string} hostDisplayName Display name (friendly name) of the host. |
234 * @param {function(boolean, function(string):void):void} fetchPin Function to | 227 * @param {function(boolean, function(string):void):void} fetchPin Function to |
235 * interactively obtain the PIN from the user. | 228 * interactively obtain the PIN from the user. |
236 * @param {function(string, string, string, | 229 * @param {function(string, string, string, |
237 * function(string, string): void): void} | 230 * function(string, string): void): void} |
238 * fetchThirdPartyToken Function to obtain a token from a third party | 231 * fetchThirdPartyToken Function to obtain a token from a third party |
239 * authenticaiton server. | 232 * authenticaiton server. |
240 * @param {string} clientPairingId The client id issued by the host when | 233 * @param {string} clientPairingId The client id issued by the host when |
241 * this device was paired, if it is already paired. | 234 * this device was paired, if it is already paired. |
242 * @param {string} clientPairedSecret The shared secret issued by the host when | 235 * @param {string} clientPairedSecret The shared secret issued by the host when |
243 * this device was paired, if it is already paired. | 236 * this device was paired, if it is already paired. |
244 * @param {boolean} refreshHostJidIfOffline Whether to refresh the JID and retry | 237 * @param {boolean} refreshHostJidIfOffline Whether to refresh the JID and retry |
245 * the connection if the current JID is offline. | 238 * the connection if the current JID is offline. |
246 * @return {void} Nothing. | 239 * @return {void} Nothing. |
247 * @private | 240 * @private |
248 */ | 241 */ |
249 remoting.SessionConnector.prototype.connectMe2MeInternal_ = | 242 remoting.SessionConnectorImpl.prototype.connectMe2MeInternal_ = |
250 function(hostId, hostJid, hostPublicKey, hostDisplayName, | 243 function(hostId, hostJid, hostPublicKey, hostDisplayName, |
251 fetchPin, fetchThirdPartyToken, | 244 fetchPin, fetchThirdPartyToken, |
252 clientPairingId, clientPairedSecret, | 245 clientPairingId, clientPairedSecret, |
253 refreshHostJidIfOffline) { | 246 refreshHostJidIfOffline) { |
254 // Cancel any existing connect operation. | 247 // Cancel any existing connect operation. |
255 this.cancel(); | 248 this.cancel(); |
256 | 249 |
257 this.hostId_ = hostId; | 250 this.hostId_ = hostId; |
258 this.hostJid_ = hostJid; | 251 this.hostJid_ = hostJid; |
259 this.hostPublicKey_ = hostPublicKey; | 252 this.hostPublicKey_ = hostPublicKey; |
260 this.fetchPin_ = fetchPin; | 253 this.fetchPin_ = fetchPin; |
261 this.fetchThirdPartyToken_ = fetchThirdPartyToken; | 254 this.fetchThirdPartyToken_ = fetchThirdPartyToken; |
262 this.hostDisplayName_ = hostDisplayName; | 255 this.hostDisplayName_ = hostDisplayName; |
263 this.connectionMode_ = remoting.ClientSession.Mode.ME2ME; | 256 this.connectionMode_ = remoting.ClientSession.Mode.ME2ME; |
264 this.refreshHostJidIfOffline_ = refreshHostJidIfOffline; | 257 this.refreshHostJidIfOffline_ = refreshHostJidIfOffline; |
265 this.updatePairingInfo(clientPairingId, clientPairedSecret); | 258 this.updatePairingInfo(clientPairingId, clientPairedSecret); |
266 | 259 |
267 this.connectSignaling_(); | 260 this.connectSignaling_(); |
268 } | 261 } |
269 | 262 |
270 /** | 263 /** |
271 * Initiate an IT2Me connection. | 264 * Initiate an IT2Me connection. |
272 * | 265 * |
273 * @param {string} accessCode The access code as entered by the user. | 266 * @param {string} accessCode The access code as entered by the user. |
274 * @return {void} Nothing. | 267 * @return {void} Nothing. |
275 */ | 268 */ |
276 remoting.SessionConnector.prototype.connectIT2Me = function(accessCode) { | 269 remoting.SessionConnectorImpl.prototype.connectIT2Me = function(accessCode) { |
277 var kSupportIdLen = 7; | 270 var kSupportIdLen = 7; |
278 var kHostSecretLen = 5; | 271 var kHostSecretLen = 5; |
279 var kAccessCodeLen = kSupportIdLen + kHostSecretLen; | 272 var kAccessCodeLen = kSupportIdLen + kHostSecretLen; |
280 | 273 |
281 // Cancel any existing connect operation. | 274 // Cancel any existing connect operation. |
282 this.cancel(); | 275 this.cancel(); |
283 | 276 |
284 var normalizedAccessCode = this.normalizeAccessCode_(accessCode); | 277 var normalizedAccessCode = this.normalizeAccessCode_(accessCode); |
285 if (normalizedAccessCode.length != kAccessCodeLen) { | 278 if (normalizedAccessCode.length != kAccessCodeLen) { |
286 this.onError_(remoting.Error.INVALID_ACCESS_CODE); | 279 this.onError_(remoting.Error.INVALID_ACCESS_CODE); |
287 return; | 280 return; |
288 } | 281 } |
289 | 282 |
290 this.hostId_ = normalizedAccessCode.substring(0, kSupportIdLen); | 283 this.hostId_ = normalizedAccessCode.substring(0, kSupportIdLen); |
291 this.passPhrase_ = normalizedAccessCode; | 284 this.passPhrase_ = normalizedAccessCode; |
292 this.connectionMode_ = remoting.ClientSession.Mode.IT2ME; | 285 this.connectionMode_ = remoting.ClientSession.Mode.IT2ME; |
293 remoting.identity.callWithToken(this.connectIT2MeWithToken_.bind(this), | 286 remoting.identity.callWithToken(this.connectIT2MeWithToken_.bind(this), |
294 this.onError_); | 287 this.onError_); |
295 }; | 288 }; |
296 | 289 |
297 /** | 290 /** |
298 * Reconnect a closed connection. | 291 * Reconnect a closed connection. |
299 * | 292 * |
300 * @return {void} Nothing. | 293 * @return {void} Nothing. |
301 */ | 294 */ |
302 remoting.SessionConnector.prototype.reconnect = function() { | 295 remoting.SessionConnectorImpl.prototype.reconnect = function() { |
303 if (this.connectionMode_ == remoting.ClientSession.Mode.IT2ME) { | 296 if (this.connectionMode_ == remoting.ClientSession.Mode.IT2ME) { |
304 console.error('reconnect not supported for IT2Me.'); | 297 console.error('reconnect not supported for IT2Me.'); |
305 return; | 298 return; |
306 } | 299 } |
307 this.connectMe2MeInternal_( | 300 this.connectMe2MeInternal_( |
308 this.hostId_, this.hostJid_, this.hostPublicKey_, this.hostDisplayName_, | 301 this.hostId_, this.hostJid_, this.hostPublicKey_, this.hostDisplayName_, |
309 this.fetchPin_, this.fetchThirdPartyToken_, | 302 this.fetchPin_, this.fetchThirdPartyToken_, |
310 this.clientPairingId_, this.clientPairedSecret_, true); | 303 this.clientPairingId_, this.clientPairedSecret_, true); |
311 }; | 304 }; |
312 | 305 |
313 /** | 306 /** |
314 * Cancel a connection-in-progress. | 307 * Cancel a connection-in-progress. |
315 */ | 308 */ |
316 remoting.SessionConnector.prototype.cancel = function() { | 309 remoting.SessionConnectorImpl.prototype.cancel = function() { |
317 if (this.clientSession_) { | 310 if (this.clientSession_) { |
318 this.clientSession_.removePlugin(); | 311 this.clientSession_.removePlugin(); |
319 this.clientSession_ = null; | 312 this.clientSession_ = null; |
320 } | 313 } |
321 if (this.pendingXhr_) { | 314 if (this.pendingXhr_) { |
322 this.pendingXhr_.abort(); | 315 this.pendingXhr_.abort(); |
323 this.pendingXhr_ = null; | 316 this.pendingXhr_ = null; |
324 } | 317 } |
325 this.reset(); | 318 this.reset(); |
326 }; | 319 }; |
327 | 320 |
328 /** | 321 /** |
329 * Get the connection mode (Me2Me or IT2Me) | 322 * Get the connection mode (Me2Me or IT2Me) |
330 * | 323 * |
331 * @return {remoting.ClientSession.Mode} | 324 * @return {remoting.ClientSession.Mode} |
332 */ | 325 */ |
333 remoting.SessionConnector.prototype.getConnectionMode = function() { | 326 remoting.SessionConnectorImpl.prototype.getConnectionMode = function() { |
334 return this.connectionMode_; | 327 return this.connectionMode_; |
335 }; | 328 }; |
336 | 329 |
337 /** | 330 /** |
338 * Get host ID. | 331 * Get host ID. |
339 * | 332 * |
340 * @return {string} | 333 * @return {string} |
341 */ | 334 */ |
342 remoting.SessionConnector.prototype.getHostId = function() { | 335 remoting.SessionConnectorImpl.prototype.getHostId = function() { |
343 return this.hostId_; | 336 return this.hostId_; |
344 }; | 337 }; |
345 | 338 |
346 /** | 339 /** |
347 * @private | 340 * @private |
348 */ | 341 */ |
349 remoting.SessionConnector.prototype.connectSignaling_ = function() { | 342 remoting.SessionConnectorImpl.prototype.connectSignaling_ = function() { |
350 base.dispose(this.signalStrategy_); | 343 base.dispose(this.signalStrategy_); |
351 this.signalStrategy_ = null; | 344 this.signalStrategy_ = null; |
352 | 345 |
353 /** @type {remoting.SessionConnector} */ | 346 /** @type {remoting.SessionConnectorImpl} */ |
354 var that = this; | 347 var that = this; |
355 | 348 |
356 /** @param {string} token */ | 349 /** @param {string} token */ |
357 function connectSignalingWithToken(token) { | 350 function connectSignalingWithToken(token) { |
358 remoting.identity.getEmail( | 351 remoting.identity.getEmail( |
359 connectSignalingWithTokenAndEmail.bind(null, token), that.onError_); | 352 connectSignalingWithTokenAndEmail.bind(null, token), that.onError_); |
360 } | 353 } |
361 | 354 |
362 /** | 355 /** |
363 * @param {string} token | 356 * @param {string} token |
(...skipping 15 matching lines...) Expand all Loading... | |
379 (new remoting.WcsAdapter(this.onSignalingState_.bind(this))); | 372 (new remoting.WcsAdapter(this.onSignalingState_.bind(this))); |
380 } | 373 } |
381 | 374 |
382 remoting.identity.callWithToken(connectSignalingWithToken, this.onError_); | 375 remoting.identity.callWithToken(connectSignalingWithToken, this.onError_); |
383 }; | 376 }; |
384 | 377 |
385 /** | 378 /** |
386 * @private | 379 * @private |
387 * @param {remoting.SignalStrategy.State} state | 380 * @param {remoting.SignalStrategy.State} state |
388 */ | 381 */ |
389 remoting.SessionConnector.prototype.onSignalingState_ = function(state) { | 382 remoting.SessionConnectorImpl.prototype.onSignalingState_ = function(state) { |
390 switch (state) { | 383 switch (state) { |
391 case remoting.SignalStrategy.State.CONNECTED: | 384 case remoting.SignalStrategy.State.CONNECTED: |
392 // Proceed only if the connection hasn't been canceled. | 385 // Proceed only if the connection hasn't been canceled. |
393 if (this.hostJid_) { | 386 if (this.hostJid_) { |
394 this.createSession_(); | 387 this.createSession_(); |
395 } | 388 } |
396 break; | 389 break; |
397 | 390 |
398 case remoting.SignalStrategy.State.FAILED: | 391 case remoting.SignalStrategy.State.FAILED: |
399 this.onError_(this.signalStrategy_.getError()); | 392 this.onError_(this.signalStrategy_.getError()); |
400 break; | 393 break; |
401 } | 394 } |
402 }; | 395 }; |
403 | 396 |
404 /** | 397 /** |
405 * Continue an IT2Me connection once an access token has been obtained. | 398 * Continue an IT2Me connection once an access token has been obtained. |
406 * | 399 * |
407 * @param {string} token An OAuth2 access token. | 400 * @param {string} token An OAuth2 access token. |
408 * @return {void} Nothing. | 401 * @return {void} Nothing. |
409 * @private | 402 * @private |
410 */ | 403 */ |
411 remoting.SessionConnector.prototype.connectIT2MeWithToken_ = function(token) { | 404 remoting.SessionConnectorImpl.prototype.connectIT2MeWithToken_ = |
405 function(token) { | |
412 // Resolve the host id to get the host JID. | 406 // Resolve the host id to get the host JID. |
413 this.pendingXhr_ = remoting.xhr.get( | 407 this.pendingXhr_ = remoting.xhr.get( |
414 remoting.settings.DIRECTORY_API_BASE_URL + '/support-hosts/' + | 408 remoting.settings.DIRECTORY_API_BASE_URL + '/support-hosts/' + |
415 encodeURIComponent(this.hostId_), | 409 encodeURIComponent(this.hostId_), |
416 this.onIT2MeHostInfo_.bind(this), | 410 this.onIT2MeHostInfo_.bind(this), |
417 '', | 411 '', |
418 { 'Authorization': 'OAuth ' + token }); | 412 { 'Authorization': 'OAuth ' + token }); |
419 }; | 413 }; |
420 | 414 |
421 /** | 415 /** |
422 * Continue an IT2Me connection once the host JID has been looked up. | 416 * Continue an IT2Me connection once the host JID has been looked up. |
423 * | 417 * |
424 * @param {XMLHttpRequest} xhr The server response to the support-hosts query. | 418 * @param {XMLHttpRequest} xhr The server response to the support-hosts query. |
425 * @return {void} Nothing. | 419 * @return {void} Nothing. |
426 * @private | 420 * @private |
427 */ | 421 */ |
428 remoting.SessionConnector.prototype.onIT2MeHostInfo_ = function(xhr) { | 422 remoting.SessionConnectorImpl.prototype.onIT2MeHostInfo_ = function(xhr) { |
429 this.pendingXhr_ = null; | 423 this.pendingXhr_ = null; |
430 if (xhr.status == 200) { | 424 if (xhr.status == 200) { |
431 var host = /** @type {{data: {jabberId: string, publicKey: string}}} */ | 425 var host = /** @type {{data: {jabberId: string, publicKey: string}}} */ |
432 jsonParseSafe(xhr.responseText); | 426 jsonParseSafe(xhr.responseText); |
433 if (host && host.data && host.data.jabberId && host.data.publicKey) { | 427 if (host && host.data && host.data.jabberId && host.data.publicKey) { |
434 this.hostJid_ = host.data.jabberId; | 428 this.hostJid_ = host.data.jabberId; |
435 this.hostPublicKey_ = host.data.publicKey; | 429 this.hostPublicKey_ = host.data.publicKey; |
436 this.hostDisplayName_ = this.hostJid_.split('/')[0]; | 430 this.hostDisplayName_ = this.hostJid_.split('/')[0]; |
437 this.createSession_(); | 431 this.createSession_(); |
438 return; | 432 return; |
439 } else { | 433 } else { |
440 console.error('Invalid "support-hosts" response from server.'); | 434 console.error('Invalid "support-hosts" response from server.'); |
441 } | 435 } |
442 } else { | 436 } else { |
443 this.onError_(this.translateSupportHostsError(xhr.status)); | 437 this.onError_(this.translateSupportHostsError_(xhr.status)); |
444 } | 438 } |
445 }; | 439 }; |
446 | 440 |
447 /** | 441 /** |
448 * Creates ClientSession object. | 442 * Creates ClientSession object. |
449 */ | 443 */ |
450 remoting.SessionConnector.prototype.createSession_ = function() { | 444 remoting.SessionConnectorImpl.prototype.createSession_ = function() { |
451 // In some circumstances, the WCS <iframe> can get reloaded, which results | 445 // In some circumstances, the WCS <iframe> can get reloaded, which results |
452 // in a new clientJid and a new callback. In this case, remove the old | 446 // in a new clientJid and a new callback. In this case, remove the old |
453 // client plugin before instantiating a new one. | 447 // client plugin before instantiating a new one. |
454 if (this.clientSession_) { | 448 if (this.clientSession_) { |
455 this.clientSession_.removePlugin(); | 449 this.clientSession_.removePlugin(); |
456 this.clientSession_ = null; | 450 this.clientSession_ = null; |
457 } | 451 } |
458 | 452 |
459 var authenticationMethods = | 453 var authenticationMethods = |
460 'third_party,spake2_pair,spake2_hmac,spake2_plain'; | 454 'third_party,spake2_pair,spake2_hmac,spake2_plain'; |
(...skipping 12 matching lines...) Expand all Loading... | |
473 /** | 467 /** |
474 * Handle a change in the state of the client session prior to successful | 468 * Handle a change in the state of the client session prior to successful |
475 * connection (after connection, this class no longer handles state change | 469 * connection (after connection, this class no longer handles state change |
476 * events). Errors that occur while connecting either trigger a reconnect | 470 * events). Errors that occur while connecting either trigger a reconnect |
477 * or notify the onError handler. | 471 * or notify the onError handler. |
478 * | 472 * |
479 * @param {remoting.ClientSession.StateEvent} event | 473 * @param {remoting.ClientSession.StateEvent} event |
480 * @return {void} Nothing. | 474 * @return {void} Nothing. |
481 * @private | 475 * @private |
482 */ | 476 */ |
483 remoting.SessionConnector.prototype.onStateChange_ = function(event) { | 477 remoting.SessionConnectorImpl.prototype.onStateChange_ = function(event) { |
484 switch (event.current) { | 478 switch (event.current) { |
485 case remoting.ClientSession.State.CONNECTED: | 479 case remoting.ClientSession.State.CONNECTED: |
486 // When the connection succeeds, deregister for state-change callbacks | 480 // When the connection succeeds, deregister for state-change callbacks |
487 // and pass the session to the onConnected callback. It is expected that | 481 // and pass the session to the onConnected callback. It is expected that |
488 // it will register a new state-change callback to handle disconnect | 482 // it will register a new state-change callback to handle disconnect |
489 // or error conditions. | 483 // or error conditions. |
490 this.clientSession_.removeEventListener( | 484 this.clientSession_.removeEventListener( |
491 remoting.ClientSession.Events.stateChanged, | 485 remoting.ClientSession.Events.stateChanged, |
492 this.bound_.onStateChange); | 486 this.bound_.onStateChange); |
493 | 487 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 // sync, and even then the version check should ensure compatibility. | 537 // sync, and even then the version check should ensure compatibility. |
544 this.onError_(remoting.Error.MISSING_PLUGIN); | 538 this.onError_(remoting.Error.MISSING_PLUGIN); |
545 } | 539 } |
546 }; | 540 }; |
547 | 541 |
548 /** | 542 /** |
549 * @param {boolean} success True if the host list was successfully refreshed; | 543 * @param {boolean} success True if the host list was successfully refreshed; |
550 * false if an error occurred. | 544 * false if an error occurred. |
551 * @private | 545 * @private |
552 */ | 546 */ |
553 remoting.SessionConnector.prototype.onHostListRefresh_ = function(success) { | 547 remoting.SessionConnectorImpl.prototype.onHostListRefresh_ = function(success) { |
554 if (success) { | 548 if (success) { |
555 var host = remoting.hostList.getHostForId(this.hostId_); | 549 var host = remoting.hostList.getHostForId(this.hostId_); |
556 if (host) { | 550 if (host) { |
557 this.connectMe2MeInternal_( | 551 this.connectMe2MeInternal_( |
558 host.hostId, host.jabberId, host.publicKey, host.hostName, | 552 host.hostId, host.jabberId, host.publicKey, host.hostName, |
559 this.fetchPin_, this.fetchThirdPartyToken_, | 553 this.fetchPin_, this.fetchThirdPartyToken_, |
560 this.clientPairingId_, this.clientPairedSecret_, false); | 554 this.clientPairingId_, this.clientPairedSecret_, false); |
561 return; | 555 return; |
562 } | 556 } |
563 } | 557 } |
564 this.onError_(remoting.Error.HOST_IS_OFFLINE); | 558 this.onError_(remoting.Error.HOST_IS_OFFLINE); |
565 }; | 559 }; |
566 | 560 |
567 /** | 561 /** |
568 * @param {number} error An HTTP error code returned by the support-hosts | 562 * @param {number} error An HTTP error code returned by the support-hosts |
569 * endpoint. | 563 * endpoint. |
570 * @return {remoting.Error} The equivalent remoting.Error code. | 564 * @return {remoting.Error} The equivalent remoting.Error code. |
571 * @private | 565 * @private |
572 */ | 566 */ |
573 remoting.SessionConnector.prototype.translateSupportHostsError = | 567 remoting.SessionConnectorImpl.prototype.translateSupportHostsError_ = |
574 function(error) { | 568 function(error) { |
575 switch (error) { | 569 switch (error) { |
576 case 0: return remoting.Error.NETWORK_FAILURE; | 570 case 0: return remoting.Error.NETWORK_FAILURE; |
577 case 404: return remoting.Error.INVALID_ACCESS_CODE; | 571 case 404: return remoting.Error.INVALID_ACCESS_CODE; |
578 case 502: // No break | 572 case 502: // No break |
579 case 503: return remoting.Error.SERVICE_UNAVAILABLE; | 573 case 503: return remoting.Error.SERVICE_UNAVAILABLE; |
580 default: return remoting.Error.UNEXPECTED; | 574 default: return remoting.Error.UNEXPECTED; |
581 } | 575 } |
582 }; | 576 }; |
583 | 577 |
584 /** | 578 /** |
585 * Normalize the access code entered by the user. | 579 * Normalize the access code entered by the user. |
586 * | 580 * |
587 * @param {string} accessCode The access code, as entered by the user. | 581 * @param {string} accessCode The access code, as entered by the user. |
588 * @return {string} The normalized form of the code (whitespace removed). | 582 * @return {string} The normalized form of the code (whitespace removed). |
583 * @private | |
589 */ | 584 */ |
590 remoting.SessionConnector.prototype.normalizeAccessCode_ = | 585 remoting.SessionConnectorImpl.prototype.normalizeAccessCode_ = |
591 function(accessCode) { | 586 function(accessCode) { |
592 // Trim whitespace. | 587 // Trim whitespace. |
593 return accessCode.replace(/\s/g, ''); | 588 return accessCode.replace(/\s/g, ''); |
594 }; | 589 }; |
590 | |
591 | |
592 /** | |
593 * @constructor | |
594 * @implements {remoting.SessionConnectorFactory} | |
595 */ | |
596 remoting.DefaultSessionConnectorFactory = function() { | |
597 }; | |
598 | |
599 /** | |
600 * @param {HTMLElement} clientContainer Container element for the client view. | |
601 * @param {function(remoting.ClientSession):void} onConnected Callback on | |
602 * success. | |
603 * @param {function(remoting.Error):void} onError Callback on error. | |
604 * @param {function(string, string):boolean} onExtensionMessage The handler for | |
605 * protocol extension messages. Returns true if a message is recognized; | |
606 * false otherwise. | |
607 */ | |
608 remoting.DefaultSessionConnectorFactory.prototype.createConnector = | |
609 function(clientContainer, onConnected, onError, onExtensionMessage) { | |
610 return new remoting.SessionConnectorImpl( | |
611 clientContainer, onConnected, onError, onExtensionMessage); | |
612 }; | |
OLD | NEW |