index.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. }
  52. .stats{
  53. padding:8px 20px;background:var(--surface);border-top:1px solid var(--border);
  54. font-size:12px;color:var(--text-dim);display:flex;gap:24px;flex-shrink:0;
  55. font-family:ui-monospace,monospace;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <div id="app">
  61. <header>
  62. <h1>Nebucast Viewer</h1>
  63. <div id="status"><span class="dot"></span><span id="status-text">Disconnected</span></div>
  64. </header>
  65. <div class="controls">
  66. <button id="btn-connect">Connect</button>
  67. </div>
  68. <div class="video-wrap">
  69. <canvas id="frame" width="1280" height="720"></canvas>
  70. </div>
  71. <div class="stats">
  72. <span>Frames: <strong id="stat-frames">0</strong></span>
  73. <span>FPS: <strong id="stat-fps">0</strong></span>
  74. <span>Received: <strong id="stat-bytes">0 B</strong></span>
  75. </div>
  76. </div>
  77. <script>
  78. (function () {
  79. var canvas = document.getElementById("frame");
  80. var ctx = canvas.getContext("2d", { alpha: false, desynchronized: true });
  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 pendingData = null;
  93. var decoding = false;
  94. function formatBytes(n) {
  95. if (n < 1024) return n + " B";
  96. if (n < 1048576) return (n / 1024).toFixed(1) + " KB";
  97. if (n < 1073741824) return (n / 1048576).toFixed(1) + " MB";
  98. return (n / 1073741824).toFixed(1) + " GB";
  99. }
  100. function wsUrlFromLocation() {
  101. var scheme = location.protocol === "https:" ? "wss:" : "ws:";
  102. return scheme + "//" + location.host + "/ws";
  103. }
  104. function decodeLatest() {
  105. if (!pendingData || decoding) return;
  106. var data = pendingData;
  107. pendingData = null;
  108. decoding = true;
  109. createImageBitmap(data).then(function (bmp) {
  110. if (canvas.width !== bmp.width || canvas.height !== bmp.height) {
  111. canvas.width = bmp.width;
  112. canvas.height = bmp.height;
  113. }
  114. ctx.drawImage(bmp, 0, 0);
  115. bmp.close();
  116. decoding = false;
  117. decodeLatest();
  118. }, function () {
  119. decoding = false;
  120. decodeLatest();
  121. });
  122. }
  123. function connect() {
  124. if (ws) disconnect();
  125. ws = new WebSocket(wsUrlFromLocation());
  126. ws.binaryType = "blob";
  127. ws.onopen = function () {
  128. statusEl.className = "live";
  129. statusTxt.textContent = "Connected";
  130. btnConn.textContent = "Disconnect";
  131. btnConn.className = "disconnect";
  132. fpsTimer = setInterval(function () {
  133. statFps.textContent = fpsCounter;
  134. statFrames.textContent = totalFrames;
  135. statBytes.textContent = formatBytes(totalBytes);
  136. fpsCounter = 0;
  137. }, 1000);
  138. };
  139. ws.onmessage = function (ev) {
  140. pendingData = ev.data;
  141. decodeLatest();
  142. totalFrames++;
  143. fpsCounter++;
  144. totalBytes += ev.data.size;
  145. };
  146. ws.onclose = function () { setDisconnected(); };
  147. ws.onerror = function () { setDisconnected(); };
  148. }
  149. function disconnect() {
  150. if (ws) { ws.close(); ws = null; }
  151. if (fpsTimer) { clearInterval(fpsTimer); fpsTimer = null; }
  152. pendingData = null;
  153. ctx.clearRect(0, 0, canvas.width, canvas.height);
  154. setDisconnected();
  155. }
  156. function setDisconnected() {
  157. statusEl.className = "";
  158. statusTxt.textContent = "Disconnected";
  159. btnConn.textContent = "Connect";
  160. btnConn.className = "";
  161. }
  162. btnConn.addEventListener("click", function () {
  163. if (ws && ws.readyState === WebSocket.OPEN) disconnect();
  164. else connect();
  165. });
  166. connect();
  167. })();
  168. </script>
  169. </body>
  170. </html>