| Index: remoting/webapp/crd/js/host_controller.js
|
| diff --git a/remoting/webapp/crd/js/host_controller.js b/remoting/webapp/crd/js/host_controller.js
|
| index a3ae6e6640545606d13f934a7a98c5f6fbd919a1..9ef8278a6118fb51de01bbaae770e15a5067cac2 100644
|
| --- a/remoting/webapp/crd/js/host_controller.js
|
| +++ b/remoting/webapp/crd/js/host_controller.js
|
| @@ -163,13 +163,8 @@ remoting.HostController.prototype.start = function(hostPin, consent) {
|
| return null;
|
| }
|
| });
|
| - var newHostId = base.generateUuid();
|
| - var pinHashPromise = this.hostDaemonFacade_.getPinHash(newHostId, hostPin);
|
| var hostOwnerPromise = this.getClientBaseJid_();
|
|
|
| - /** @type {boolean} */
|
| - var hostRegistered = false;
|
| -
|
| // Register the host and extract an auth code from the host response
|
| // and, optionally an email address for the robot account.
|
| /** @type {!Promise<remoting.HostListApi.RegisterResult>} */
|
| @@ -183,10 +178,19 @@ remoting.HostController.prototype.start = function(hostPin, consent) {
|
| var keyPair = /** @type {remoting.KeyPair} */ (a[2]);
|
|
|
| return remoting.HostListApi.getInstance().register(
|
| - newHostId, hostName, keyPair.publicKey, hostClientId);
|
| - }).then(function(/** remoting.HostListApi.RegisterResult */ result) {
|
| - hostRegistered = true;
|
| - return result;
|
| + hostName, keyPair.publicKey, hostClientId);
|
| + });
|
| +
|
| + // For convenience, make the host ID available as a separate promise.
|
| + /** @type {!Promise<string>} */
|
| + var hostIdPromise = registerResultPromise.then(function(registerResult) {
|
| + return registerResult.hostId;
|
| + });
|
| +
|
| + // Get the PIN hash based on the host ID.
|
| + /** @type {!Promise<string>} */
|
| + var pinHashPromise = hostIdPromise.then(function(hostId) {
|
| + return that.hostDaemonFacade_.getPinHash(hostId, hostPin);
|
| });
|
|
|
| // Get XMPP creditials.
|
| @@ -230,7 +234,6 @@ remoting.HostController.prototype.start = function(hostPin, consent) {
|
| var hostConfig = {
|
| xmpp_login: xmppCreds.userEmail,
|
| oauth_refresh_token: xmppCreds.refreshToken,
|
| - host_id: newHostId,
|
| host_name: hostName,
|
| host_secret_hash: hostSecretHash,
|
| private_key: keyPair.privateKey,
|
| @@ -239,8 +242,11 @@ remoting.HostController.prototype.start = function(hostPin, consent) {
|
| if (hostOwnerEmail != hostOwner) {
|
| hostConfig['host_owner_email'] = hostOwnerEmail;
|
| }
|
| - if (registerResult.gcdId) {
|
| - hostConfig['gcd_device_id'] = registerResult.gcdId;
|
| + if (registerResult.isLegacy) {
|
| + hostConfig['host_id'] = registerResult.hostId;
|
| + }
|
| + else {
|
| + hostConfig['gcd_device_id'] = registerResult.hostId;
|
| }
|
| return hostConfig;
|
| });
|
| @@ -253,24 +259,24 @@ remoting.HostController.prototype.start = function(hostPin, consent) {
|
| });
|
|
|
| // Update the UI or report an error.
|
| - return startDaemonResultPromise.then(function(result) {
|
| - if (result == remoting.HostController.AsyncResult.OK) {
|
| - return hostNamePromise.then(function(hostName) {
|
| - return keyPairPromise.then(function(keyPair) {
|
| - remoting.hostList.onLocalHostStarted(
|
| - hostName, newHostId, keyPair.publicKey);
|
| + return hostIdPromise.then(function(hostId) {
|
| + return startDaemonResultPromise.then(function(result) {
|
| + if (result == remoting.HostController.AsyncResult.OK) {
|
| + return hostNamePromise.then(function(hostName) {
|
| + return keyPairPromise.then(function(keyPair) {
|
| + remoting.hostList.onLocalHostStarted(
|
| + hostName, hostId, keyPair.publicKey);
|
| + });
|
| });
|
| - });
|
| - } else if (result == remoting.HostController.AsyncResult.CANCELLED) {
|
| - throw new remoting.Error(remoting.Error.Tag.CANCELLED);
|
| - } else {
|
| - throw remoting.Error.unexpected();
|
| - }
|
| - }).catch(function(error) {
|
| - if (hostRegistered) {
|
| - remoting.hostList.unregisterHostById(newHostId);
|
| - }
|
| - throw error;
|
| + } else if (result == remoting.HostController.AsyncResult.CANCELLED) {
|
| + throw new remoting.Error(remoting.Error.Tag.CANCELLED);
|
| + } else {
|
| + throw remoting.Error.unexpected();
|
| + }
|
| + }).catch(function(error) {
|
| + remoting.hostList.unregisterHostById(hostId);
|
| + throw error;
|
| + });
|
| });
|
| };
|
|
|
| @@ -399,7 +405,10 @@ remoting.HostController.prototype.getLocalHostId = function(onDone) {
|
| function onConfig(config) {
|
| var hostId = null;
|
| if (isHostConfigValid_(config)) {
|
| - hostId = /** @type {string} */ (config['host_id']);
|
| + // Use the |gcd_device_id| field if it exists, or the |host_id|
|
| + // field otherwise.
|
| + hostId = base.getStringAttr(
|
| + config, 'gcd_device_id', base.getStringAttr(config, 'host_id'));
|
| }
|
| onDone(hostId);
|
| };
|
|
|