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..e29a0d00b84547852ee085d46c1b12b514ad48c4 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 */ |
Jamie
2015/04/27 22:44:06
@return {Promise<Array<remoting.Host>>}?
John Williams
2015/04/27 23:05:42
I generally don't like to repeat the type declarat
|
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,50 @@ 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) { |
Jamie
2015/04/27 22:44:06
You're passing a hostId to a function expecting a
John Williams
2015/04/27 23:05:42
It's imposed by GCD. We could use GCD's own "id"
|
+ var gcdId = null; |
+ for (var i = 0; i < devices.length; i++) { |
+ var device = devices[i]; |
+ 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; |
}; |
})(); |