Timers: built-in LTC listener, configured in the admin page
The LTC listener now lives inside the module: it spawns the native ltc-capture helper (moved into the module folder, compiled on first use, exact-name device matching) for the admin-selected input device, extracts the configured channel, and decodes SMPTE LTC in-process (ltc.js — the engine, shared with tools/ltc-reader.js, which remains the remote-machine option posting to /ltc). Admin config: an "LTC listener" switch, an audio-device select populated live from the new GET /ltc/devices route, and a 1-based channel number. The switch off means LTC is gone entirely: no LTC entry in the Add-tile picker, no LTC row in the Timers menu or All-timers grid, no stage/API probes, and POST /ltc answers 409. Source precedence with it on: listener-with-data, fresh remote reader, listener's own no-signal verdict, then the legacy API/stage chain. Shell (admin page): `select` fields learn `optionsRoute` — options fetched from a module route at render, saved value kept selectable when the route or device is gone. Documented in MODULE-GUIDE; backward compatible. Coordinate with the shell lane before its next admin.js change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
c4db412014
commit
b95aa7dc34
+30
-9
@@ -83,7 +83,7 @@ function healthText(mod) {
|
||||
return mod.hasServer ? 'Mounted.' : 'Client-only module (no server part).';
|
||||
}
|
||||
|
||||
function fieldFor(key, spec, value, passwordSet) {
|
||||
function fieldFor(key, spec, value, passwordSet, moduleId) {
|
||||
const type = spec?.type || 'string';
|
||||
const label = spec?.label || key;
|
||||
const field = document.createElement('label');
|
||||
@@ -122,17 +122,38 @@ function fieldFor(key, spec, value, passwordSet) {
|
||||
row.append(host, sep, port);
|
||||
field.append(span, row);
|
||||
read = () => ({ host: host.value.trim(), port: Number(port.value) || 0 });
|
||||
} else if (type === 'select' && Array.isArray(spec.options)) {
|
||||
} else if (type === 'select' && (Array.isArray(spec.options) || spec.optionsRoute)) {
|
||||
const span = document.createElement('span');
|
||||
span.textContent = label;
|
||||
const select = document.createElement('select');
|
||||
for (const opt of spec.options) {
|
||||
const o = document.createElement('option');
|
||||
o.value = String(typeof opt === 'object' ? opt.value : opt);
|
||||
o.textContent = String(typeof opt === 'object' ? (opt.label ?? opt.value) : opt);
|
||||
select.appendChild(o);
|
||||
const fill = (options) => {
|
||||
select.innerHTML = '';
|
||||
// The saved value must stay selectable even when it isn't among the
|
||||
// live options (device unplugged, module route down).
|
||||
const saved = String(value ?? '');
|
||||
if (saved && !options.some((opt) => String(typeof opt === 'object' ? opt.value : opt) === saved)) {
|
||||
options = [{ value: saved, label: `${saved} (saved)` }, ...options];
|
||||
}
|
||||
if (!saved) options = [{ value: '', label: '— choose —' }, ...options];
|
||||
for (const opt of options) {
|
||||
const o = document.createElement('option');
|
||||
o.value = String(typeof opt === 'object' ? opt.value : opt);
|
||||
o.textContent = String(typeof opt === 'object' ? (opt.label ?? opt.value) : opt);
|
||||
select.appendChild(o);
|
||||
}
|
||||
select.value = saved;
|
||||
};
|
||||
fill(Array.isArray(spec.options) ? spec.options : []);
|
||||
if (spec.optionsRoute && moduleId) {
|
||||
// Options discovered at runtime (audio devices, ports, sources…):
|
||||
// the module serves them from one of its own routes.
|
||||
fetch(`/api/modules/${encodeURIComponent(moduleId)}${spec.optionsRoute}`)
|
||||
.then((res) => (res.ok ? res.json() : null))
|
||||
.then((body) => {
|
||||
if (Array.isArray(body?.options)) fill(body.options);
|
||||
})
|
||||
.catch(() => { /* keep the static/saved options */ });
|
||||
}
|
||||
select.value = String(value ?? '');
|
||||
field.append(span, select);
|
||||
read = () => select.value;
|
||||
} else {
|
||||
@@ -227,7 +248,7 @@ function buildModuleCard(mod) {
|
||||
form.className = 'module-form';
|
||||
const readers = new Map();
|
||||
for (const [key, spec] of schemaKeys) {
|
||||
const { field, read } = fieldFor(key, spec, mod.config[key], mod.passwordSet[key]);
|
||||
const { field, read } = fieldFor(key, spec, mod.config[key], mod.passwordSet[key], mod.id);
|
||||
readers.set(key, read);
|
||||
form.appendChild(field);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user