fix Livekit Audio

This commit is contained in:
PxlLoewe
2025-07-18 18:21:39 -07:00
parent adc11ec647
commit 41a3086d82
2 changed files with 24 additions and 14 deletions

View File

@@ -4,30 +4,38 @@ import {
RemoteParticipant,
RemoteTrack,
RemoteTrackPublication,
Track,
} from "livekit-client";
const initialTrackTimeouts = new Map<string, NodeJS.Timeout>();
export const handleTrackSubscribed = (
track: RemoteTrack,
publication: RemoteTrackPublication,
participant: RemoteParticipant,
) => {
const element = track.attach();
element.pause();
if (!track.isMuted) {
initialTrackTimeouts.set(
participant.sid,
setTimeout(() => {
useAudioStore.getState().addSpeakingParticipant(participant);
}, 1000),
);
setTimeout(() => {
element.play();
}, 1000);
}
track.on("unmuted", () => {
useAudioStore.getState().addSpeakingParticipant(participant);
}
if (track.kind === Track.Kind.Video || track.kind === Track.Kind.Audio) {
// attach it to a new HTMLVideoElement or HTMLAudioElement
const element = track.attach();
element.play();
track.on("unmuted", () => {
useAudioStore.getState().addSpeakingParticipant(participant);
element.volume = useAudioStore.getState().settings.radioVolume;
});
}
element.volume = useAudioStore.getState().settings.radioVolume;
});
track.on("muted", () => {
clearTimeout(initialTrackTimeouts.get(participant.sid));
initialTrackTimeouts.get(participant.sid);
useAudioStore.getState().removeSpeakingParticipant(participant);
});
};