| Index: remoting/webapp/crd/js/host_list_api_gcd_impl.js
|
| diff --git a/remoting/webapp/crd/js/host_list_api_gcd_impl.js b/remoting/webapp/crd/js/host_list_api_gcd_impl.js
|
| index 02db52e6d41920cbceec8a68834aad2f6517afb2..005b237fd2d4c915aa68f9b4cef95f305fcabe18 100644
|
| --- a/remoting/webapp/crd/js/host_list_api_gcd_impl.js
|
| +++ b/remoting/webapp/crd/js/host_list_api_gcd_impl.js
|
| @@ -60,9 +60,18 @@ remoting.HostListApiGcdImpl.prototype.register = function(
|
|
|
| /** @override */
|
| remoting.HostListApiGcdImpl.prototype.get = function() {
|
| - // TODO(jrw)
|
| - this.gcd_.listDevices();
|
| - return Promise.resolve([]);
|
| + return this.gcd_.listDevices().
|
| + then(function(devices) {
|
| + var hosts = [];
|
| + devices.forEach(function(device) {
|
| + try {
|
| + hosts.push(remoting.HostListApiGcdImpl.deviceToHost(device));
|
| + } catch (/** @type {*} */ error) {
|
| + console.warn('Invalid device spec:', error);
|
| + }
|
| + });
|
| + return hosts;
|
| + });
|
| };
|
|
|
| /** @override */
|
| @@ -74,8 +83,52 @@ remoting.HostListApiGcdImpl.prototype.put =
|
|
|
| /** @override */
|
| remoting.HostListApiGcdImpl.prototype.remove = function(hostId) {
|
| - // TODO(jrw)
|
| - throw new Error('Not implemented');
|
| + var that = this;
|
| + return this.gcd_.listDevices(hostId).then(function(devices) {
|
| + var gcdId = null;
|
| + for (var i = 0; i < devices.length; i++) {
|
| + var device = devices[i];
|
| + // The "name" field in GCD holds what Chromoting considers to be
|
| + // the host ID.
|
| + if (device.name == hostId) {
|
| + gcdId = device.id;
|
| + }
|
| + }
|
| + if (gcdId == null) {
|
| + return false;
|
| + } else {
|
| + return that.gcd_.deleteDevice(gcdId);
|
| + }
|
| + });
|
| +};
|
| +
|
| +/**
|
| + * @param {!Object} device
|
| + * @return {!remoting.Host}
|
| + */
|
| +remoting.HostListApiGcdImpl.deviceToHost = function(device) {
|
| + var statusMap = {
|
| + 'online': 'ONLINE',
|
| + 'offline': 'OFFLINE'
|
| + };
|
| + var hostId = base.getStringAttr(device, 'name');
|
| + var host = new remoting.Host(hostId);
|
| + host.hostName = base.getStringAttr(device, 'displayName');
|
| + host.status = base.getStringAttr(
|
| + statusMap, base.getStringAttr(device, 'connectionStatus'));
|
| + var state = base.getObjectAttr(device, 'state', {});
|
| + host.publicKey = base.getStringAttr(state, 'publicKey');
|
| + host.jabberId = base.getStringAttr(state, 'jabberId', '');
|
| + host.hostVersion = base.getStringAttr(state, 'hostVersion', '');
|
| + var creationTimeMs = base.getNumberAttr(device, 'creationTimeMs', 0);
|
| + if (creationTimeMs) {
|
| + host.createdTime = new Date(creationTimeMs).toISOString();
|
| + }
|
| + var lastUpdateTimeMs = base.getNumberAttr(device, 'lastUpdateTimeMs', 0);
|
| + if (lastUpdateTimeMs) {
|
| + host.updatedTime = new Date(lastUpdateTimeMs).toISOString();
|
| + }
|
| + return host;
|
| };
|
|
|
| })();
|
|
|