Skip to content

Commit

Permalink
Add game Sounds to Team Displays
Browse files Browse the repository at this point in the history
  • Loading branch information
cpapplefamily committed Nov 30, 2024
1 parent 4055824 commit e99faa9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 13 additions & 1 deletion static/js/alliance_station_display.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ var handleMatchTime = function(data) {
});
};


// Handles a websocket message to play a sound to signal match start/stop/etc.
const handlePlaySound = function(sound) {
$("audio").each(function(k, v) {
// Stop and reset any sounds that are still playing.
v.pause();
v.currentTime = 0;
});
$("#sound-" + sound)[0].play();
};

// Handles a websocket message to update the match score.
var handleRealtimeScore = function(data) {
$("#redScore").text(
Expand All @@ -140,6 +151,7 @@ $(function() {
matchLoad: function(event) { handleMatchLoad(event.data); },
matchTime: function(event) { handleMatchTime(event.data); },
matchTiming: function(event) { handleMatchTiming(event.data); },
realtimeScore: function(event) { handleRealtimeScore(event.data); }
realtimeScore: function(event) { handleRealtimeScore(event.data); },
playSound: function(event) { handlePlaySound(event.data); }
});
});
4 changes: 4 additions & 0 deletions templates/alliance_station_display.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@
<script src="/static/js/cheesy-websocket.js"></script>
<script src="/static/js/match_timing.js"></script>
<script src="/static/js/alliance_station_display.js"></script>
{{range $sound := .MatchSounds}}
<audio id="sound-{{$sound.Name}}" src="/static/audio/{{$sound.Name}}.{{$sound.FileExtension}}" preload="auto">
</audio>
{{end}}
</body>
</html>

0 comments on commit e99faa9

Please sign in to comment.