fixed force end call
This commit is contained in:
@@ -74,31 +74,6 @@ export const handleConnectDispatch =
|
|||||||
io.to("dispatchers").emit("dispatchers-update", connectedDispatcherEntry);
|
io.to("dispatchers").emit("dispatchers-update", connectedDispatcherEntry);
|
||||||
io.to("pilots").emit("dispatchers-update", connectedDispatcherEntry);
|
io.to("pilots").emit("dispatchers-update", connectedDispatcherEntry);
|
||||||
|
|
||||||
socket.on("stop-other-transmition", async ({ ownRole, otherRole }) => {
|
|
||||||
const aircrafts = await prisma.connectedAircraft.findMany({
|
|
||||||
where: {
|
|
||||||
Station: {
|
|
||||||
bosCallsignShort: otherRole,
|
|
||||||
},
|
|
||||||
logoutTime: null,
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
Station: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const dispatchers = await prisma.connectedDispatcher.findMany({
|
|
||||||
where: {
|
|
||||||
zone: otherRole,
|
|
||||||
logoutTime: null,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
[...aircrafts, ...dispatchers].forEach((entry) => {
|
|
||||||
io.to(`user:${entry.userId}`).emit("force-end-transmission", {
|
|
||||||
by: ownRole,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on("disconnect", async () => {
|
socket.on("disconnect", async () => {
|
||||||
await prisma.connectedDispatcher.update({
|
await prisma.connectedDispatcher.update({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -45,10 +45,9 @@ export const Audio = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { selectedStation, status: pilotState } = usePilotConnectionStore((state) => state);
|
const { selectedStation, status: pilotState } = usePilotConnectionStore((state) => state);
|
||||||
|
|
||||||
const { selectedZone, status: dispatcherState } = useDispatchConnectionStore((state) => state);
|
const { selectedZone, status: dispatcherState } = useDispatchConnectionStore((state) => state);
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
|
const [isReceivingBlick, setIsReceivingBlick] = useState(false);
|
||||||
const [recentSpeakers, setRecentSpeakers] = useState<typeof speakingParticipants>([]);
|
const [recentSpeakers, setRecentSpeakers] = useState<typeof speakingParticipants>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -63,6 +62,20 @@ export const Audio = () => {
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [speakingParticipants]);
|
}, [speakingParticipants]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (speakingParticipants.length > 0) {
|
||||||
|
setIsReceivingBlick(true);
|
||||||
|
|
||||||
|
const timeout = setInterval(() => {
|
||||||
|
setIsReceivingBlick((s) => !s);
|
||||||
|
}, 1000);
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
setIsReceivingBlick(false);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, [setIsReceivingBlick, speakingParticipants]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (message && state !== "error") {
|
if (message && state !== "error") {
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
@@ -93,39 +106,37 @@ export const Audio = () => {
|
|||||||
className={cn("btn btn-sm btn-ghost border-warning bg-transparent ")}
|
className={cn("btn btn-sm btn-ghost border-warning bg-transparent ")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
removeMessage();
|
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}
|
{message}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{(displayedSpeakers.length || message) && (
|
{displayedSpeakers.length > 0 && (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"tooltip-left tooltip-error font-semibold",
|
"tooltip-left tooltip-error font-semibold",
|
||||||
canStopOtherSpeakers && "tooltip",
|
canStopOtherSpeakers && speakingParticipants.length > 0 && "tooltip",
|
||||||
)}
|
)}
|
||||||
data-tip="Funkspruch unterbrechen"
|
data-tip="Funkspruch unterbrechen"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className={cn(
|
className={cn(
|
||||||
"btn btn-sm btn-soft border-none bg-transparent",
|
"btn btn-sm btn-soft bg-transparent border",
|
||||||
canStopOtherSpeakers && "hover:bg-error",
|
canStopOtherSpeakers && speakingParticipants.length > 0 && "hover:bg-error",
|
||||||
|
speakingParticipants.length > 0 && " hover:bg-errorborder",
|
||||||
|
isReceivingBlick && "border-warning",
|
||||||
)}
|
)}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!canStopOtherSpeakers) return;
|
if (!canStopOtherSpeakers) return;
|
||||||
speakingParticipants.forEach((p) => {
|
const payload = JSON.stringify({
|
||||||
dispatchSocket.emit("stop-other-transmition", {
|
by: role,
|
||||||
ownRole: role,
|
});
|
||||||
otherRole: p.attributes.role,
|
speakingParticipants.forEach(async (p) => {
|
||||||
|
await room?.localParticipant.performRpc({
|
||||||
|
destinationIdentity: p.identity,
|
||||||
|
method: "force-mute",
|
||||||
|
payload,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useDebounce } from "_helpers/useDebounce";
|
import { useDebounce } from "_helpers/useDebounce";
|
||||||
|
import { useAudioStore } from "_store/audioStore";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
export const useSounds = ({
|
export const useSounds = ({
|
||||||
@@ -11,6 +12,7 @@ export const useSounds = ({
|
|||||||
isTransmitting: boolean;
|
isTransmitting: boolean;
|
||||||
unpausedTracks: unknown[];
|
unpausedTracks: unknown[];
|
||||||
}) => {
|
}) => {
|
||||||
|
const { room } = useAudioStore();
|
||||||
// Sounds as refs
|
// Sounds as refs
|
||||||
const connectionStart = useRef<HTMLAudioElement | null>(null);
|
const connectionStart = useRef<HTMLAudioElement | null>(null);
|
||||||
const connectionEnd = useRef<HTMLAudioElement | null>(null);
|
const connectionEnd = useRef<HTMLAudioElement | null>(null);
|
||||||
@@ -70,10 +72,10 @@ export const useSounds = ({
|
|||||||
}
|
}
|
||||||
}, [isReceiving]);
|
}, [isReceiving]);
|
||||||
|
|
||||||
// Hotmic warning after 30 seconds
|
// Hotmic warning after 25 seconds
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isTransmitting) {
|
if (isTransmitting) {
|
||||||
const timeout = setTimeout(() => {
|
const soundsTimeout = setTimeout(() => {
|
||||||
if (isTransmitting) {
|
if (isTransmitting) {
|
||||||
callToLong.current!.loop = true;
|
callToLong.current!.loop = true;
|
||||||
callToLong.current!.currentTime = 0;
|
callToLong.current!.currentTime = 0;
|
||||||
@@ -81,8 +83,19 @@ export const useSounds = ({
|
|||||||
callToLong.current!.play();
|
callToLong.current!.play();
|
||||||
}
|
}
|
||||||
}, 25000);
|
}, 25000);
|
||||||
|
const forceEndTransmitionTimeout = setTimeout(() => {
|
||||||
|
if (isTransmitting) {
|
||||||
|
room?.localParticipant.setMicrophoneEnabled(false);
|
||||||
|
useAudioStore.setState({
|
||||||
|
isTalking: false,
|
||||||
|
message: "Hotmic erkannt! Ruf wurde beendet.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 25000 + 10000);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
clearTimeout(timeout);
|
clearTimeout(soundsTimeout);
|
||||||
|
clearTimeout(forceEndTransmitionTimeout);
|
||||||
callToLong.current!.pause();
|
callToLong.current!.pause();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
handleTrackSubscribed,
|
handleTrackSubscribed,
|
||||||
handleTrackUnsubscribed,
|
handleTrackUnsubscribed,
|
||||||
} from "_helpers/liveKitEventHandler";
|
} from "_helpers/liveKitEventHandler";
|
||||||
import { ConnectionQuality, Participant, Room, RoomEvent } from "livekit-client";
|
import { ConnectionQuality, Participant, Room, RoomEvent, RpcInvocationData } from "livekit-client";
|
||||||
import { pilotSocket } from "pilot/socket";
|
import { pilotSocket } from "pilot/socket";
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
@@ -129,11 +129,22 @@ export const useAudioStore = create<TalkState>((set, get) => ({
|
|||||||
.on(RoomEvent.TrackUnsubscribed, handleTrackUnsubscribed)
|
.on(RoomEvent.TrackUnsubscribed, handleTrackUnsubscribed)
|
||||||
.on(RoomEvent.LocalTrackUnpublished, handleLocalTrackUnpublished);
|
.on(RoomEvent.LocalTrackUnpublished, handleLocalTrackUnpublished);
|
||||||
await room.connect(url, token, {});
|
await room.connect(url, token, {});
|
||||||
|
|
||||||
room.localParticipant.setAttributes({
|
room.localParticipant.setAttributes({
|
||||||
role,
|
role,
|
||||||
});
|
});
|
||||||
set({ room });
|
set({ room });
|
||||||
|
|
||||||
|
room.registerRpcMethod("force-mute", async (data: RpcInvocationData) => {
|
||||||
|
const { by } = JSON.parse(data.payload);
|
||||||
|
room.localParticipant.setMicrophoneEnabled(false);
|
||||||
|
useAudioStore.setState({
|
||||||
|
isTalking: false,
|
||||||
|
message: `Ruf beendet durch ${by || "eine unsichtbare Macht"}`,
|
||||||
|
});
|
||||||
|
return `Hello, ${data.callerIdentity}!`;
|
||||||
|
});
|
||||||
|
|
||||||
interval = setInterval(() => {
|
interval = setInterval(() => {
|
||||||
set({
|
set({
|
||||||
remoteParticipants: room.numParticipants === 0 ? 0 : room.numParticipants - 1, // Unreliable and delayed
|
remoteParticipants: room.numParticipants === 0 ? 0 : room.numParticipants - 1, // Unreliable and delayed
|
||||||
@@ -174,19 +185,5 @@ const handlePTT = (data: PTTData) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleForceEndTransmission = ({ by }: { by?: string }) => {
|
|
||||||
const { room } = useAudioStore.getState();
|
|
||||||
|
|
||||||
if (!room) return;
|
|
||||||
room.localParticipant.setMicrophoneEnabled(false);
|
|
||||||
useAudioStore.setState({
|
|
||||||
isTalking: false,
|
|
||||||
message: `Ruf beendet durch ${by || "unknown"}`,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
pilotSocket.on("ptt", handlePTT);
|
pilotSocket.on("ptt", handlePTT);
|
||||||
dispatchSocket.on("ptt", handlePTT);
|
dispatchSocket.on("ptt", handlePTT);
|
||||||
|
|
||||||
pilotSocket.on("force-end-transmission", handleForceEndTransmission);
|
|
||||||
dispatchSocket.on("force-end-transmission", handleForceEndTransmission);
|
|
||||||
|
|||||||
@@ -25,10 +25,8 @@ export const GET = async (request: NextRequest) => {
|
|||||||
if (!user || !user.permissions.includes("AUDIO"))
|
if (!user || !user.permissions.includes("AUDIO"))
|
||||||
return Response.json({ message: "Missing permissions" }, { status: 401 });
|
return Response.json({ message: "Missing permissions" }, { status: 401 });
|
||||||
|
|
||||||
const participantName = user.publicId;
|
|
||||||
|
|
||||||
const at = new AccessToken(process.env.LIVEKIT_API_KEY, process.env.LIVEKIT_API_SECRET, {
|
const at = new AccessToken(process.env.LIVEKIT_API_KEY, process.env.LIVEKIT_API_SECRET, {
|
||||||
identity: participantName,
|
identity: user.publicId,
|
||||||
// Token to expire after 10 minutes
|
// Token to expire after 10 minutes
|
||||||
ttl: "1d",
|
ttl: "1d",
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user