Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Unified Diff: remoting/webapp/crd/js/host_list_api_gcd_impl.js

Issue 1104383002: Added ability to list and delete hosts with GCD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for review Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/webapp/crd/js/gcd_client.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
};
})();
« no previous file with comments | « remoting/webapp/crd/js/gcd_client.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698