fix(cameras): PTZ page waits for each step's OK, drops zoom, narrows MQTT ACL

neolink 0.6.2 moves for amount/32 s per command and queues them, so the page
sends the next step only after the previous reply; in/out are todo!() upstream.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ginnoirandClaude Opus 5.5 committed 2026-10-08 02:05:46 -05:00
1 parent b78a8d51ad
commit 981c7a65b5
3 files changed
+41 -27

No files matched your search

+5 -2
View File
@@ -1,10 +1,13 @@
# Seeded to /config/mosquitto/acl on valhalla.
# Lines before the first `user` apply to anonymous clients (the browser PTZ page).
topic write neolink/e1/control/ptz
# Never grant anonymous neolink/config — it echoes the camera password and rewrites
# neolink's live config. No status/# either: status/preview is a base64 JPEG flood.
topic readwrite neolink/e1/control/ptz
topic write neolink/e1/control/ptz/preset
topic write neolink/e1/control/ptz/assign
topic write neolink/e1/query/ptz/preset
topic read neolink/e1/status/#
topic read neolink/e1/status
topic read neolink/e1/status/ptz
topic read neolink/status
user neolink
+35 -24
View File
@@ -44,8 +44,6 @@
}
button:active, button.held { background: var(--btn-active); color: var(--btn-active-text); border-color: var(--btn-active); }
.pad button { font-size: 22px; }
.zoom { display: flex; gap: 8px; justify-content: center; }
.zoom button { width: 100px; height: 44px; }
label { font-size: 13px; color: var(--muted); display: grid; gap: 6px; }
input[type=range] { width: 100%; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
@@ -72,11 +70,7 @@
<button data-dir="left" aria-label="Pan left">◀</button><span></span><button data-dir="right" aria-label="Pan right">▶</button>
<span></span><button data-dir="down" aria-label="Tilt down">▼</button><span></span>
</div>
<div class="zoom">
<button data-dir="out" aria-label="Zoom out">− Zoom</button>
<button data-dir="in" aria-label="Zoom in">+ Zoom</button>
</div>
<label>Speed <input type="range" id="speed" min="8" max="64" step="4" value="32"></label>
<label>Step size <span id="stepLabel"></span><input type="range" id="step" min="4" max="32" step="2" value="10"></label>
<section>
<h2>Presets</h2>
<div class="presets" id="presets"><span class="empty">loading…</span></div>
@@ -114,7 +108,8 @@ function setStatus() {
state.textContent = !client.connected ? 'broker offline' : camOnline ? 'ready' : 'camera offline';
}
client.on('connect', () => {
client.subscribe([`neolink/status`, `${BASE}/status/#`]);
// Not status/# — neolink 0.6.2 floods status/preview with base64 JPEGs.
client.subscribe([`neolink/status`, `${BASE}/status`, `${BASE}/status/ptz`, `${BASE}/control/ptz`]);
client.publish(`${BASE}/query/ptz/preset`, '');
setStatus();
});
@@ -124,33 +119,49 @@ client.on('message', (topic, payload) => {
if (topic === 'neolink/status' || topic === `${BASE}/status`) {
camOnline = msg.trim() !== 'offline' && msg.trim() !== 'disconnected';
setStatus();
} else if (topic === `${BASE}/status/ptz/preset`) {
} else if (topic === `${BASE}/status/ptz`) {
renderPresets(msg);
} else if (topic === `${BASE}/control/ptz` && (msg === 'OK' || msg === 'FAIL')) {
// neolink echoes our command on this topic too; only replies settle the step
if (pendingReply) { pendingReply(); pendingReply = null; }
}
});
// --- Move: tap = one step, hold = repeat while pressed ---
const speed = document.getElementById('speed');
const REPEAT_MS = 350;
function move(dir) {
if (client.connected) client.publish(`${BASE}/control/ptz`, `${dir} ${speed.value}`);
// --- Move ---
// neolink 0.6.2: payload "<dir> <amount>" moves at fixed speed 32 for amount/32 seconds,
// then sends stop. Commands queue camera-side, so never send the next step until the
// previous one replied OK/FAIL — otherwise the camera keeps moving after release.
// (in/out are todo!() in 0.6.2 and would panic neolink; the E1 has no zoom anyway.)
const step = document.getElementById('step');
const stepLabel = document.getElementById('stepLabel');
const showStep = () => stepLabel.textContent = `(${(step.value / 32).toFixed(2)} s)`;
step.addEventListener('input', showStep); showStep();
let pendingReply = null, busy = false;
function moveOnce(dir) {
if (!client.connected || busy) return Promise.resolve();
busy = true;
return new Promise(resolve => {
const done = () => { busy = false; resolve(); };
pendingReply = done;
setTimeout(() => { if (pendingReply === done) { pendingReply = null; done(); } }, 3000);
client.publish(`${BASE}/control/ptz`, `${dir} ${step.value}`);
});
}
document.querySelectorAll('button[data-dir]').forEach(btn => {
let timer = null;
const stop = () => { clearInterval(timer); timer = null; btn.classList.remove('held'); };
btn.addEventListener('pointerdown', e => {
let held = false;
const release = () => { held = false; btn.classList.remove('held'); };
btn.addEventListener('pointerdown', async e => {
e.preventDefault();
btn.setPointerCapture(e.pointerId);
btn.classList.add('held');
move(btn.dataset.dir);
timer = setInterval(() => move(btn.dataset.dir), REPEAT_MS);
held = true; btn.classList.add('held');
do { await moveOnce(btn.dataset.dir); } while (held);
});
['pointerup', 'pointercancel', 'lostpointercapture'].forEach(ev => btn.addEventListener(ev, stop));
['pointerup', 'pointercancel', 'lostpointercapture'].forEach(ev => btn.addEventListener(ev, release));
});
const keys = {ArrowUp: 'up', ArrowDown: 'down', ArrowLeft: 'left', ArrowRight: 'right', '+': 'in', '=': 'in', '-': 'out'};
const keys = {ArrowUp: 'up', ArrowDown: 'down', ArrowLeft: 'left', ArrowRight: 'right'};
document.addEventListener('keydown', e => {
if (e.target.tagName === 'INPUT') return;
if (keys[e.key]) { e.preventDefault(); move(keys[e.key]); }
if (e.target.tagName === 'INPUT' || e.repeat) return;
if (keys[e.key]) { e.preventDefault(); moveOnce(keys[e.key]); }
});
// --- Presets (neolink returns the camera's XML preset list) ---