mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-08 20:09:19 +00:00
Only load reaction sound effects if enabled.
This commit is contained in:
@@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||||||
Please see LICENSE in the repository root for full details.
|
Please see LICENSE in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ReactNode, useDeferredValue, useEffect } from "react";
|
import { ReactNode, useDeferredValue, useEffect, useState } from "react";
|
||||||
|
|
||||||
import { useReactions } from "../useReactions";
|
import { useReactions } from "../useReactions";
|
||||||
import { playReactionsSound, useSetting } from "../settings/settings";
|
import { playReactionsSound, useSetting } from "../settings/settings";
|
||||||
@@ -21,17 +21,25 @@ const SoundMap = Object.fromEntries([
|
|||||||
[GenericReaction.name, GenericReaction.sound],
|
[GenericReaction.name, GenericReaction.sound],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const Sounds = prefetchSounds(SoundMap);
|
let SoundCache: ReturnType<typeof prefetchSounds> | null = null;
|
||||||
|
|
||||||
export function ReactionsAudioRenderer(): ReactNode {
|
export function ReactionsAudioRenderer(): ReactNode {
|
||||||
const { reactions } = useReactions();
|
const { reactions } = useReactions();
|
||||||
const [shouldPlay] = useSetting(playReactionsSound);
|
const [shouldPlay] = useSetting(playReactionsSound);
|
||||||
|
const [soundCache, setSoundCache] = useState(SoundCache);
|
||||||
const audioEngineCtx = useAudioContext({
|
const audioEngineCtx = useAudioContext({
|
||||||
sounds: Sounds,
|
sounds: soundCache,
|
||||||
latencyHint: "interactive",
|
latencyHint: "interactive",
|
||||||
});
|
});
|
||||||
const audioEngineRef = useLatest(audioEngineCtx);
|
const audioEngineRef = useLatest(audioEngineCtx);
|
||||||
const oldReactions = useDeferredValue(reactions);
|
const oldReactions = useDeferredValue(reactions);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!shouldPlay || SoundCache) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SoundCache = prefetchSounds(SoundMap);
|
||||||
|
setSoundCache(SoundCache);
|
||||||
|
}, [shouldPlay]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!shouldPlay || !audioEngineRef.current) {
|
if (!shouldPlay || !audioEngineRef.current) {
|
||||||
|
|||||||
@@ -86,9 +86,6 @@ export const SettingsModal: FC<Props> = ({
|
|||||||
const [soundVolume, setSoundVolume] = useSetting(soundEffectVolumeSetting);
|
const [soundVolume, setSoundVolume] = useSetting(soundEffectVolumeSetting);
|
||||||
const [soundVolumeRaw, setSoundVolumeRaw] = useState(soundVolume);
|
const [soundVolumeRaw, setSoundVolumeRaw] = useState(soundVolume);
|
||||||
|
|
||||||
// Debounce saving the sound volume as it triggers certain components to reload.
|
|
||||||
useEffect(() => {});
|
|
||||||
|
|
||||||
const audioTab: Tab<SettingsTab> = {
|
const audioTab: Tab<SettingsTab> = {
|
||||||
key: "audio",
|
key: "audio",
|
||||||
name: t("common.audio"),
|
name: t("common.audio"),
|
||||||
|
|||||||
Reference in New Issue
Block a user