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
3 // found in the LICENSE file.
7 * Class handling creation and teardown of a remoting host session.
9 * This abstracts a <embed> element and controls the plugin which does the
10 * actual remoting work. There should be no UI code inside this class. It
11 * should be purely thought of as a controller of sorts.
16 /** @suppress {duplicate} */
17 var remoting
= remoting
|| {};
21 * @implements {base.Disposable}
23 remoting
.HostSession = function() {
24 /** @type {remoting.It2MeHostFacade} @private */
25 this.hostFacade_
= null;
28 // Note that these values are copied directly from host_script_object.h and
29 // must be kept in sync.
31 remoting
.HostSession
.State
= {
35 REQUESTED_ACCESS_CODE
: 2,
36 RECEIVED_ACCESS_CODE
: 3,
40 INVALID_DOMAIN_ERROR
: 7
43 remoting
.HostSession
.prototype.dispose = function() {
44 base
.dispose(this.hostFacade_
);
45 this.hostFacade_
= null;
49 * @param {string} stateString The string representation of the host state.
50 * @return {remoting.HostSession.State} The HostSession.State enum value
51 * corresponding to stateString.
53 remoting
.HostSession
.State
.fromString = function(stateString
) {
54 if (!remoting
.HostSession
.State
.hasOwnProperty(stateString
)) {
55 console
.error('Unexpected HostSession.State string: ', stateString
);
56 return remoting
.HostSession
.State
.UNKNOWN
;
58 return remoting
.HostSession
.State
[stateString
];
62 * Initiates a connection.
63 * @param {remoting.It2MeHostFacade} hostFacade It2Me host facade to use.
64 * @param {string} email The user's email address.
65 * @param {string} accessToken A valid OAuth2 access token.
66 * @param {function(remoting.HostSession.State):void} onStateChanged
67 * Callback for notifications of changes to the host plugin's state.
68 * @param {function(boolean):void} onNatTraversalPolicyChanged Callback
69 * for notification of changes to the NAT traversal policy.
70 * @param {function(string):void} logDebugInfo Callback allowing the plugin
71 * to log messages to the debug log.
72 * @param {function():void} onError Callback to invoke in case of an error.
74 remoting
.HostSession
.prototype.connect
=
75 function(hostFacade
, email
, accessToken
, onStateChanged
,
76 onNatTraversalPolicyChanged
, logDebugInfo
, onError
) {
78 this.hostFacade_
= hostFacade
;
80 this.hostFacade_
.connect(email
, 'oauth2:' + accessToken
, onStateChanged
,
81 onNatTraversalPolicyChanged
, logDebugInfo
,
82 remoting
.settings
.XMPP_SERVER
,
83 remoting
.settings
.XMPP_SERVER_USE_TLS
,
84 remoting
.settings
.DIRECTORY_BOT_JID
, onError
);
88 * Get the access code generated by the it2me host. Valid only after the
89 * host state is RECEIVED_ACCESS_CODE.
90 * @return {string} The access code.
92 remoting
.HostSession
.prototype.getAccessCode = function() {
93 return this.hostFacade_
.getAccessCode();
97 * Get the lifetime for the access code. Valid only after the host state is
98 * RECEIVED_ACCESS_CODE.
99 * @return {number} The access code lifetime, in seconds.
101 remoting
.HostSession
.prototype.getAccessCodeLifetime = function() {
102 return this.hostFacade_
.getAccessCodeLifetime();
106 * Get the email address of the connected client. Valid only after the plugin
107 * state is CONNECTED.
108 * @return {string} The client's email address.
110 remoting
.HostSession
.prototype.getClient = function() {
111 return this.hostFacade_
.getClient();
115 * Disconnect the it2me session.
116 * @return {void} Nothing.
118 remoting
.HostSession
.prototype.disconnect = function() {
119 this.hostFacade_
.disconnect();