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>
210 lines
9.3 KiB
HTML
210 lines
9.3 KiB
HTML
<!doctype html>
|
|
<!-- Seeded to /config/caddy/site/cam-ptz/ on valhalla; served at cam.ginnoir.com/ptz/
|
|
behind Authentik. Video = Frigate's go2rtc MSE websocket; PTZ = MQTT over
|
|
wss://cam.ginnoir.com/mqtt -> mosquitto -> neolink -> E1 (Baichuan). -->
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
<title>E1 Pan/Tilt</title>
|
|
<style>
|
|
:root {
|
|
--bg: #f4f4f5; --panel: #ffffff; --text: #18181b; --muted: #71717a;
|
|
--btn: #e4e4e7; --btn-active: #2563eb; --btn-active-text: #fff; --border: #d4d4d8;
|
|
--ok: #16a34a; --bad: #dc2626;
|
|
}
|
|
@media (prefers-color-scheme: dark) {
|
|
:root:not([data-theme="light"]) {
|
|
--bg: #09090b; --panel: #18181b; --text: #f4f4f5; --muted: #a1a1aa;
|
|
--btn: #27272a; --btn-active: #3b82f6; --btn-active-text: #fff; --border: #3f3f46;
|
|
}
|
|
}
|
|
* { box-sizing: border-box; }
|
|
body {
|
|
margin: 0; background: var(--bg); color: var(--text);
|
|
font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
-webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
|
|
}
|
|
main { max-width: 1100px; margin: 0 auto; padding: 12px 16px 24px; }
|
|
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
|
|
h1 { font-size: 17px; margin: 0; }
|
|
header a { color: var(--muted); font-size: 13px; }
|
|
.status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
|
|
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }
|
|
.dot.on { background: var(--ok); }
|
|
.layout { display: grid; gap: 14px; grid-template-columns: 1fr; }
|
|
@media (min-width: 860px) { .layout { grid-template-columns: 1fr 280px; } }
|
|
.video { background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 16 / 9; }
|
|
.video video { width: 100%; height: 100%; display: block; object-fit: contain; }
|
|
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px; display: grid; gap: 16px; align-content: start; }
|
|
.pad { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 64px); gap: 8px; justify-content: center; }
|
|
button {
|
|
font: inherit; color: var(--text); background: var(--btn); border: 1px solid var(--border);
|
|
border-radius: 10px; cursor: pointer; touch-action: none;
|
|
}
|
|
button:active, button.held { background: var(--btn-active); color: var(--btn-active-text); border-color: var(--btn-active); }
|
|
.pad button { font-size: 22px; }
|
|
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; }
|
|
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
.presets button { padding: 8px 12px; }
|
|
.presets .empty { color: var(--muted); font-size: 13px; }
|
|
.save { display: flex; gap: 8px; margin-top: 10px; }
|
|
.save input { flex: 1; min-width: 0; font: inherit; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); -webkit-user-select: text; user-select: text; }
|
|
.save button { padding: 8px 12px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<header>
|
|
<h1>E1 Pan/Tilt</h1>
|
|
<div class="status"><span class="dot" id="dot"></span><span id="state">connecting…</span></div>
|
|
<a href="/">Frigate</a>
|
|
</header>
|
|
<div class="layout">
|
|
<div class="video"><cam-video id="video"></cam-video></div>
|
|
<div class="panel">
|
|
<div class="pad" aria-label="Pan and tilt">
|
|
<span></span><button data-dir="up" aria-label="Tilt up">▲</button><span></span>
|
|
<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>
|
|
<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>
|
|
<div class="save">
|
|
<input id="presetName" placeholder="Save current view as…" maxlength="31">
|
|
<button id="saveBtn">Save</button>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<script src="mqtt.min.js"></script>
|
|
<script type="module">
|
|
import {VideoRTC} from './video-rtc.js';
|
|
|
|
// --- Video: Frigate's go2rtc restream over MSE (WebRTC needs :8555 ICE, not exposed) ---
|
|
class CamVideo extends VideoRTC {}
|
|
customElements.define('cam-video', CamVideo);
|
|
const video = document.getElementById('video');
|
|
video.mode = 'mse';
|
|
video.background = true;
|
|
video.src = `wss://${location.host}/live/mse/api/ws?src=e1`;
|
|
|
|
// --- MQTT ---
|
|
const BASE = 'neolink/e1';
|
|
const dot = document.getElementById('dot');
|
|
const state = document.getElementById('state');
|
|
const client = mqtt.connect(`wss://${location.host}/mqtt`, {reconnectPeriod: 2000, clean: true});
|
|
let camOnline = false;
|
|
|
|
function setStatus() {
|
|
const ok = client.connected && camOnline;
|
|
dot.classList.toggle('on', ok);
|
|
state.textContent = !client.connected ? 'broker offline' : camOnline ? 'ready' : 'camera offline';
|
|
}
|
|
client.on('connect', () => {
|
|
// 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();
|
|
});
|
|
client.on('close', setStatus);
|
|
client.on('message', (topic, payload) => {
|
|
const msg = payload.toString();
|
|
if (topic === 'neolink/status' || topic === `${BASE}/status`) {
|
|
camOnline = msg.trim() !== 'offline' && msg.trim() !== 'disconnected';
|
|
setStatus();
|
|
} 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 ---
|
|
// 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 held = false;
|
|
const release = () => { held = false; btn.classList.remove('held'); };
|
|
btn.addEventListener('pointerdown', async e => {
|
|
e.preventDefault();
|
|
btn.setPointerCapture(e.pointerId);
|
|
held = true; btn.classList.add('held');
|
|
do { await moveOnce(btn.dataset.dir); } while (held);
|
|
});
|
|
['pointerup', 'pointercancel', 'lostpointercapture'].forEach(ev => btn.addEventListener(ev, release));
|
|
});
|
|
const keys = {ArrowUp: 'up', ArrowDown: 'down', ArrowLeft: 'left', ArrowRight: 'right'};
|
|
document.addEventListener('keydown', e => {
|
|
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) ---
|
|
const presetsEl = document.getElementById('presets');
|
|
let presets = [];
|
|
function renderPresets(xml) {
|
|
const doc = new DOMParser().parseFromString(xml, 'application/xml');
|
|
presets = [...doc.getElementsByTagName('preset')]
|
|
.map(p => ({
|
|
id: p.getElementsByTagName('id')[0]?.textContent,
|
|
name: p.getElementsByTagName('name')[0]?.textContent,
|
|
enable: p.getElementsByTagName('enable')[0]?.textContent,
|
|
}))
|
|
.filter(p => p.id != null && p.name && p.enable !== '0');
|
|
presetsEl.replaceChildren();
|
|
if (!presets.length) {
|
|
const s = document.createElement('span');
|
|
s.className = 'empty';
|
|
s.textContent = 'No presets yet';
|
|
presetsEl.append(s);
|
|
return;
|
|
}
|
|
for (const p of presets) {
|
|
const b = document.createElement('button');
|
|
b.textContent = p.name;
|
|
b.addEventListener('click', () => client.publish(`${BASE}/control/ptz/preset`, p.id));
|
|
presetsEl.append(b);
|
|
}
|
|
}
|
|
setTimeout(() => { if (presetsEl.querySelector('.empty')?.textContent === 'loading…') renderPresets('<x/>'); }, 8000);
|
|
|
|
document.getElementById('saveBtn').addEventListener('click', () => {
|
|
const input = document.getElementById('presetName');
|
|
const name = input.value.trim().replace(/\s+/g, '_');
|
|
if (!name) return;
|
|
const used = new Set(presets.map(p => Number(p.id)));
|
|
let id = 0;
|
|
while (used.has(id)) id++;
|
|
client.publish(`${BASE}/control/ptz/assign`, `${id} ${name}`);
|
|
input.value = '';
|
|
setTimeout(() => client.publish(`${BASE}/query/ptz/preset`, ''), 1500);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|