Skip to content

Commit

Permalink
fix(Sound Player): An errant reset function was being called to often…
Browse files Browse the repository at this point in the history
…, causing sounds to be chopped off. This fixes that problem.
  • Loading branch information
Alex Anderson committed May 16, 2020
1 parent 0bced7f commit c03ea39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
11 changes: 5 additions & 6 deletions src/components/client/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const ResetCache: React.FC<{
}> = ({clientId, reset, station}) => {
const client = useApolloClient();
const {playSound, removeAllSounds} = useSounds();
const excludeStation =
(station?.name && excludedStations.includes(station?.name)) ||
station?.cards.find(c => excludedStations.indexOf(c.component) > -1);

React.useEffect(() => {
const cacheSub = client
Expand All @@ -32,11 +35,7 @@ const ResetCache: React.FC<{
next: () => {
// Reset all of the sounds that are currently playing
removeAllSounds();
if (
(station?.name && excludedStations.includes(station?.name)) ||
station?.cards.find(c => excludedStations.indexOf(c.component) > -1)
)
return;
if (excludeStation) return;
playSound({url: "/sciences.ogg"});
reset?.();
publish("widgetClose");
Expand All @@ -48,7 +47,7 @@ const ResetCache: React.FC<{
return () => {
cacheSub.unsubscribe();
};
}, [client, clientId, playSound, removeAllSounds, reset, station]);
}, [client, clientId, excludeStation, playSound, removeAllSounds, reset]);

return null;
};
Expand Down
20 changes: 3 additions & 17 deletions src/components/client/soundPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,11 @@ const SoundPlayer: React.FC<{
};
}, [client, playSound, removeAllSounds, simulator.id]);

if (invisible)
return (
<Reset
clientId={clientId}
station={{name: "Sound", cards: []}}
reset={() => {
removeAllSounds();
}}
/>
);
const station = React.useMemo(() => ({name: "Sound", cards: []}), []);
if (invisible) return <Reset clientId={clientId} station={station} />;
return (
<div className="keyboard-holder">
<Reset
clientId={clientId}
station={{name: "Sound", cards: []}}
reset={() => {
removeAllSounds();
}}
/>
<Reset clientId={clientId} station={station} />
<FormattedMessage id="sound-player" defaultMessage="Sound Player" />
<ClientLighting simulator={simulator} clientId={clientId} />
</div>
Expand Down

0 comments on commit c03ea39

Please sign in to comment.