Index: remoting/webapp/session_connector_impl.js |
diff --git a/remoting/webapp/session_connector.js b/remoting/webapp/session_connector_impl.js |
similarity index 87% |
copy from remoting/webapp/session_connector.js |
copy to remoting/webapp/session_connector_impl.js |
index 04fe425e21634d38e4dd7579a1ed8f8d9f8c30f5..b571be050f1920f95038f41d25a6ec047fd39e2c 100644 |
--- a/remoting/webapp/session_connector.js |
+++ b/remoting/webapp/session_connector_impl.js |
@@ -21,8 +21,9 @@ var remoting = remoting || {}; |
* protocol extension messages. Returns true if a message is recognized; |
* false otherwise. |
* @constructor |
+ * @implements {remoting.SessionConnector} |
*/ |
-remoting.SessionConnector = function(clientContainer, onConnected, onError, |
+remoting.SessionConnectorImpl = function(clientContainer, onConnected, onError, |
onExtensionMessage) { |
/** |
* @type {HTMLElement} |
@@ -87,15 +88,7 @@ remoting.SessionConnector = function(clientContainer, onConnected, onError, |
* Reset the per-connection state so that the object can be re-used for a |
* second connection. Note the none of the shared WCS state is reset. |
*/ |
-remoting.SessionConnector.prototype.reset = function() { |
- /** |
- * Set to true to indicate that the user requested pairing when entering |
- * their PIN for a Me2Me connection. |
- * |
- * @type {boolean} |
- */ |
- this.pairingRequested = false; |
- |
+remoting.SessionConnectorImpl.prototype.reset = function() { |
/** |
* String used to identify the host to which to connect. For IT2Me, this is |
* the first 7 digits of the access code; for Me2Me it is the host identifier. |
@@ -203,7 +196,7 @@ remoting.SessionConnector.prototype.reset = function() { |
* this device was paired, if it is already paired. |
* @return {void} Nothing. |
*/ |
-remoting.SessionConnector.prototype.connectMe2Me = |
+remoting.SessionConnectorImpl.prototype.connectMe2Me = |
function(host, fetchPin, fetchThirdPartyToken, |
clientPairingId, clientPairedSecret) { |
this.connectMe2MeInternal_( |
@@ -218,7 +211,7 @@ remoting.SessionConnector.prototype.connectMe2Me = |
* @param {string} clientId The paired client id. |
* @param {string} sharedSecret The shared secret. |
*/ |
-remoting.SessionConnector.prototype.updatePairingInfo = |
+remoting.SessionConnectorImpl.prototype.updatePairingInfo = |
function(clientId, sharedSecret) { |
this.clientPairingId_ = clientId; |
this.clientPairedSecret_ = sharedSecret; |
@@ -246,7 +239,7 @@ remoting.SessionConnector.prototype.updatePairingInfo = |
* @return {void} Nothing. |
* @private |
*/ |
-remoting.SessionConnector.prototype.connectMe2MeInternal_ = |
+remoting.SessionConnectorImpl.prototype.connectMe2MeInternal_ = |
function(hostId, hostJid, hostPublicKey, hostDisplayName, |
fetchPin, fetchThirdPartyToken, |
clientPairingId, clientPairedSecret, |
@@ -273,7 +266,7 @@ remoting.SessionConnector.prototype.connectMe2MeInternal_ = |
* @param {string} accessCode The access code as entered by the user. |
* @return {void} Nothing. |
*/ |
-remoting.SessionConnector.prototype.connectIT2Me = function(accessCode) { |
+remoting.SessionConnectorImpl.prototype.connectIT2Me = function(accessCode) { |
var kSupportIdLen = 7; |
var kHostSecretLen = 5; |
var kAccessCodeLen = kSupportIdLen + kHostSecretLen; |
@@ -299,7 +292,7 @@ remoting.SessionConnector.prototype.connectIT2Me = function(accessCode) { |
* |
* @return {void} Nothing. |
*/ |
-remoting.SessionConnector.prototype.reconnect = function() { |
+remoting.SessionConnectorImpl.prototype.reconnect = function() { |
if (this.connectionMode_ == remoting.ClientSession.Mode.IT2ME) { |
console.error('reconnect not supported for IT2Me.'); |
return; |
@@ -313,7 +306,7 @@ remoting.SessionConnector.prototype.reconnect = function() { |
/** |
* Cancel a connection-in-progress. |
*/ |
-remoting.SessionConnector.prototype.cancel = function() { |
+remoting.SessionConnectorImpl.prototype.cancel = function() { |
if (this.clientSession_) { |
this.clientSession_.removePlugin(); |
this.clientSession_ = null; |
@@ -330,7 +323,7 @@ remoting.SessionConnector.prototype.cancel = function() { |
* |
* @return {remoting.ClientSession.Mode} |
*/ |
-remoting.SessionConnector.prototype.getConnectionMode = function() { |
+remoting.SessionConnectorImpl.prototype.getConnectionMode = function() { |
return this.connectionMode_; |
}; |
@@ -339,18 +332,18 @@ remoting.SessionConnector.prototype.getConnectionMode = function() { |
* |
* @return {string} |
*/ |
-remoting.SessionConnector.prototype.getHostId = function() { |
+remoting.SessionConnectorImpl.prototype.getHostId = function() { |
return this.hostId_; |
}; |
/** |
* @private |
*/ |
-remoting.SessionConnector.prototype.connectSignaling_ = function() { |
+remoting.SessionConnectorImpl.prototype.connectSignaling_ = function() { |
base.dispose(this.signalStrategy_); |
this.signalStrategy_ = null; |
- /** @type {remoting.SessionConnector} */ |
+ /** @type {remoting.SessionConnectorImpl} */ |
var that = this; |
/** @param {string} token */ |
@@ -386,7 +379,7 @@ remoting.SessionConnector.prototype.connectSignaling_ = function() { |
* @private |
* @param {remoting.SignalStrategy.State} state |
*/ |
-remoting.SessionConnector.prototype.onSignalingState_ = function(state) { |
+remoting.SessionConnectorImpl.prototype.onSignalingState_ = function(state) { |
switch (state) { |
case remoting.SignalStrategy.State.CONNECTED: |
// Proceed only if the connection hasn't been canceled. |
@@ -408,7 +401,8 @@ remoting.SessionConnector.prototype.onSignalingState_ = function(state) { |
* @return {void} Nothing. |
* @private |
*/ |
-remoting.SessionConnector.prototype.connectIT2MeWithToken_ = function(token) { |
+remoting.SessionConnectorImpl.prototype.connectIT2MeWithToken_ = |
+ function(token) { |
// Resolve the host id to get the host JID. |
this.pendingXhr_ = remoting.xhr.get( |
remoting.settings.DIRECTORY_API_BASE_URL + '/support-hosts/' + |
@@ -425,7 +419,7 @@ remoting.SessionConnector.prototype.connectIT2MeWithToken_ = function(token) { |
* @return {void} Nothing. |
* @private |
*/ |
-remoting.SessionConnector.prototype.onIT2MeHostInfo_ = function(xhr) { |
+remoting.SessionConnectorImpl.prototype.onIT2MeHostInfo_ = function(xhr) { |
this.pendingXhr_ = null; |
if (xhr.status == 200) { |
var host = /** @type {{data: {jabberId: string, publicKey: string}}} */ |
@@ -440,14 +434,14 @@ remoting.SessionConnector.prototype.onIT2MeHostInfo_ = function(xhr) { |
console.error('Invalid "support-hosts" response from server.'); |
} |
} else { |
- this.onError_(this.translateSupportHostsError(xhr.status)); |
+ this.onError_(this.translateSupportHostsError_(xhr.status)); |
} |
}; |
/** |
* Creates ClientSession object. |
*/ |
-remoting.SessionConnector.prototype.createSession_ = function() { |
+remoting.SessionConnectorImpl.prototype.createSession_ = function() { |
// In some circumstances, the WCS <iframe> can get reloaded, which results |
// in a new clientJid and a new callback. In this case, remove the old |
// client plugin before instantiating a new one. |
@@ -480,7 +474,7 @@ remoting.SessionConnector.prototype.createSession_ = function() { |
* @return {void} Nothing. |
* @private |
*/ |
-remoting.SessionConnector.prototype.onStateChange_ = function(event) { |
+remoting.SessionConnectorImpl.prototype.onStateChange_ = function(event) { |
switch (event.current) { |
case remoting.ClientSession.State.CONNECTED: |
// When the connection succeeds, deregister for state-change callbacks |
@@ -550,7 +544,7 @@ remoting.SessionConnector.prototype.onStateChange_ = function(event) { |
* false if an error occurred. |
* @private |
*/ |
-remoting.SessionConnector.prototype.onHostListRefresh_ = function(success) { |
+remoting.SessionConnectorImpl.prototype.onHostListRefresh_ = function(success) { |
if (success) { |
var host = remoting.hostList.getHostForId(this.hostId_); |
if (host) { |
@@ -570,7 +564,7 @@ remoting.SessionConnector.prototype.onHostListRefresh_ = function(success) { |
* @return {remoting.Error} The equivalent remoting.Error code. |
* @private |
*/ |
-remoting.SessionConnector.prototype.translateSupportHostsError = |
+remoting.SessionConnectorImpl.prototype.translateSupportHostsError_ = |
function(error) { |
switch (error) { |
case 0: return remoting.Error.NETWORK_FAILURE; |
@@ -586,9 +580,33 @@ remoting.SessionConnector.prototype.translateSupportHostsError = |
* |
* @param {string} accessCode The access code, as entered by the user. |
* @return {string} The normalized form of the code (whitespace removed). |
+ * @private |
*/ |
-remoting.SessionConnector.prototype.normalizeAccessCode_ = |
+remoting.SessionConnectorImpl.prototype.normalizeAccessCode_ = |
function(accessCode) { |
// Trim whitespace. |
return accessCode.replace(/\s/g, ''); |
}; |
+ |
+ |
+/** |
+ * @constructor |
+ * @implements {remoting.SessionConnectorFactory} |
+ */ |
+remoting.DefaultSessionConnectorFactory = function() { |
+}; |
+ |
+/** |
+ * @param {HTMLElement} clientContainer Container element for the client view. |
+ * @param {function(remoting.ClientSession):void} onConnected Callback on |
+ * success. |
+ * @param {function(remoting.Error):void} onError Callback on error. |
+ * @param {function(string, string):boolean} onExtensionMessage The handler for |
+ * protocol extension messages. Returns true if a message is recognized; |
+ * false otherwise. |
+ */ |
+remoting.DefaultSessionConnectorFactory.prototype.createConnector = |
+ function(clientContainer, onConnected, onError, onExtensionMessage) { |
+ return new remoting.SessionConnectorImpl( |
+ clientContainer, onConnected, onError, onExtensionMessage); |
+}; |