From ce2b4c3cca0542b33f06015d132cd2ddd06f585b Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Mon, 11 Nov 2024 14:50:26 +0000 Subject: [PATCH] Add support for specifying custom sounds via state events. --- src/button/ReactionToggleButton.tsx | 4 ++-- src/reactions/index.ts | 4 ++++ src/room/ReactionAudioRenderer.tsx | 6 +++--- src/useReactions.tsx | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/button/ReactionToggleButton.tsx b/src/button/ReactionToggleButton.tsx index 09e0dac2..cda4d4ee 100644 --- a/src/button/ReactionToggleButton.tsx +++ b/src/button/ReactionToggleButton.tsx @@ -33,7 +33,6 @@ import { useMatrixRTCSessionMemberships } from "../useMatrixRTCSessionMembership import styles from "./ReactionToggleButton.module.css"; import { ReactionOption, - ReactionSet, ElementCallReactionEventType, } from "../reactions"; import { Modal } from "../Modal"; @@ -77,9 +76,10 @@ export function ReactionPopupMenu({ }): ReactNode { const { t } = useTranslation(); const [isFullyExpanded, setExpanded] = useState(false); + const { allReactions } = useReactions(); const filteredReactionSet = useMemo( - () => (isFullyExpanded ? ReactionSet : ReactionSet.slice(0, 6)), + () => (isFullyExpanded ? allReactions : allReactions.slice(0, 6)), [isFullyExpanded], ); diff --git a/src/reactions/index.ts b/src/reactions/index.ts index 0e270a6d..63aac589 100644 --- a/src/reactions/index.ts +++ b/src/reactions/index.ts @@ -64,6 +64,10 @@ export interface ECallReactionEventContent { name: string; } +export interface ECallReactionSoundsEventContent { + reactions: ReactionOption[], +} + export const GenericReaction: ReactionOption = { name: "generic", emoji: "", // Filled in by user diff --git a/src/room/ReactionAudioRenderer.tsx b/src/room/ReactionAudioRenderer.tsx index cc0b4a57..97aee7e0 100644 --- a/src/room/ReactionAudioRenderer.tsx +++ b/src/room/ReactionAudioRenderer.tsx @@ -13,10 +13,10 @@ import { soundEffectVolumeSetting as effectSoundVolumeSetting, useSetting, } from "../settings/settings"; -import { GenericReaction, ReactionSet } from "../reactions"; +import { GenericReaction } from "../reactions"; export function ReactionsAudioRenderer(): ReactNode { - const { reactions } = useReactions(); + const { reactions, allReactions } = useReactions(); const [shouldPlay] = useSetting(playReactionsSound); const [effectSoundVolume] = useSetting(effectSoundVolumeSetting); const audioElements = useRef>({}); @@ -52,7 +52,7 @@ export function ReactionsAudioRenderer(): ReactNode { // be delayed. return ( <> - {[GenericReaction, ...ReactionSet].map( + {[GenericReaction, ...allReactions].map( (r) => r.sound && (