You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

472 lines
22 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!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 previewStage = document.querySelector(".preview-stage");
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 setPreviewAspectRatio() {
if (!previewStage || !image.naturalWidth || !image.naturalHeight) return;
previewStage.style.setProperty("--preview-ratio", image.naturalWidth + " / " + image.naturalHeight);
}
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() {
setPreviewAspectRatio();
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);
if (/auto(?:matic)?.*exposure|exposure.*auto(?:matic)?/i.test(control.name)) {
const note = document.createElement("p");
note.className = "control-note";
note.textContent = "1 = Off (manual exposure).";
card.appendChild(note);
}
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.classList.contains("variable-slider"))
? 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 isControlId = variable.name === "auto_brightness";
const isRatio = variable.name === "filter_ratio" ||
variable.name === "auto_brightness_target";
const input = document.createElement(isControlId ? "select" : "input");
input.className = "variable-value";
input.dataset.name = variable.name;
input.setAttribute("aria-label", variable.name + " value");
if (isControlId) {
const currentId = String(variable.value);
const disabledOption = document.createElement("option");
disabledOption.value = "0";
disabledOption.textContent = "Disabled (ID: 0)";
input.appendChild(disabledOption);
if (currentId !== "0" && !controls.some(function(control) {
return String(control.id) === currentId;
})) {
const currentOption = document.createElement("option");
currentOption.value = currentId;
currentOption.textContent = "Unavailable control (ID: " + currentId + ")";
input.appendChild(currentOption);
}
controls.forEach(function(control) {
if (String(control.id) === "0") return;
const option = document.createElement("option");
option.value = String(control.id);
option.textContent = control.name + " (ID: " + control.id + ")";
input.appendChild(option);
});
input.value = currentId;
} else if (isRatio) {
const slider = document.createElement("input");
slider.className = "control-slider variable-slider";
slider.type = "range";
slider.min = "0";
slider.max = "1";
slider.step = "0.01";
slider.value = variable.value;
slider.dataset.name = variable.name;
slider.setAttribute("aria-label", variable.name + " slider");
input.type = "number";
input.min = "0";
input.max = "1";
input.step = "0.01";
input.value = variable.value;
input.setAttribute("aria-label", variable.name + " value");
let submitTimeout;
slider.addEventListener("input", function() {
input.value = slider.value;
window.clearTimeout(submitTimeout);
submitTimeout = window.setTimeout(function() {
submitVariable(input);
}, 300);
});
slider.addEventListener("change", function() {
window.clearTimeout(submitTimeout);
submitVariable(input);
});
input.addEventListener("input", function() {
slider.value = input.value;
});
editor.classList.add("setting-slider-editor");
editor.append(slider);
} else {
input.type = "number";
input.step = "any";
input.value = variable.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().then(refreshVariables);
}
}
refreshCtrls().then(refreshVariables);
window.setInterval(refresh, 500);
</script>
</body>
</html>