a9820abc37
- Add POST /api/homekit/pair endpoint that calls hap.Pair() from go2rtc - Rewrite homekit.html with PIN input UI (XXX-XX-XXX format) - Auto-advance between digit fields, paste support, error/success states - On successful pairing, redirect to create.html with homekit:// URL - Pass mdns_port and mdns_paired from probe to homekit.html - Detect HomeKit cameras regardless of pairing status
565 lines
18 KiB
HTML
565 lines
18 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
<meta name="theme-color" content="#0a0a0f">
|
|
<title>Strix - HomeKit Pairing</title>
|
|
<style>
|
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
:root {
|
|
--bg-primary: #0a0a0f;
|
|
--bg-secondary: #1a1a24;
|
|
--bg-tertiary: #24242f;
|
|
--bg-elevated: #2a2a38;
|
|
--purple-primary: #8b5cf6;
|
|
--purple-light: #a78bfa;
|
|
--purple-dark: #7c3aed;
|
|
--purple-glow: rgba(139, 92, 246, 0.3);
|
|
--purple-glow-strong: rgba(139, 92, 246, 0.5);
|
|
--text-primary: #e0e0e8;
|
|
--text-secondary: #a0a0b0;
|
|
--text-tertiary: #606070;
|
|
--success: #10b981;
|
|
--error: #ef4444;
|
|
--border-color: rgba(139, 92, 246, 0.15);
|
|
--font-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
|
--font-mono: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
|
|
--transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
--transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
--shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
|
|
}
|
|
|
|
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
|
|
|
|
body {
|
|
font-family: var(--font-primary);
|
|
background: var(--bg-primary);
|
|
color: var(--text-primary);
|
|
line-height: 1.5;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.screen {
|
|
min-height: 100vh; padding: 1.5rem;
|
|
display: flex; align-items: flex-start; justify-content: center;
|
|
animation: fadeIn var(--transition-base);
|
|
}
|
|
|
|
.container { max-width: 520px; width: 100%; margin-top: 6vh; }
|
|
|
|
@media (min-width: 768px) {
|
|
.screen { padding: 3rem 1.5rem; }
|
|
}
|
|
|
|
.btn-back {
|
|
display: inline-flex; align-items: center; gap: 0.5rem;
|
|
background: none; border: none;
|
|
color: var(--text-secondary); font-size: 0.875rem;
|
|
font-family: var(--font-primary); cursor: pointer;
|
|
padding: 0.5rem 0; margin-bottom: 2rem;
|
|
transition: color var(--transition-fast);
|
|
}
|
|
.btn-back:hover { color: var(--purple-primary); }
|
|
|
|
.card {
|
|
background: var(--bg-secondary);
|
|
border: 1px solid var(--border-color);
|
|
border-radius: 12px;
|
|
padding: 2rem;
|
|
text-align: center;
|
|
}
|
|
|
|
.card-icon {
|
|
width: 48px; height: 48px;
|
|
margin: 0 auto 1.25rem;
|
|
color: var(--purple-light);
|
|
}
|
|
|
|
.card-title {
|
|
font-size: 1.25rem; font-weight: 600;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.card-badge {
|
|
display: inline-block;
|
|
padding: 0.25rem 0.75rem;
|
|
background: rgba(139, 92, 246, 0.15);
|
|
border: 1px solid rgba(139, 92, 246, 0.3);
|
|
border-radius: 6px;
|
|
font-size: 0.75rem; font-weight: 600;
|
|
color: var(--purple-light);
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.05em;
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
|
|
.device-info {
|
|
background: var(--bg-tertiary);
|
|
border: 1px solid var(--border-color);
|
|
border-radius: 8px;
|
|
padding: 1rem;
|
|
margin-bottom: 1.5rem;
|
|
text-align: left;
|
|
}
|
|
|
|
.device-row {
|
|
display: flex; justify-content: space-between;
|
|
padding: 0.375rem 0;
|
|
font-size: 0.8125rem;
|
|
}
|
|
|
|
.device-row:not(:last-child) {
|
|
border-bottom: 1px solid rgba(139, 92, 246, 0.07);
|
|
}
|
|
|
|
.device-label { color: var(--text-tertiary); }
|
|
.device-value { color: var(--text-primary); font-family: var(--font-mono); font-size: 0.75rem; }
|
|
|
|
/* PIN input */
|
|
.pin-section { margin-bottom: 1.5rem; }
|
|
|
|
.pin-label {
|
|
font-size: 0.875rem; font-weight: 500;
|
|
color: var(--text-secondary);
|
|
margin-bottom: 0.75rem;
|
|
}
|
|
|
|
.pin-hint {
|
|
font-size: 0.75rem; color: var(--text-tertiary);
|
|
margin-top: 0.625rem;
|
|
}
|
|
|
|
.pin-row {
|
|
display: flex; align-items: center; justify-content: center;
|
|
gap: 0;
|
|
}
|
|
|
|
.pin-group {
|
|
display: flex; gap: 0.375rem;
|
|
}
|
|
|
|
.pin-separator {
|
|
font-size: 1.5rem; font-weight: 300;
|
|
color: var(--text-tertiary);
|
|
padding: 0 0.5rem;
|
|
line-height: 1;
|
|
user-select: none;
|
|
}
|
|
|
|
.pin-digit {
|
|
width: 44px; height: 56px;
|
|
background: var(--bg-primary);
|
|
border: 2px solid var(--border-color);
|
|
border-radius: 8px;
|
|
color: var(--text-primary);
|
|
font-family: var(--font-mono);
|
|
font-size: 1.375rem; font-weight: 600;
|
|
text-align: center;
|
|
outline: none;
|
|
transition: all var(--transition-fast);
|
|
caret-color: var(--purple-primary);
|
|
-moz-appearance: textfield;
|
|
}
|
|
|
|
.pin-digit::-webkit-inner-spin-button,
|
|
.pin-digit::-webkit-outer-spin-button {
|
|
-webkit-appearance: none; margin: 0;
|
|
}
|
|
|
|
.pin-digit:focus {
|
|
border-color: var(--purple-primary);
|
|
box-shadow: 0 0 0 3px var(--purple-glow);
|
|
}
|
|
|
|
.pin-digit.filled {
|
|
border-color: var(--purple-light);
|
|
background: rgba(139, 92, 246, 0.06);
|
|
}
|
|
|
|
.pin-digit.error {
|
|
border-color: var(--error);
|
|
box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
|
|
animation: shake 0.4s ease;
|
|
}
|
|
|
|
.pin-digit.success {
|
|
border-color: var(--success);
|
|
box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
|
|
}
|
|
|
|
@media (max-width: 400px) {
|
|
.pin-digit { width: 36px; height: 48px; font-size: 1.125rem; }
|
|
.pin-separator { padding: 0 0.25rem; font-size: 1.25rem; }
|
|
.pin-group { gap: 0.25rem; }
|
|
}
|
|
|
|
/* Error message */
|
|
.error-msg {
|
|
margin-top: 1rem; padding: 0.75rem 1rem;
|
|
background: rgba(239, 68, 68, 0.08);
|
|
border: 1px solid rgba(239, 68, 68, 0.2);
|
|
border-radius: 8px;
|
|
font-size: 0.8125rem; color: var(--error);
|
|
text-align: left;
|
|
display: none;
|
|
animation: fadeIn var(--transition-fast);
|
|
}
|
|
|
|
.error-msg.visible { display: block; }
|
|
|
|
/* Buttons */
|
|
.btn {
|
|
display: inline-flex; align-items: center; justify-content: center;
|
|
gap: 0.5rem; padding: 1rem 1.5rem; border-radius: 8px;
|
|
font-size: 0.9375rem; font-weight: 600; font-family: var(--font-primary);
|
|
cursor: pointer; transition: all var(--transition-fast);
|
|
border: none; outline: none; width: 100%;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, var(--purple-primary), var(--purple-dark));
|
|
color: white; box-shadow: 0 4px 12px var(--purple-glow);
|
|
}
|
|
.btn-primary:hover:not(:disabled) {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 8px 20px var(--purple-glow-strong);
|
|
}
|
|
.btn-primary:active:not(:disabled) { transform: translateY(0); }
|
|
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
|
|
.btn-outline {
|
|
background: transparent; color: var(--text-secondary);
|
|
border: 1px solid var(--border-color);
|
|
margin-top: 0.75rem;
|
|
}
|
|
.btn-outline:hover { border-color: var(--purple-primary); color: var(--purple-light); }
|
|
|
|
/* Pairing state */
|
|
.pairing-spinner {
|
|
width: 20px; height: 20px;
|
|
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
border-top-color: white;
|
|
border-radius: 50%;
|
|
animation: spin 0.7s linear infinite;
|
|
}
|
|
|
|
@keyframes spin { to { transform: rotate(360deg); } }
|
|
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
|
@keyframes shake {
|
|
0%, 100% { transform: translateX(0); }
|
|
20%, 60% { transform: translateX(-4px); }
|
|
40%, 80% { transform: translateX(4px); }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="screen">
|
|
<div class="container">
|
|
<button class="btn-back" id="btn-back">
|
|
<svg width="20" height="20" viewBox="0 0 20 20" fill="none">
|
|
<path d="M12 4L6 10l6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
|
</svg>
|
|
Back
|
|
</button>
|
|
|
|
<div class="card">
|
|
<svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z"/>
|
|
<polyline points="9 22 9 12 15 12 15 22"/>
|
|
</svg>
|
|
|
|
<h2 class="card-title" id="card-title">HomeKit Camera</h2>
|
|
<div class="card-badge">Apple HomeKit</div>
|
|
|
|
<div id="device-info" class="device-info"></div>
|
|
|
|
<div class="pin-section">
|
|
<div class="pin-label">Enter the 8-digit code from your camera</div>
|
|
|
|
<div class="pin-row" id="pin-row">
|
|
<div class="pin-group" id="group-0"></div>
|
|
<span class="pin-separator">-</span>
|
|
<div class="pin-group" id="group-1"></div>
|
|
<span class="pin-separator">-</span>
|
|
<div class="pin-group" id="group-2"></div>
|
|
</div>
|
|
|
|
<div class="pin-hint">Printed on the camera or in the manual</div>
|
|
</div>
|
|
|
|
<div class="error-msg" id="error-msg"></div>
|
|
|
|
<button class="btn btn-primary" id="btn-pair" disabled>Pair Device</button>
|
|
<button class="btn btn-outline" id="btn-standard">Try Standard Discovery</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
var params = new URLSearchParams(location.search);
|
|
|
|
var ip = params.get('ip') || '';
|
|
var ports = params.get('ports') || '';
|
|
var mac = params.get('mac') || '';
|
|
var vendor = params.get('vendor') || '';
|
|
var server = params.get('server') || '';
|
|
var hostname = params.get('hostname') || '';
|
|
var latency = params.get('latency') || '';
|
|
var mdnsName = params.get('mdns_name') || '';
|
|
var mdnsModel = params.get('mdns_model') || '';
|
|
var mdnsCategory = params.get('mdns_category') || '';
|
|
var mdnsPort = params.get('mdns_port') || '';
|
|
var mdnsPaired = params.get('mdns_paired') || '';
|
|
var mdnsDeviceId = params.get('mdns_device_id') || '';
|
|
|
|
// title
|
|
if (mdnsName) document.getElementById('card-title').textContent = mdnsName;
|
|
|
|
// device info
|
|
var infoDiv = document.getElementById('device-info');
|
|
var rows = [];
|
|
if (ip) rows.push(['IP Address', ip]);
|
|
if (mdnsModel) rows.push(['Model', mdnsModel]);
|
|
if (mdnsCategory) rows.push(['Category', mdnsCategory]);
|
|
if (vendor) rows.push(['Vendor', vendor]);
|
|
if (mac) rows.push(['MAC', mac]);
|
|
|
|
rows.forEach(function(r) {
|
|
var row = document.createElement('div');
|
|
row.className = 'device-row';
|
|
var label = document.createElement('span');
|
|
label.className = 'device-label';
|
|
label.textContent = r[0];
|
|
var value = document.createElement('span');
|
|
value.className = 'device-value';
|
|
value.textContent = r[1];
|
|
row.appendChild(label);
|
|
row.appendChild(value);
|
|
infoDiv.appendChild(row);
|
|
});
|
|
|
|
if (rows.length === 0) infoDiv.style.display = 'none';
|
|
|
|
// PIN input -- 8 digits: 3-2-3
|
|
var pinGroups = [3, 2, 3];
|
|
var inputs = [];
|
|
|
|
pinGroups.forEach(function(count, gi) {
|
|
var group = document.getElementById('group-' + gi);
|
|
for (var i = 0; i < count; i++) {
|
|
var input = document.createElement('input');
|
|
input.type = 'text';
|
|
input.inputMode = 'numeric';
|
|
input.pattern = '[0-9]';
|
|
input.maxLength = 1;
|
|
input.className = 'pin-digit';
|
|
input.autocomplete = 'off';
|
|
group.appendChild(input);
|
|
inputs.push(input);
|
|
}
|
|
});
|
|
|
|
inputs.forEach(function(input, idx) {
|
|
input.addEventListener('input', function(e) {
|
|
var v = input.value.replace(/\D/g, '');
|
|
input.value = v ? v[0] : '';
|
|
|
|
hideError();
|
|
|
|
if (v && idx < inputs.length - 1) {
|
|
inputs[idx + 1].focus();
|
|
}
|
|
|
|
updateState();
|
|
});
|
|
|
|
input.addEventListener('keydown', function(e) {
|
|
if (e.key === 'Backspace') {
|
|
if (input.value === '' && idx > 0) {
|
|
inputs[idx - 1].focus();
|
|
inputs[idx - 1].value = '';
|
|
updateState();
|
|
e.preventDefault();
|
|
}
|
|
}
|
|
|
|
if (e.key === 'ArrowLeft' && idx > 0) {
|
|
inputs[idx - 1].focus();
|
|
e.preventDefault();
|
|
}
|
|
if (e.key === 'ArrowRight' && idx < inputs.length - 1) {
|
|
inputs[idx + 1].focus();
|
|
e.preventDefault();
|
|
}
|
|
|
|
if (e.key === 'Enter') {
|
|
doPair();
|
|
}
|
|
});
|
|
|
|
input.addEventListener('focus', function() {
|
|
input.select();
|
|
});
|
|
|
|
// paste support -- distribute digits across fields
|
|
input.addEventListener('paste', function(e) {
|
|
e.preventDefault();
|
|
var text = (e.clipboardData || window.clipboardData).getData('text');
|
|
var digits = text.replace(/\D/g, '');
|
|
|
|
for (var i = 0; i < digits.length && idx + i < inputs.length; i++) {
|
|
inputs[idx + i].value = digits[i];
|
|
}
|
|
|
|
var next = Math.min(idx + digits.length, inputs.length - 1);
|
|
inputs[next].focus();
|
|
updateState();
|
|
});
|
|
});
|
|
|
|
function getPin() {
|
|
var pin = '';
|
|
for (var i = 0; i < inputs.length; i++) {
|
|
pin += inputs[i].value;
|
|
}
|
|
return pin;
|
|
}
|
|
|
|
function updateState() {
|
|
var pin = getPin();
|
|
document.getElementById('btn-pair').disabled = pin.length !== 8;
|
|
|
|
inputs.forEach(function(input) {
|
|
if (input.value) {
|
|
input.classList.add('filled');
|
|
} else {
|
|
input.classList.remove('filled');
|
|
}
|
|
input.classList.remove('error');
|
|
input.classList.remove('success');
|
|
});
|
|
}
|
|
|
|
function showError(msg) {
|
|
var el = document.getElementById('error-msg');
|
|
el.textContent = msg;
|
|
el.classList.add('visible');
|
|
inputs.forEach(function(input) { input.classList.add('error'); });
|
|
}
|
|
|
|
function hideError() {
|
|
document.getElementById('error-msg').classList.remove('visible');
|
|
}
|
|
|
|
function showSuccess() {
|
|
inputs.forEach(function(input) {
|
|
input.classList.remove('error');
|
|
input.classList.add('success');
|
|
});
|
|
}
|
|
|
|
// pair
|
|
var btnPair = document.getElementById('btn-pair');
|
|
btnPair.addEventListener('click', doPair);
|
|
|
|
async function doPair() {
|
|
var pin = getPin();
|
|
if (pin.length !== 8) return;
|
|
|
|
var port = parseInt(mdnsPort, 10);
|
|
if (!ip || !port || !mdnsDeviceId) {
|
|
showError('Missing device information. Go back and re-probe.');
|
|
return;
|
|
}
|
|
|
|
hideError();
|
|
|
|
btnPair.disabled = true;
|
|
var origText = btnPair.textContent;
|
|
btnPair.textContent = '';
|
|
|
|
var spinner = document.createElement('div');
|
|
spinner.className = 'pairing-spinner';
|
|
btnPair.appendChild(spinner);
|
|
|
|
var label = document.createTextNode(' Pairing...');
|
|
btnPair.appendChild(label);
|
|
|
|
inputs.forEach(function(input) { input.disabled = true; });
|
|
|
|
try {
|
|
var r = await fetch('api/homekit/pair', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
ip: ip,
|
|
port: port,
|
|
device_id: mdnsDeviceId,
|
|
pin: pin
|
|
})
|
|
});
|
|
|
|
if (!r.ok) {
|
|
var text = await r.text();
|
|
inputs.forEach(function(input) { input.disabled = false; });
|
|
btnPair.textContent = origText;
|
|
updateState();
|
|
showError(text || 'Pairing failed (HTTP ' + r.status + ')');
|
|
inputs[0].focus();
|
|
return;
|
|
}
|
|
|
|
var data = await r.json();
|
|
|
|
showSuccess();
|
|
btnPair.textContent = '';
|
|
var check = document.createTextNode('Paired!');
|
|
btnPair.appendChild(check);
|
|
|
|
// redirect to create.html with the homekit URL
|
|
setTimeout(function() {
|
|
var p = new URLSearchParams();
|
|
p.set('url', data.url);
|
|
if (ip) p.set('ip', ip);
|
|
if (mac) p.set('mac', mac);
|
|
if (vendor) p.set('vendor', vendor);
|
|
if (mdnsName) p.set('model', mdnsName);
|
|
if (hostname) p.set('hostname', hostname);
|
|
window.location.href = 'create.html?' + p.toString();
|
|
}, 800);
|
|
|
|
} catch (e) {
|
|
inputs.forEach(function(input) { input.disabled = false; });
|
|
btnPair.textContent = origText;
|
|
updateState();
|
|
showError('Connection error: ' + e.message);
|
|
}
|
|
}
|
|
|
|
// navigation
|
|
document.getElementById('btn-back').addEventListener('click', function() {
|
|
window.location.href = 'index.html';
|
|
});
|
|
|
|
document.getElementById('btn-standard').addEventListener('click', function() {
|
|
var p = new URLSearchParams();
|
|
if (ip) p.set('ip', ip);
|
|
if (ports) p.set('ports', ports);
|
|
if (mac) p.set('mac', mac);
|
|
if (vendor) p.set('vendor', vendor);
|
|
if (server) p.set('server', server);
|
|
if (hostname) p.set('hostname', hostname);
|
|
if (latency) p.set('latency', latency);
|
|
window.location.href = 'standard.html?' + p.toString();
|
|
});
|
|
|
|
// autofocus first input
|
|
inputs[0].focus();
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|