fixed force end call

This commit is contained in:
PxlLoewe
2025-06-03 23:16:46 -07:00
parent 0eb3ba8104
commit 2da27298bc
5 changed files with 58 additions and 64 deletions

View File

@@ -45,10 +45,9 @@ export const Audio = () => {
});
const { selectedStation, status: pilotState } = usePilotConnectionStore((state) => state);
const { selectedZone, status: dispatcherState } = useDispatchConnectionStore((state) => state);
const session = useSession();
const [isReceivingBlick, setIsReceivingBlick] = useState(false);
const [recentSpeakers, setRecentSpeakers] = useState<typeof speakingParticipants>([]);
useEffect(() => {
@@ -63,6 +62,20 @@ export const Audio = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [speakingParticipants]);
useEffect(() => {
if (speakingParticipants.length > 0) {
setIsReceivingBlick(true);
const timeout = setInterval(() => {
setIsReceivingBlick((s) => !s);
}, 1000);
return () => {
clearTimeout(timeout);
setIsReceivingBlick(false);
};
}
}, [setIsReceivingBlick, speakingParticipants]);
useEffect(() => {
if (message && state !== "error") {
const timeout = setTimeout(() => {
@@ -93,39 +106,37 @@ export const Audio = () => {
className={cn("btn btn-sm btn-ghost border-warning bg-transparent ")}
onClick={() => {
removeMessage();
// Probably via socket event to set ppt = false for participant
if (!canStopOtherSpeakers) return;
speakingParticipants.forEach((p) => {
dispatchSocket.emit("stop-other-transmition", {
ownRole: role,
otherRole: p.attributes.role,
});
});
}}
>
{message}
</button>
</div>
)}
{(displayedSpeakers.length || message) && (
{displayedSpeakers.length > 0 && (
<div
className={cn(
"tooltip-left tooltip-error font-semibold",
canStopOtherSpeakers && "tooltip",
canStopOtherSpeakers && speakingParticipants.length > 0 && "tooltip",
)}
data-tip="Funkspruch unterbrechen"
>
<button
className={cn(
"btn btn-sm btn-soft border-none bg-transparent",
canStopOtherSpeakers && "hover:bg-error",
"btn btn-sm btn-soft bg-transparent border",
canStopOtherSpeakers && speakingParticipants.length > 0 && "hover:bg-error",
speakingParticipants.length > 0 && " hover:bg-errorborder",
isReceivingBlick && "border-warning",
)}
onClick={() => {
if (!canStopOtherSpeakers) return;
speakingParticipants.forEach((p) => {
dispatchSocket.emit("stop-other-transmition", {
ownRole: role,
otherRole: p.attributes.role,
const payload = JSON.stringify({
by: role,
});
speakingParticipants.forEach(async (p) => {
await room?.localParticipant.performRpc({
destinationIdentity: p.identity,
method: "force-mute",
payload,
});
});
}}

View File

@@ -1,5 +1,6 @@
"use client";
import { useDebounce } from "_helpers/useDebounce";
import { useAudioStore } from "_store/audioStore";
import { useEffect, useRef, useState } from "react";
export const useSounds = ({
@@ -11,6 +12,7 @@ export const useSounds = ({
isTransmitting: boolean;
unpausedTracks: unknown[];
}) => {
const { room } = useAudioStore();
// Sounds as refs
const connectionStart = useRef<HTMLAudioElement | null>(null);
const connectionEnd = useRef<HTMLAudioElement | null>(null);
@@ -70,10 +72,10 @@ export const useSounds = ({
}
}, [isReceiving]);
// Hotmic warning after 30 seconds
// Hotmic warning after 25 seconds
useEffect(() => {
if (isTransmitting) {
const timeout = setTimeout(() => {
const soundsTimeout = setTimeout(() => {
if (isTransmitting) {
callToLong.current!.loop = true;
callToLong.current!.currentTime = 0;
@@ -81,8 +83,19 @@ export const useSounds = ({
callToLong.current!.play();
}
}, 25000);
const forceEndTransmitionTimeout = setTimeout(() => {
if (isTransmitting) {
room?.localParticipant.setMicrophoneEnabled(false);
useAudioStore.setState({
isTalking: false,
message: "Hotmic erkannt! Ruf wurde beendet.",
});
}
}, 25000 + 10000);
return () => {
clearTimeout(timeout);
clearTimeout(soundsTimeout);
clearTimeout(forceEndTransmitionTimeout);
callToLong.current!.pause();
};
}