index.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. button{
  37. background:var(--accent);color:#fff;border:none;border-radius:6px;
  38. padding:6px 16px;font-size:13px;font-weight:500;cursor:pointer;
  39. transition:opacity .15s;
  40. }
  41. button:hover{opacity:.85}
  42. button:active{opacity:.7}
  43. button.disconnect{background:var(--red)}
  44. .video-wrap{
  45. flex:1;display:flex;align-items:center;justify-content:center;
  46. padding:16px;min-height:0;overflow:hidden;
  47. }
  48. #frame{
  49. max-width:100%;max-height:100%;border-radius:8px;
  50. background:#000;box-shadow:0 4px 24px rgba(0,0,0,.5);
  51. image-rendering:auto;
  52. }
  53. .stats{
  54. padding:8px 20px;background:var(--surface);border-top:1px solid var(--border);
  55. font-size:12px;color:var(--text-dim);display:flex;gap:24px;flex-shrink:0;
  56. font-family:ui-monospace,monospace;
  57. }
  58. </style>
  59. </head>
  60. <body>
  61. <div id="app">
  62. <header>
  63. <h1>Nebucast Viewer</h1>
  64. <div id="status"><span class="dot"></span><span id="status-text">Disconnected</span></div>
  65. </header>
  66. <div class="controls">
  67. <button id="btn-connect">Connect</button>
  68. </div>
  69. <div class="video-wrap">
  70. <img id="frame" alt="">
  71. </div>
  72. <div class="stats">
  73. <span>Frames: <strong id="stat-frames">0</strong></span>
  74. <span>FPS: <strong id="stat-fps">0</strong></span>
  75. <span>Received: <strong id="stat-bytes">0 B</strong></span>
  76. </div>
  77. </div>
  78. <script>
  79. (function () {
  80. var frame = document.getElementById("frame");
  81. var btnConn = document.getElementById("btn-connect");
  82. var statusEl = document.getElementById("status");
  83. var statusTxt = document.getElementById("status-text");
  84. var statFrames = document.getElementById("stat-frames");
  85. var statFps = document.getElementById("stat-fps");
  86. var statBytes = document.getElementById("stat-bytes");
  87. var ws = null;
  88. var totalFrames = 0;
  89. var totalBytes = 0;
  90. var fpsCounter = 0;
  91. var fpsTimer = null;
  92. var prevUrl = null;
  93. function formatBytes(n) {
  94. if (n < 1024) return n + " B";
  95. if (n < 1048576) return (n / 1024).toFixed(1) + " KB";
  96. if (n < 1073741824) return (n / 1048576).toFixed(1) + " MB";
  97. return (n / 1073741824).toFixed(1) + " GB";
  98. }
  99. function wsUrlFromLocation() {
  100. var scheme = location.protocol === "https:" ? "wss:" : "ws:";
  101. return scheme + "//" + location.host + "/ws";
  102. }
  103. function connect() {
  104. if (ws) disconnect();
  105. ws = new WebSocket(wsUrlFromLocation());
  106. ws.binaryType = "arraybuffer";
  107. ws.onopen = function () {
  108. statusEl.className = "live";
  109. statusTxt.textContent = "Connected";
  110. btnConn.textContent = "Disconnect";
  111. btnConn.className = "disconnect";
  112. fpsTimer = setInterval(function () {
  113. statFps.textContent = fpsCounter;
  114. fpsCounter = 0;
  115. }, 1000);
  116. };
  117. ws.onmessage = function (ev) {
  118. var blob = new Blob([ev.data], { type: "image/jpeg" });
  119. var url = URL.createObjectURL(blob);
  120. if (prevUrl) URL.revokeObjectURL(prevUrl);
  121. prevUrl = url;
  122. frame.src = url;
  123. totalFrames++;
  124. fpsCounter++;
  125. totalBytes += ev.data.byteLength;
  126. statFrames.textContent = totalFrames;
  127. statBytes.textContent = formatBytes(totalBytes);
  128. };
  129. ws.onclose = function () { setDisconnected(); };
  130. ws.onerror = function () { setDisconnected(); };
  131. }
  132. function disconnect() {
  133. if (ws) { ws.close(); ws = null; }
  134. if (fpsTimer) { clearInterval(fpsTimer); fpsTimer = null; }
  135. if (prevUrl) { URL.revokeObjectURL(prevUrl); prevUrl = null; }
  136. setDisconnected();
  137. }
  138. function setDisconnected() {
  139. statusEl.className = "";
  140. statusTxt.textContent = "Disconnected";
  141. btnConn.textContent = "Connect";
  142. btnConn.className = "";
  143. }
  144. btnConn.addEventListener("click", function () {
  145. if (ws && ws.readyState === WebSocket.OPEN) disconnect();
  146. else connect();
  147. });
  148. })();
  149. </script>
  150. </body>
  151. </html>