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

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: Gate devices page on enable_mdns=1 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..01ac725ba3750faa4fbc7a1d4000adfff8473022 100644
--- a/chrome/browser/resources/local_discovery/local_discovery.js
+++ b/chrome/browser/resources/local_discovery/local_discovery.js
@@ -14,7 +14,7 @@
* Appends a row to the output table listing the new device.
* @param {string} name of the device service.
James Hawkins 2013/07/29 16:27:03 nit: The format of the parameter doc should be: @
Noam Samuel 2013/08/02 22:20:02 Done.
* @param {string} info - additional info of the device,
James Hawkins 2013/07/29 16:27:03 nit: Remove '-' character and capitalize the doc s
Noam Samuel 2013/08/02 22:20:02 Done.
- * if empty device need to be deleted
+ * if empty device need to be deleted.
James Hawkins 2013/07/29 16:27:03 nit: Wrapped documentation should be indented 4 sp
Noam Samuel 2013/08/02 22:20:02 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 = 'Register';
James Hawkins 2013/07/29 16:27:03 Needs to be localized.
+ button.addEventListener('click', sendRegisterDevice.bind(null, name));
+ td.appendChild(button);
+ } else {
+ td.textContent = '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;
+ $('infoConsole').appendChild(div);
+}
+
+/**
+ * Register a device.
+ * @param {string} device The device to register.
+ */
+function sendRegisterDevice(device) {
+ chrome.send('register', [device]);
+ logToInfoConsole('Registering ' + device + '...');
+}
+
+/**
+ * Announce that a registration failed.
+ * @param {string} reason The error message.
+ */
+function registrationFailed(reason) {
+ logToInfoConsole('Registration failed: ' + reason);
+}
+
+/**
+ * Announce that a registration succeeeded.
+ * @param {string} id The id of the newly registered device.
+ */
+function registrationSuccess(id) {
+ logToInfoConsole('Registered as ' + id);
+}
+
+document.addEventListener('DOMContentLoaded', function() {
+ chrome.send('start');
+});

Powered by Google App Engine
This is Rietveld 408576698