You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.5 KiB

6 days ago
  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.0">
  6. <title>Projector View</title>
  7. <style>
  8. body {
  9. font-family: Futura, sans-serif;
  10. font-size: 32px;
  11. background-color: green;
  12. color: white;
  13. text-align: center; /* Align text to the left */
  14. margin: 0;
  15. padding: 0;
  16. -webkit-text-fill-color: white;
  17. -webkit-text-stroke-color: black;
  18. -webkit-text-stroke-width: 6.00px;
  19. paint-order: stroke fill;
  20. }
  21. #container {
  22. overflow: hidden;
  23. height: 200px; /* Ensure container is tall enough for 4 lines */
  24. max-width: 42ch;
  25. position: relative;
  26. padding-left: 20px; /* Add some padding to the left */
  27. margin-left: auto;
  28. margin-right: auto;
  29. }
  30. #content {
  31. position: absolute;
  32. top: 0;
  33. transition: top 0.5s ease; /* Smooth scrolling */
  34. }
  35. .line {
  36. opacity: 1;
  37. white-space: normal; /* Allow lines to wrap */
  38. word-wrap: break-word; /* Break long words if needed */
  39. margin: 5px 0;
  40. }
  41. .currentLine {
  42. font-weight: bold;
  43. opacity: 1;
  44. }
  45. /* Ensure there's space for 4 lines to be displayed */
  46. #container {
  47. max-height: 400px;
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <div id="container">
  53. <div id="content"></div>
  54. </div>
  55. <script src="/socket.io/socket.io.js"></script>
  56. <script>
  57. const socket = io();
  58. const contentElement = document.getElementById('content');
  59. let speechLines = [];
  60. let currentLineIndex = 0;
  61. // Display 4 lines (previous, current, next, and an extra one above the current line)
  62. function updateDisplay() {
  63. contentElement.innerHTML = ''; // Clear previous lines
  64. const start = Math.max(0, currentLineIndex - 2); // Show 2 lines before current
  65. const end = Math.min(speechLines.length, currentLineIndex + 2); // Show 2 lines after current
  66. // Create a new block of lines
  67. const displayLines = speechLines.slice(start, end).map((line, index) => {
  68. const div = document.createElement('div');
  69. div.classList.add('line');
  70. if (index === 2) div.classList.add('currentLine'); // Highlight the current line
  71. div.textContent = line;
  72. return div;
  73. });
  74. displayLines.forEach(div => contentElement.appendChild(div));
  75. // Scroll animation based on the height of each line
  76. const lineHeight = document.querySelector('.line').offsetHeight;
  77. const previousLinesHeight = (currentLineIndex - start - 1) * lineHeight; // Offset for lines above the current line
  78. contentElement.style.top = `-${previousLinesHeight}px`;
  79. }
  80. // Receive updates from the server
  81. socket.on('update_caption', (newPosition) => {
  82. currentLineIndex = newPosition;
  83. updateDisplay();
  84. });
  85. // Load the speech when a new client connects
  86. socket.on('load_speech', (lines) => {
  87. speechLines = lines;
  88. currentLineIndex = 0;
  89. updateDisplay(); // Display the initial lines
  90. });
  91. </script>
  92. </body>
  93. </html>