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, 52 insertions, 30 deletions
diff --git a/remoting/webapp/host_session.js b/remoting/webapp/host_session.js
index 72007a3..a2524ee 100644
--- a/remoting/webapp/host_session.js
+++ b/remoting/webapp/host_session.js
@@ -20,11 +20,10 @@ 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} */
@@ -41,6 +40,19 @@ 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.
*/
@@ -54,48 +66,59 @@ remoting.HostSession.createPlugin = function() {
};
/**
- * Create the host plugin and initiate a connection.
+ * Create the host dispatcher 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(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(boolean):void} onNatTraversalPolicyChanged Callback
+ * for notification of changes to the NAT traversal policy.
* @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.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);
+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);
};
/**
- * Get the access code generated by the host plugin. Valid only after the
- * plugin state is RECEIVED_ACCESS_CODE.
+ * Get the access code generated by the it2me host. Valid only after the
+ * host state is RECEIVED_ACCESS_CODE.
* @return {string} The access code.
*/
remoting.HostSession.prototype.getAccessCode = function() {
- return this.plugin.accessCode;
+ return this.hostDispatcher_.getAccessCode();
};
/**
- * Get the lifetime for the access code. Valid only after the plugin state is
+ * Get the lifetime for the access code. Valid only after the host state is
* RECEIVED_ACCESS_CODE.
* @return {number} The access code lifetime, in seconds.
*/
remoting.HostSession.prototype.getAccessCodeLifetime = function() {
- return this.plugin.accessCodeLifetime;
+ return this.hostDispatcher_.getAccessCodeLifetime();
};
/**
@@ -104,22 +127,21 @@ remoting.HostSession.prototype.getAccessCodeLifetime = function() {
* @return {string} The client's email address.
*/
remoting.HostSession.prototype.getClient = function() {
- return this.plugin.client;
+ return this.hostDispatcher_.getClient();
};
/**
- * Disconnect the client.
+ * Disconnect the it2me session.
* @return {void} Nothing.
*/
remoting.HostSession.prototype.disconnect = function() {
- this.plugin.disconnect();
+ this.hostDispatcher_.disconnect();
};
/**
- * Remove the plugin element from the document.
* @return {void} Nothing.
*/
-remoting.HostSession.prototype.removePlugin = function() {
- this.plugin.parentNode.removeChild(this.plugin);
+remoting.HostSession.prototype.cleanup = function() {
+ this.hostDispatcher_.cleanup();
};