Skip to content

Commit

Permalink
fix(Sounds): Add missing functionality for StopAllSounds and StopLoop…
Browse files Browse the repository at this point in the history
…ingSounds macros. Fixes #3165
  • Loading branch information
smotired authored Jun 24, 2021
1 parent 7b0abf1 commit 40ef572
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion server/events/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,20 @@ App.on(
},
);
App.on("stopAllSounds", ({simulatorId, station}) => {
// If Random Station is selected, pick a random station from the list of available stations
if (station === "random") {
station = App.clients[Math.floor(Math.random() * App.clients.length)].station;
}
const clients = App.clients.filter(s => {
if (s.simulatorId !== simulatorId) return false;
if (station) {
// If the currently iterated station matches the requested station, return true to stop the sound on that station.
// If All Sound Players is selected, and the selected station has a sound player, return true.
// If All Stations is selected, return true.
if (
s.station === station ||
s.id === station ||
station === "all" ||
(station === "Sound" && s.soundPlayer)
)
return true;
Expand All @@ -341,10 +349,23 @@ App.on("stopAllSounds", ({simulatorId, station}) => {
pubsub.publish("cancelAllSounds", clients);
});
App.on("cancelLoopingSounds", ({simulatorId, station}) => {
// If Random Station is selected, pick a random station from the list of available stations
if (station === "random") {
station = App.clients[Math.floor(Math.random() * App.clients.length)].station;
}
const clients = App.clients.filter(s => {
if (s.simulatorId !== simulatorId) return false;
if (station) {
if (s.station === station || s.id === station) return true;
// If the currently iterated station matches the requested station, return true to stop the sound on that station.
// If All Sound Players is selected, and the selected station has a sound player, return true.
// If All Stations is selected, return true.
if (
s.station === station ||
s.id === station ||
station === "all" ||
(station === "Sound" && s.soundPlayer)
)
return true;
return false;
}
return true;
Expand Down

0 comments on commit 40ef572

Please sign in to comment.