diff --git a/lightsync/frontend/app.js b/lightsync/frontend/app.js
index 3e726ff..af44126 100644
--- a/lightsync/frontend/app.js
+++ b/lightsync/frontend/app.js
@@ -4,6 +4,21 @@
const WS_URL = `ws://${location.host}/ws`;
+async function apiPost(path, data) {
+ const res = await fetch(path, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(data),
+ });
+ if (!res.ok) throw new Error(`POST ${path}: HTTP ${res.status}`);
+ return res.json();
+}
+
+async function apiDelete(path) {
+ const res = await fetch(path, { method: "DELETE" });
+ if (!res.ok && res.status !== 204) throw new Error(`DELETE ${path}: HTTP ${res.status}`);
+}
+
class LightSyncClient {
constructor() {
this.ws = null;
@@ -68,8 +83,11 @@ async function loadDevices() {
}
list.innerHTML = devices.map(d =>
`
-
${escapeHtml(d.name)}
-
${escapeHtml(d.strip_type)} / ${d.led_count} LEDs / ${escapeHtml(d.ip)}:${d.port}
+
+ ${escapeHtml(d.name)}
+ ${escapeHtml(d.strip_type)} / ${d.led_count} LEDs / ${escapeHtml(d.ip)}:${d.port}
+
+
`
).join("");
} catch (err) {
@@ -79,6 +97,16 @@ async function loadDevices() {
}
}
+async function removeDevice(id) {
+ try {
+ await apiDelete(`/api/devices/${id}`);
+ await loadDevices();
+ } catch (err) {
+ console.error("[devices] remove failed:", err);
+ }
+}
+window.removeDevice = removeDevice;
+
function escapeHtml(str) {
const div = document.createElement("div");
div.appendChild(document.createTextNode(String(str)));
@@ -86,3 +114,23 @@ function escapeHtml(str) {
}
loadDevices();
+
+document.getElementById("add-device-form").addEventListener("submit", async (e) => {
+ e.preventDefault();
+ const form = e.target;
+ const data = {
+ name: form.name.value.trim(),
+ strip_type: form.strip_type.value,
+ led_count: parseInt(form.led_count.value, 10),
+ ip: form.ip.value.trim(),
+ port: parseInt(form.port.value, 10),
+ };
+ try {
+ await apiPost("/api/devices", data);
+ form.reset();
+ form.port.value = "21324";
+ await loadDevices();
+ } catch (err) {
+ console.error("[devices] add failed:", err);
+ }
+});
diff --git a/lightsync/frontend/index.html b/lightsync/frontend/index.html
index 2720f65..d154fe6 100644
--- a/lightsync/frontend/index.html
+++ b/lightsync/frontend/index.html
@@ -20,23 +20,37 @@