added HPG VEhicles Mission, Audio settings; mission Context menu
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
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 {
|
||||
@@ -17,6 +15,8 @@ import { create } from "zustand";
|
||||
let interval: NodeJS.Timeout;
|
||||
|
||||
type TalkState = {
|
||||
micDeviceId: string | null;
|
||||
micVolume: number;
|
||||
isTalking: boolean;
|
||||
source: string;
|
||||
state: "connecting" | "connected" | "disconnected" | "error";
|
||||
@@ -24,7 +24,7 @@ type TalkState = {
|
||||
connectionQuality: ConnectionQuality;
|
||||
remoteParticipants: number;
|
||||
toggleTalking: () => void;
|
||||
|
||||
setMic: (micDeviceId: string | null, volume: number) => void;
|
||||
connect: (roomName: string) => void;
|
||||
disconnect: () => void;
|
||||
room: Room | null;
|
||||
@@ -38,15 +38,23 @@ const getToken = async (roomName: string) => {
|
||||
export const useAudioStore = create<TalkState>((set, get) => ({
|
||||
isTalking: false,
|
||||
message: null,
|
||||
micDeviceId: null,
|
||||
micVolume: 1,
|
||||
state: "disconnected",
|
||||
source: "",
|
||||
remoteParticipants: 0,
|
||||
connectionQuality: ConnectionQuality.Unknown,
|
||||
room: null,
|
||||
setMic: (micDeviceId, micVolume) => {
|
||||
set({ micDeviceId, micVolume });
|
||||
},
|
||||
toggleTalking: () => {
|
||||
const { room, isTalking } = get();
|
||||
const { room, isTalking, micDeviceId, micVolume } = get();
|
||||
if (!room) return;
|
||||
room.localParticipant.setMicrophoneEnabled(!isTalking);
|
||||
// Todo: use micVolume
|
||||
room.localParticipant.setMicrophoneEnabled(!isTalking, {
|
||||
deviceId: micDeviceId ?? undefined,
|
||||
});
|
||||
|
||||
if (!isTalking) {
|
||||
// If old status was not talking, we need to emit the PTT event
|
||||
@@ -94,23 +102,19 @@ export const useAudioStore = create<TalkState>((set, get) => ({
|
||||
|
||||
handleDisconnect();
|
||||
})
|
||||
.on(RoomEvent.ConnectionQualityChanged, (connectionQuality) =>
|
||||
set({ connectionQuality }),
|
||||
)
|
||||
.on(RoomEvent.ConnectionQualityChanged, (connectionQuality) => set({ connectionQuality }))
|
||||
|
||||
// Track events
|
||||
.on(RoomEvent.TrackSubscribed, handleTrackSubscribed)
|
||||
.on(RoomEvent.TrackUnsubscribed, handleTrackUnsubscribed)
|
||||
.on(RoomEvent.ActiveSpeakersChanged, handleActiveSpeakerChange)
|
||||
.on(RoomEvent.LocalTrackUnpublished, handleLocalTrackUnpublished);
|
||||
await room.connect(url, token);
|
||||
console.log(room);
|
||||
await room.connect(url, token, {});
|
||||
set({ room });
|
||||
|
||||
interval = setInterval(() => {
|
||||
set({
|
||||
remoteParticipants:
|
||||
room.numParticipants === 0 ? 0 : room.numParticipants - 1, // Unreliable and delayed
|
||||
remoteParticipants: room.numParticipants === 0 ? 0 : room.numParticipants - 1, // Unreliable and delayed
|
||||
});
|
||||
}, 500);
|
||||
} catch (error: Error | unknown) {
|
||||
@@ -150,11 +154,7 @@ const handlePTT = (data: PTTData) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleOtherPTT = (data: {
|
||||
publicUser: PublicUser;
|
||||
channel: string;
|
||||
source: string;
|
||||
}) => {
|
||||
const handleOtherPTT = (data: { publicUser: PublicUser; channel: string; source: string }) => {
|
||||
const currentChannel = useAudioStore.getState().room?.name;
|
||||
console.log("Other PTT", data);
|
||||
if (data.channel === currentChannel)
|
||||
|
||||
Reference in New Issue
Block a user