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:
1 parent
b78a8d51ad
commit
981c7a65b5
3 files changed
+41
-27
No files matched your search
@@ -172,7 +172,7 @@ neolink (now `mqtt-rtsp`) ◄── mosquitto:1883 ────┘ topics neol
|
|||||||
clients to:
|
clients to:
|
||||||
- publish: `neolink/e1/control/ptz`, `neolink/e1/control/ptz/preset`,
|
- publish: `neolink/e1/control/ptz`, `neolink/e1/control/ptz/preset`,
|
||||||
`neolink/e1/query/ptz/preset`
|
`neolink/e1/query/ptz/preset`
|
||||||
- read: `neolink/e1/status/#`, `neolink/status`
|
- read: `neolink/e1/status`, `neolink/e1/status/ptz`, `neolink/status` (not `status/#`: preview flood)
|
||||||
- **not** `neolink/config`, which echoes the camera password and can rewrite the live
|
- **not** `neolink/config`, which echoes the camera password and can rewrite the live
|
||||||
config.
|
config.
|
||||||
- Authentik forward_auth on the `/mqtt` path is the browser-side gate.
|
- Authentik forward_auth on the `/mqtt` path is the browser-side gate.
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
# Seeded to /config/mosquitto/acl on valhalla.
|
# Seeded to /config/mosquitto/acl on valhalla.
|
||||||
# Lines before the first `user` apply to anonymous clients (the browser PTZ page).
|
# 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/preset
|
||||||
topic write neolink/e1/control/ptz/assign
|
topic write neolink/e1/control/ptz/assign
|
||||||
topic write neolink/e1/query/ptz/preset
|
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
|
topic read neolink/status
|
||||||
|
|
||||||
user neolink
|
user neolink
|
||||||
|
|||||||
@@ -44,8 +44,6 @@
|
|||||||
}
|
}
|
||||||
button:active, button.held { background: var(--btn-active); color: var(--btn-active-text); border-color: var(--btn-active); }
|
button:active, button.held { background: var(--btn-active); color: var(--btn-active-text); border-color: var(--btn-active); }
|
||||||
.pad button { font-size: 22px; }
|
.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; }
|
label { font-size: 13px; color: var(--muted); display: grid; gap: 6px; }
|
||||||
input[type=range] { width: 100%; }
|
input[type=range] { width: 100%; }
|
||||||
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
|
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>
|
<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>
|
<span></span><button data-dir="down" aria-label="Tilt down">▼</button><span></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="zoom">
|
<label>Step size <span id="stepLabel"></span><input type="range" id="step" min="4" max="32" step="2" value="10"></label>
|
||||||
<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>
|
|
||||||
<section>
|
<section>
|
||||||
<h2>Presets</h2>
|
<h2>Presets</h2>
|
||||||
<div class="presets" id="presets"><span class="empty">loading…</span></div>
|
<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';
|
state.textContent = !client.connected ? 'broker offline' : camOnline ? 'ready' : 'camera offline';
|
||||||
}
|
}
|
||||||
client.on('connect', () => {
|
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`, '');
|
client.publish(`${BASE}/query/ptz/preset`, '');
|
||||||
setStatus();
|
setStatus();
|
||||||
});
|
});
|
||||||
@@ -124,33 +119,49 @@ client.on('message', (topic, payload) => {
|
|||||||
if (topic === 'neolink/status' || topic === `${BASE}/status`) {
|
if (topic === 'neolink/status' || topic === `${BASE}/status`) {
|
||||||
camOnline = msg.trim() !== 'offline' && msg.trim() !== 'disconnected';
|
camOnline = msg.trim() !== 'offline' && msg.trim() !== 'disconnected';
|
||||||
setStatus();
|
setStatus();
|
||||||
} else if (topic === `${BASE}/status/ptz/preset`) {
|
} else if (topic === `${BASE}/status/ptz`) {
|
||||||
renderPresets(msg);
|
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 ---
|
// --- Move ---
|
||||||
const speed = document.getElementById('speed');
|
// neolink 0.6.2: payload "<dir> <amount>" moves at fixed speed 32 for amount/32 seconds,
|
||||||
const REPEAT_MS = 350;
|
// then sends stop. Commands queue camera-side, so never send the next step until the
|
||||||
function move(dir) {
|
// previous one replied OK/FAIL — otherwise the camera keeps moving after release.
|
||||||
if (client.connected) client.publish(`${BASE}/control/ptz`, `${dir} ${speed.value}`);
|
// (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 => {
|
document.querySelectorAll('button[data-dir]').forEach(btn => {
|
||||||
let timer = null;
|
let held = false;
|
||||||
const stop = () => { clearInterval(timer); timer = null; btn.classList.remove('held'); };
|
const release = () => { held = false; btn.classList.remove('held'); };
|
||||||
btn.addEventListener('pointerdown', e => {
|
btn.addEventListener('pointerdown', async e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
btn.setPointerCapture(e.pointerId);
|
btn.setPointerCapture(e.pointerId);
|
||||||
btn.classList.add('held');
|
held = true; btn.classList.add('held');
|
||||||
move(btn.dataset.dir);
|
do { await moveOnce(btn.dataset.dir); } while (held);
|
||||||
timer = setInterval(() => move(btn.dataset.dir), REPEAT_MS);
|
|
||||||
});
|
});
|
||||||
['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 => {
|
document.addEventListener('keydown', e => {
|
||||||
if (e.target.tagName === 'INPUT') return;
|
if (e.target.tagName === 'INPUT' || e.repeat) return;
|
||||||
if (keys[e.key]) { e.preventDefault(); move(keys[e.key]); }
|
if (keys[e.key]) { e.preventDefault(); moveOnce(keys[e.key]); }
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- Presets (neolink returns the camera's XML preset list) ---
|
// --- Presets (neolink returns the camera's XML preset list) ---
|
||||||
|
|||||||
Reference in new issue
Block a user