fixed Sound nach Verbinden auf RG

This commit is contained in:
PxlLoewe
2026-01-15 22:22:36 +01:00
parent 022d20356c
commit 72c214a189
2 changed files with 19 additions and 3 deletions

View File

@@ -1,7 +1,10 @@
"use client"; "use client";
import { useAudioStore } from "_store/audioStore";
import { RoomEvent } from "livekit-client";
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
export const useSounds = () => { export const useSounds = () => {
const { room } = useAudioStore((state) => state);
const longBtnPressSoundRef = useRef<HTMLAudioElement>(null); const longBtnPressSoundRef = useRef<HTMLAudioElement>(null);
const statusSentSoundRef = useRef<HTMLAudioElement>(null); const statusSentSoundRef = useRef<HTMLAudioElement>(null);
const sdsReceivedSoundRef = useRef<HTMLAudioElement>(null); const sdsReceivedSoundRef = useRef<HTMLAudioElement>(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 { return {
longBtnPressSoundRef, longBtnPressSoundRef,
statusSentSoundRef, statusSentSoundRef,

View File

@@ -25,8 +25,6 @@ import { ROOMS } from "_data/livekitRooms";
let interval: NodeJS.Timeout; let interval: NodeJS.Timeout;
const connectedSound = new Audio("/sounds/403.wav");
type TalkState = { type TalkState = {
addSpeakingParticipant: (participant: Participant) => void; addSpeakingParticipant: (participant: Participant) => void;
connect: (room: (typeof ROOMS)[number] | undefined, role: string) => void; connect: (room: (typeof ROOMS)[number] | undefined, role: string) => void;
@@ -190,6 +188,7 @@ export const useAudioStore = create<TalkState>((set, get) => ({
if (!token) throw new Error("Fehlende Berechtigung"); if (!token) throw new Error("Fehlende Berechtigung");
const room = new Room({}); const room = new Room({});
await room.prepareConnection(url, token); await room.prepareConnection(url, token);
const roomConnectedSound = new Audio("/sounds/403.wav");
room room
// Connection events // Connection events
.on(RoomEvent.Connected, async () => { .on(RoomEvent.Connected, async () => {
@@ -219,7 +218,7 @@ export const useAudioStore = create<TalkState>((set, get) => ({
source: Track.Source.Microphone, source: Track.Source.Microphone,
}); });
await publishedTrack.mute(); await publishedTrack.mute();
connectedSound.play().catch((e) => console.error("Fehler beim Abspielen des Sounds", e)); roomConnectedSound.play();
set({ localRadioTrack: publishedTrack }); set({ localRadioTrack: publishedTrack });
set({ state: "connected", room, isTalking: false, message: null }); set({ state: "connected", room, isTalking: false, message: null });