feat(cameras): pan/tilt page — mosquitto + neolink mqtt-rtsp + cam.ginnoir.com/ptz
Deploy Caddyfile to valhalla / deploy (push) Failing after 10s
Deploy Caddyfile to valhalla / deploy (push) Failing after 10s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d6a331465e
commit
b78a8d51ad
10 files changed
+1014
-1
No files matched your search
@@ -0,0 +1,198 @@
|
||||
<!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; }
|
||||
.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; }
|
||||
.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>
|
||||
<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>
|
||||
<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', () => {
|
||||
client.subscribe([`neolink/status`, `${BASE}/status/#`]);
|
||||
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/preset`) {
|
||||
renderPresets(msg);
|
||||
}
|
||||
});
|
||||
|
||||
// --- 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}`);
|
||||
}
|
||||
document.querySelectorAll('button[data-dir]').forEach(btn => {
|
||||
let timer = null;
|
||||
const stop = () => { clearInterval(timer); timer = null; btn.classList.remove('held'); };
|
||||
btn.addEventListener('pointerdown', e => {
|
||||
e.preventDefault();
|
||||
btn.setPointerCapture(e.pointerId);
|
||||
btn.classList.add('held');
|
||||
move(btn.dataset.dir);
|
||||
timer = setInterval(() => move(btn.dataset.dir), REPEAT_MS);
|
||||
});
|
||||
['pointerup', 'pointercancel', 'lostpointercapture'].forEach(ev => btn.addEventListener(ev, stop));
|
||||
});
|
||||
const keys = {ArrowUp: 'up', ArrowDown: 'down', ArrowLeft: 'left', ArrowRight: 'right', '+': 'in', '=': 'in', '-': 'out'};
|
||||
document.addEventListener('keydown', e => {
|
||||
if (e.target.tagName === 'INPUT') return;
|
||||
if (keys[e.key]) { e.preventDefault(); move(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>
|
||||
Reference in new issue
Block a user