From a4a31dd43eef5c3e1d2b62cf4bb6e491e382f988 Mon Sep 17 00:00:00 2001 From: MAZE Date: Sat, 31 Aug 2024 19:22:07 +0330 Subject: [PATCH] refactor: remove extra hook --- src/hooks/use-sound-effect.ts | 55 ----------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 src/hooks/use-sound-effect.ts diff --git a/src/hooks/use-sound-effect.ts b/src/hooks/use-sound-effect.ts deleted file mode 100644 index a461d62..0000000 --- a/src/hooks/use-sound-effect.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { useMemo, useEffect, useCallback } from 'react'; -import { Howl } from 'howler'; - -import { useSSR } from './use-ssr'; - -/** - * A custom React hook to manage sound effects using Howler.js. - * - * @param {string} src - The source URL of the sound file. - * @param {number} [volume=1] - The initial volume of the sound, ranging from 0.0 to 1.0. - * @returns {{ play: () => void, stop: () => void, pause: () => void }} An object containing control functions for the sound: - * - play: Function to play the sound. - * - stop: Function to stop the sound. - * - pause: Function to pause the sound. - */ -export function useSoundEffect(src: string, volume: number = 1) { - const { isBrowser } = useSSR(); - - const sound = useMemo(() => { - let sound: Howl | null = null; - - if (isBrowser) { - sound = new Howl({ - html5: true, - src: src, - }); - } - - return sound; - }, [src, isBrowser]); - - useEffect(() => { - if (sound) sound.volume(volume ?? 1); - }, [sound, volume]); - - const play = useCallback(() => { - if (sound) { - if (!sound.playing()) { - sound.play(); - } - } - }, [sound]); - - const stop = useCallback(() => { - if (sound) sound.stop(); - }, [sound]); - - const pause = useCallback(() => { - if (sound) sound.pause(); - }, [sound]); - - const control = useMemo(() => ({ pause, play, stop }), [play, stop, pause]); - - return control; -}