diff --git a/locales/de/app.json b/locales/de/app.json index aa57f824..e20848b4 100644 --- a/locales/de/app.json +++ b/locales/de/app.json @@ -146,7 +146,6 @@ "screenshare_button_label": "Bildschirm teilen", "settings": { "audio_tab": { - "effect_volume_description": "Lautstärke anpassen, mit der Reaktionen und Handmeldungen abgespielt werden", "effect_volume_label": "Lautstärke der Soundeffekte" }, "developer_settings_label": "Entwicklereinstellungen", diff --git a/locales/en/app.json b/locales/en/app.json index e500f66c..0b783405 100644 --- a/locales/en/app.json +++ b/locales/en/app.json @@ -147,7 +147,7 @@ "screenshare_button_label": "Share screen", "settings": { "audio_tab": { - "effect_volume_description": "Adjust the volume at which reactions and hand raised effects play", + "effect_volume_description": "Volume at which sound effects (such as reactions and call membership sounds) play", "effect_volume_label": "Sound effect volume" }, "developer_settings_label": "Developer Settings", diff --git a/src/useAudioContext.tsx b/src/useAudioContext.tsx index 4b3b9b2c..c8b261a9 100644 --- a/src/useAudioContext.tsx +++ b/src/useAudioContext.tsx @@ -13,7 +13,6 @@ import { useSetting, } from "./settings/settings"; import { useMediaDevices } from "./livekit/MediaDevicesContext"; -import { useInitial } from "./useInitial"; type SoundDefinition = { mp3?: string; ogg: string }; @@ -53,11 +52,9 @@ function getPreferredAudioFormat(): "ogg" | "mp3" { return "mp3"; } -type PrefetchedSounds = Promise>; +const preferredFormat = getPreferredAudioFormat(); -// We prefer to load these sounds ahead of time, so there -// is no delay on call join. -const PreferredFormat = getPreferredAudioFormat(); +type PrefetchedSounds = Promise>; /** * Prefetch sounds to be used by the AudioContext. This should @@ -76,7 +73,7 @@ export async function prefetchSounds( // Use preferred format, fallback to ogg if no mp3 is provided. // Load an audio file const response = await fetch( - PreferredFormat === "ogg" ? ogg : (mp3 ?? ogg), + preferredFormat === "ogg" ? ogg : (mp3 ?? ogg), ); if (!response.ok) { // If the sound doesn't load, it's not the end of the world. We won't play @@ -92,7 +89,7 @@ export async function prefetchSounds( } interface Props { - sounds: PrefetchedSounds; + sounds: PrefetchedSounds | null; latencyHint: AudioContextLatencyCategory; } @@ -113,9 +110,12 @@ export function useAudioContext( const devices = useMediaDevices(); const [audioContext, setAudioContext] = useState(); const [audioBuffers, setAudioBuffers] = useState>(); - const soundCache = useInitial(async () => props.sounds); useEffect(() => { + const soundList = props.sounds; + if (!soundList) { + return; + } const ctx = new AudioContext({ // We want low latency for these effects. latencyHint: props.latencyHint, @@ -126,11 +126,10 @@ export function useAudioContext( // close during this process, so it's okay if it throws. (async (): Promise => { const buffers: Record = {}; - for (const [name, buffer] of Object.entries(await soundCache)) { - const audioBuffer = await ctx.decodeAudioData( - // Type quirk, this is *definitely* a ArrayBuffer. - (buffer as ArrayBuffer).slice(0), - ); + for (const [name, buffer] of Object.entries( + await soundList, + )) { + const audioBuffer = await ctx.decodeAudioData(buffer.slice(0)); buffers[name] = audioBuffer; } setAudioBuffers(buffers as Record); @@ -145,7 +144,7 @@ export function useAudioContext( }); setAudioContext(undefined); }; - }, [soundCache, props.latencyHint]); + }, [props.sounds, props.latencyHint]); // Update the sink ID whenever we change devices. useEffect(() => {