summaryrefslogtreecommitdiffstats
path: root/remoting/webapp/host_session.js
diff options
context:
space:
mode:
Diffstat (limited to 'remoting/webapp/host_session.js')
-rw-r--r--remoting/webapp/host_session.js82
1 files changed, 30 insertions, 52 deletions
diff --git a/remoting/webapp/host_session.js b/remoting/webapp/host_session.js
index a2524ee..72007a3 100644
--- a/remoting/webapp/host_session.js
+++ b/remoting/webapp/host_session.js
@@ -20,10 +20,11 @@ var remoting = remoting || {};
* @constructor
*/
remoting.HostSession = function() {
- /** @type {remoting.HostIt2MeDispatcher} @private */
- this.hostDispatcher_ = null;
};
+/** @type {remoting.HostPlugin} */
+remoting.HostSession.prototype.plugin = null;
+
// Note that these values are copied directly from host_script_object.h and
// must be kept in sync.
/** @enum {number} */
@@ -40,19 +41,6 @@ remoting.HostSession.State = {
};
/**
- * @param {string} stateString The string representation of the host state.
- * @return {remoting.HostSession.State} The HostSession.State enum value
- * corresponding to stateString.
- */
-remoting.HostSession.stateFromString = function(stateString) {
- if (!remoting.HostSession.State.hasOwnProperty(stateString)) {
- console.error('NativeMessaging: unexpected state string: ', stateString);
- return remoting.HostSession.State.UNKNOWN;
- }
- return remoting.HostSession.State[stateString];
-}
-
-/**
* Create an instance of the host plugin.
* @return {remoting.HostPlugin} The new plugin instance.
*/
@@ -66,59 +54,48 @@ remoting.HostSession.createPlugin = function() {
};
/**
- * Create the host dispatcher and initiate a connection.
+ * Create the host plugin and initiate a connection.
* @param {Element} container The parent element to which to add the plugin.
* @param {string} email The user's email address.
* @param {string} accessToken A valid OAuth2 access token.
- * @param {function(remoting.HostSession.State):void} onStateChanged
- * Callback for notifications of changes to the host plugin's state.
* @param {function(boolean):void} onNatTraversalPolicyChanged Callback
* for notification of changes to the NAT traversal policy.
+ * @param {function(remoting.HostSession.State):void} onStateChanged
+ * Callback for notifications of changes to the host plugin's state.
* @param {function(string):void} logDebugInfo Callback allowing the plugin
* to log messages to the debug log.
- * @param {function():void} onError Callback to invoke if neither the native
- * messaging host nor the npapi plugin works.
- * @return {void} Nothing.
*/
-remoting.HostSession.prototype.createDispatcherAndConnect =
- function(container, email, accessToken, onStateChanged,
- onNatTraversalPolicyChanged, logDebugInfo, onError) {
- /** @type {remoting.HostIt2MeDispatcher} @private */
- this.hostDispatcher_ = new remoting.HostIt2MeDispatcher();
-
- /** @return {remoting.HostPlugin} */
- var createPluginForIt2Me = function() {
- var plugin = remoting.HostSession.createPlugin();
- container.appendChild(plugin);
- return plugin;
- };
-
- this.hostDispatcher_.initAndConnect(
- createPluginForIt2Me,
- email, 'oauth2:' + accessToken,
- onStateChanged, onNatTraversalPolicyChanged,
- remoting.settings.XMPP_SERVER_ADDRESS,
- remoting.settings.XMPP_SERVER_USE_TLS,
- remoting.settings.DIRECTORY_BOT_JID,
- onError);
+remoting.HostSession.prototype.createPluginAndConnect =
+ function(container, email, accessToken,
+ onNatTraversalPolicyChanged, onStateChanged, logDebugInfo) {
+ this.plugin = remoting.HostSession.createPlugin();
+ container.appendChild(this.plugin);
+ this.plugin.onNatTraversalPolicyChanged = onNatTraversalPolicyChanged;
+ this.plugin.onStateChanged = onStateChanged;
+ this.plugin.logDebugInfo = logDebugInfo;
+ this.plugin.localize(chrome.i18n.getMessage);
+ this.plugin.xmppServerAddress = remoting.settings.XMPP_SERVER_ADDRESS;
+ this.plugin.xmppServerUseTls = remoting.settings.XMPP_SERVER_USE_TLS;
+ this.plugin.directoryBotJid = remoting.settings.DIRECTORY_BOT_JID;
+ this.plugin.connect(email, 'oauth2:' + accessToken);
};
/**
- * Get the access code generated by the it2me host. Valid only after the
- * host state is RECEIVED_ACCESS_CODE.
+ * Get the access code generated by the host plugin. Valid only after the
+ * plugin state is RECEIVED_ACCESS_CODE.
* @return {string} The access code.
*/
remoting.HostSession.prototype.getAccessCode = function() {
- return this.hostDispatcher_.getAccessCode();
+ return this.plugin.accessCode;
};
/**
- * Get the lifetime for the access code. Valid only after the host state is
+ * Get the lifetime for the access code. Valid only after the plugin state is
* RECEIVED_ACCESS_CODE.
* @return {number} The access code lifetime, in seconds.
*/
remoting.HostSession.prototype.getAccessCodeLifetime = function() {
- return this.hostDispatcher_.getAccessCodeLifetime();
+ return this.plugin.accessCodeLifetime;
};
/**
@@ -127,21 +104,22 @@ remoting.HostSession.prototype.getAccessCodeLifetime = function() {
* @return {string} The client's email address.
*/
remoting.HostSession.prototype.getClient = function() {
- return this.hostDispatcher_.getClient();
+ return this.plugin.client;
};
/**
- * Disconnect the it2me session.
+ * Disconnect the client.
* @return {void} Nothing.
*/
remoting.HostSession.prototype.disconnect = function() {
- this.hostDispatcher_.disconnect();
+ this.plugin.disconnect();
};
/**
+ * Remove the plugin element from the document.
* @return {void} Nothing.
*/
-remoting.HostSession.prototype.cleanup = function() {
- this.hostDispatcher_.cleanup();
+remoting.HostSession.prototype.removePlugin = function() {
+ this.plugin.parentNode.removeChild(this.plugin);
};