enhanced overall Chat experience
This commit is contained in:
@@ -46,7 +46,7 @@ export const useAudioStore = create<TalkState>((set, get) => ({
|
||||
micDeviceId: null,
|
||||
speakingParticipants: [],
|
||||
micVolume: 1,
|
||||
state: "disconnected",
|
||||
state: "disconnected" as const,
|
||||
remoteParticipants: 0,
|
||||
connectionQuality: ConnectionQuality.Unknown,
|
||||
room: null,
|
||||
@@ -77,16 +77,23 @@ export const useAudioStore = create<TalkState>((set, get) => ({
|
||||
set({ micDeviceId, micVolume });
|
||||
},
|
||||
toggleTalking: () => {
|
||||
const { room, isTalking, micDeviceId, micVolume, speakingParticipants } = get();
|
||||
const { room, isTalking, micDeviceId, micVolume, speakingParticipants, transmitBlocked } =
|
||||
get();
|
||||
if (!room) return;
|
||||
|
||||
if (speakingParticipants.length > 0 && !isTalking) {
|
||||
if (speakingParticipants.length > 0 && !isTalking && !transmitBlocked) {
|
||||
// Wenn andere sprechen, nicht reden
|
||||
set({
|
||||
message: "Rufgruppe besetzt",
|
||||
transmitBlocked: true,
|
||||
});
|
||||
return;
|
||||
} else if (!isTalking && transmitBlocked) {
|
||||
set({
|
||||
message: null,
|
||||
transmitBlocked: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Todo: use micVolume
|
||||
room.localParticipant.setMicrophoneEnabled(!isTalking, {
|
||||
|
||||
@@ -30,21 +30,30 @@ export const useLeftMenuStore = create<ChatStore>((set, get) => ({
|
||||
chatOpen: false,
|
||||
selectedChat: null,
|
||||
setChatOpen: (open: boolean) => set({ chatOpen: open }),
|
||||
setSelectedChat: (chatId: string | null) => set({ selectedChat: chatId }),
|
||||
setSelectedChat: (chatId: string | null) => {
|
||||
const { setChatNotification } = get();
|
||||
set({ selectedChat: chatId });
|
||||
if (chatId) {
|
||||
setChatNotification(chatId, false); // Set notification to false when chat is selected
|
||||
}
|
||||
},
|
||||
setOwnId: (id: string) => set({ ownId: id }),
|
||||
chats: {},
|
||||
sendMessage: (userId: string, message: string) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(dispatchSocket.connected){
|
||||
|
||||
dispatchSocket.emit("send-message", { userId, message }, ({ error }: { error?: string }) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
} else if(pilotSocket.connected){
|
||||
if (dispatchSocket.connected) {
|
||||
dispatchSocket.emit(
|
||||
"send-message",
|
||||
{ userId, message },
|
||||
({ error }: { error?: string }) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
);
|
||||
} else if (pilotSocket.connected) {
|
||||
pilotSocket.emit("send-message", { userId, message }, ({ error }: { error?: string }) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
@@ -66,7 +75,6 @@ export const useLeftMenuStore = create<ChatStore>((set, get) => ({
|
||||
setChatNotification: (userId, notification) => {
|
||||
const chat = get().chats[userId];
|
||||
if (!chat) return;
|
||||
console.log("setChatNotification", userId, notification);
|
||||
set((state) => {
|
||||
return {
|
||||
chats: {
|
||||
@@ -95,7 +103,7 @@ export const useLeftMenuStore = create<ChatStore>((set, get) => ({
|
||||
[userId]: {
|
||||
...user,
|
||||
name: isSender ? message.receiverName : message.senderName,
|
||||
notification: !isSender && (state.selectedChat !== userId || !state.chatOpen),
|
||||
notification: state.selectedChat !== userId || !state.chatOpen,
|
||||
messages: [...user.messages, message], // Neuen Zustand erzeugen
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user