|
|
<!doctype html>
|
|
|
<html lang="en">
|
|
|
<head>
|
|
|
<meta charset="utf-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
<meta name="theme-color" content="#101820">
|
|
|
<link rel="stylesheet" href="default.css">
|
|
|
<title>MiniWebCam</title>
|
|
|
</head>
|
|
|
<body>
|
|
|
<div class="app-shell">
|
|
|
<header class="topbar">
|
|
|
<a class="brand" href="/" aria-label="MiniWebCam home">
|
|
|
<span class="brand-mark" aria-hidden="true">
|
|
|
<svg viewBox="0 0 24 24"><path d="M4 7.5h3l1.5-2h7l1.5 2h3A1.5 1.5 0 0 1 21.5 9v9a1.5 1.5 0 0 1-1.5 1.5H4A1.5 1.5 0 0 1 2.5 18V9A1.5 1.5 0 0 1 4 7.5Z"/><circle cx="12" cy="13" r="4"/></svg>
|
|
|
</span>
|
|
|
<span>
|
|
|
<strong>MiniWebCam</strong>
|
|
|
<small>Camera dashboard</small>
|
|
|
</span>
|
|
|
</a>
|
|
|
<div class="connection-status" id="connection-status" role="status">
|
|
|
<span class="status-dot" aria-hidden="true"></span>
|
|
|
<span id="status-text">Connecting…</span>
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
<main>
|
|
|
<section class="page-heading">
|
|
|
<div>
|
|
|
<p class="eyebrow">LIVE MONITOR</p>
|
|
|
<h1>Camera overview</h1>
|
|
|
<p class="subtitle">Live video and device controls in one place.</p>
|
|
|
</div>
|
|
|
<label class="toggle-card" for="floatimage">
|
|
|
<span class="toggle-copy">
|
|
|
<strong>Filter processing</strong>
|
|
|
<small>Show the processed image</small>
|
|
|
</span>
|
|
|
<input id="floatimage" type="checkbox" role="switch">
|
|
|
<span class="toggle-track" aria-hidden="true"></span>
|
|
|
</label>
|
|
|
</section>
|
|
|
|
|
|
<section class="preview-card" aria-label="Live camera preview">
|
|
|
<div class="section-bar">
|
|
|
<div class="section-title">
|
|
|
<span class="live-indicator" aria-hidden="true"></span>
|
|
|
<h2>Live preview</h2>
|
|
|
</div>
|
|
|
<span class="preview-label" id="preview-label">Standard image</span>
|
|
|
</div>
|
|
|
<div class="preview-stage">
|
|
|
<img id="webcamimage" src="snapshot.jpg" alt="Live webcam preview">
|
|
|
<div class="preview-error" id="preview-error" hidden>Waiting for camera image…</div>
|
|
|
</div>
|
|
|
<div class="preview-footer">
|
|
|
<span>Image updates automatically</span>
|
|
|
<span id="last-updated">Waiting for first frame</span>
|
|
|
</div>
|
|
|
</section>
|
|
|
|
|
|
<div class="content-grid">
|
|
|
<section class="panel controls-panel">
|
|
|
<div class="panel-heading">
|
|
|
<div>
|
|
|
<p class="eyebrow">DEVICE</p>
|
|
|
<h2>Camera controls</h2>
|
|
|
</div>
|
|
|
<span class="count-badge" id="control-count">0 controls</span>
|
|
|
</div>
|
|
|
<label class="search-box" for="control-search">
|
|
|
<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="10.8" cy="10.8" r="6.8"/><path d="m16 16 5 5"/></svg>
|
|
|
<input id="control-search" type="search" placeholder="Find a control…" autocomplete="off">
|
|
|
</label>
|
|
|
<div class="control-list" id="controls">
|
|
|
<div class="empty-state">Loading camera controls…</div>
|
|
|
</div>
|
|
|
<p class="panel-hint">Adjust a slider or enter a value, then select Apply. Press Enter to apply from the value field.</p>
|
|
|
</section>
|
|
|
|
|
|
<section class="panel settings-panel">
|
|
|
<div class="panel-heading">
|
|
|
<div>
|
|
|
<p class="eyebrow">PROCESSING</p>
|
|
|
<h2>Image settings</h2>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="settings-list" id="variables">
|
|
|
<div class="empty-state">Loading image settings…</div>
|
|
|
</div>
|
|
|
<p class="panel-hint">Changes take effect immediately. Press Enter or select Apply to save.</p>
|
|
|
</section>
|
|
|
</div>
|
|
|
<div class="notice" id="notice" role="alert" hidden></div>
|
|
|
</main>
|
|
|
|
|
|
<footer class="footer">
|
|
|
<span>MiniWebCam</span>
|
|
|
<span>Local camera dashboard</span>
|
|
|
</footer>
|
|
|
</div>
|
|
|
|
|
|
<script>
|
|
|
const image = document.getElementById("webcamimage");
|
|
|
const controlsElement = document.getElementById("controls");
|
|
|
const variablesElement = document.getElementById("variables");
|
|
|
const notice = document.getElementById("notice");
|
|
|
const statusText = document.getElementById("status-text");
|
|
|
const connectionStatus = document.getElementById("connection-status");
|
|
|
let controls = [];
|
|
|
let filterEnabled = false;
|
|
|
let refreshCount = 0;
|
|
|
|
|
|
function post(url) {
|
|
|
return fetch(url, { method: "POST" }).then(function(response) {
|
|
|
if (!response.ok) throw new Error("Request failed: " + response.status);
|
|
|
return response.text();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function setStatus(connected, message) {
|
|
|
connectionStatus.classList.toggle("offline", !connected);
|
|
|
statusText.textContent = message;
|
|
|
}
|
|
|
|
|
|
function showError(message) {
|
|
|
notice.textContent = message;
|
|
|
notice.hidden = false;
|
|
|
}
|
|
|
|
|
|
function clearError() {
|
|
|
notice.hidden = true;
|
|
|
notice.textContent = "";
|
|
|
}
|
|
|
|
|
|
function reloadImage() {
|
|
|
const imageName = filterEnabled ? "snapshot-float.jpg" : "snapshot.jpg";
|
|
|
image.src = imageName + "?" + Date.now();
|
|
|
document.getElementById("preview-label").textContent =
|
|
|
filterEnabled ? "Processed image" : "Standard image";
|
|
|
}
|
|
|
|
|
|
image.addEventListener("load", function() {
|
|
|
document.getElementById("preview-error").hidden = true;
|
|
|
document.getElementById("last-updated").textContent =
|
|
|
"Updated " + new Date().toLocaleTimeString();
|
|
|
});
|
|
|
|
|
|
image.addEventListener("error", function() {
|
|
|
document.getElementById("preview-error").hidden = false;
|
|
|
});
|
|
|
|
|
|
document.getElementById("floatimage").addEventListener("change", function() {
|
|
|
filterEnabled = this.checked;
|
|
|
reloadImage();
|
|
|
});
|
|
|
|
|
|
function makeControlCard(control) {
|
|
|
const card = document.createElement("article");
|
|
|
card.className = "control-card";
|
|
|
card.dataset.name = String(control.name).toLocaleLowerCase();
|
|
|
|
|
|
const header = document.createElement("div");
|
|
|
header.className = "control-header";
|
|
|
const name = document.createElement("h3");
|
|
|
name.textContent = control.name;
|
|
|
const range = document.createElement("span");
|
|
|
range.className = "range-label";
|
|
|
range.textContent = control.min + " – " + control.max;
|
|
|
header.append(name, range);
|
|
|
|
|
|
const inputRow = document.createElement("div");
|
|
|
inputRow.className = "control-input-row";
|
|
|
const slider = document.createElement("input");
|
|
|
slider.className = "control-slider";
|
|
|
slider.type = "range";
|
|
|
slider.min = control.min;
|
|
|
slider.max = control.max;
|
|
|
slider.value = control.value;
|
|
|
slider.dataset.id = control.id;
|
|
|
slider.setAttribute("aria-label", control.name + " slider");
|
|
|
slider.disabled = Number(control.max) <= Number(control.min);
|
|
|
|
|
|
const value = document.createElement("input");
|
|
|
value.className = "control-value";
|
|
|
value.type = "number";
|
|
|
value.inputMode = "numeric";
|
|
|
value.min = control.min;
|
|
|
value.max = control.max;
|
|
|
value.value = control.value;
|
|
|
value.dataset.id = control.id;
|
|
|
value.setAttribute("aria-label", control.name + " value");
|
|
|
|
|
|
let submitTimeout;
|
|
|
slider.addEventListener("input", function() {
|
|
|
value.value = slider.value;
|
|
|
window.clearTimeout(submitTimeout);
|
|
|
submitTimeout = window.setTimeout(function() {
|
|
|
submitControl(value);
|
|
|
}, 300);
|
|
|
});
|
|
|
slider.addEventListener("change", function() {
|
|
|
window.clearTimeout(submitTimeout);
|
|
|
submitControl(value);
|
|
|
});
|
|
|
|
|
|
const apply = document.createElement("button");
|
|
|
apply.className = "button button-small";
|
|
|
apply.type = "button";
|
|
|
apply.dataset.action = "apply-control";
|
|
|
apply.textContent = "Apply";
|
|
|
apply.addEventListener("click", function() {
|
|
|
submitControl(value);
|
|
|
});
|
|
|
inputRow.append(slider, value, apply);
|
|
|
card.append(header, inputRow);
|
|
|
return card;
|
|
|
}
|
|
|
|
|
|
function refreshCtrls() {
|
|
|
return post("get/ctrls")
|
|
|
.then(function(response) {
|
|
|
const data = JSON.parse(response);
|
|
|
controls = data.ctrls || [];
|
|
|
const activeId = document.activeElement &&
|
|
|
(document.activeElement.classList.contains("control-value") ||
|
|
|
document.activeElement.classList.contains("control-slider"))
|
|
|
? document.activeElement.dataset.id
|
|
|
: null;
|
|
|
|
|
|
if (activeId === null) {
|
|
|
controlsElement.replaceChildren();
|
|
|
if (controls.length === 0) {
|
|
|
const empty = document.createElement("div");
|
|
|
empty.className = "empty-state";
|
|
|
empty.textContent = "No camera controls are available.";
|
|
|
controlsElement.appendChild(empty);
|
|
|
} else {
|
|
|
controls.forEach(function(control) {
|
|
|
controlsElement.appendChild(makeControlCard(control));
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
controls.forEach(function(control) {
|
|
|
const input = controlsElement.querySelector(
|
|
|
'.control-value[data-id="' + CSS.escape(String(control.id)) + '"]'
|
|
|
);
|
|
|
if (input) {
|
|
|
input.min = control.min;
|
|
|
input.max = control.max;
|
|
|
}
|
|
|
const card = input && input.closest(".control-card");
|
|
|
if (card) {
|
|
|
const slider = card.querySelector(".control-slider");
|
|
|
const isActive = input === document.activeElement ||
|
|
|
slider === document.activeElement;
|
|
|
if (!isActive) {
|
|
|
input.value = control.value;
|
|
|
slider.value = control.value;
|
|
|
}
|
|
|
slider.min = control.min;
|
|
|
slider.max = control.max;
|
|
|
slider.dataset.id = control.id;
|
|
|
slider.disabled = Number(control.max) <= Number(control.min);
|
|
|
card.querySelector(".range-label").textContent =
|
|
|
control.min + " – " + control.max;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
document.getElementById("control-count").textContent =
|
|
|
controls.length + (controls.length === 1 ? " control" : " controls");
|
|
|
setStatus(true, "Camera connected");
|
|
|
clearError();
|
|
|
filterControls();
|
|
|
}, function() {
|
|
|
setStatus(false, "Connection issue");
|
|
|
showError("Could not load camera controls. The camera service may be unavailable.");
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function refreshVariables() {
|
|
|
return post("get/variables")
|
|
|
.then(function(response) {
|
|
|
const data = JSON.parse(response);
|
|
|
const variables = data.variables || [];
|
|
|
const activeName = document.activeElement &&
|
|
|
document.activeElement.classList.contains("variable-value")
|
|
|
? document.activeElement.dataset.name
|
|
|
: null;
|
|
|
if (activeName !== null) return;
|
|
|
|
|
|
variablesElement.replaceChildren();
|
|
|
if (variables.length === 0) {
|
|
|
const empty = document.createElement("div");
|
|
|
empty.className = "empty-state";
|
|
|
empty.textContent = "No image settings are available.";
|
|
|
variablesElement.appendChild(empty);
|
|
|
return;
|
|
|
}
|
|
|
variables.forEach(function(variable) {
|
|
|
const row = document.createElement("article");
|
|
|
row.className = "setting-row";
|
|
|
const details = document.createElement("div");
|
|
|
details.className = "setting-details";
|
|
|
const name = document.createElement("h3");
|
|
|
name.textContent = variable.name.replaceAll("_", " ");
|
|
|
const description = document.createElement("p");
|
|
|
description.textContent = variable.desc;
|
|
|
details.append(name, description);
|
|
|
|
|
|
const editor = document.createElement("div");
|
|
|
editor.className = "setting-editor";
|
|
|
const input = document.createElement("input");
|
|
|
input.className = "variable-value";
|
|
|
input.type = "number";
|
|
|
input.step = "any";
|
|
|
input.value = variable.value;
|
|
|
input.dataset.name = variable.name;
|
|
|
input.setAttribute("aria-label", variable.name + " value");
|
|
|
const apply = document.createElement("button");
|
|
|
apply.className = "button button-small";
|
|
|
apply.type = "button";
|
|
|
apply.textContent = "Apply";
|
|
|
apply.addEventListener("click", function() {
|
|
|
submitVariable(input);
|
|
|
});
|
|
|
editor.append(input, apply);
|
|
|
row.append(details, editor);
|
|
|
variablesElement.appendChild(row);
|
|
|
});
|
|
|
}, function() {
|
|
|
showError("Could not load image settings.");
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function submitControl(input) {
|
|
|
if (!input.value.trim()) {
|
|
|
input.focus();
|
|
|
return;
|
|
|
}
|
|
|
post("set/ctrl/" + encodeURIComponent(input.dataset.id) + "=" +
|
|
|
encodeURIComponent(input.value)).then(function() {
|
|
|
clearError();
|
|
|
refreshCtrls();
|
|
|
}, function() {
|
|
|
showError("Could not apply the camera control.");
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function submitVariable(input) {
|
|
|
if (!input.value.trim()) {
|
|
|
input.focus();
|
|
|
return;
|
|
|
}
|
|
|
post("set/var/" + encodeURIComponent(input.dataset.name) + "=" +
|
|
|
encodeURIComponent(input.value)).then(function() {
|
|
|
clearError();
|
|
|
refreshVariables();
|
|
|
}, function() {
|
|
|
showError("Could not apply the image setting.");
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function filterControls() {
|
|
|
const query = document.getElementById("control-search").value
|
|
|
.trim().toLocaleLowerCase();
|
|
|
controlsElement.querySelectorAll(".control-card").forEach(function(card) {
|
|
|
card.hidden = !card.dataset.name.includes(query);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
document.getElementById("control-search").addEventListener("input", filterControls);
|
|
|
document.addEventListener("keydown", function(event) {
|
|
|
if (event.key !== "Enter") return;
|
|
|
if (event.target.classList.contains("control-value")) {
|
|
|
submitControl(event.target);
|
|
|
} else if (event.target.classList.contains("variable-value")) {
|
|
|
submitVariable(event.target);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
function refresh() {
|
|
|
reloadImage();
|
|
|
if (refreshCount++ % 25 === 0) {
|
|
|
refreshCtrls();
|
|
|
refreshVariables();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
refreshCtrls();
|
|
|
refreshVariables();
|
|
|
window.setInterval(refresh, 500);
|
|
|
</script>
|
|
|
</body>
|
|
|
</html>
|