diff --git a/apps/dispatch/app/(app)/pilot/_components/mrt/useSounds.ts b/apps/dispatch/app/(app)/pilot/_components/mrt/useSounds.ts index 77fcfefa..2ca442cb 100644 --- a/apps/dispatch/app/(app)/pilot/_components/mrt/useSounds.ts +++ b/apps/dispatch/app/(app)/pilot/_components/mrt/useSounds.ts @@ -1,7 +1,10 @@ "use client"; +import { useAudioStore } from "_store/audioStore"; +import { RoomEvent } from "livekit-client"; import { useEffect, useRef } from "react"; export const useSounds = () => { + const { room } = useAudioStore((state) => state); const longBtnPressSoundRef = useRef(null); const statusSentSoundRef = useRef(null); const sdsReceivedSoundRef = useRef(null); @@ -14,6 +17,20 @@ export const useSounds = () => { } }, []); + useEffect(() => { + const handleRoomConnected = () => { + // Play a sound when connected to the room + // connectedSound.play(); + statusSentSoundRef.current?.play(); + console.log("Room connected - played sound"); + }; + room?.on(RoomEvent.Connected, handleRoomConnected); + + return () => { + room?.off(RoomEvent.Connected, handleRoomConnected); + }; + }, [room]); + return { longBtnPressSoundRef, statusSentSoundRef, diff --git a/apps/dispatch/app/_store/audioStore.ts b/apps/dispatch/app/_store/audioStore.ts index 714264b2..72aabd9f 100644 --- a/apps/dispatch/app/_store/audioStore.ts +++ b/apps/dispatch/app/_store/audioStore.ts @@ -25,8 +25,6 @@ import { ROOMS } from "_data/livekitRooms"; let interval: NodeJS.Timeout; -const connectedSound = new Audio("/sounds/403.wav"); - type TalkState = { addSpeakingParticipant: (participant: Participant) => void; connect: (room: (typeof ROOMS)[number] | undefined, role: string) => void; @@ -190,6 +188,7 @@ export const useAudioStore = create((set, get) => ({ if (!token) throw new Error("Fehlende Berechtigung"); const room = new Room({}); await room.prepareConnection(url, token); + const roomConnectedSound = new Audio("/sounds/403.wav"); room // Connection events .on(RoomEvent.Connected, async () => { @@ -219,7 +218,7 @@ export const useAudioStore = create((set, get) => ({ source: Track.Source.Microphone, }); await publishedTrack.mute(); - connectedSound.play().catch((e) => console.error("Fehler beim Abspielen des Sounds", e)); + roomConnectedSound.play(); set({ localRadioTrack: publishedTrack }); set({ state: "connected", room, isTalking: false, message: null });