Skip to content

Commit e99faa9

Browse files
committed
Add game Sounds to Team Displays
1 parent 4055824 commit e99faa9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

static/js/alliance_station_display.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ var handleMatchTime = function(data) {
118118
});
119119
};
120120

121+
122+
// Handles a websocket message to play a sound to signal match start/stop/etc.
123+
const handlePlaySound = function(sound) {
124+
$("audio").each(function(k, v) {
125+
// Stop and reset any sounds that are still playing.
126+
v.pause();
127+
v.currentTime = 0;
128+
});
129+
$("#sound-" + sound)[0].play();
130+
};
131+
121132
// Handles a websocket message to update the match score.
122133
var handleRealtimeScore = function(data) {
123134
$("#redScore").text(
@@ -140,6 +151,7 @@ $(function() {
140151
matchLoad: function(event) { handleMatchLoad(event.data); },
141152
matchTime: function(event) { handleMatchTime(event.data); },
142153
matchTiming: function(event) { handleMatchTiming(event.data); },
143-
realtimeScore: function(event) { handleRealtimeScore(event.data); }
154+
realtimeScore: function(event) { handleRealtimeScore(event.data); },
155+
playSound: function(event) { handlePlaySound(event.data); }
144156
});
145157
});

templates/alliance_station_display.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,9 @@
3939
<script src="/static/js/cheesy-websocket.js"></script>
4040
<script src="/static/js/match_timing.js"></script>
4141
<script src="/static/js/alliance_station_display.js"></script>
42+
{{range $sound := .MatchSounds}}
43+
<audio id="sound-{{$sound.Name}}" src="/static/audio/{{$sound.Name}}.{{$sound.FileExtension}}" preload="auto">
44+
</audio>
45+
{{end}}
4246
</body>
4347
</html>

0 commit comments

Comments
 (0)