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 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Class handling creation and teardown of a remoting client session. | 7 * Class handling creation and teardown of a remoting client session. |
8 * | 8 * |
9 * The ClientSession class controls lifetime of the client plugin | 9 * The ClientSession class controls lifetime of the client plugin |
10 * object and provides the plugin with the functionality it needs to | 10 * object and provides the plugin with the functionality it needs to |
(...skipping 14 matching lines...) Expand all Loading... |
25 /** | 25 /** |
26 * Interval that determines how often the web-app should send a new access token | 26 * Interval that determines how often the web-app should send a new access token |
27 * to the host. | 27 * to the host. |
28 * | 28 * |
29 * @const | 29 * @const |
30 * @type {number} | 30 * @type {number} |
31 */ | 31 */ |
32 remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS = 15 * 60 * 1000; | 32 remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS = 15 * 60 * 1000; |
33 | 33 |
34 /** | 34 /** |
| 35 * @param {remoting.Host} host The host to connect to. |
35 * @param {remoting.SignalStrategy} signalStrategy Signal strategy. | 36 * @param {remoting.SignalStrategy} signalStrategy Signal strategy. |
36 * @param {HTMLElement} container Container element for the client view. | 37 * @param {HTMLElement} container Container element for the client view. |
37 * @param {string} hostDisplayName A human-readable name for the host. | |
38 * @param {string} accessCode The IT2Me access code. Blank for Me2Me. | 38 * @param {string} accessCode The IT2Me access code. Blank for Me2Me. |
39 * @param {function(boolean, function(string): void): void} fetchPin | 39 * @param {function(boolean, function(string): void): void} fetchPin |
40 * Called by Me2Me connections when a PIN needs to be obtained | 40 * Called by Me2Me connections when a PIN needs to be obtained |
41 * interactively. | 41 * interactively. |
42 * @param {function(string, string, string, | 42 * @param {function(string, string, string, |
43 * function(string, string): void): void} | 43 * function(string, string): void): void} |
44 * fetchThirdPartyToken Called by Me2Me connections when a third party | 44 * fetchThirdPartyToken Called by Me2Me connections when a third party |
45 * authentication token must be obtained. | 45 * authentication token must be obtained. |
46 * @param {string} authenticationMethods Comma-separated list of | 46 * @param {string} authenticationMethods Comma-separated list of |
47 * authentication methods the client should attempt to use. | 47 * authentication methods the client should attempt to use. |
48 * @param {string} hostId The host identifier for Me2Me, or empty for IT2Me. | |
49 * Mixed into authentication hashes for some authentication methods. | |
50 * @param {string} hostJid The jid of the host to connect to. | |
51 * @param {string} hostPublicKey The base64 encoded version of the host's | |
52 * public key. | |
53 * @param {remoting.DesktopConnectedView.Mode} mode The mode of this connection. | 48 * @param {remoting.DesktopConnectedView.Mode} mode The mode of this connection. |
54 * @param {string} clientPairingId For paired Me2Me connections, the | 49 * @param {string} clientPairingId For paired Me2Me connections, the |
55 * pairing id for this client, as issued by the host. | 50 * pairing id for this client, as issued by the host. |
56 * @param {string} clientPairedSecret For paired Me2Me connections, the | 51 * @param {string} clientPairedSecret For paired Me2Me connections, the |
57 * paired secret for this client, as issued by the host. | 52 * paired secret for this client, as issued by the host. |
58 * @param {string} defaultRemapKeys The default set of remap keys, to use | 53 * @param {string} defaultRemapKeys The default set of remap keys, to use |
59 * when the client doesn't define any. | 54 * when the client doesn't define any. |
60 * @constructor | 55 * @constructor |
61 * @extends {base.EventSourceImpl} | 56 * @extends {base.EventSourceImpl} |
62 */ | 57 */ |
63 remoting.ClientSession = function(signalStrategy, container, hostDisplayName, | 58 remoting.ClientSession = function(host, signalStrategy, container, accessCode, |
64 accessCode, fetchPin, fetchThirdPartyToken, | 59 fetchPin, fetchThirdPartyToken, |
65 authenticationMethods, hostId, hostJid, | 60 authenticationMethods, mode, clientPairingId, |
66 hostPublicKey, mode, clientPairingId, | |
67 clientPairedSecret, defaultRemapKeys) { | 61 clientPairedSecret, defaultRemapKeys) { |
68 /** @private */ | 62 /** @private */ |
69 this.state_ = remoting.ClientSession.State.CREATED; | 63 this.state_ = remoting.ClientSession.State.CREATED; |
70 | 64 |
71 /** @private */ | 65 /** @private */ |
72 this.error_ = remoting.Error.NONE; | 66 this.error_ = remoting.Error.NONE; |
73 | 67 |
74 /** @private */ | 68 /** @private */ |
75 this.hostJid_ = hostJid; | 69 this.host_ = host; |
76 /** @private */ | |
77 this.hostPublicKey_ = hostPublicKey; | |
78 /** @private */ | 70 /** @private */ |
79 this.accessCode_ = accessCode; | 71 this.accessCode_ = accessCode; |
80 /** @private */ | 72 /** @private */ |
81 this.fetchPin_ = fetchPin; | 73 this.fetchPin_ = fetchPin; |
82 /** @private */ | 74 /** @private */ |
83 this.fetchThirdPartyToken_ = fetchThirdPartyToken; | 75 this.fetchThirdPartyToken_ = fetchThirdPartyToken; |
84 /** @private */ | 76 /** @private */ |
85 this.authenticationMethods_ = authenticationMethods; | 77 this.authenticationMethods_ = authenticationMethods; |
86 /** @private */ | 78 /** @private */ |
87 this.hostId_ = hostId; | |
88 /** @private */ | |
89 this.clientPairingId_ = clientPairingId; | 79 this.clientPairingId_ = clientPairingId; |
90 /** @private */ | 80 /** @private */ |
91 this.clientPairedSecret_ = clientPairedSecret; | 81 this.clientPairedSecret_ = clientPairedSecret; |
92 | 82 |
93 /** @private */ | 83 /** @private */ |
94 this.uiHandler_ = new remoting.DesktopConnectedView( | 84 this.uiHandler_ = new remoting.DesktopConnectedView( |
95 this, container, hostDisplayName, hostId, mode, defaultRemapKeys, | 85 this, container, this.host_, mode, defaultRemapKeys, |
96 this.onPluginInitialized_.bind(this)); | 86 this.onPluginInitialized_.bind(this)); |
97 remoting.desktopConnectedView = this.uiHandler_; | 87 remoting.desktopConnectedView = this.uiHandler_; |
98 | 88 |
99 /** @private */ | 89 /** @private */ |
100 this.sessionId_ = ''; | 90 this.sessionId_ = ''; |
101 /** @type {remoting.ClientPlugin} | 91 /** @type {remoting.ClientPlugin} |
102 * @private */ | 92 * @private */ |
103 this.plugin_ = null; | 93 this.plugin_ = null; |
104 /** @private */ | 94 /** @private */ |
105 this.hasReceivedFrame_ = false; | 95 this.hasReceivedFrame_ = false; |
106 this.logToServer = new remoting.LogToServer(signalStrategy, mode); | 96 this.logToServer = new remoting.LogToServer(signalStrategy, mode); |
107 | 97 |
108 /** @private */ | 98 /** @private */ |
109 this.signalStrategy_ = signalStrategy; | 99 this.signalStrategy_ = signalStrategy; |
110 base.debug.assert(this.signalStrategy_.getState() == | 100 base.debug.assert(this.signalStrategy_.getState() == |
111 remoting.SignalStrategy.State.CONNECTED); | 101 remoting.SignalStrategy.State.CONNECTED); |
112 this.signalStrategy_.setIncomingStanzaCallback( | 102 this.signalStrategy_.setIncomingStanzaCallback( |
113 this.onIncomingMessage_.bind(this)); | 103 this.onIncomingMessage_.bind(this)); |
114 remoting.formatIq.setJids(this.signalStrategy_.getJid(), hostJid); | 104 remoting.formatIq.setJids(this.signalStrategy_.getJid(), host.jabberId); |
115 | 105 |
116 /** | 106 /** |
117 * Allow host-offline error reporting to be suppressed in situations where it | 107 * Allow host-offline error reporting to be suppressed in situations where it |
118 * would not be useful, for example, when using a cached host JID. | 108 * would not be useful, for example, when using a cached host JID. |
119 * | 109 * |
120 * @type {boolean} @private | 110 * @type {boolean} @private |
121 */ | 111 */ |
122 this.logHostOfflineErrors_ = true; | 112 this.logHostOfflineErrors_ = true; |
123 | 113 |
124 /** @type {remoting.GnubbyAuthHandler} @private */ | 114 /** @type {remoting.GnubbyAuthHandler} @private */ |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 }; | 355 }; |
366 | 356 |
367 /** | 357 /** |
368 * Deletes the <embed> element from the container and disconnects. | 358 * Deletes the <embed> element from the container and disconnects. |
369 * | 359 * |
370 * @return {void} Nothing. | 360 * @return {void} Nothing. |
371 */ | 361 */ |
372 remoting.ClientSession.prototype.cleanup = function() { | 362 remoting.ClientSession.prototype.cleanup = function() { |
373 this.sendIq_( | 363 this.sendIq_( |
374 '<cli:iq ' + | 364 '<cli:iq ' + |
375 'to="' + this.hostJid_ + '" ' + | 365 'to="' + this.host_.jabberId + '" ' + |
376 'type="set" ' + | 366 'type="set" ' + |
377 'id="session-terminate" ' + | 367 'id="session-terminate" ' + |
378 'xmlns:cli="jabber:client">' + | 368 'xmlns:cli="jabber:client">' + |
379 '<jingle ' + | 369 '<jingle ' + |
380 'xmlns="urn:xmpp:jingle:1" ' + | 370 'xmlns="urn:xmpp:jingle:1" ' + |
381 'action="session-terminate" ' + | 371 'action="session-terminate" ' + |
382 'sid="' + this.sessionId_ + '">' + | 372 'sid="' + this.sessionId_ + '">' + |
383 '<reason><success/></reason>' + | 373 '<reason><success/></reason>' + |
384 '</jingle>' + | 374 '</jingle>' + |
385 '</cli:iq>'); | 375 '</cli:iq>'); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 * @private | 448 * @private |
459 */ | 449 */ |
460 remoting.ClientSession.prototype.onIncomingMessage_ = function(message) { | 450 remoting.ClientSession.prototype.onIncomingMessage_ = function(message) { |
461 if (!this.plugin_) { | 451 if (!this.plugin_) { |
462 return; | 452 return; |
463 } | 453 } |
464 var formatted = new XMLSerializer().serializeToString(message); | 454 var formatted = new XMLSerializer().serializeToString(message); |
465 console.log(remoting.timestamp(), | 455 console.log(remoting.timestamp(), |
466 remoting.formatIq.prettifyReceiveIq(formatted)); | 456 remoting.formatIq.prettifyReceiveIq(formatted)); |
467 this.plugin_.onIncomingIq(formatted); | 457 this.plugin_.onIncomingIq(formatted); |
468 } | 458 }; |
469 | 459 |
470 /** | 460 /** |
471 * @private | 461 * @private |
472 */ | 462 */ |
473 remoting.ClientSession.prototype.initiateConnection_ = function() { | 463 remoting.ClientSession.prototype.initiateConnection_ = function() { |
474 /** @type {remoting.ClientSession} */ | 464 /** @type {remoting.ClientSession} */ |
475 var that = this; | 465 var that = this; |
476 | 466 |
477 /** @param {string} sharedSecret Shared secret. */ | 467 /** @param {string} sharedSecret Shared secret. */ |
478 function onSharedSecretReceived(sharedSecret) { | 468 function onSharedSecretReceived(sharedSecret) { |
479 that.plugin_.connect( | 469 that.plugin_.connect(that.host_.jabberId, that.host_.publicKey, |
480 that.hostJid_, that.hostPublicKey_, that.signalStrategy_.getJid(), | 470 that.signalStrategy_.getJid(), sharedSecret, |
481 sharedSecret, that.authenticationMethods_, that.hostId_, | 471 that.authenticationMethods_, that.host_.hostId, |
482 that.clientPairingId_, that.clientPairedSecret_); | 472 that.clientPairingId_, that.clientPairedSecret_); |
483 }; | 473 } |
484 | 474 |
485 this.getSharedSecret_(onSharedSecretReceived); | 475 this.getSharedSecret_(onSharedSecretReceived); |
486 } | 476 }; |
487 | 477 |
488 /** | 478 /** |
489 * Gets shared secret to be used for connection. | 479 * Gets shared secret to be used for connection. |
490 * | 480 * |
491 * @param {function(string)} callback Callback called with the shared secret. | 481 * @param {function(string)} callback Callback called with the shared secret. |
492 * @return {void} Nothing. | 482 * @return {void} Nothing. |
493 * @private | 483 * @private |
494 */ | 484 */ |
495 remoting.ClientSession.prototype.getSharedSecret_ = function(callback) { | 485 remoting.ClientSession.prototype.getSharedSecret_ = function(callback) { |
496 /** @type remoting.ClientSession */ | 486 /** @type remoting.ClientSession */ |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 } | 586 } |
597 | 587 |
598 this.uiHandler_.onConnectionReady(ready); | 588 this.uiHandler_.onConnectionReady(ready); |
599 | 589 |
600 this.raiseEvent(remoting.ClientSession.Events.videoChannelStateChanged, | 590 this.raiseEvent(remoting.ClientSession.Events.videoChannelStateChanged, |
601 ready); | 591 ready); |
602 }; | 592 }; |
603 | 593 |
604 /** | 594 /** |
605 * Called when the client-host capabilities negotiation is complete. | 595 * Called when the client-host capabilities negotiation is complete. |
| 596 * TODO(kelvinp): Move this function out of ClientSession. |
606 * | 597 * |
607 * @param {!Array<string>} capabilities The set of capabilities negotiated | 598 * @param {!Array<string>} capabilities The set of capabilities negotiated |
608 * between the client and host. | 599 * between the client and host. |
609 * @return {void} Nothing. | 600 * @return {void} Nothing. |
610 * @private | 601 * @private |
611 */ | 602 */ |
612 remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) { | 603 remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) { |
613 if (this.capabilities_ != null) { | 604 if (this.capabilities_ != null) { |
614 console.error('onSetCapabilities_() is called more than once'); | 605 console.error('onSetCapabilities_() is called more than once'); |
615 return; | 606 return; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 * @param {Object} message The parsed extension message data. | 831 * @param {Object} message The parsed extension message data. |
841 * @return {boolean} True if the message was recognized, false otherwise. | 832 * @return {boolean} True if the message was recognized, false otherwise. |
842 */ | 833 */ |
843 remoting.ClientSession.prototype.handleExtensionMessage = | 834 remoting.ClientSession.prototype.handleExtensionMessage = |
844 function(type, message) { | 835 function(type, message) { |
845 if (this.uiHandler_.handleExtensionMessage(type, message)) { | 836 if (this.uiHandler_.handleExtensionMessage(type, message)) { |
846 return true; | 837 return true; |
847 } | 838 } |
848 return false; | 839 return false; |
849 }; | 840 }; |
OLD | NEW |