fixes #117
This commit is contained in:
@@ -25,28 +25,29 @@ import { usePilotConnectionStore } from "_store/pilot/connectionStore";
|
||||
let interval: NodeJS.Timeout;
|
||||
|
||||
type TalkState = {
|
||||
addSpeakingParticipant: (participant: Participant) => void;
|
||||
connect: (roomName: string, role: string) => void;
|
||||
connectionQuality: ConnectionQuality;
|
||||
disconnect: () => void;
|
||||
isTalking: boolean;
|
||||
localRadioTrack: LocalTrackPublication | undefined;
|
||||
message: string | null;
|
||||
removeMessage: () => void;
|
||||
removeSpeakingParticipant: (speakingParticipants: Participant) => void;
|
||||
remoteParticipants: number;
|
||||
resetSpeakingParticipants: (source: string) => void;
|
||||
room: Room | null;
|
||||
setSettings: (settings: Partial<TalkState["settings"]>) => void;
|
||||
settings: {
|
||||
micDeviceId: string | null;
|
||||
micVolume: number;
|
||||
radioVolume: number;
|
||||
dmeVolume: number;
|
||||
};
|
||||
isTalking: boolean;
|
||||
transmitBlocked: boolean;
|
||||
removeMessage: () => void;
|
||||
state: "connecting" | "connected" | "disconnected" | "error";
|
||||
message: string | null;
|
||||
connectionQuality: ConnectionQuality;
|
||||
remoteParticipants: number;
|
||||
toggleTalking: () => void;
|
||||
setSettings: (settings: Partial<TalkState["settings"]>) => void;
|
||||
connect: (roomName: string, role: string) => void;
|
||||
disconnect: () => void;
|
||||
speakingParticipants: Participant[];
|
||||
addSpeakingParticipant: (participant: Participant) => void;
|
||||
removeSpeakingParticipant: (speakingParticipants: Participant) => void;
|
||||
room: Room | null;
|
||||
localRadioTrack: LocalTrackPublication | undefined;
|
||||
state: "connecting" | "connected" | "disconnected" | "error";
|
||||
toggleTalking: () => void;
|
||||
transmitBlocked: boolean;
|
||||
};
|
||||
const getToken = async (roomName: string) => {
|
||||
const response = await axios.get(`/api/livekit-token?roomName=${roomName}`);
|
||||
@@ -71,6 +72,15 @@ export const useAudioStore = create<TalkState>((set, get) => ({
|
||||
remoteParticipants: 0,
|
||||
connectionQuality: ConnectionQuality.Unknown,
|
||||
room: null,
|
||||
resetSpeakingParticipants: (source: string) => {
|
||||
set({
|
||||
speakingParticipants: [],
|
||||
isTalking: false,
|
||||
transmitBlocked: false,
|
||||
message: `Ruf beendet durch ${source || "eine unsichtbare Macht"}`,
|
||||
});
|
||||
get().room?.localParticipant.setMicrophoneEnabled(false);
|
||||
},
|
||||
addSpeakingParticipant: (participant) => {
|
||||
set((state) => {
|
||||
if (!state.speakingParticipants.some((p) => p.identity === participant.identity)) {
|
||||
@@ -201,10 +211,15 @@ export const useAudioStore = create<TalkState>((set, get) => ({
|
||||
|
||||
set({ localRadioTrack: publishedTrack });
|
||||
|
||||
set({ state: "connected", room, message: null });
|
||||
set({ state: "connected", room, isTalking: false, message: null });
|
||||
})
|
||||
.on(RoomEvent.Disconnected, () => {
|
||||
set({ state: "disconnected", speakingParticipants: [], transmitBlocked: false });
|
||||
set({
|
||||
state: "disconnected",
|
||||
speakingParticipants: [],
|
||||
transmitBlocked: false,
|
||||
isTalking: false,
|
||||
});
|
||||
|
||||
handleDisconnect();
|
||||
})
|
||||
@@ -223,17 +238,22 @@ export const useAudioStore = create<TalkState>((set, get) => ({
|
||||
|
||||
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}!`;
|
||||
get().resetSpeakingParticipants(by);
|
||||
return "OK";
|
||||
});
|
||||
|
||||
interval = setInterval(() => {
|
||||
// Filter forgotten participants
|
||||
const oldSpeakingParticipants = get().speakingParticipants;
|
||||
const speakingParticipants = oldSpeakingParticipants.filter((oP) => {
|
||||
return Array.from(room.remoteParticipants.values()).find(
|
||||
(p) => p.identity === oP.identity,
|
||||
);
|
||||
});
|
||||
|
||||
set({
|
||||
remoteParticipants: room.numParticipants === 0 ? 0 : room.numParticipants - 1, // Unreliable and delayed
|
||||
speakingParticipants,
|
||||
});
|
||||
}, 500);
|
||||
} catch (error: Error | unknown) {
|
||||
|
||||
Reference in New Issue
Block a user