index.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>Nebucast Viewer</title>
  7. <style>
  8. *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
  9. :root{
  10. --bg:#0f0f0f; --surface:#1a1a1a; --border:#2a2a2a;
  11. --text:#e0e0e0; --text-dim:#888; --accent:#6c8cff; --red:#ff5555;
  12. }
  13. html,body{height:100%;font-family:system-ui,-apple-system,sans-serif;background:var(--bg);color:var(--text)}
  14. #app{display:flex;flex-direction:column;height:100vh}
  15. header{
  16. display:flex;align-items:center;justify-content:space-between;
  17. padding:12px 20px;background:var(--surface);border-bottom:1px solid var(--border);
  18. flex-shrink:0;
  19. }
  20. header h1{font-size:16px;font-weight:600;letter-spacing:-.3px}
  21. #status{
  22. display:flex;align-items:center;gap:8px;
  23. font-size:13px;color:var(--text-dim);
  24. }
  25. #status .dot{
  26. width:8px;height:8px;border-radius:50%;background:var(--red);
  27. transition:background .3s;
  28. }
  29. #status.live .dot{background:#44cc44;animation:pulse 2s infinite}
  30. @keyframes pulse{0%,100%{opacity:1}50%{opacity:.4}}
  31. .controls{
  32. display:flex;align-items:center;gap:12px;
  33. padding:10px 20px;background:var(--surface);border-bottom:1px solid var(--border);
  34. flex-shrink:0;
  35. }
  36. .controls label{font-size:13px;color:var(--text-dim)}
  37. .controls input[type=text]{
  38. background:var(--bg);border:1px solid var(--border);border-radius:6px;
  39. color:var(--text);padding:6px 10px;font-size:13px;width:280px;
  40. font-family:ui-monospace,monospace;
  41. }
  42. .controls input:focus{outline:none;border-color:var(--accent)}
  43. button{
  44. background:var(--accent);color:#fff;border:none;border-radius:6px;
  45. padding:6px 16px;font-size:13px;font-weight:500;cursor:pointer;
  46. transition:opacity .15s;
  47. }
  48. button:hover{opacity:.85}
  49. button:active{opacity:.7}
  50. button.disconnect{background:var(--red)}
  51. .video-wrap{
  52. flex:1;display:flex;align-items:center;justify-content:center;
  53. padding:16px;min-height:0;overflow:hidden;
  54. }
  55. #frame{
  56. max-width:100%;max-height:100%;border-radius:8px;
  57. background:#000;box-shadow:0 4px 24px rgba(0,0,0,.5);
  58. image-rendering:auto;
  59. }
  60. .stats{
  61. padding:8px 20px;background:var(--surface);border-top:1px solid var(--border);
  62. font-size:12px;color:var(--text-dim);display:flex;gap:24px;flex-shrink:0;
  63. font-family:ui-monospace,monospace;
  64. }
  65. </style>
  66. </head>
  67. <body>
  68. <div id="app">
  69. <header>
  70. <h1>Nebucast Viewer</h1>
  71. <div id="status"><span class="dot"></span><span id="status-text">Disconnected</span></div>
  72. </header>
  73. <div class="controls">
  74. <label for="ws-url">Server</label>
  75. <input type="text" id="ws-url" value="ws://localhost:9000">
  76. <button id="btn-connect">Connect</button>
  77. </div>
  78. <div class="video-wrap">
  79. <img id="frame" alt="">
  80. </div>
  81. <div class="stats">
  82. <span>Frames: <strong id="stat-frames">0</strong></span>
  83. <span>FPS: <strong id="stat-fps">0</strong></span>
  84. <span>Received: <strong id="stat-bytes">0 B</strong></span>
  85. </div>
  86. </div>
  87. <script>
  88. (function () {
  89. var frame = document.getElementById("frame");
  90. var urlInput = document.getElementById("ws-url");
  91. var btnConn = document.getElementById("btn-connect");
  92. var statusEl = document.getElementById("status");
  93. var statusTxt = document.getElementById("status-text");
  94. var statFrames = document.getElementById("stat-frames");
  95. var statFps = document.getElementById("stat-fps");
  96. var statBytes = document.getElementById("stat-bytes");
  97. var ws = null;
  98. var totalFrames = 0;
  99. var totalBytes = 0;
  100. var fpsCounter = 0;
  101. var fpsTimer = null;
  102. var prevUrl = null;
  103. function formatBytes(n) {
  104. if (n < 1024) return n + " B";
  105. if (n < 1048576) return (n / 1024).toFixed(1) + " KB";
  106. if (n < 1073741824) return (n / 1048576).toFixed(1) + " MB";
  107. return (n / 1073741824).toFixed(1) + " GB";
  108. }
  109. function connect() {
  110. var url = urlInput.value.trim();
  111. if (!url) return;
  112. if (ws) disconnect();
  113. ws = new WebSocket(url);
  114. ws.binaryType = "arraybuffer";
  115. ws.onopen = function () {
  116. statusEl.className = "live";
  117. statusTxt.textContent = "Connected";
  118. btnConn.textContent = "Disconnect";
  119. btnConn.className = "disconnect";
  120. fpsTimer = setInterval(function () {
  121. statFps.textContent = fpsCounter;
  122. fpsCounter = 0;
  123. }, 1000);
  124. };
  125. ws.onmessage = function (ev) {
  126. var blob = new Blob([ev.data], { type: "image/jpeg" });
  127. var url = URL.createObjectURL(blob);
  128. if (prevUrl) URL.revokeObjectURL(prevUrl);
  129. prevUrl = url;
  130. frame.src = url;
  131. totalFrames++;
  132. fpsCounter++;
  133. totalBytes += ev.data.byteLength;
  134. statFrames.textContent = totalFrames;
  135. statBytes.textContent = formatBytes(totalBytes);
  136. };
  137. ws.onclose = function () { setDisconnected(); };
  138. ws.onerror = function () { setDisconnected(); };
  139. }
  140. function disconnect() {
  141. if (ws) { ws.close(); ws = null; }
  142. if (fpsTimer) { clearInterval(fpsTimer); fpsTimer = null; }
  143. if (prevUrl) { URL.revokeObjectURL(prevUrl); prevUrl = null; }
  144. setDisconnected();
  145. }
  146. function setDisconnected() {
  147. statusEl.className = "";
  148. statusTxt.textContent = "Disconnected";
  149. btnConn.textContent = "Connect";
  150. btnConn.className = "";
  151. }
  152. btnConn.addEventListener("click", function () {
  153. if (ws && ws.readyState === WebSocket.OPEN) disconnect();
  154. else connect();
  155. });
  156. if (location.hash.length > 1) {
  157. urlInput.value = decodeURIComponent(location.hash.slice(1));
  158. connect();
  159. }
  160. })();
  161. </script>
  162. </body>
  163. </html>