fixed force end call
This commit is contained in:
@@ -5,7 +5,7 @@ import {
|
||||
handleTrackSubscribed,
|
||||
handleTrackUnsubscribed,
|
||||
} 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 { create } from "zustand";
|
||||
import axios from "axios";
|
||||
@@ -129,11 +129,22 @@ export const useAudioStore = create<TalkState>((set, get) => ({
|
||||
.on(RoomEvent.TrackUnsubscribed, handleTrackUnsubscribed)
|
||||
.on(RoomEvent.LocalTrackUnpublished, handleLocalTrackUnpublished);
|
||||
await room.connect(url, token, {});
|
||||
|
||||
room.localParticipant.setAttributes({
|
||||
role,
|
||||
});
|
||||
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(() => {
|
||||
set({
|
||||
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);
|
||||
dispatchSocket.on("ptt", handlePTT);
|
||||
|
||||
pilotSocket.on("force-end-transmission", handleForceEndTransmission);
|
||||
dispatchSocket.on("force-end-transmission", handleForceEndTransmission);
|
||||
|
||||
Reference in New Issue
Block a user