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.

74 lines
2.2 KiB

1 month 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>Speaker View</title>
  7. <style>
  8. body {
  9. font-family: Arial, sans-serif;
  10. padding: 20px;
  11. background-color: white;
  12. }
  13. .line {
  14. font-size: 20px;
  15. margin: 5px 0;
  16. }
  17. .currentLine {
  18. background-color: yellow;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <h1>Speaker View</h1>
  24. <div id="speech"></div>
  25. <script src="/socket.io/socket.io.js"></script>
  26. <script>
  27. const socket = io();
  28. const speechDiv = document.getElementById('speech');
  29. let speechLines = [];
  30. let currentLineIndex = 0;
  31. // Render the speech and highlight the current line
  32. function renderSpeech() {
  33. speechDiv.innerHTML = '';
  34. speechLines.forEach((line, index) => {
  35. const div = document.createElement('div');
  36. div.classList.add('line');
  37. if (index === currentLineIndex) {
  38. div.classList.add('currentLine');
  39. }
  40. div.textContent = line;
  41. div.onclick = () => updatePosition(index); // Allow clicking to select a line
  42. speechDiv.appendChild(div);
  43. });
  44. }
  45. // Send updated position to the server
  46. function updatePosition(newPosition) {
  47. currentLineIndex = newPosition;
  48. socket.emit('update_position', currentLineIndex);
  49. renderSpeech();
  50. }
  51. // Listen for speech text and load it
  52. socket.on('load_speech', (lines) => {
  53. speechLines = lines;
  54. currentLineIndex = 0;
  55. renderSpeech();
  56. });
  57. // Add keyboard navigation
  58. document.addEventListener('keydown', (event) => {
  59. if (event.key === 'ArrowDown' && currentLineIndex < speechLines.length - 1) {
  60. updatePosition(currentLineIndex + 1);
  61. } else if (event.key === 'ArrowUp' && currentLineIndex > 0) {
  62. updatePosition(currentLineIndex - 1);
  63. }
  64. });
  65. </script>
  66. </body>
  67. </html>