@@ -4,6 +4,8 @@ import "./styles.scss";
44import { Button } from "antd" ;
55import {
66 ApiOutlined ,
7+ AudioMutedOutlined ,
8+ AudioOutlined ,
79 PhoneOutlined ,
810 VideoCameraOutlined ,
911} from "@ant-design/icons" ;
@@ -23,6 +25,7 @@ const VideoPanel = () => {
2325 ) ;
2426 const [ userStream , setUserStream ] = useState < MediaStream | null > ( null ) ;
2527 const [ videoOn , setVideoOn ] = useState < boolean > ( true ) ;
28+ const [ muteOn , setMuteOn ] = useState < boolean > ( false ) ;
2629
2730 const handleCall = ( ) => {
2831 navigator . mediaDevices
@@ -52,6 +55,17 @@ const VideoPanel = () => {
5255 if ( sender ) {
5356 sender . replaceTrack ( videoTrack ) ; // Replace the video track in the call
5457 }
58+
59+ const audioTrack = userStream . getAudioTracks ( ) [ 0 ] ;
60+
61+ const sender2 = call . peerConnection . getSenders ( ) . find ( ( s ) => {
62+ if ( s . track ) {
63+ return s . track . kind === "audio" ;
64+ }
65+ } ) ;
66+ if ( sender2 ) {
67+ sender2 . replaceTrack ( audioTrack ) ; // Replace the video track in the call
68+ }
5569 }
5670 }
5771 }
@@ -104,7 +118,6 @@ const VideoPanel = () => {
104118
105119 const toggleVideo = ( ) => {
106120 if ( userStream ) {
107- console . log ( userStream . getVideoTracks ( ) ) ;
108121 const videoTrack = userStream . getVideoTracks ( ) [ 0 ] ;
109122
110123 if ( videoTrack ) {
@@ -134,33 +147,102 @@ const VideoPanel = () => {
134147 }
135148 } ;
136149
150+ const toggleMute = ( ) => {
151+ if ( userStream ) {
152+ console . log ( userStream . getAudioTracks ( ) ) ;
153+ const audioTrack = userStream . getAudioTracks ( ) [ 0 ] ;
154+
155+ if ( audioTrack ) {
156+ if ( muteOn ) {
157+ // Unmute the audio track
158+ audioTrack . enabled = true ;
159+ setMuteOn ( false ) ;
160+ } else {
161+ // Mute the audio track
162+ audioTrack . enabled = false ;
163+ setMuteOn ( true ) ;
164+
165+ if ( callInstance ) {
166+ const sender = callInstance . peerConnection
167+ . getSenders ( )
168+ . find ( ( s ) => {
169+ if ( s . track ) {
170+ return s . track . kind === "audio" ;
171+ }
172+ } ) ;
173+ if ( sender ) {
174+ sender . replaceTrack ( audioTrack ) ; // Replace the video track in the call
175+ }
176+ }
177+ }
178+ }
179+ }
180+ } ;
181+
137182 return (
138183 < div className = "video-panel" >
139- < p className = "header-tag" > Video Feed for: { currentUsername } </ p >
184+ { /* <p className="header-tag">Video Feed for: {currentUsername}</p> */ }
140185 < video
141186 className = "user-video"
142187 playsInline
143188 ref = { currentUserVideoRef }
144189 autoPlay
145- muted
146190 />
147- < Button
148- onClick = { toggleVideo }
149- icon = { < VideoCameraOutlined /> }
150- type = { videoOn ? "default" : "primary" }
151- >
152- { videoOn ? "Off Webcam" : "On Webcam" }
153- </ Button >
154- < Button onClick = { handleCall } icon = { < ApiOutlined /> } type = "primary" >
155- Initiate Call
156- </ Button >
157- < p className = "header-tag" > Video Feed for: { matchedUsername } </ p >
191+ < div className = "buttons-container" >
192+ < Button
193+ onClick = { toggleVideo }
194+ icon = {
195+ videoOn ? (
196+ < div className = "icon-padding" >
197+ < svg
198+ xmlns = "http://www.w3.org/2000/svg"
199+ width = "1.2em"
200+ height = "1.2em"
201+ viewBox = "0 0 32 32"
202+ >
203+ < path
204+ fill = "currentColor"
205+ d = "M21 26H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h17a2 2 0 0 1 2 2v4.06l5.42-3.87A1 1 0 0 1 30 9v14a1 1 0 0 1-1.58.81L23 19.94V24a2 2 0 0 1-2 2M4 8v16h17v-6a1 1 0 0 1 1.58-.81L28 21.06V10.94l-5.42 3.87A1 1 0 0 1 21 14V8Z"
206+ > </ path >
207+ </ svg >
208+ </ div >
209+ ) : (
210+ < div className = "icon-padding" >
211+ < svg
212+ xmlns = "http://www.w3.org/2000/svg"
213+ width = "1.2em"
214+ height = "1.2em"
215+ viewBox = "0 0 32 32"
216+ >
217+ < path
218+ fill = "currentColor"
219+ d = "M29.46 8.11a1 1 0 0 0-1 .08L23 12.06v-1.62l7-7L28.56 2L2 28.56L3.44 30l4-4H21a2 2 0 0 0 2-2v-4.06l5.42 3.87A1 1 0 0 0 30 23V9a1 1 0 0 0-.54-.89M28 21.06l-5.42-3.87A1 1 0 0 0 21 18v6H9.44L21 12.44V14a1 1 0 0 0 1.58.81L28 10.94zM4 24V8h16V6H4a2 2 0 0 0-2 2v16z"
220+ > </ path >
221+ </ svg >
222+ </ div >
223+ )
224+ }
225+ type = { videoOn ? "default" : "primary" }
226+ >
227+ { videoOn ? "Off Cam" : "On Cam" }
228+ </ Button >
229+ < Button
230+ onClick = { toggleMute }
231+ type = { ! muteOn ? "default" : "primary" }
232+ icon = { muteOn ? < AudioMutedOutlined /> : < AudioOutlined /> }
233+ >
234+ { muteOn ? "On Mic" : "Off Mic" }
235+ </ Button >
236+ < Button onClick = { handleCall } icon = { < ApiOutlined /> } type = "primary" >
237+ Call
238+ </ Button >
239+ </ div >
240+ { /* <p className="header-tag">Video Feed for: {matchedUsername}</p> */ }
158241 < video
159242 className = "matched-user-video"
160243 playsInline
161244 ref = { remoteVideoRef }
162245 autoPlay
163- muted
164246 />
165247 </ div >
166248 ) ;
0 commit comments