From 11754f060ef9ed3456ce6a10a79ec584fcf0365d Mon Sep 17 00:00:00 2001 From: pb-coding Date: Thu, 19 Oct 2023 09:36:20 +0200 Subject: [PATCH] adds mic mute button --- src/App.tsx | 2 ++ src/components/SessionManager.tsx | 9 +-------- src/components/TopFixedChips.tsx | 24 ++++++++++++++++++++++++ src/components/VoiceChat.tsx | 23 ++++++++++++++++++----- src/global/Button.tsx | 2 +- src/global/RoundChip.tsx | 17 +++++++++++++++++ src/global/icons/HeadsetIcon.tsx | 19 +++++++++++++++++++ tailwind.config.js | 15 +++++++++++++++ 8 files changed, 97 insertions(+), 14 deletions(-) create mode 100644 src/components/TopFixedChips.tsx create mode 100644 src/global/RoundChip.tsx create mode 100644 src/global/icons/HeadsetIcon.tsx diff --git a/src/App.tsx b/src/App.tsx index 845c36b..41e0ff3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,6 +6,7 @@ import { Footer } from "./components/Footer"; import { SessionManager } from "./components/SessionManager"; import { Game } from "./types/gameTypes"; import MessageDisplay from "./components/MessageDisplay"; +import TopFixedChips from "./components/TopFixedChips"; export default function App() { const [isConnected, setIsConnected] = useState(socket.connected); @@ -87,6 +88,7 @@ export default function App() { setSession={setSession} /> )} + ); } diff --git a/src/components/SessionManager.tsx b/src/components/SessionManager.tsx index 94fb82a..2cda9be 100644 --- a/src/components/SessionManager.tsx +++ b/src/components/SessionManager.tsx @@ -3,7 +3,6 @@ import { socket } from "../socket"; import { ConnectedIndicator, DisconnectedIndicator } from "./Indicators"; import Button from "../global/Button"; -import VoiceChat from "./VoiceChat"; type SessionManagerProps = { isConnected: boolean; @@ -49,12 +48,7 @@ export const SessionManager: FC = ({ return (
-
+

Skylo @@ -101,7 +95,6 @@ export const SessionManager: FC = ({ Game Server: {isConnected ? : }

-
diff --git a/src/components/TopFixedChips.tsx b/src/components/TopFixedChips.tsx new file mode 100644 index 0000000..415f658 --- /dev/null +++ b/src/components/TopFixedChips.tsx @@ -0,0 +1,24 @@ +import { FC } from "react"; + +import VoiceChat from "./VoiceChat"; +import RoundChip from "../global/RoundChip"; + +type TopFixedChipsProps = { + session: string; +}; + +const TopFixedChips: FC = ({ session }) => { + const isActiveSession = session !== ""; + + if (!isActiveSession) return null; + + return ( +
+ + + +
+ ); +}; + +export default TopFixedChips; diff --git a/src/components/VoiceChat.tsx b/src/components/VoiceChat.tsx index 830f48d..9a177d1 100644 --- a/src/components/VoiceChat.tsx +++ b/src/components/VoiceChat.tsx @@ -1,6 +1,8 @@ -import { FC, useEffect, useRef } from "react"; +import { FC, useEffect, useRef, useState } from "react"; import { socket } from "../socket"; +import HeadsetIcon from "../global/icons/HeadsetIcon"; + type VoiceChatProps = { session: string; }; @@ -18,6 +20,8 @@ const VoiceChat: FC = ({ session }) => { iceCandidatePoolSize: 10, }; + const [isAudioEnabled, setIsAudioEnabled] = useState(false); + // const localAudioRef = useRef(null); const remoteAudioRef = useRef(null); @@ -135,13 +139,22 @@ const VoiceChat: FC = ({ session }) => { console.log("Offer created"); }; + const disableAudio = () => { + pc.current.close(); + console.log("Audio disabled"); + }; + + const toggleAudio = async () => { + isAudioEnabled ? disableAudio() : enableAudio(); + setIsAudioEnabled((previous) => !previous); + }; + return ( -
+
{/**/} - -
); diff --git a/src/global/Button.tsx b/src/global/Button.tsx index dcb2907..be33f99 100644 --- a/src/global/Button.tsx +++ b/src/global/Button.tsx @@ -18,7 +18,7 @@ const Button: FC = ({ variant, children, ...rest }) => { } return (