| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Nebucast Viewer</title>
- <style>
- *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
- :root{
- --bg:#0f0f0f; --surface:#1a1a1a; --border:#2a2a2a;
- --text:#e0e0e0; --text-dim:#888; --accent:#6c8cff; --red:#ff5555;
- }
- html,body{height:100%;font-family:system-ui,-apple-system,sans-serif;background:var(--bg);color:var(--text)}
- #app{display:flex;flex-direction:column;height:100vh}
- header{
- display:flex;align-items:center;justify-content:space-between;
- padding:12px 20px;background:var(--surface);border-bottom:1px solid var(--border);
- flex-shrink:0;
- }
- header h1{font-size:16px;font-weight:600;letter-spacing:-.3px}
- #status{
- display:flex;align-items:center;gap:8px;
- font-size:13px;color:var(--text-dim);
- }
- #status .dot{
- width:8px;height:8px;border-radius:50%;background:var(--red);
- transition:background .3s;
- }
- #status.live .dot{background:#44cc44;animation:pulse 2s infinite}
- @keyframes pulse{0%,100%{opacity:1}50%{opacity:.4}}
- .controls{
- display:flex;align-items:center;gap:12px;
- padding:10px 20px;background:var(--surface);border-bottom:1px solid var(--border);
- flex-shrink:0;
- }
- button{
- background:var(--accent);color:#fff;border:none;border-radius:6px;
- padding:6px 16px;font-size:13px;font-weight:500;cursor:pointer;
- transition:opacity .15s;
- }
- button:hover{opacity:.85}
- button:active{opacity:.7}
- button.disconnect{background:var(--red)}
- .video-wrap{
- flex:1;display:flex;align-items:center;justify-content:center;
- padding:16px;min-height:0;overflow:hidden;
- }
- #frame{
- max-width:100%;max-height:100%;border-radius:8px;
- background:#000;box-shadow:0 4px 24px rgba(0,0,0,.5);
- image-rendering:auto;
- }
- .stats{
- padding:8px 20px;background:var(--surface);border-top:1px solid var(--border);
- font-size:12px;color:var(--text-dim);display:flex;gap:24px;flex-shrink:0;
- font-family:ui-monospace,monospace;
- }
- </style>
- </head>
- <body>
- <div id="app">
- <header>
- <h1>Nebucast Viewer</h1>
- <div id="status"><span class="dot"></span><span id="status-text">Disconnected</span></div>
- </header>
- <div class="controls">
- <button id="btn-connect">Connect</button>
- </div>
- <div class="video-wrap">
- <img id="frame" alt="">
- </div>
- <div class="stats">
- <span>Frames: <strong id="stat-frames">0</strong></span>
- <span>FPS: <strong id="stat-fps">0</strong></span>
- <span>Received: <strong id="stat-bytes">0 B</strong></span>
- </div>
- </div>
- <script>
- (function () {
- var frame = document.getElementById("frame");
- var btnConn = document.getElementById("btn-connect");
- var statusEl = document.getElementById("status");
- var statusTxt = document.getElementById("status-text");
- var statFrames = document.getElementById("stat-frames");
- var statFps = document.getElementById("stat-fps");
- var statBytes = document.getElementById("stat-bytes");
- var ws = null;
- var totalFrames = 0;
- var totalBytes = 0;
- var fpsCounter = 0;
- var fpsTimer = null;
- var prevUrl = null;
- function formatBytes(n) {
- if (n < 1024) return n + " B";
- if (n < 1048576) return (n / 1024).toFixed(1) + " KB";
- if (n < 1073741824) return (n / 1048576).toFixed(1) + " MB";
- return (n / 1073741824).toFixed(1) + " GB";
- }
- function wsUrlFromLocation() {
- var scheme = location.protocol === "https:" ? "wss:" : "ws:";
- return scheme + "//" + location.host + "/ws";
- }
- function connect() {
- if (ws) disconnect();
- ws = new WebSocket(wsUrlFromLocation());
- ws.binaryType = "arraybuffer";
- ws.onopen = function () {
- statusEl.className = "live";
- statusTxt.textContent = "Connected";
- btnConn.textContent = "Disconnect";
- btnConn.className = "disconnect";
- fpsTimer = setInterval(function () {
- statFps.textContent = fpsCounter;
- fpsCounter = 0;
- }, 1000);
- };
- ws.onmessage = function (ev) {
- var blob = new Blob([ev.data], { type: "image/jpeg" });
- var url = URL.createObjectURL(blob);
- if (prevUrl) URL.revokeObjectURL(prevUrl);
- prevUrl = url;
- frame.src = url;
- totalFrames++;
- fpsCounter++;
- totalBytes += ev.data.byteLength;
- statFrames.textContent = totalFrames;
- statBytes.textContent = formatBytes(totalBytes);
- };
- ws.onclose = function () { setDisconnected(); };
- ws.onerror = function () { setDisconnected(); };
- }
- function disconnect() {
- if (ws) { ws.close(); ws = null; }
- if (fpsTimer) { clearInterval(fpsTimer); fpsTimer = null; }
- if (prevUrl) { URL.revokeObjectURL(prevUrl); prevUrl = null; }
- setDisconnected();
- }
- function setDisconnected() {
- statusEl.className = "";
- statusTxt.textContent = "Disconnected";
- btnConn.textContent = "Connect";
- btnConn.className = "";
- }
- btnConn.addEventListener("click", function () {
- if (ws && ws.readyState === WebSocket.OPEN) disconnect();
- else connect();
- });
- })();
- </script>
- </body>
- </html>
|