changes
This commit is contained in:
+132
@@ -0,0 +1,132 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>WASM Camera Test</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, system-ui, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background: #1a1a2e;
|
||||
color: #eee;
|
||||
}
|
||||
h1 { color: #e94560; }
|
||||
video, canvas {
|
||||
max-width: 100%;
|
||||
border: 2px solid #0f3460;
|
||||
border-radius: 8px;
|
||||
background: #000;
|
||||
}
|
||||
button {
|
||||
padding: 10px 24px;
|
||||
margin: 8px 4px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
background: #e94560;
|
||||
color: white;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
button:hover:not(:disabled) { background: #c73e54; }
|
||||
#status { color: #16c79a; margin: 10px 0; }
|
||||
.container { display: flex; flex-wrap: wrap; gap: 16px; }
|
||||
.panel { flex: 1; min-width: 300px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>WASM Camera Test</h1>
|
||||
<p id="status">Click "Start Camera" to begin.</p>
|
||||
|
||||
<div>
|
||||
<button id="startBtn">Start Camera</button>
|
||||
<button id="compassBtn" disabled>Enable Compass</button>
|
||||
<button id="captureBtn" disabled>Capture Frame</button>
|
||||
<button id="saveBtn" disabled>Save PNG</button>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="panel">
|
||||
<h2>Live Feed <span id="compass" style="font-size: 0.8em; color: #16c79a;">--</span> <span id="tilt" style="font-size: 0.8em; color: #e9a945;">--</span></h2>
|
||||
<video id="video" autoplay playsinline></video>
|
||||
</div>
|
||||
<div class="panel">
|
||||
<h2>Captured Frame</h2>
|
||||
<canvas id="canvas"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="module">
|
||||
const status = document.getElementById('status');
|
||||
const startBtn = document.getElementById('startBtn');
|
||||
const captureBtn = document.getElementById('captureBtn');
|
||||
const saveBtn = document.getElementById('saveBtn');
|
||||
const compassBtn = document.getElementById('compassBtn');
|
||||
|
||||
let wasm = null;
|
||||
|
||||
async function loadWasm() {
|
||||
if (wasm) return;
|
||||
status.textContent = 'Loading WASM module...';
|
||||
wasm = await import('./pkg/rust_panorama_wasm.js');
|
||||
await wasm.default();
|
||||
}
|
||||
|
||||
startBtn.addEventListener('click', async () => {
|
||||
try {
|
||||
await loadWasm();
|
||||
status.textContent = 'Requesting camera access...';
|
||||
startBtn.disabled = true;
|
||||
await wasm.init_camera('video');
|
||||
|
||||
status.textContent = 'Camera active!';
|
||||
captureBtn.disabled = false;
|
||||
compassBtn.disabled = false;
|
||||
} catch (e) {
|
||||
status.textContent = 'Error: ' + e;
|
||||
startBtn.disabled = false;
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
compassBtn.addEventListener('click', async () => {
|
||||
try {
|
||||
await loadWasm();
|
||||
compassBtn.disabled = true;
|
||||
status.textContent = 'Requesting compass permission...';
|
||||
await wasm.start_orientation('compass', 'tilt');
|
||||
status.textContent = 'Compass active!';
|
||||
} catch (e) {
|
||||
status.textContent = 'Compass not available: ' + e;
|
||||
compassBtn.disabled = false;
|
||||
console.warn('Orientation:', e);
|
||||
}
|
||||
});
|
||||
|
||||
captureBtn.addEventListener('click', () => {
|
||||
try {
|
||||
wasm.capture_frame('video', 'canvas', 1920, 1080);
|
||||
const c = document.getElementById('canvas');
|
||||
status.textContent = `Frame captured! ${c.width}x${c.height} (Full HD fit)`;
|
||||
saveBtn.disabled = false;
|
||||
} catch (e) {
|
||||
status.textContent = 'Capture error: ' + e;
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
saveBtn.addEventListener('click', () => {
|
||||
try {
|
||||
wasm.save_png('canvas', 'capture.png');
|
||||
status.textContent = 'PNG saved!';
|
||||
} catch (e) {
|
||||
status.textContent = 'Save error: ' + e;
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user