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

Unified Diff: chrome/browser/resources/local_discovery/local_discovery.js

Issue 20070002: Demo UI for device discovery and registration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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
Index: chrome/browser/resources/local_discovery/local_discovery.js
diff --git a/chrome/browser/resources/local_discovery/local_discovery.js b/chrome/browser/resources/local_discovery/local_discovery.js
index 1ef4eb18253a7a0b1935bf65acea6f9e38f663e4..7c42c8a088a6964b93fc7951f800c39b1c35cfd5 100644
--- a/chrome/browser/resources/local_discovery/local_discovery.js
+++ b/chrome/browser/resources/local_discovery/local_discovery.js
@@ -12,9 +12,9 @@
/**
* Appends a row to the output table listing the new device.
- * @param {string} name of the device service.
- * @param {string} info - additional info of the device,
- * if empty device need to be deleted
+ * @param {string} name Name of the device.
+ * @param {string} info Additional info of the device, if empty device need to
+ * be deleted.
Dan Beam 2013/08/06 21:21:38 nit: 4 \s wrapping indent * @param {string} info
Noam Samuel 2013/08/06 23:54:05 Done.
*/
function onServiceUpdate(name, info) {
var table = $('devices-table');
@@ -26,7 +26,6 @@ function onServiceUpdate(name, info) {
params[2] = info.ip;
params[3] = info.metadata;
params[4] = info.lastSeen;
- params[5] = info.registered;
}
for (var i = 0, row; row = table.rows[i]; i++) {
@@ -60,5 +59,55 @@ function onServiceUpdate(name, info) {
tr.appendChild(td);
}
+ td = document.createElement('td');
+ if (!info.registered) {
+ var button = document.createElement('button');
+ button.textContent = loadTimeData.getString('serviceRegister');
+ button.addEventListener('click', sendRegisterDevice.bind(null, name));
+ td.appendChild(button);
+ } else {
+ td.textContent = loadTimeData.getString('registered');
+ }
+ tr.appendChild(td);
+
table.appendChild(tr);
}
+
+/**
+ * Adds a row to the logging console.
+ * @param {string} msg The message to log.
+ */
+function logToInfoConsole(msg) {
+ var div = document.createElement('div');
+ div.textContent = msg;
+ $('info-console').appendChild(div);
+}
+
+/**
+ * Register a device.
+ * @param {string} device The device to register.
+ */
+function sendRegisterDevice(device) {
+ chrome.send('register', [device]);
+ logToInfoConsole(loadTimeData.getStringF('registeringService', device));
+}
+
+/**
+ * Announce that a registration failed.
+ * @param {string} reason The error message.
+ */
+function registrationFailed(reason) {
+ logToInfoConsole(loadTimeData.getStringF('registrationFailed', reason));
+}
+
+/**
+ * Announce that a registration succeeeded.
+ * @param {string} id The id of the newly registered device.
+ */
+function registrationSuccess(id) {
+ logToInfoConsole(loadTimeData.getStringF('registrationSucceeded', id));
+}
+
+document.addEventListener('DOMContentLoaded', function() {
+ chrome.send('start');
+});

Powered by Google App Engine
This is Rietveld 408576698