DustyP 9 months ago
parent b450a93724
commit 8c9e9046ad

@ -147,7 +147,7 @@ templ RaceManage(groups []models.Group, currentGroup models.Group, heats []model
// WebSocket connections
const timerSocket = new WebSocket(`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws/timer`);
const adminSocket = new WebSocket(`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws/admin`);
const eventsSocket = new WebSocket(`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws/events`);
const eventsSocket = new WebSocket(`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/events`);
const timerDisplay = document.getElementById('timer');
const statusIndicator = document.getElementById('status-indicator');

File diff suppressed because one or more lines are too long

@ -110,7 +110,7 @@ templ RacePublic(currentGroup models.Group, heats []models.Heat, racers []models
};
// Events WebSocket for race events
const eventsSocket = new WebSocket(`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws/events`);
const eventsSocket = new WebSocket(`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/events`);
eventsSocket.onmessage = function(event) {
const data = JSON.parse(event.data);

@ -125,7 +125,7 @@ func RacePublic(currentGroup models.Group, heats []models.Heat, racers []models.
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "</div></div></div></div></div><script>\r\n // WebSocket connection for timer updates\r\n const timerSocket = new WebSocket(`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws/timer`);\r\n const timerDisplay = document.getElementById('timer');\r\n const statusIndicator = document.getElementById('status-indicator');\r\n \r\n timerSocket.onmessage = function(event) {\r\n const data = JSON.parse(event.data);\r\n \r\n if (data.type === 'time') {\r\n timerDisplay.textContent = data.time.toFixed(3);\r\n } else if (data.type === 'status') {\r\n statusIndicator.textContent = data.status;\r\n \r\n // Update status indicator color\r\n statusIndicator.className = 'badge ';\r\n if (data.status === 'Ready') {\r\n statusIndicator.className += 'bg-secondary';\r\n } else if (data.status === 'Running') {\r\n statusIndicator.className += 'bg-success';\r\n } else if (data.status === 'Finished') {\r\n statusIndicator.className += 'bg-primary';\r\n }\r\n } else if (data.type === 'lane-time') {\r\n // Update lane time display\r\n const laneTimeElement = document.getElementById(`lane-${data.lane}-time`);\r\n if (laneTimeElement) {\r\n laneTimeElement.textContent = data.time.toFixed(3);\r\n }\r\n } else if (data.type === 'lane-position') {\r\n // Update lane position display\r\n const lanePositionElement = document.getElementById(`lane-${data.lane}-position`);\r\n if (lanePositionElement) {\r\n lanePositionElement.textContent = data.position;\r\n }\r\n } else if (data.type === 'reload') {\r\n // Reload the page when heat changes\r\n window.location.reload();\r\n }\r\n };\r\n \r\n // Events WebSocket for race events\r\n const eventsSocket = new WebSocket(`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws/events`);\r\n \r\n eventsSocket.onmessage = function(event) {\r\n const data = JSON.parse(event.data);\r\n \r\n if (data.event === 'race_start') {\r\n // Race has started\r\n console.log('Race started!');\r\n // You could add visual effects or sounds here\r\n } else if (data.event === 'lane_finish') {\r\n // A lane has finished\r\n console.log(`Lane ${data.lane} finished with time ${data.time}`);\r\n // You could add visual effects or sounds here\r\n } else if (data.event === 'race_end') {\r\n // Race has ended\r\n console.log('Race ended!');\r\n // You could add visual effects or sounds here\r\n \r\n // Reload the page after a short delay to show final results\r\n setTimeout(() => {\r\n window.location.reload();\r\n }, 3000);\r\n }\r\n };\r\n \r\n // Auto-refresh the page every 30 seconds to keep data current\r\n setTimeout(() => {\r\n window.location.reload();\r\n }, 30000);\r\n </script>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "</div></div></div></div></div><script>\r\n // WebSocket connection for timer updates\r\n const timerSocket = new WebSocket(`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws/timer`);\r\n const timerDisplay = document.getElementById('timer');\r\n const statusIndicator = document.getElementById('status-indicator');\r\n \r\n timerSocket.onmessage = function(event) {\r\n const data = JSON.parse(event.data);\r\n \r\n if (data.type === 'time') {\r\n timerDisplay.textContent = data.time.toFixed(3);\r\n } else if (data.type === 'status') {\r\n statusIndicator.textContent = data.status;\r\n \r\n // Update status indicator color\r\n statusIndicator.className = 'badge ';\r\n if (data.status === 'Ready') {\r\n statusIndicator.className += 'bg-secondary';\r\n } else if (data.status === 'Running') {\r\n statusIndicator.className += 'bg-success';\r\n } else if (data.status === 'Finished') {\r\n statusIndicator.className += 'bg-primary';\r\n }\r\n } else if (data.type === 'lane-time') {\r\n // Update lane time display\r\n const laneTimeElement = document.getElementById(`lane-${data.lane}-time`);\r\n if (laneTimeElement) {\r\n laneTimeElement.textContent = data.time.toFixed(3);\r\n }\r\n } else if (data.type === 'lane-position') {\r\n // Update lane position display\r\n const lanePositionElement = document.getElementById(`lane-${data.lane}-position`);\r\n if (lanePositionElement) {\r\n lanePositionElement.textContent = data.position;\r\n }\r\n } else if (data.type === 'reload') {\r\n // Reload the page when heat changes\r\n window.location.reload();\r\n }\r\n };\r\n \r\n // Events WebSocket for race events\r\n const eventsSocket = new WebSocket(`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/events`);\r\n \r\n eventsSocket.onmessage = function(event) {\r\n const data = JSON.parse(event.data);\r\n \r\n if (data.event === 'race_start') {\r\n // Race has started\r\n console.log('Race started!');\r\n // You could add visual effects or sounds here\r\n } else if (data.event === 'lane_finish') {\r\n // A lane has finished\r\n console.log(`Lane ${data.lane} finished with time ${data.time}`);\r\n // You could add visual effects or sounds here\r\n } else if (data.event === 'race_end') {\r\n // Race has ended\r\n console.log('Race ended!');\r\n // You could add visual effects or sounds here\r\n \r\n // Reload the page after a short delay to show final results\r\n setTimeout(() => {\r\n window.location.reload();\r\n }, 3000);\r\n }\r\n };\r\n \r\n // Auto-refresh the page every 30 seconds to keep data current\r\n setTimeout(() => {\r\n window.location.reload();\r\n }, 30000);\r\n </script>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}

Loading…
Cancel
Save