added last talking info to Audio Pannel

This commit is contained in:
PxlLoewe
2025-05-21 15:20:04 -07:00
parent c2799fbb49
commit f22335b1bf
6 changed files with 82 additions and 16 deletions

View File

@@ -39,9 +39,12 @@ export const Audio = () => {
useEffect(() => {
setShowSource(true);
setTimeout(() => {
const timeout = setTimeout(() => {
setShowSource(false);
}, 2000);
}, 6000);
return () => {
clearTimeout(timeout);
};
}, [source, isTalking]);
useEffect(() => {
const joinRoom = async () => {
@@ -65,7 +68,7 @@ export const Audio = () => {
<div className="h-4 flex items-center">{message}</div>
)}
{showSource && source && (
<div className="h-4 flex items-center">{source}</div>
<div className="h-4 flex items-center ml-2">{source}</div>
)}
<button
onClick={() => {

View File

@@ -1,3 +1,6 @@
import { PublicUser } from "@repo/db";
import { usePilotConnectionStore } from "_store/pilot/connectionStore";
import { channel } from "diagnostics_channel";
import { dispatchSocket } from "dispatch/socket";
import { serverApi } from "helpers/axios";
import {
@@ -44,6 +47,20 @@ export const useAudioStore = create<TalkState>((set, get) => ({
const { room, isTalking } = get();
if (!room) return;
room.localParticipant.setMicrophoneEnabled(!isTalking);
if (!isTalking) {
// If old status was not talking, we need to emit the PTT event
if (pilotSocket.connected) {
pilotSocket.emit("ptt", {
shouldTransmit: true,
channel: room.name,
});
}
if (dispatchSocket.connected)
dispatchSocket.emit("ptt", {
shouldTransmit: true,
channel: room.name,
});
}
set((state) => ({ isTalking: !state.isTalking, source: "web-app" }));
},
@@ -132,11 +149,17 @@ const handlePTT = (data: PTTData) => {
}
};
const handleOtherPTT = (data: PTTData) => {
const handleOtherPTT = (data: {
publicUser: PublicUser;
channel: string;
source: string;
}) => {
const currentChannel = useAudioStore.getState().room?.name;
console.log("Other PTT", data);
useAudioStore.setState({
source: data.source,
});
if (data.channel === currentChannel)
useAudioStore.setState({
source: data.source,
});
};
pilotSocket.on("ptt", handlePTT);