refactor(simulator): enhance mobile simulator UI with updated styles, improved security policies, and WebRTC signaling support

This commit is contained in:
2026-02-03 11:00:00 +00:00
parent f1919ca0e1
commit a2f6a22f97
5 changed files with 1184 additions and 790 deletions

View File

@@ -51,8 +51,12 @@ app.use(
helmet({ helmet({
contentSecurityPolicy: { contentSecurityPolicy: {
directives: { directives: {
scriptSrc: ["'self'", 'https://cdn.jsdelivr.net'], ...helmet.contentSecurityPolicy.getDefaultDirectives(),
connectSrc: ["'self'", 'https://cdn.jsdelivr.net'], "script-src": ["'self'", "'unsafe-inline'", "cdn.jsdelivr.net", "cdn.tailwindcss.com"],
"style-src": ["'self'", "'unsafe-inline'", "cdn.jsdelivr.net", "fonts.googleapis.com"],
"font-src": ["'self'", "fonts.gstatic.com"],
"connect-src": ["'self'", "cdn.jsdelivr.net"],
"img-src": ["'self'", "data:", "blob:"],
}, },
}, },
}), }),

View File

@@ -1,239 +1,308 @@
<!doctype html> <!DOCTYPE html>
<html lang="en" data-theme="night"> <html lang="en" data-theme="black">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SecureCam Mobile Simulator</title> <title>SecureCam Mobile Simulator</title>
<link href="https://cdn.jsdelivr.net/npm/daisyui@5" rel="stylesheet" type="text/css" /> <link href="https://cdn.jsdelivr.net/npm/daisyui@4.6.0/dist/full.min.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script> <script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style> <style>
.screen { body {
font-family: 'Inter', sans-serif;
}
.mockup-phone {
max-height: 850px;
}
.artboard {
height: 100%;
max-height: 100%;
}
/* Custom Scrollbar for activity feed */
.scrollbar-hide::-webkit-scrollbar {
display: none; display: none;
} }
.scrollbar-hide {
.screen.active { -ms-overflow-style: none;
display: block; scrollbar-width: none;
} }
.glass-panel {
.mock-block { background: rgba(20, 20, 25, 0.7);
white-space: pre-wrap; backdrop-filter: blur(10px);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace; border: 1px solid rgba(255, 255, 255, 0.08);
font-size: 12px;
} }
.btn-premium {
.chip.online { background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
--badge-color: color-mix(in oklab, var(--color-success) 35%, transparent); border: none;
--badge-fg: var(--color-success-content); color: white;
transition: all 0.2s ease;
} }
.btn-premium:hover {
.chip.offline { transform: translateY(-1px);
--badge-color: color-mix(in oklab, var(--color-error) 35%, transparent); box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
--badge-fg: var(--color-error-content);
} }
.status-dot {
.chip { height: 8px;
background: var(--badge-color); width: 8px;
color: var(--badge-fg); border-radius: 50%;
border: 1px solid color-mix(in oklab, currentColor 35%, transparent); display: inline-block;
} }
.status-online { background-color: #10b981; box-shadow: 0 0 8px rgba(16, 185, 129, 0.4); }
.status-offline { background-color: #ef4444; box-shadow: 0 0 8px rgba(239, 68, 68, 0.4); }
.nav { /* Toast Animations */
position: sticky; @keyframes slideIn {
bottom: 0; from { transform: translateY(100%); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
.toast-enter {
animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
} }
</style> </style>
</head> </head>
<body class="min-h-screen bg-base-300 p-4"> <body class="min-h-screen bg-gray-900 flex items-center justify-center p-4">
<div class="mx-auto max-w-md">
<div class="mockup-phone border-primary/30 bg-base-100 shadow-2xl"> <!-- Toast Container -->
<div class="camera"></div> <div id="toast-container" class="toast toast-center toast-bottom z-50 w-full max-w-sm" style="bottom: 80px;"></div>
<div class="mockup-phone border-gray-800 bg-gray-950 shadow-2xl">
<div class="camera bg-gray-900"></div>
<div class="display"> <div class="display">
<div class="artboard artboard-demo phone-1 bg-base-200"> <div class="artboard artboard-demo phone-1 bg-gray-950 flex flex-col relative overflow-hidden">
<div class="flex h-full flex-col">
<header class="navbar border-b border-base-300 bg-base-100/90 px-3 py-2"> <!-- Top Bar -->
<div class="flex-1"> <header class="w-full glass-panel px-4 py-3 z-10 flex justify-between items-center bg-gray-900/90 border-b border-white/5">
<div> <div>
<h1 class="text-sm font-semibold tracking-wide">SecureCam Mobile</h1> <h1 class="text-xs font-bold tracking-widest text-gray-400 uppercase">SecureCam</h1>
<p id="topSubtitle" class="text-xs text-base-content/70">Open app to continue</p> <div id="connectionStatus" class="flex items-center gap-1.5 mt-0.5">
<span class="status-dot status-offline transition-colors duration-300"></span>
<span class="text-[10px] text-gray-500 font-medium tracking-wide">OFFLINE</span>
</div> </div>
</div> </div>
<div class="flex items-center gap-1">
<span id="authChip" class="chip badge badge-sm offline">signed out</span> <div class="flex items-center gap-2">
<span id="socketChip" class="chip badge badge-sm offline">offline</span> <div id="authStatusBadge" class="badge badge-xs gap-1 border-white/10 bg-white/5 text-gray-400 p-2">
Signed Out
</div>
</div> </div>
</header> </header>
<main class="flex-1 space-y-3 overflow-auto p-3"> <!-- Main Scrollable Area -->
<section id="screen-auth" class="screen active"> <main class="flex-1 w-full overflow-y-auto overflow-x-hidden relative scrollbar-hide py-4 px-4 space-y-4">
<div class="card border border-base-300 bg-base-100 shadow-sm">
<div class="card-body gap-2 p-4">
<h2 class="card-title text-lg">Welcome</h2>
<p class="text-sm text-base-content/70">Sign in or create an account to use this phone as a camera or client.</p>
<label class="form-control w-full"> <!-- AUTH SCREEN -->
<span class="label-text text-xs">Name</span> <section id="screen-auth" class="flex flex-col h-full justify-center space-y-6 animate-fade-in">
<input id="authName" class="input input-bordered w-full" placeholder="Optional" /> <div class="text-center space-y-2">
</label> <div class="w-16 h-16 bg-gradient-to-tr from-blue-600 to-indigo-600 rounded-2xl mx-auto flex items-center justify-center shadow-lg shadow-blue-900/20">
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<label class="form-control w-full"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" />
<span class="label-text text-xs">Email</span> </svg>
<input id="authEmail" class="input input-bordered w-full" placeholder="you@example.com" />
</label>
<label class="form-control w-full">
<span class="label-text text-xs">Password</span>
<input id="authPassword" type="password" class="input input-bordered w-full" placeholder="password" />
</label>
<div class="mt-1 grid grid-cols-2 gap-2">
<button id="signUpBtn" class="btn btn-outline btn-primary">Create Account</button>
<button id="signInBtn" class="btn btn-primary">Sign In</button>
</div> </div>
<h2 class="text-2xl font-bold text-white">Welcome Back</h2>
<p class="text-sm text-gray-500">Sign in to manage visual security.</p>
</div>
<div class="space-y-3">
<div class="form-control">
<input id="authEmail" type="email" placeholder="Email address" class="input input-bordered bg-gray-900/50 border-white/10 text-sm focus:border-blue-500 focus:outline-none transition-colors" />
</div>
<div class="form-control">
<input id="authPassword" type="password" placeholder="Password" class="input input-bordered bg-gray-900/50 border-white/10 text-sm focus:border-blue-500 focus:outline-none transition-colors" />
</div>
<div id="authNameField" class="form-control hidden">
<input id="authName" type="text" placeholder="Your Name" class="input input-bordered bg-gray-900/50 border-white/10 text-sm focus:border-blue-500 focus:outline-none transition-colors" />
</div>
</div>
<div class="space-y-3 pt-2">
<button id="signInBtn" class="btn btn-premium w-full shadow-lg shadow-blue-900/20">Sign In</button>
<div class="divider text-xs text-gray-600 my-0">OR</div>
<button id="toggleAuthModeBtn" class="btn btn-ghost btn-sm w-full text-gray-400 font-normal hover:text-white hover:bg-white/5">Create an account</button>
</div>
</section>
<!-- ONBOARDING SCREEN -->
<section id="screen-onboarding" class="hidden flex-col h-full space-y-6">
<div class="text-left space-y-1">
<h2 class="text-xl font-bold text-white">Device Setup</h2>
<p class="text-xs text-gray-500">Configure this browser session as a device.</p>
</div>
<div class="p-4 rounded-xl bg-gray-900/50 border border-white/5 space-y-4">
<div class="form-control w-full">
<label class="label"><span class="label-text text-xs font-medium text-gray-400">DEVICE NAME</span></label>
<input id="deviceName" type="text" placeholder="e.g. Living Room Cam" class="input input-sm input-bordered bg-black/40 border-white/10" />
</div>
<div class="form-control w-full">
<label class="label"><span class="label-text text-xs font-medium text-gray-400">ROLE</span></label>
<div class="grid grid-cols-2 gap-2 p-1 bg-black/40 rounded-lg border border-white/5">
<button class="btn btn-sm btn-ghost normal-case text-gray-400 data-[active=true]:bg-blue-600 data-[active=true]:text-white" id="btn-role-camera" data-role="camera" data-active="false">Camera</button>
<button class="btn btn-sm btn-ghost normal-case text-gray-400 data-[active=true]:bg-blue-600 data-[active=true]:text-white" id="btn-role-client" data-role="client" data-active="true">Client</button>
</div>
<input type="hidden" id="role" value="client">
</div>
<div class="form-control w-full">
<label class="label"><span class="label-text text-xs font-medium text-gray-400">PUSH TOKEN (OPTIONAL)</span></label>
<input id="pushToken" type="text" placeholder="simulated_token_123" class="input input-sm input-bordered bg-black/40 border-white/10" />
</div>
</div>
<div class="pt-4">
<button id="registerBtn" class="btn btn-primary w-full text-white">Complete Setup</button>
<button id="loadSavedBtn" class="btn btn-ghost btn-xs w-full mt-2 text-gray-500">Load previously saved device</button>
</div>
</section>
<!-- CAMERA DASHBOARD -->
<section id="screen-home-camera" class="hidden space-y-5">
<!-- Monitoring Card -->
<div class="relative overflow-hidden rounded-2xl bg-gray-900 border border-white/5 aspect-video flex flex-col items-center justify-center group">
<div id="cameraPreview" class="absolute inset-0 bg-black/50 flex items-center justify-center transition-colors">
<video id="cameraVideo" class="absolute inset-0 w-full h-full object-cover hidden" autoplay playsinline muted></video>
<div class="animate-pulse flex flex-col items-center gap-2">
<span class="w-3 h-3 bg-red-500 rounded-full shadow-[0_0_12px_rgba(239,68,68,0.6)]"></span>
<span class="text-xs text-red-400 font-mono tracking-widest uppercase">Recording</span>
</div>
</div>
<div id="cameraOfflineOverlay" class="absolute inset-0 bg-gray-900 z-10 flex flex-col items-center justify-center gap-3">
<svg xmlns="http://www.w3.org/2000/svg" class="h-10 w-10 text-gray-700" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636" />
</svg>
<p class="text-xs text-gray-500 font-medium">Camera Offline</p>
<button id="cameraGoOnlineBtn" class="btn btn-outline btn-xs btn-success gap-1">
Go Online
</button>
</div>
</div>
<!-- Controls -->
<div class="grid grid-cols-2 gap-3">
<button id="startMotionBtn" class="btn h-auto py-3 flex-col bg-gray-900/60 border-white/5 hover:bg-red-900/20 hover:border-red-500/30 group">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-red-500 mb-1 group-hover:scale-110 transition-transform" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
</svg>
<span class="text-xs text-gray-400">Trigger Motion</span>
</button>
<button id="endMotionBtn" class="btn h-auto py-3 flex-col bg-gray-900/60 border-white/5 hover:bg-gray-800 disabled:opacity-30" disabled>
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-gray-400 mb-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 10a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1h-4a1 1 0 01-1-1v-4z" />
</svg>
<span class="text-xs text-gray-400">Stop Recording</span>
</button>
</div>
<!-- Recent Logs -->
<div class="space-y-2">
<h3 class="text-xs font-bold text-gray-500 uppercase tracking-wider pl-1">System Logs</h3>
<div id="cameraLogs" class="bg-black/30 rounded-lg p-2 text-[10px] font-mono text-gray-400 h-32 overflow-auto border border-white/5">
<div class="text-gray-600 italic">No activity yet...</div>
</div> </div>
</div> </div>
</section> </section>
<section id="screen-onboarding" class="screen">
<div class="card border border-base-300 bg-base-100 shadow-sm">
<div class="card-body gap-2 p-4">
<h2 class="card-title text-lg">Set Up This Phone</h2>
<p class="text-sm text-base-content/70">Choose how this phone should behave in your home security setup.</p>
<label class="form-control w-full"> <!-- CLIENT DASHBOARD -->
<span class="label-text text-xs">Device Name</span> <section id="screen-home-client" class="hidden space-y-5">
<input id="deviceName" class="input input-bordered w-full" placeholder="e.g. Hallway iPhone" /> <div class="relative overflow-hidden rounded-2xl bg-gray-900 border border-white/5 aspect-video">
</label> <video id="clientStreamVideo" class="absolute inset-0 w-full h-full object-cover hidden" autoplay playsinline></video>
<img id="clientStreamImage" class="absolute inset-0 w-full h-full object-cover hidden" alt="Live stream preview" />
<div id="clientStreamPlaceholder" class="absolute inset-0 flex flex-col items-center justify-center gap-2 text-gray-500">
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 text-gray-700" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z" />
</svg>
<p class="text-xs">No active live stream</p>
</div>
</div>
<label class="form-control w-full"> <!-- Quick Actions -->
<span class="label-text text-xs">Mode</span> <div class="flex gap-2 overflow-x-auto pb-1 scrollbar-hide">
<select id="role" class="select select-bordered w-full"> <button id="linkCameraBtn" class="btn btn-sm btn-outline border-white/10 text-gray-300 gap-2 shrink-0">
<option value="client">Client (viewer)</option> <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" /></svg>
<option value="camera">Camera (records)</option> Link Camera
</select> </button>
</label> <button id="refreshClientBtn" class="btn btn-sm btn-ghost btn-square shrink-0">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" /></svg>
</button>
</div>
<label class="form-control w-full"> <!-- Live Feeds Section -->
<span class="label-text text-xs">Push Token (optional)</span> <div class="space-y-3">
<input id="pushToken" class="input input-bordered w-full" placeholder="simulated push token" /> <h3 class="text-xs font-bold text-gray-500 uppercase tracking-wider pl-1">Linked Cameras</h3>
</label> <div id="linkedCamerasList" class="space-y-3">
<!-- Populated by JS -->
<div class="text-center py-8 bg-gray-900/30 rounded-xl border border-dashed border-gray-800">
<p class="text-gray-600 text-xs">No cameras linked yet</p>
</div>
</div>
</div>
<button id="registerBtn" class="btn btn-primary mt-1">Finish Setup</button> <!-- Recordings Section -->
<button id="loadSavedBtn" class="btn btn-outline">Load Existing Device</button> <div class="space-y-3">
<h3 class="text-xs font-bold text-gray-500 uppercase tracking-wider pl-1">Recent Recordings</h3>
<div id="recordingsList" class="space-y-2">
<!-- Populated by JS -->
</div> </div>
</div> </div>
</section> </section>
<section id="screen-home-client" class="screen"> <!-- ACTIVITY SCREEN -->
<div class="card border border-base-300 bg-base-100 shadow-sm"> <section id="screen-activity" class="hidden space-y-4">
<div class="card-body gap-2 p-4"> <div class="flex items-center justify-between">
<h2 class="card-title text-lg">Client Home</h2> <h2 class="text-lg font-bold text-white">Activity Feed</h2>
<p class="text-sm text-base-content/70">Monitor cameras and request live streams.</p> <button id="clearActivityBtn" class="btn btn-ghost btn-xs text-gray-500">Clear</button>
<div class="grid grid-cols-2 gap-2">
<button id="connectBtn" class="btn btn-success">Go Online</button>
<button id="disconnectBtn" class="btn btn-outline">Go Offline</button>
</div> </div>
<label class="form-control w-full"> <div id="activityFeedList" class="space-y-3">
<span class="label-text text-xs">Camera Device ID</span> <!-- Empty State -->
<input id="targetCameraId" class="input input-bordered w-full" placeholder="camera uuid" /> <div class="text-center py-10 opacity-50">
</label> <svg xmlns="http://www.w3.org/2000/svg" class="h-10 w-10 mx-auto mb-2 text-gray-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9" />
<div class="grid grid-cols-2 gap-2"> </svg>
<button id="linkBtn" class="btn btn-outline btn-primary">Link Camera</button> <p class="text-sm text-gray-500">No notifications yet</p>
<button id="requestStreamBtn" class="btn btn-primary">Request Live View</button>
</div>
<div class="grid grid-cols-2 gap-2">
<button id="fetchSubscribeBtn" class="btn btn-outline">Subscribe Credentials</button>
<button id="fetchPlaybackBtn" class="btn btn-outline">Playback Token</button>
</div>
<div class="grid grid-cols-2 gap-2">
<button id="listRecordingsBtn" class="btn btn-outline">My Recordings</button>
<button id="downloadLatestRecordingBtn" class="btn btn-outline">Latest Download URL</button>
</div>
</div> </div>
</div> </div>
</section> </section>
<section id="screen-home-camera" class="screen"> <!-- SETTINGS SCREEN -->
<div class="card border border-base-300 bg-base-100 shadow-sm"> <section id="screen-settings" class="hidden space-y-5">
<div class="card-body gap-2 p-4"> <div class="p-4 rounded-xl bg-gray-900/50 border border-white/5 text-center">
<h2 class="card-title text-lg">Camera Home</h2> <div class="w-16 h-16 bg-gray-800 rounded-full mx-auto mb-3 flex items-center justify-center text-xl font-bold text-gray-400" id="profileInitials">U</div>
<p class="text-sm text-base-content/70">Detect motion, stream live, and finalize recordings.</p> <h3 class="text-white font-medium" id="profileName">User</h3>
<p class="text-xs text-gray-500" id="profileEmail">user@example.com</p>
<div class="grid grid-cols-2 gap-2">
<button id="connectBtnCam" class="btn btn-success">Go Online</button>
<button id="disconnectBtnCam" class="btn btn-outline">Go Offline</button>
</div> </div>
<div class="grid grid-cols-2 gap-2"> <div class="menu bg-gray-900/30 rounded-lg p-2 border border-white/5 text-sm">
<button id="startMotionBtn" class="btn btn-warning">Start Motion</button> <li><a id="checkOpsBtn" class="gap-3 text-gray-300"><svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" /></svg> Run Diagnostics</a></li>
<button id="endMotionBtn" class="btn btn-error">End Motion</button> <li><a class="gap-3 text-gray-300"><svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" /><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /></svg> Device Info</a></li>
</div> </div>
<div class="grid grid-cols-2 gap-2"> <button id="signOutBtn" class="btn btn-error btn-outline w-full gap-2">
<button id="fetchPublishBtn" class="btn btn-outline">Publish Credentials</button> <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 11-6 0v-1m6 0H9" /></svg>
<button id="finalizeRecordingBtn" class="btn btn-outline">Finalize Latest Recording</button> Sign Out
</div> </button>
</div>
</div>
</section> </section>
<section id="screen-activity" class="screen">
<div class="card border border-base-300 bg-base-100 shadow-sm">
<div class="card-body gap-2 p-4">
<h2 class="card-title text-lg">Activity</h2>
<p class="text-sm text-base-content/70">Realtime events and push inbox.</p>
<div class="grid grid-cols-2 gap-2">
<button id="pollPushInboxBtn" class="btn btn-outline">Refresh Push Inbox</button>
<button id="markLatestPushReadBtn" class="btn btn-outline">Mark Latest Read</button>
</div>
<div class="grid grid-cols-2 gap-2">
<button id="dispatchPushWorkerBtn" class="btn btn-outline">Dispatch Push Worker</button>
<button id="fetchAuditBtn" class="btn btn-outline">My Audit Logs</button>
</div>
<div id="activityState" class="mock-block rounded-box border border-base-300 bg-base-200 p-3"></div>
<div id="eventLog" class="mock-block rounded-box max-h-72 overflow-auto border border-base-300 bg-base-200 p-3"></div>
</div>
</div>
</section>
<section id="screen-account" class="screen">
<div class="card border border-base-300 bg-base-100 shadow-sm">
<div class="card-body gap-2 p-4">
<h2 class="card-title text-lg">Account</h2>
<div class="grid grid-cols-2 gap-2">
<button id="sessionBtn" class="btn btn-outline">Check Session</button>
<button id="signOutBtn" class="btn btn-error">Sign Out</button>
</div>
<div class="grid grid-cols-3 gap-2">
<button id="checkLiveBtn" class="btn btn-outline btn-sm">Ops Live</button>
<button id="checkReadyBtn" class="btn btn-outline btn-sm">Ops Ready</button>
<button id="checkMetricsBtn" class="btn btn-outline btn-sm">Ops Metrics</button>
</div>
<div id="accountState" class="mock-block rounded-box border border-base-300 bg-base-200 p-3"></div>
</div>
</div>
</section>
</main> </main>
<nav id="bottomNav" class="nav hidden border-t border-base-300 bg-base-100 p-2"> <!-- Navigation Bar (Dynamic) -->
<div class="grid grid-cols-3 gap-2"> <nav id="bottomNav" class="w-full glass-panel border-t border-white/5 py-4 px-6 flex justify-between items-center z-10 hidden">
<button id="navHome" class="btn btn-primary btn-sm">Home</button> <button class="nav-btn w-10 h-10 rounded-full flex items-center justify-center text-gray-500 hover:text-blue-500 hover:bg-blue-500/10 transition-all data-[active=true]:text-blue-500 data-[active=true]:bg-blue-500/10" data-target="home">
<button id="navActivity" class="btn btn-outline btn-sm">Activity</button> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" /></svg>
<button id="navAccount" class="btn btn-outline btn-sm">Account</button> </button>
</div> <button class="nav-btn w-10 h-10 rounded-full flex items-center justify-center text-gray-500 hover:text-blue-500 hover:bg-blue-500/10 transition-all relative data-[active=true]:text-blue-500 data-[active=true]:bg-blue-500/10" data-target="activity">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9" /></svg>
<span id="notificationDot" class="absolute top-2 right-2 w-2 h-2 bg-red-500 rounded-full hidden"></span>
</button>
<button class="nav-btn w-10 h-10 rounded-full flex items-center justify-center text-gray-500 hover:text-blue-500 hover:bg-blue-500/10 transition-all data-[active=true]:text-blue-500 data-[active=true]:bg-blue-500/10" data-target="settings">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" /><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /></svg>
</button>
</nav> </nav>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

File diff suppressed because it is too large Load Diff

View File

@@ -19,6 +19,13 @@ const commandAckSchema = z.object({
error: z.string().optional(), error: z.string().optional(),
}); });
const webrtcSignalSchema = z.object({
toDeviceId: z.string().uuid(),
streamSessionId: z.string().uuid(),
signalType: z.enum(['offer', 'answer', 'candidate', 'hangup']),
data: z.record(z.string(), z.unknown()).nullable().optional(),
});
const roomForDevice = (deviceId: string): string => `device:${deviceId}`; const roomForDevice = (deviceId: string): string => `device:${deviceId}`;
let io: SocketIOServer | null = null; let io: SocketIOServer | null = null;
@@ -286,6 +293,34 @@ export const setupRealtimeGateway = (server: HttpServer): SocketIOServer => {
}); });
}); });
socket.on('webrtc:signal', async (input) => {
const parsed = webrtcSignalSchema.safeParse(input);
if (!parsed.success) {
socket.emit('error:webrtc_signal', {
message: 'Invalid WebRTC signal payload',
errors: parsed.error.flatten(),
});
return;
}
const targetDevice = await db.query.devices.findFirst({
where: and(eq(devices.id, parsed.data.toDeviceId), eq(devices.userId, auth.userId)),
});
if (!targetDevice) {
socket.emit('error:webrtc_signal', { message: 'Target device not found for this account' });
return;
}
io?.to(roomForDevice(parsed.data.toDeviceId)).emit('webrtc:signal', {
fromDeviceId: auth.deviceId,
streamSessionId: parsed.data.streamSessionId,
signalType: parsed.data.signalType,
data: parsed.data.data ?? null,
});
});
socket.on('disconnect', async () => { socket.on('disconnect', async () => {
// Small delay allows fast reconnects to reuse presence without flapping. // Small delay allows fast reconnects to reuse presence without flapping.
setTimeout(async () => { setTimeout(async () => {

View File

@@ -3,7 +3,7 @@ import { Router } from 'express';
import { z } from 'zod'; import { z } from 'zod';
import { db } from '../db/client'; import { db } from '../db/client';
import { devices } from '../db/schema'; import { deviceLinks, devices } from '../db/schema';
import { requireAuth } from '../middleware/auth'; import { requireAuth } from '../middleware/auth';
import { requireDeviceAuth } from '../middleware/device-auth'; import { requireDeviceAuth } from '../middleware/device-auth';
import { createDeviceToken } from '../utils/device-token'; import { createDeviceToken } from '../utils/device-token';
@@ -84,6 +84,22 @@ router.post('/register', requireAuth, async (req, res) => {
return; return;
} }
const oppositeRole = device.role === 'camera' ? 'client' : 'camera';
const oppositeDevices = await db.query.devices.findMany({
where: and(eq(devices.userId, device.userId), eq(devices.role, oppositeRole)),
});
if (oppositeDevices.length > 0) {
const linksToCreate = oppositeDevices.map((otherDevice) => ({
ownerUserId: device.userId,
cameraDeviceId: device.role === 'camera' ? device.id : otherDevice.id,
clientDeviceId: device.role === 'client' ? device.id : otherDevice.id,
status: 'active' as const,
}));
await db.insert(deviceLinks).values(linksToCreate).onConflictDoNothing();
}
const deviceToken = createDeviceToken({ const deviceToken = createDeviceToken({
userId: device.userId, userId: device.userId,
deviceId: device.id, deviceId: device.id,