From 40ef572883089916fece2fc1de30eccdc66b670a Mon Sep 17 00:00:00 2001 From: Sam Hill Date: Thu, 24 Jun 2021 09:07:33 -0600 Subject: [PATCH] fix(Sounds): Add missing functionality for StopAllSounds and StopLoopingSounds macros. Fixes #3165 --- server/events/clients.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/server/events/clients.ts b/server/events/clients.ts index 6986018b9..8f436a60c 100644 --- a/server/events/clients.ts +++ b/server/events/clients.ts @@ -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; @@ -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;